@sitecore-jss/sitecore-jss
Advanced tools
Comparing version 9.0.5 to 10.0.0-preview.1
@@ -20,7 +20,3 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var axios_1 = __importDefault(require("axios")); | ||
var ResponseError = /** @class */ (function (_super) { | ||
@@ -36,3 +32,3 @@ __extends(ResponseError, _super); | ||
}(Error)); | ||
var checkStatus = function (response) { | ||
function checkStatus(response) { | ||
if (response.status >= 200 && response.status < 300) { | ||
@@ -43,23 +39,16 @@ return response; | ||
throw error; | ||
}; | ||
} | ||
// note: encodeURIComponent is available via browser (window) or natively in node.js | ||
// if you use another js engine for server-side rendering you may not have native encodeURIComponent | ||
// and would then need to install a package for that functionality | ||
var getQueryString = function (params) { | ||
function getQueryString(params) { | ||
return Object.keys(params) | ||
.map(function (k) { return encodeURIComponent(k) + "=" + encodeURIComponent(params[k]); }) | ||
.join('&'); | ||
}; | ||
// note: axios needs to use `withCredentials: true` in order for Sitecore cookies to be included in CORS requests | ||
// which is necessary for analytics and such | ||
var fetchData = function (url, params, options) { | ||
} | ||
function fetchData(url, fetcher, params) { | ||
if (params === void 0) { params = {}; } | ||
if (options === void 0) { options = {}; } | ||
var fetchOptions = Object.assign({}, options, { | ||
withCredentials: true, | ||
}); | ||
var qs = getQueryString(params); | ||
var fetchUrl = url.indexOf('?') !== -1 ? url + "&" + qs : url + "?" + qs; | ||
return axios_1.default | ||
.get(fetchUrl, fetchOptions) | ||
return fetcher(fetchUrl) | ||
.then(checkStatus) | ||
@@ -70,3 +59,3 @@ .then(function (response) { | ||
}); | ||
}; | ||
} | ||
var resolveLayoutServiceUrl = function (options, verb) { | ||
@@ -83,8 +72,8 @@ if (options === void 0) { options = {}; } | ||
*/ | ||
exports.fetchRouteData = function (itemPath, options) { | ||
if (options === void 0) { options = {}; } | ||
var querystringParams = options.querystringParams, layoutServiceConfig = options.layoutServiceConfig, requestConfig = options.requestConfig; | ||
function fetchRouteData(itemPath, options) { | ||
var querystringParams = options.querystringParams, layoutServiceConfig = options.layoutServiceConfig; | ||
var fetchUrl = resolveLayoutServiceUrl(layoutServiceConfig, 'render'); | ||
return fetchData(fetchUrl, __assign({ item: itemPath }, querystringParams), requestConfig); | ||
}; | ||
return fetchData(fetchUrl, options.fetcher, __assign({ item: itemPath }, querystringParams)); | ||
} | ||
exports.fetchRouteData = fetchRouteData; | ||
/** | ||
@@ -94,7 +83,7 @@ * Makes a request to Sitecore Layout Service for the specified placeholder in | ||
*/ | ||
exports.fetchPlaceholderData = function (placeholderName, itemPath, options) { | ||
if (options === void 0) { options = {}; } | ||
var querystringParams = options.querystringParams, layoutServiceConfig = options.layoutServiceConfig, requestConfig = options.requestConfig; | ||
function fetchPlaceholderData(placeholderName, itemPath, options) { | ||
var querystringParams = options.querystringParams, layoutServiceConfig = options.layoutServiceConfig; | ||
var fetchUrl = resolveLayoutServiceUrl(layoutServiceConfig, 'placeholder'); | ||
return fetchData(fetchUrl, __assign({ placeholderName: placeholderName, item: itemPath }, querystringParams), requestConfig); | ||
}; | ||
return fetchData(fetchUrl, options.fetcher, __assign({ placeholderName: placeholderName, item: itemPath }, querystringParams)); | ||
} | ||
exports.fetchPlaceholderData = fetchPlaceholderData; |
@@ -14,7 +14,2 @@ "use strict"; | ||
exports.mediaApi = mediaApi; | ||
var dynamicPlaceholders_1 = require("./dynamicPlaceholders"); | ||
exports.getDynamicPlaceholderKey = dynamicPlaceholders_1.getDynamicPlaceholderKey; | ||
var dataConversion_1 = require("./dataConversion"); | ||
exports.convertPropDataToLayoutServiceFormat = dataConversion_1.convertPropDataToLayoutServiceFormat; | ||
exports.convertRouteToLayoutServiceFormat = dataConversion_1.convertRouteToLayoutServiceFormat; | ||
var util_1 = require("./util"); | ||
@@ -21,0 +16,0 @@ exports.isExperienceEditorActive = util_1.isExperienceEditorActive; |
@@ -52,3 +52,3 @@ "use strict"; | ||
var parsed = URL(url, {}, true); | ||
parsed.query = params || parsed.query; | ||
parsed.set('query', params || parsed.query); | ||
var match = mediaUrlPrefixRegex.exec(parsed.pathname); | ||
@@ -55,0 +55,0 @@ if (match && match.length > 1) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isJson = function (str) { | ||
try { | ||
JSON.parse(str); | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
exports.tryParseJson = function (jsonString) { | ||
try { | ||
var o = JSON.parse(jsonString); | ||
// Handle non-exception-throwing cases: | ||
if (o && typeof o === 'object' && o !== null) { | ||
return o; | ||
} | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
return false; | ||
}; | ||
exports.isPrimitive = function (arg) { | ||
var type = typeof arg; | ||
return arg === null || (type !== 'object' && type !== 'function'); | ||
}; | ||
exports.getCookieValue = function (cookieName, cookies) { | ||
var cookieValue = ''; | ||
var beginIndex = 0; | ||
var endIndex = 0; | ||
if (cookies.length > 0) { | ||
beginIndex = cookies.indexOf(cookieName + "="); | ||
if (beginIndex !== -1) { | ||
beginIndex += cookieName.length + 1; | ||
endIndex = cookies.indexOf(';', beginIndex); | ||
// if it the last cookie | ||
if (endIndex === -1) { | ||
endIndex = cookies.length; | ||
} | ||
cookieValue = unescape(cookies.substring(beginIndex, endIndex)); | ||
} | ||
} | ||
return cookieValue; | ||
}; | ||
exports.isServer = function () { return !(typeof window !== 'undefined' && window.document); }; | ||
@@ -48,0 +4,0 @@ exports.isExperienceEditorActive = function () { |
{ | ||
"name": "@sitecore-jss/sitecore-jss", | ||
"version": "9.0.5", | ||
"version": "10.0.0-preview.1", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build": "yarn clean && tsc", | ||
"build": "npm run clean && tsc", | ||
"clean": "del-cli dist types", | ||
"lint": "tslint -p . -c ../../tslint.json 'src/**/*.ts'", | ||
"test": "mocha --require ts-node/register \"./src/**/*.test.ts\"", | ||
"prepublishOnly": "yarn build" | ||
"prepublishOnly": "npm run build", | ||
"coverage": "nyc --require ts-node/register npm test" | ||
}, | ||
"engines": { | ||
"node": ">=8.1" | ||
}, | ||
"author": { | ||
@@ -28,2 +32,3 @@ "name": "Sitecore Corporation", | ||
"@types/url-parse": "^1.1.0", | ||
"axios": "^0.17.1", | ||
"axios-mock-adapter": "^1.13.1", | ||
@@ -41,3 +46,2 @@ "chai": "^4.1.2", | ||
"dependencies": { | ||
"axios": "^0.17.1", | ||
"lodash.unescape": "^4.0.1", | ||
@@ -47,3 +51,4 @@ "url-parse": "^1.4.1" | ||
"description": "", | ||
"types": "types/index.d.ts" | ||
"types": "types/index.d.ts", | ||
"gitHead": "dead320dec4c4c5444972a89aee2b86dd83f93d3" | ||
} |
@@ -1,3 +0,3 @@ | ||
import { AxiosRequestConfig } from 'axios'; | ||
import { LayoutServiceData, PlaceholderData } from './dataModels'; | ||
import { HttpJsonFetcher } from './httpClientInterface'; | ||
export interface LayoutServiceConfig { | ||
@@ -18,3 +18,3 @@ /** | ||
} | ||
export interface BaseRequestOptions { | ||
export interface BaseRequestOptions<T> { | ||
/** | ||
@@ -26,8 +26,6 @@ * An object of key:value pairs to be stringified and used as querystring parameters. | ||
}; | ||
/** | ||
* Configuration options for XHR requests. | ||
*/ | ||
requestConfig?: AxiosRequestConfig; | ||
/** The fetcher that performs the HTTP request and returns a promise to JSON */ | ||
fetcher: HttpJsonFetcher<T>; | ||
} | ||
export interface LayoutServiceRequestOptions extends BaseRequestOptions { | ||
export interface LayoutServiceRequestOptions<T> extends BaseRequestOptions<T> { | ||
/** | ||
@@ -41,3 +39,3 @@ * Configuration options for Layout Service requests. | ||
*/ | ||
export declare const fetchRouteData: (itemPath: string, options?: LayoutServiceRequestOptions) => Promise<LayoutServiceData>; | ||
export declare function fetchRouteData(itemPath: string, options: LayoutServiceRequestOptions<LayoutServiceData>): Promise<LayoutServiceData>; | ||
/** | ||
@@ -47,2 +45,2 @@ * Makes a request to Sitecore Layout Service for the specified placeholder in | ||
*/ | ||
export declare const fetchPlaceholderData: (placeholderName: string, itemPath: string, options?: LayoutServiceRequestOptions) => Promise<PlaceholderData>; | ||
export declare function fetchPlaceholderData(placeholderName: string, itemPath: string, options: LayoutServiceRequestOptions<PlaceholderData>): Promise<PlaceholderData>; |
@@ -17,2 +17,3 @@ /** | ||
pageState?: 'preview' | 'edit' | 'normal'; | ||
visitorIdentificationTimestamp?: number; | ||
site?: { | ||
@@ -19,0 +20,0 @@ name?: string; |
@@ -5,6 +5,5 @@ import * as dataApi from './dataApi'; | ||
export { LayoutServiceRequestOptions } from './dataApi'; | ||
export { getDynamicPlaceholderKey } from './dynamicPlaceholders'; | ||
export { convertPropDataToLayoutServiceFormat, convertRouteToLayoutServiceFormat, } from './dataConversion'; | ||
export { isExperienceEditorActive, isServer, resetExperienceEditorChromes } from './util'; | ||
export { LayoutServiceData, LayoutServiceContextData, RouteData, PlaceholderData, ComponentRendering, HtmlElementRendering, Field, Item, PlaceholdersData, ComponentFields, ComponentParams } from './dataModels'; | ||
export { getFieldValue, getChildPlaceholder } from './layoutDataUtils'; | ||
export { HttpJsonFetcher, HttpResponse } from './httpClientInterface'; |
@@ -1,7 +0,3 @@ | ||
export declare const isJson: (str: string) => boolean; | ||
export declare const tryParseJson: (jsonString: string) => any; | ||
export declare const isPrimitive: (arg: any) => boolean; | ||
export declare const getCookieValue: (cookieName: string, cookies: string) => string; | ||
export declare const isServer: () => boolean; | ||
export declare const isExperienceEditorActive: () => boolean; | ||
export declare const resetExperienceEditorChromes: () => void; |
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
2
27712
17
18
471
1
- Removedaxios@^0.17.1
- Removedaxios@0.17.1(transitive)
- Removedfollow-redirects@1.15.9(transitive)
- Removedis-buffer@1.1.6(transitive)