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

opensearch-browser

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

opensearch-browser - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

dist/parameter.js

2

dist/formats/atom.js

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

var entry = {
id: (0, _utils.xPath)(node, 'atom:id/text()'),
id: (0, _utils.xPath)(node, 'dc:identifier/text()') || (0, _utils.xPath)(node, 'atom:id/text()'),
properties: {

@@ -51,0 +51,0 @@ title: (0, _utils.xPath)(node, 'atom:title/text()'),

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

var item = {
id: (0, _utils.xPath)(node, 'guid/text()'),
id: (0, _utils.xPath)(node, 'dc:identifier/text()') || (0, _utils.xPath)(node, 'guid/text()'),
properties: {

@@ -51,0 +51,0 @@ title: (0, _utils.xPath)(node, 'title/text()'),

@@ -12,88 +12,8 @@ 'use strict';

var _urlParse = require('url-parse');
var _urlParse2 = _interopRequireDefault(_urlParse);
var _wellknown = require('wellknown');
var _utils = require('./utils');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _parameter = require('./parameter');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var typeRE = /{([a-zA-Z:]+)([?]?)}/;
function parseType(value) {
var match = typeRE.exec(value);
if (match) {
return match[1];
}
return null;
}
function isMandatory(value) {
return typeRE.exec(value)[2] !== '?';
}
function parseTemplateParameters(templateUrl) {
var parameters = [];
var parsed = (0, _urlParse2.default)(templateUrl, true);
Object.keys(parsed.query).forEach(function (name) {
var parameterType = parseType(parsed.query[name]);
if (parameterType) {
parameters.push({
name: name,
type: parameterType,
mandatory: isMandatory(parsed.query[name])
});
}
});
return parameters;
}
function eoValueToString(value) {
var isDate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var convertDate = function convertDate(dateValue) {
if (dateValue instanceof Date) {
return dateValue.toISOString();
}
return value;
};
if (typeof value === 'number') {
return value.toString();
} else if (isDate && value instanceof Date) {
return convertDate(value);
} else if (Array.isArray(value)) {
if (isDate) {
return '{' + value.map(convertDate).join(',') + '}';
}
return '{' + value.join(',') + '}';
}
var left = null;
var right = null;
if (value.hasOwnProperty('min')) {
left = '[' + (isDate ? convertDate(value.min) : value.min);
} else if (value.hasOwnProperty('minExclusive')) {
left = ']' + (isDate ? convertDate(value.minExclusive) : value.minExclusive);
}
if (value.hasOwnProperty('max')) {
right = (isDate ? convertDate(value.max) : value.max) + ']';
} else if (value.hasOwnProperty('maxExclusive')) {
right = (isDate ? convertDate(value.maxExclusive) : value.maxExclusive) + '[';
}
if (left !== null && right !== null) {
return left + ',' + right;
} else if (left !== null) {
return left;
}
return right;
}
/**

@@ -110,3 +30,2 @@ * Class to parse a single URL of an OpenSearchDescription XML document and

*/
var OpenSearchUrl = exports.OpenSearchUrl = function () {

@@ -202,48 +121,6 @@ /**

}
}, {
key: 'serializeParameter',
value: function serializeParameter(type, value) {
switch (type) {
case 'time:start':
case 'time:end':
if (value instanceof Date) {
return value.toISOString();
}
break;
case 'geo:box':
if (Array.isArray(value)) {
return value.join(',');
}
break;
case 'geo:geometry':
return (0, _wellknown.stringify)(value);
case 'eo:orbitNumber':
case 'eo:track':
case 'eo:frame':
case 'eo:cloudCover':
case 'eo:snowCover':
case 'eo:startTimeFromAscendingNode':
case 'eo:completionTimeFromAscendingNode':
case 'eo:illuminationAzimuthAngle':
case 'eo:illuminationZenithAngle':
case 'eo:illuminationElevationAngle':
case 'eo:minimumIncidenceAngle':
case 'eo:maximumIncidenceAngle':
case 'eo:dopplerFrequency':
case 'eo:incidenceAngleVariation':
return eoValueToString(value);
case 'eo:availabilityTime':
case 'eo:creationDate':
case 'eo:modificationDate':
case 'eo:processingDate':
return eoValueToString(value, true);
default:
break;
}
return value;
}
/**
* Create a request for the given parameters
* @param {object} parameters An object mapping the name or type to the value
* @param {object} parameterValues An object mapping the name or type to the value
* @returns {Request} The {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Request}

@@ -256,7 +133,7 @@ * object for the

key: 'createRequest',
value: function createRequest(parameters) {
value: function createRequest(parameterValues) {
var _this3 = this;
// check parameters
Object.keys(parameters).forEach(function (key) {
Object.keys(parameterValues).forEach(function (key) {
if (!_this3._parametersByType.hasOwnProperty(key) && !_this3._parametersByName.hasOwnProperty(key)) {

@@ -268,3 +145,3 @@ throw new Error('Invalid parameter \'' + key + '\'.');

var missingMandatoryParameters = this.parameters.filter(function (parameter) {
return parameter.mandatory && !parameters.hasOwnProperty(parameter.name) && !parameters.hasOwnProperty(parameter.type);
return parameter.mandatory && !parameterValues.hasOwnProperty(parameter.name) && !parameterValues.hasOwnProperty(parameter.type);
}).map(function (parameter) {

@@ -275,3 +152,3 @@ return parameter.type;

var missingOptionalParameters = this.parameters.filter(function (parameter) {
return !parameter.mandatory && !parameters.hasOwnProperty(parameter.name) && !parameters.hasOwnProperty(parameter.type);
return !parameter.mandatory && !parameterValues.hasOwnProperty(parameter.name) && !parameterValues.hasOwnProperty(parameter.type);
}).map(function (parameter) {

@@ -290,5 +167,5 @@ return parameter.type;

Object.keys(parameters).forEach(function (key) {
var type = (_this3._parametersByType[key] || _this3._parametersByName[key]).type;
url = url.replace(new RegExp('{' + type + '[?]?}'), _this3.serializeParameter(type, parameters[key]));
Object.keys(parameterValues).forEach(function (key) {
var parameter = _this3._parametersByType[key] || _this3._parametersByName[key];
url = url.replace(new RegExp('{' + parameter.type + '[?]?}'), parameter.serialize(parameterValues[key]));
});

@@ -312,6 +189,6 @@

if (enctype === 'application/x-www-form-urlencoded') {
body = Object.keys(parameters).map(function (key) {
body = Object.keys(parameterValues).map(function (key) {
var param = _this3._parametersByType[key] || _this3._parametersByName[key];
var k = encodeURIComponent(param.name);
var v = encodeURIComponent(_this3.serializeParameter(param.type, parameters[key]));
var v = encodeURIComponent(param.serialize(parameterValues[key]));
return k + '=' + v;

@@ -321,5 +198,5 @@ }).join('&');

body = new FormData();
Object.keys(parameters).forEach(function (key) {
Object.keys(parameterValues).forEach(function (key) {
var param = _this3._parametersByType[key] || _this3._parametersByName[key];
body.append(param.name, _this3.serializeParameter(param.type, parameters[key]));
body.append(param.name, param.serialize(parameterValues[key]));
});

@@ -425,18 +302,5 @@ } else {

var parametersFromTemplate = parseTemplateParameters(node.getAttribute('template'));
var parametersFromTemplate = (0, _parameter.parseTemplateParameters)(node.getAttribute('template'));
var parametersFromNode = parameterNodes.map(function (parameterNode) {
var type = parseType(parameterNode.getAttribute('value'));
var name = parameterNode.getAttribute('name');
var mandatory = parameterNode.hasAttribute('minimum') ? parameterNode.getAttribute('minimum') !== '0' : undefined;
var optionNodes = (0, _utils.xPathArray)(parameterNode, 'parameters:Option', _utils.resolver);
var options = void 0;
if (optionNodes.length) {
options = optionNodes.map(function (optionNode) {
return {
label: optionNode.getAttribute('label'),
value: optionNode.getAttribute('value')
};
});
}
return { name: name, type: type, mandatory: mandatory, options: options };
return new _parameter.OpenSearchParameter(parameterNode);
});

@@ -460,8 +324,3 @@

if (p2) {
return {
name: p1.name,
type: p1.type,
mandatory: typeof p2.mandatory !== 'undefined' ? p2.mandatory : p1.mandatory,
options: p2.options
};
return p1.combine(p2);
}

@@ -489,3 +348,3 @@ return p1;

var parameters = parseTemplateParameters(templateUrl);
var parameters = (0, _parameter.parseTemplateParameters)(templateUrl);
return new OpenSearchUrl(type, templateUrl, parameters, method, enctype);

@@ -492,0 +351,0 @@ }

@@ -13,2 +13,3 @@ 'use strict';

exports.fetchAndCheck = fetchAndCheck;
exports.isNullOrUndefined = isNullOrUndefined;

@@ -104,2 +105,6 @@ require('isomorphic-fetch');

});
}
function isNullOrUndefined(value) {
return typeof value === 'undefined' || value === null;
}
{
"name": "opensearch-browser",
"version": "0.0.8",
"version": "0.0.9",
"description": "An OpenSearch client supporting the geo and time extensions.",

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

"isomorphic-fetch": "^2.2.1",
"url-parse": "^1.1.1",
"url-parse": "^1.1.7",
"wellknown": "^0.5.0",

@@ -38,19 +38,19 @@ "xpath": "0.0.23"

"devDependencies": {
"babel-cli": "^6.11.4",
"babel-eslint": "^6.1.2",
"babel-cli": "^6.18.0",
"babel-eslint": "^7.1.1",
"babel-plugin-transform-object-assign": "^6.8.0",
"babel-polyfill": "^6.13.0",
"babel-preset-es2015": "^6.13.1",
"babel-register": "^6.11.6",
"babel-polyfill": "^6.16.0",
"babel-preset-es2015": "^6.18.0",
"babel-register": "^6.18.0",
"babelify": "^7.3.0",
"chai": "^3.5.0",
"eslint": "^3.10.0",
"eslint": "^3.11.1",
"eslint-config-airbnb": "^13.0.0",
"eslint-config-pedant": "^0.8.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.6.0",
"fetch-mock": "^5.0.5",
"eslint-plugin-jsx-a11y": "^3.0.1",
"eslint-plugin-react": "^6.7.1",
"fetch-mock": "^5.5.0",
"mochify": "^2.18.1",
"sinon": "^1.17.5",
"sinon": "^1.17.6",
"sinon-chai": "^2.8.0",

@@ -57,0 +57,0 @@ "stringify": "^5.1.0"

@@ -19,3 +19,3 @@ import { parseXml, xPath, xPathArray } from '../utils';

const entry = {
id: xPath(node, 'atom:id/text()'),
id: xPath(node, 'dc:identifier/text()') || xPath(node, 'atom:id/text()'),
properties: {

@@ -22,0 +22,0 @@ title: xPath(node, 'atom:title/text()'),

@@ -19,3 +19,3 @@ import { parseXml, xPath, xPathArray } from '../utils';

const item = {
id: xPath(node, 'guid/text()'),
id: xPath(node, 'dc:identifier/text()') || xPath(node, 'guid/text()'),
properties: {

@@ -22,0 +22,0 @@ title: xPath(node, 'title/text()'),

@@ -1,78 +0,5 @@

import parse from 'url-parse';
import { stringify } from 'wellknown';
import { xPathArray, resolver, namespaces, getAttributeNS } from './utils';
import { OpenSearchParameter, parseTemplateParameters } from './parameter';
const typeRE = /{([a-zA-Z:]+)([?]?)}/;
function parseType(value) {
const match = typeRE.exec(value);
if (match) {
return match[1];
}
return null;
}
function isMandatory(value) {
return typeRE.exec(value)[2] !== '?';
}
function parseTemplateParameters(templateUrl) {
const parameters = [];
const parsed = parse(templateUrl, true);
Object.keys(parsed.query).forEach(name => {
const parameterType = parseType(parsed.query[name]);
if (parameterType) {
parameters.push({
name,
type: parameterType,
mandatory: isMandatory(parsed.query[name]),
});
}
});
return parameters;
}
function eoValueToString(value, isDate = false) {
const convertDate = (dateValue) => {
if (dateValue instanceof Date) {
return dateValue.toISOString();
}
return value;
};
if (typeof value === 'number') {
return value.toString();
} else if (isDate && value instanceof Date) {
return convertDate(value);
} else if (Array.isArray(value)) {
if (isDate) {
return `{${value.map(convertDate).join(',')}}`;
}
return `{${value.join(',')}}`;
}
let left = null;
let right = null;
if (value.hasOwnProperty('min')) {
left = `[${isDate ? convertDate(value.min) : value.min}`;
} else if (value.hasOwnProperty('minExclusive')) {
left = `]${isDate ? convertDate(value.minExclusive) : value.minExclusive}`;
}
if (value.hasOwnProperty('max')) {
right = `${isDate ? convertDate(value.max) : value.max}]`;
} else if (value.hasOwnProperty('maxExclusive')) {
right = `${isDate ? convertDate(value.maxExclusive) : value.maxExclusive}[`;
}
if (left !== null && right !== null) {
return `${left},${right}`;
} else if (left !== null) {
return left;
}
return right;
}
/**

@@ -215,46 +142,5 @@ * Class to parse a single URL of an OpenSearchDescription XML document and

serializeParameter(type, value) {
switch (type) {
case 'time:start':
case 'time:end':
if (value instanceof Date) {
return value.toISOString();
}
break;
case 'geo:box':
if (Array.isArray(value)) {
return value.join(',');
}
break;
case 'geo:geometry':
return stringify(value);
case 'eo:orbitNumber':
case 'eo:track':
case 'eo:frame':
case 'eo:cloudCover':
case 'eo:snowCover':
case 'eo:startTimeFromAscendingNode':
case 'eo:completionTimeFromAscendingNode':
case 'eo:illuminationAzimuthAngle':
case 'eo:illuminationZenithAngle':
case 'eo:illuminationElevationAngle':
case 'eo:minimumIncidenceAngle':
case 'eo:maximumIncidenceAngle':
case 'eo:dopplerFrequency':
case 'eo:incidenceAngleVariation':
return eoValueToString(value);
case 'eo:availabilityTime':
case 'eo:creationDate':
case 'eo:modificationDate':
case 'eo:processingDate':
return eoValueToString(value, true);
default:
break;
}
return value;
}
/**
* Create a request for the given parameters
* @param {object} parameters An object mapping the name or type to the value
* @param {object} parameterValues An object mapping the name or type to the value
* @returns {Request} The {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Request}

@@ -264,5 +150,5 @@ * object for the

*/
createRequest(parameters) {
createRequest(parameterValues) {
// check parameters
Object.keys(parameters).forEach(key => {
Object.keys(parameterValues).forEach(key => {
if (!this._parametersByType.hasOwnProperty(key)

@@ -276,4 +162,4 @@ && !this._parametersByName.hasOwnProperty(key)) {

(parameter) => parameter.mandatory
&& !parameters.hasOwnProperty(parameter.name)
&& !parameters.hasOwnProperty(parameter.type)
&& !parameterValues.hasOwnProperty(parameter.name)
&& !parameterValues.hasOwnProperty(parameter.type)
).map((parameter) => parameter.type);

@@ -283,4 +169,4 @@

(parameter) => !parameter.mandatory
&& !parameters.hasOwnProperty(parameter.name)
&& !parameters.hasOwnProperty(parameter.type)
&& !parameterValues.hasOwnProperty(parameter.name)
&& !parameterValues.hasOwnProperty(parameter.type)
).map((parameter) => parameter.type);

@@ -296,7 +182,7 @@

Object.keys(parameters).forEach(key => {
const type = (this._parametersByType[key] || this._parametersByName[key]).type;
Object.keys(parameterValues).forEach(key => {
const parameter = this._parametersByType[key] || this._parametersByName[key];
url = url.replace(
new RegExp(`{${type}[?]?}`),
this.serializeParameter(type, parameters[key])
new RegExp(`{${parameter.type}[?]?}`),
parameter.serialize(parameterValues[key])
);

@@ -316,6 +202,6 @@ });

if (enctype === 'application/x-www-form-urlencoded') {
body = Object.keys(parameters).map(key => {
body = Object.keys(parameterValues).map(key => {
const param = (this._parametersByType[key] || this._parametersByName[key]);
const k = encodeURIComponent(param.name);
const v = encodeURIComponent(this.serializeParameter(param.type, parameters[key]));
const v = encodeURIComponent(param.serialize(parameterValues[key]));
return `${k}=${v}`;

@@ -325,5 +211,5 @@ }).join('&');

body = new FormData();
Object.keys(parameters).forEach(key => {
Object.keys(parameterValues).forEach(key => {
const param = (this._parametersByType[key] || this._parametersByName[key]);
body.append(param.name, this.serializeParameter(param.type, parameters[key]));
body.append(param.name, param.serialize(parameterValues[key]));
});

@@ -358,17 +244,3 @@ } else {

const parametersFromTemplate = parseTemplateParameters(node.getAttribute('template'));
const parametersFromNode = parameterNodes.map((parameterNode) => {
const type = parseType(parameterNode.getAttribute('value'));
const name = parameterNode.getAttribute('name');
const mandatory = parameterNode.hasAttribute('minimum')
? parameterNode.getAttribute('minimum') !== '0' : undefined;
const optionNodes = xPathArray(parameterNode, 'parameters:Option', resolver);
let options;
if (optionNodes.length) {
options = optionNodes.map(optionNode => ({
label: optionNode.getAttribute('label'),
value: optionNode.getAttribute('value'),
}));
}
return { name, type, mandatory, options };
});
const parametersFromNode = parameterNodes.map((parameterNode) => new OpenSearchParameter(parameterNode));

@@ -385,8 +257,3 @@ const parametersNotInTemplate = parametersFromNode.filter(

if (p2) {
return {
name: p1.name,
type: p1.type,
mandatory: (typeof p2.mandatory !== 'undefined') ? p2.mandatory : p1.mandatory,
options: p2.options,
};
return p1.combine(p2);
}

@@ -393,0 +260,0 @@ return p1;

@@ -87,1 +87,5 @@ import 'isomorphic-fetch';

}
export function isNullOrUndefined(value) {
return typeof value === 'undefined' || value === null;
}

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

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