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

@arcteryx/js-cms

Package Overview
Dependencies
Maintainers
6
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 1.27.12 to 1.27.13

tests/i18nOptions.test.js

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

## [1.27.13](https://bitbucket.org/arcteryx/arcteryx-js-helpers/compare/@arcteryx/js-cms@1.27.12...@arcteryx/js-cms@1.27.13) (2020-02-27)
**Note:** Version bump only for package @arcteryx/js-cms
## [1.27.12](https://bitbucket.org/arcteryx/arcteryx-js-helpers/compare/@arcteryx/js-cms@1.27.11...@arcteryx/js-cms@1.27.12) (2020-02-27)

@@ -8,0 +16,0 @@

141

dist/cjs/index.js

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

/*
Function GetDrupalData
Function getDrupalData
Description: Get JSON:API response from Drupal and will flatten the JSON:API response

@@ -142,18 +142,8 @@

function GetDrupalData(_x) {
return _GetDrupalData.apply(this, arguments);
function getDrupalData(_x) {
return _getDrupalData.apply(this, arguments);
}
/*
Function GetSimplePage
Description: Get data for a 'Simple Page' ContentType from Drupal based
@param cmsUrl - Drupal url (e.g. https://cms.arcteryx.com)
@param market - outdoor, urban or leaf
@param country (- Country Code (e.g. ca, us)
@param language - Language code (e.g. "en", "fr", "de", "es", "no", "zh", "jp")
@param path - The String path saved in the path field in Drupal (e.g. /home, /help)
*/
function _GetDrupalData() {
_GetDrupalData = _asyncToGenerator(
function _getDrupalData() {
_getDrupalData = _asyncToGenerator(
/*#__PURE__*/

@@ -190,10 +180,24 @@ regeneratorRuntime.mark(function _callee(fetchUrl) {

}));
return _GetDrupalData.apply(this, arguments);
return _getDrupalData.apply(this, arguments);
}
function GetSimplePage(_x2, _x3, _x4, _x5, _x6) {
return _GetSimplePage.apply(this, arguments);
function GetDrupalData(fetchUrl) {
return getDrupalData(fetchUrl);
}
/*
Function GetBasicBlock
Function getSimplePage
Description: Get data for a 'Simple Page' ContentType from Drupal based
@param cmsUrl - Drupal url (e.g. https://cms.arcteryx.com)
@param market - outdoor, urban or leaf
@param country (- Country Code (e.g. ca, us)
@param language - Language code (e.g. "en", "fr", "de", "es", "no", "zh", "jp")
@param path - The String path saved in the path field in Drupal (e.g. /home, /help)
*/
function getSimplePage(_x2, _x3, _x4, _x5, _x6) {
return _getSimplePage.apply(this, arguments);
}
/*
Function getBasicBlock
Description: Get data for a 'Basic Block' ContentType from Drupal based

@@ -206,4 +210,4 @@

function _GetSimplePage() {
_GetSimplePage = _asyncToGenerator(
function _getSimplePage() {
_getSimplePage = _asyncToGenerator(
/*#__PURE__*/

@@ -230,10 +234,10 @@ regeneratorRuntime.mark(function _callee2(cmsUrl, market, country, language, path) {

}));
return _GetSimplePage.apply(this, arguments);
return _getSimplePage.apply(this, arguments);
}
function GetBasicBlock(_x7, _x8, _x9) {
return _GetBasicBlock.apply(this, arguments);
function getBasicBlock(_x7, _x8, _x9) {
return _getBasicBlock.apply(this, arguments);
}
/*
Function GetReusableData
Function getReusableData
Description: Get data for a 'Resuable Strings' ContentType from Drupal based

@@ -246,4 +250,4 @@

function _GetBasicBlock() {
_GetBasicBlock = _asyncToGenerator(
function _getBasicBlock() {
_getBasicBlock = _asyncToGenerator(
/*#__PURE__*/

@@ -270,10 +274,10 @@ regeneratorRuntime.mark(function _callee3(cmsUrl, title, language) {

}));
return _GetBasicBlock.apply(this, arguments);
return _getBasicBlock.apply(this, arguments);
}
function GetReusableData(_x10, _x11, _x12) {
return _GetReusableData.apply(this, arguments);
function getReusableData(_x10, _x11, _x12) {
return _getReusableData.apply(this, arguments);
}
/*
Function GetReusableText
Functiong getReusableText
Description: Returns requested text value (field_reusable_string_text) if exists in the reusable_string object from Drupal

@@ -289,4 +293,4 @@

function _GetReusableData() {
_GetReusableData = _asyncToGenerator(
function _getReusableData() {
_getReusableData = _asyncToGenerator(
/*#__PURE__*/

@@ -313,6 +317,6 @@ regeneratorRuntime.mark(function _callee4(cmsUrl, stringsArray, language) {

}));
return _GetReusableData.apply(this, arguments);
return _getReusableData.apply(this, arguments);
}
function GetReusableText(titleKey, resuableStrings) {
function getReusableText(titleKey, resuableStrings) {
if (typeof resuableStrings !== "undefined") {

@@ -328,3 +332,58 @@ for (var i = 0; i < resuableStrings.length; i++) {

}
/*
Function parseDrupalJsonForI18n
Description: This function parses the JSON data respnonse from Drupal's jsonapi for resuable_strings node and converts it into
the format for the i18next translation library
@param data - the data object from Drupal jsoonapi response
Example; [
{ title: "Hello World", field_reusable_string_text: "Hello World" },
{ title: "Test", field_reusable_string_text: "This a test" }
]
*/
var parseDrupalJsonForI18n = function parseDrupalJsonForI18n(data) {
var json = JSON.parse(data);
var flattenJson = json.data.map(function (label) {
return flattenCMSJson(label, json.included);
});
var t = {};
flattenJson.forEach(function (item) {
t[item.title] = item.field_reusable_string_text;
});
return t;
};
var i18nPath = function i18nPath(cmsUrl, language, translationKeys) {
return "".concat(cmsUrl, "/").concat(language, "/jsonapi/node/reusable_string/?").concat(queryOptionsForReusableString(translationKeys));
};
/*
Function i18nOptions
Description: Returns a basic initialization configuration for i18next
@param cmsUrl - Drupal url (e.g. https://cms.arcteryx.com or //cms.arcteryx.com)
@param stringsArray - Array of Strings that represents the title key in Drupal (e.g. ["New", "Revised", "Pro Exlusive"])
@param language - Language code (e.g. "en", "fr", "de", "es", "no", "zh", "jp")
*/
var i18nOptions = function i18nOptions(cmsUrl, language, translationKeys) {
return {
lng: language,
fallbackLng: "en",
// use en if detected lng is not available
// debug: true,
interpolation: {
escapeValue: false
},
react: {
wait: true
},
backend: {
loadPath: i18nPath(cmsUrl, language, translationKeys),
parse: function parse(data) {
return parseDrupalJsonForI18n(data);
}
}
};
};
exports.flattenCMSJson = flattenCMSJson;

@@ -334,7 +393,11 @@ exports.queryOptionsForSimplePages = queryOptionsForSimplePages;

exports.queryOptionsForReusableString = queryOptionsForReusableString;
exports.getDrupalData = getDrupalData;
exports.GetDrupalData = GetDrupalData;
exports.GetSimplePage = GetSimplePage;
exports.GetBasicBlock = GetBasicBlock;
exports.GetReusableData = GetReusableData;
exports.GetReusableText = GetReusableText;
exports.getSimplePage = getSimplePage;
exports.getBasicBlock = getBasicBlock;
exports.getReusableData = getReusableData;
exports.getReusableText = getReusableText;
exports.parseDrupalJsonForI18n = parseDrupalJsonForI18n;
exports.i18nPath = i18nPath;
exports.i18nOptions = i18nOptions;
//# sourceMappingURL=index.js.map

@@ -130,3 +130,3 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {

/*
Function GetDrupalData
Function getDrupalData
Description: Get JSON:API response from Drupal and will flatten the JSON:API response

@@ -138,18 +138,8 @@

function GetDrupalData(_x) {
return _GetDrupalData.apply(this, arguments);
function getDrupalData(_x) {
return _getDrupalData.apply(this, arguments);
}
/*
Function GetSimplePage
Description: Get data for a 'Simple Page' ContentType from Drupal based
@param cmsUrl - Drupal url (e.g. https://cms.arcteryx.com)
@param market - outdoor, urban or leaf
@param country (- Country Code (e.g. ca, us)
@param language - Language code (e.g. "en", "fr", "de", "es", "no", "zh", "jp")
@param path - The String path saved in the path field in Drupal (e.g. /home, /help)
*/
function _GetDrupalData() {
_GetDrupalData = _asyncToGenerator(
function _getDrupalData() {
_getDrupalData = _asyncToGenerator(
/*#__PURE__*/

@@ -186,10 +176,24 @@ regeneratorRuntime.mark(function _callee(fetchUrl) {

}));
return _GetDrupalData.apply(this, arguments);
return _getDrupalData.apply(this, arguments);
}
function GetSimplePage(_x2, _x3, _x4, _x5, _x6) {
return _GetSimplePage.apply(this, arguments);
function GetDrupalData(fetchUrl) {
return getDrupalData(fetchUrl);
}
/*
Function GetBasicBlock
Function getSimplePage
Description: Get data for a 'Simple Page' ContentType from Drupal based
@param cmsUrl - Drupal url (e.g. https://cms.arcteryx.com)
@param market - outdoor, urban or leaf
@param country (- Country Code (e.g. ca, us)
@param language - Language code (e.g. "en", "fr", "de", "es", "no", "zh", "jp")
@param path - The String path saved in the path field in Drupal (e.g. /home, /help)
*/
function getSimplePage(_x2, _x3, _x4, _x5, _x6) {
return _getSimplePage.apply(this, arguments);
}
/*
Function getBasicBlock
Description: Get data for a 'Basic Block' ContentType from Drupal based

@@ -202,4 +206,4 @@

function _GetSimplePage() {
_GetSimplePage = _asyncToGenerator(
function _getSimplePage() {
_getSimplePage = _asyncToGenerator(
/*#__PURE__*/

@@ -226,10 +230,10 @@ regeneratorRuntime.mark(function _callee2(cmsUrl, market, country, language, path) {

}));
return _GetSimplePage.apply(this, arguments);
return _getSimplePage.apply(this, arguments);
}
function GetBasicBlock(_x7, _x8, _x9) {
return _GetBasicBlock.apply(this, arguments);
function getBasicBlock(_x7, _x8, _x9) {
return _getBasicBlock.apply(this, arguments);
}
/*
Function GetReusableData
Function getReusableData
Description: Get data for a 'Resuable Strings' ContentType from Drupal based

@@ -242,4 +246,4 @@

function _GetBasicBlock() {
_GetBasicBlock = _asyncToGenerator(
function _getBasicBlock() {
_getBasicBlock = _asyncToGenerator(
/*#__PURE__*/

@@ -266,10 +270,10 @@ regeneratorRuntime.mark(function _callee3(cmsUrl, title, language) {

}));
return _GetBasicBlock.apply(this, arguments);
return _getBasicBlock.apply(this, arguments);
}
function GetReusableData(_x10, _x11, _x12) {
return _GetReusableData.apply(this, arguments);
function getReusableData(_x10, _x11, _x12) {
return _getReusableData.apply(this, arguments);
}
/*
Function GetReusableText
Functiong getReusableText
Description: Returns requested text value (field_reusable_string_text) if exists in the reusable_string object from Drupal

@@ -285,4 +289,4 @@

function _GetReusableData() {
_GetReusableData = _asyncToGenerator(
function _getReusableData() {
_getReusableData = _asyncToGenerator(
/*#__PURE__*/

@@ -309,6 +313,6 @@ regeneratorRuntime.mark(function _callee4(cmsUrl, stringsArray, language) {

}));
return _GetReusableData.apply(this, arguments);
return _getReusableData.apply(this, arguments);
}
function GetReusableText(titleKey, resuableStrings) {
function getReusableText(titleKey, resuableStrings) {
if (typeof resuableStrings !== "undefined") {

@@ -324,4 +328,59 @@ for (var i = 0; i < resuableStrings.length; i++) {

}
/*
Function parseDrupalJsonForI18n
Description: This function parses the JSON data respnonse from Drupal's jsonapi for resuable_strings node and converts it into
the format for the i18next translation library
export { flattenCMSJson, queryOptionsForSimplePages, queryOptionsForBasicBlock, queryOptionsForReusableString, GetDrupalData, GetSimplePage, GetBasicBlock, GetReusableData, GetReusableText };
@param data - the data object from Drupal jsoonapi response
Example; [
{ title: "Hello World", field_reusable_string_text: "Hello World" },
{ title: "Test", field_reusable_string_text: "This a test" }
]
*/
var parseDrupalJsonForI18n = function parseDrupalJsonForI18n(data) {
var json = JSON.parse(data);
var flattenJson = json.data.map(function (label) {
return flattenCMSJson(label, json.included);
});
var t = {};
flattenJson.forEach(function (item) {
t[item.title] = item.field_reusable_string_text;
});
return t;
};
var i18nPath = function i18nPath(cmsUrl, language, translationKeys) {
return "".concat(cmsUrl, "/").concat(language, "/jsonapi/node/reusable_string/?").concat(queryOptionsForReusableString(translationKeys));
};
/*
Function i18nOptions
Description: Returns a basic initialization configuration for i18next
@param cmsUrl - Drupal url (e.g. https://cms.arcteryx.com or //cms.arcteryx.com)
@param stringsArray - Array of Strings that represents the title key in Drupal (e.g. ["New", "Revised", "Pro Exlusive"])
@param language - Language code (e.g. "en", "fr", "de", "es", "no", "zh", "jp")
*/
var i18nOptions = function i18nOptions(cmsUrl, language, translationKeys) {
return {
lng: language,
fallbackLng: "en",
// use en if detected lng is not available
// debug: true,
interpolation: {
escapeValue: false
},
react: {
wait: true
},
backend: {
loadPath: i18nPath(cmsUrl, language, translationKeys),
parse: function parse(data) {
return parseDrupalJsonForI18n(data);
}
}
};
};
export { flattenCMSJson, queryOptionsForSimplePages, queryOptionsForBasicBlock, queryOptionsForReusableString, getDrupalData, GetDrupalData, getSimplePage, getBasicBlock, getReusableData, getReusableText, parseDrupalJsonForI18n, i18nPath, i18nOptions };
//# sourceMappingURL=index.js.map

@@ -136,3 +136,3 @@ (function (global, factory) {

/*
Function GetDrupalData
Function getDrupalData
Description: Get JSON:API response from Drupal and will flatten the JSON:API response

@@ -144,18 +144,8 @@

function GetDrupalData(_x) {
return _GetDrupalData.apply(this, arguments);
function getDrupalData(_x) {
return _getDrupalData.apply(this, arguments);
}
/*
Function GetSimplePage
Description: Get data for a 'Simple Page' ContentType from Drupal based
@param cmsUrl - Drupal url (e.g. https://cms.arcteryx.com)
@param market - outdoor, urban or leaf
@param country (- Country Code (e.g. ca, us)
@param language - Language code (e.g. "en", "fr", "de", "es", "no", "zh", "jp")
@param path - The String path saved in the path field in Drupal (e.g. /home, /help)
*/
function _GetDrupalData() {
_GetDrupalData = _asyncToGenerator(
function _getDrupalData() {
_getDrupalData = _asyncToGenerator(
/*#__PURE__*/

@@ -192,10 +182,24 @@ regeneratorRuntime.mark(function _callee(fetchUrl) {

}));
return _GetDrupalData.apply(this, arguments);
return _getDrupalData.apply(this, arguments);
}
function GetSimplePage(_x2, _x3, _x4, _x5, _x6) {
return _GetSimplePage.apply(this, arguments);
function GetDrupalData(fetchUrl) {
return getDrupalData(fetchUrl);
}
/*
Function GetBasicBlock
Function getSimplePage
Description: Get data for a 'Simple Page' ContentType from Drupal based
@param cmsUrl - Drupal url (e.g. https://cms.arcteryx.com)
@param market - outdoor, urban or leaf
@param country (- Country Code (e.g. ca, us)
@param language - Language code (e.g. "en", "fr", "de", "es", "no", "zh", "jp")
@param path - The String path saved in the path field in Drupal (e.g. /home, /help)
*/
function getSimplePage(_x2, _x3, _x4, _x5, _x6) {
return _getSimplePage.apply(this, arguments);
}
/*
Function getBasicBlock
Description: Get data for a 'Basic Block' ContentType from Drupal based

@@ -208,4 +212,4 @@

function _GetSimplePage() {
_GetSimplePage = _asyncToGenerator(
function _getSimplePage() {
_getSimplePage = _asyncToGenerator(
/*#__PURE__*/

@@ -232,10 +236,10 @@ regeneratorRuntime.mark(function _callee2(cmsUrl, market, country, language, path) {

}));
return _GetSimplePage.apply(this, arguments);
return _getSimplePage.apply(this, arguments);
}
function GetBasicBlock(_x7, _x8, _x9) {
return _GetBasicBlock.apply(this, arguments);
function getBasicBlock(_x7, _x8, _x9) {
return _getBasicBlock.apply(this, arguments);
}
/*
Function GetReusableData
Function getReusableData
Description: Get data for a 'Resuable Strings' ContentType from Drupal based

@@ -248,4 +252,4 @@

function _GetBasicBlock() {
_GetBasicBlock = _asyncToGenerator(
function _getBasicBlock() {
_getBasicBlock = _asyncToGenerator(
/*#__PURE__*/

@@ -272,10 +276,10 @@ regeneratorRuntime.mark(function _callee3(cmsUrl, title, language) {

}));
return _GetBasicBlock.apply(this, arguments);
return _getBasicBlock.apply(this, arguments);
}
function GetReusableData(_x10, _x11, _x12) {
return _GetReusableData.apply(this, arguments);
function getReusableData(_x10, _x11, _x12) {
return _getReusableData.apply(this, arguments);
}
/*
Function GetReusableText
Functiong getReusableText
Description: Returns requested text value (field_reusable_string_text) if exists in the reusable_string object from Drupal

@@ -291,4 +295,4 @@

function _GetReusableData() {
_GetReusableData = _asyncToGenerator(
function _getReusableData() {
_getReusableData = _asyncToGenerator(
/*#__PURE__*/

@@ -315,6 +319,6 @@ regeneratorRuntime.mark(function _callee4(cmsUrl, stringsArray, language) {

}));
return _GetReusableData.apply(this, arguments);
return _getReusableData.apply(this, arguments);
}
function GetReusableText(titleKey, resuableStrings) {
function getReusableText(titleKey, resuableStrings) {
if (typeof resuableStrings !== "undefined") {

@@ -330,3 +334,58 @@ for (var i = 0; i < resuableStrings.length; i++) {

}
/*
Function parseDrupalJsonForI18n
Description: This function parses the JSON data respnonse from Drupal's jsonapi for resuable_strings node and converts it into
the format for the i18next translation library
@param data - the data object from Drupal jsoonapi response
Example; [
{ title: "Hello World", field_reusable_string_text: "Hello World" },
{ title: "Test", field_reusable_string_text: "This a test" }
]
*/
var parseDrupalJsonForI18n = function parseDrupalJsonForI18n(data) {
var json = JSON.parse(data);
var flattenJson = json.data.map(function (label) {
return flattenCMSJson(label, json.included);
});
var t = {};
flattenJson.forEach(function (item) {
t[item.title] = item.field_reusable_string_text;
});
return t;
};
var i18nPath = function i18nPath(cmsUrl, language, translationKeys) {
return "".concat(cmsUrl, "/").concat(language, "/jsonapi/node/reusable_string/?").concat(queryOptionsForReusableString(translationKeys));
};
/*
Function i18nOptions
Description: Returns a basic initialization configuration for i18next
@param cmsUrl - Drupal url (e.g. https://cms.arcteryx.com or //cms.arcteryx.com)
@param stringsArray - Array of Strings that represents the title key in Drupal (e.g. ["New", "Revised", "Pro Exlusive"])
@param language - Language code (e.g. "en", "fr", "de", "es", "no", "zh", "jp")
*/
var i18nOptions = function i18nOptions(cmsUrl, language, translationKeys) {
return {
lng: language,
fallbackLng: "en",
// use en if detected lng is not available
// debug: true,
interpolation: {
escapeValue: false
},
react: {
wait: true
},
backend: {
loadPath: i18nPath(cmsUrl, language, translationKeys),
parse: function parse(data) {
return parseDrupalJsonForI18n(data);
}
}
};
};
exports.flattenCMSJson = flattenCMSJson;

@@ -336,7 +395,11 @@ exports.queryOptionsForSimplePages = queryOptionsForSimplePages;

exports.queryOptionsForReusableString = queryOptionsForReusableString;
exports.getDrupalData = getDrupalData;
exports.GetDrupalData = GetDrupalData;
exports.GetSimplePage = GetSimplePage;
exports.GetBasicBlock = GetBasicBlock;
exports.GetReusableData = GetReusableData;
exports.GetReusableText = GetReusableText;
exports.getSimplePage = getSimplePage;
exports.getBasicBlock = getBasicBlock;
exports.getReusableData = getReusableData;
exports.getReusableText = getReusableText;
exports.parseDrupalJsonForI18n = parseDrupalJsonForI18n;
exports.i18nPath = i18nPath;
exports.i18nOptions = i18nOptions;

@@ -343,0 +406,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

@@ -10,8 +10,8 @@ const base = require("../scripts/jest.config.base.js");

global: {
branches: 90,
functions: 100,
lines: 100,
statements: 100,
branches: 92,
functions: 92,
lines: 95,
statements: 95,
},
},
};
{
"name": "@arcteryx/js-cms",
"version": "1.27.12",
"version": "1.27.13",
"source": "src/index.js",

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

"license": "ISC",
"gitHead": "3318a9a955f4195128768e2842cf42a6d5c880ba"
"gitHead": "0e1a0afe373ffc9b88934154e49aa67e5e76d668"
}
import React, { useState, useEffect } from "react";
import PropTypes from "prop-types";
import { GetBasicBlock } from "../index";
import { getBasicBlock } from "../index";

@@ -10,3 +10,3 @@ function BasicBlock(cmsUrl, title, language) {

const fetchData = async () => {
const result = await GetBasicBlock(cmsUrl, title, language);
const result = await getBasicBlock(cmsUrl, title, language);
setData(result);

@@ -13,0 +13,0 @@ };

@@ -72,3 +72,3 @@ import { toQueryParams } from "@arcteryx/js-url";

/*
Function GetDrupalData
Function getDrupalData
Description: Get JSON:API response from Drupal and will flatten the JSON:API response

@@ -79,3 +79,3 @@

*/
export async function GetDrupalData(fetchUrl) {
export async function getDrupalData(fetchUrl) {
return await fetch(fetchUrl)

@@ -90,5 +90,8 @@ .then(resp => resp.json())

}
export function GetDrupalData(fetchUrl) {
return getDrupalData(fetchUrl);
}
/*
Function GetSimplePage
Function getSimplePage
Description: Get data for a 'Simple Page' ContentType from Drupal based

@@ -102,3 +105,3 @@

*/
export async function GetSimplePage(cmsUrl, market, country, language, path) {
export async function getSimplePage(cmsUrl, market, country, language, path) {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/simple_page/?`;

@@ -109,3 +112,3 @@ return await GetDrupalData(cmsApi + queryOptionsForSimplePages(market, country, path));

/*
Function GetBasicBlock
Function getBasicBlock
Description: Get data for a 'Basic Block' ContentType from Drupal based

@@ -117,3 +120,3 @@

*/
export async function GetBasicBlock(cmsUrl, title, language) {
export async function getBasicBlock(cmsUrl, title, language) {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/basic_block/?`;

@@ -124,3 +127,3 @@ return await GetDrupalData(cmsApi + queryOptionsForBasicBlock(title));

/*
Function GetReusableData
Function getReusableData
Description: Get data for a 'Resuable Strings' ContentType from Drupal based

@@ -132,3 +135,3 @@

*/
export async function GetReusableData(cmsUrl, stringsArray, language) {
export async function getReusableData(cmsUrl, stringsArray, language) {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/reusable_string/?`;

@@ -139,3 +142,3 @@ return await GetDrupalData(cmsApi + queryOptionsForReusableString(stringsArray));

/*
Function GetReusableText
Functiong getReusableText
Description: Returns requested text value (field_reusable_string_text) if exists in the reusable_string object from Drupal

@@ -150,3 +153,3 @@

*/
export function GetReusableText(titleKey, resuableStrings) {
export function getReusableText(titleKey, resuableStrings) {
if (typeof resuableStrings !== "undefined") {

@@ -161,1 +164,51 @@ for (let i = 0; i < resuableStrings.length; i++) {

}
/*
Function parseDrupalJsonForI18n
Description: This function parses the JSON data respnonse from Drupal's jsonapi for resuable_strings node and converts it into
the format for the i18next translation library
@param data - the data object from Drupal jsoonapi response
Example; [
{ title: "Hello World", field_reusable_string_text: "Hello World" },
{ title: "Test", field_reusable_string_text: "This a test" }
]
*/
export const parseDrupalJsonForI18n = data => {
const json = JSON.parse(data);
const flattenJson = json.data.map(label => flattenCMSJson(label, json.included));
const t = {};
flattenJson.forEach(item => {
t[item.title] = item.field_reusable_string_text;
});
return t;
};
export const i18nPath = (cmsUrl, language, translationKeys) =>
`${cmsUrl}/${language}/jsonapi/node/reusable_string/?${queryOptionsForReusableString(translationKeys)}`;
/*
Function i18nOptions
Description: Returns a basic initialization configuration for i18next
@param cmsUrl - Drupal url (e.g. https://cms.arcteryx.com or //cms.arcteryx.com)
@param stringsArray - Array of Strings that represents the title key in Drupal (e.g. ["New", "Revised", "Pro Exlusive"])
@param language - Language code (e.g. "en", "fr", "de", "es", "no", "zh", "jp")
*/
export const i18nOptions = (cmsUrl, language, translationKeys) => ({
lng: language,
fallbackLng: "en", // use en if detected lng is not available
// debug: true,
interpolation: {
escapeValue: false,
},
react: {
wait: true,
},
backend: {
loadPath: i18nPath(cmsUrl, language, translationKeys),
parse(data) {
return parseDrupalJsonForI18n(data);
},
},
});

@@ -43,3 +43,3 @@ import React from "react";

mockBasicBlock.forEach(mockData => {
describe("GetBasicBlock Component", () => {
describe("BasicBlock Component", () => {
beforeEach(() => {

@@ -46,0 +46,0 @@ const mockSuccessResponse = mockData;

@@ -7,2 +7,5 @@ export const mockReusableData = [

export const mockIl18nData =
'{"jsonapi":{"version":"1.0","meta":{"links":{"self":{"href":"http://jsonapi.org/format/1.0/"}}}},"data":[{"type":"node--reusable_string","id":"43d4fab4-5cc5-4b36-8768-0de93ddb31a5","links":{"self":{"href":"http://cms.arcteryx.com/en/jsonapi/node/reusable_string/43d4fab4-5cc5-4b36-8768-0de93ddb31a5?resourceVersion=id%3A20796"}},"attributes":{"title":"My Cart","field_reusable_string_text":"My Cart"}},{"type":"node--reusable_string","id":"e59f61aa-b462-46fc-87b0-f6dadeb07cc5","links":{"self":{"href":"http://cms.arcteryx.com/en/jsonapi/node/reusable_string/e59f61aa-b462-46fc-87b0-f6dadeb07cc5?resourceVersion=id%3A20797"}},"attributes":{"title":"Item","field_reusable_string_text":"Item"}},{"type":"node--reusable_string","id":"7a3125ec-ebf3-4282-ba54-14baee482339","links":{"self":{"href":"http://cms.arcteryx.com/en/jsonapi/node/reusable_string/7a3125ec-ebf3-4282-ba54-14baee482339?resourceVersion=id%3A20798"}},"attributes":{"title":"Quantity","field_reusable_string_text":"Quantity"}}],"links":{"self":{"href":"http://cms.arcteryx.com/en/jsonapi/node/reusable_string/?fields%5Bnode--reusable_string%5D=title%2Cfield_reusable_string_text\u0026filter%5Btitle%5D%5Boperator%5D=IN\u0026filter%5Btitle%5D%5Bvalue%5D%5B0%5D=My%20Cart\u0026filter%5Btitle%5D%5Bvalue%5D%5B1%5D=Item\u0026filter%5Btitle%5D%5Bvalue%5D%5B2%5D=Quantity"}}}';
export const mockReusableStringJsonApiResponse = {

@@ -9,0 +12,0 @@ data: [

/* eslint no-undef: 0*/
import { GetBasicBlock } from "../src/index";
import { getBasicBlock } from "../src/index";
import { mockBasicBlockJsonApiResponse } from "./drupal.mockdata";
describe("CMS Drupal Helpers: GetBasicBlock", () => {
describe("CMS Drupal Helpers: getBasicBlock", () => {
let mockSuccessResponse = mockBasicBlockJsonApiResponse;

@@ -23,3 +23,3 @@ let mockJsonPromise = Promise.resolve(mockSuccessResponse);

test("Build the correct request for a Basic Block for 'OUTDOOR Empty Cart' in English", done => {
GetBasicBlock("https://cms.arcteryx.com", "OUTDOOR Empty Cart", "en").then(result => {
getBasicBlock("https://cms.arcteryx.com", "OUTDOOR Empty Cart", "en").then(result => {
expect(global.fetch).toHaveBeenCalledTimes(1);

@@ -41,3 +41,3 @@ expect(global.fetch).toHaveBeenCalledWith(

global.fetch = jest.fn().mockImplementation(() => mockFetchPromise);
GetBasicBlock("https://localhost", "Test Null", "en").then(result => {
getBasicBlock("https://localhost", "Test Null", "en").then(result => {
expect(result).toMatchInlineSnapshot(`null`);

@@ -44,0 +44,0 @@ done();

/* eslint no-undef: 0*/
import { GetReusableData } from "../src/index";
import { getReusableData } from "../src/index";
import { mockReusableStringJsonApiResponse } from "./drupal.mockdata";
describe("CMS Drupal Helpers: GetReusableData", () => {
describe("CMS Drupal Helpers: getReusableData", () => {
beforeEach(() => {

@@ -25,3 +25,3 @@ const mockSuccessResponse = mockReusableStringJsonApiResponse;

test("Build the correct request for Reusable Strings for 'New', 'Revised', 'Pro Exlusive' in English", done => {
GetReusableData("https://cms.arcteryx.com", ["New", "Revised", "Pro Exlusive"], "en").then(result => {
getReusableData("https://cms.arcteryx.com", ["New", "Revised", "Pro Exlusive"], "en").then(result => {
expect(global.fetch).toHaveBeenCalledTimes(1);

@@ -28,0 +28,0 @@ expect(global.fetch).toHaveBeenCalledWith(

/* eslint no-undef: 0*/
import { GetReusableText } from "../src/index";
import { getReusableText } from "../src/index";
import { mockReusableData } from "./drupal.mockdata";
describe("CMS Drupal Helpers: GetReusableText", () => {
describe("CMS Drupal Helpers: getReusableText", () => {
beforeEach(() => {

@@ -25,12 +25,12 @@ const mockSuccessResponse = mockReusableData;

test("Get correct text from Reusable Data for title key of 'Refine'", () => {
expect(GetReusableText("Refine", mockReusableData)).toMatchInlineSnapshot(`"Refine"`);
expect(getReusableText("Refine", mockReusableData)).toMatchInlineSnapshot(`"Refine"`);
});
test("Get same text from Reusable Data for title key that is not in Drupal", () => {
expect(GetReusableText("Not in Drupal", mockReusableData)).toMatchInlineSnapshot(`"Not in Drupal"`);
expect(getReusableText("Not in Drupal", mockReusableData)).toMatchInlineSnapshot(`"Not in Drupal"`);
});
test("Get same text from Reusable Data if Reusable Data is undefined", () => {
expect(GetReusableText("Not in Drupal", undefined)).toMatchInlineSnapshot(`"Not in Drupal"`);
expect(getReusableText("Not in Drupal", undefined)).toMatchInlineSnapshot(`"Not in Drupal"`);
});
});
/* eslint no-undef: 0*/
import { GetSimplePage } from "../src/index";
import { getSimplePage } from "../src/index";
import { mockSimplePageApiResponse } from "./drupal.mockdata";
describe("CMS Drupal Helpers: GetSimplePage", () => {
describe("CMS Drupal Helpers: getSimplePage", () => {
beforeEach(() => {

@@ -25,3 +25,3 @@ const mockSuccessResponse = mockSimplePageApiResponse;

test("Build the correct request for a Simple Page for Outdoor /ca/en/help", done => {
GetSimplePage("https://cms.arcteryx.com", "outdoor", "ca", "en", "help").then(result => {
getSimplePage("https://cms.arcteryx.com", "outdoor", "ca", "en", "help").then(result => {
expect(global.fetch).toHaveBeenCalledTimes(1);

@@ -36,3 +36,3 @@ expect(global.fetch).toHaveBeenCalledWith(

test("Build the correct request for a Simple Page for Outdoor for undefined path", done => {
GetSimplePage("https://cms.arcteryx.com", "outdoor", "ca", "en", undefined).then(result => {
getSimplePage("https://cms.arcteryx.com", "outdoor", "ca", "en", undefined).then(result => {
expect(global.fetch).toHaveBeenCalledTimes(1);

@@ -39,0 +39,0 @@ expect(global.fetch).toHaveBeenCalledWith(

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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