Socket
Socket
Sign inDemoInstall

rest

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rest - npm Package Compare versions

Comparing version 0.9.2 to 0.9.3

test/client/fixtures/data.js

46

client/jsonp.js

@@ -11,2 +11,4 @@ /*

var undef;
define(function (require) {

@@ -27,3 +29,3 @@

if (propertyName in scope) {
scope[propertyName] = undefined;
scope[propertyName] = undef;
}

@@ -34,14 +36,18 @@ }

function cleanupScriptNode(response) {
if (response.raw && response.raw.parentNode) {
response.raw.parentNode.removeChild(response.raw);
try {
if (response.raw && response.raw.parentNode) {
response.raw.parentNode.removeChild(response.raw);
}
} catch (e) {
// ignore
}
}
function registerCallback(prefix, resolver, response) {
var name;
do {
name = prefix + Math.floor(new Date().getTime() * Math.random());
function registerCallback(prefix, resolver, response, name) {
if (!name) {
do {
name = prefix + Math.floor(new Date().getTime() * Math.random());
}
while (name in global);
}
while (name in global);

@@ -65,4 +71,10 @@ global[name] = function jsonpCallback(data) {

* @param {Object} [request.params] parameters to bind to the path
* @param {string} [request.callback.param='callback'] the parameter name for which the callback function name is the value
* @param {string} [request.callback.prefix='jsonp'] prefix for the callback function, as the callback is attached to the window object, a unique, unobtrusive prefix is desired
* @param {string} [request.callback.param='callback'] the parameter name for
* which the callback function name is the value
* @param {string} [request.callback.prefix='jsonp'] prefix for the callback
* function, as the callback is attached to the window object, a unique,
* unobtrusive prefix is desired
* @param {string} [request.callback.name=<generated>] pins the name of the
* callback function, useful for cases where the server doesn't allow
* custom callback names. Generally not recomended.
*

@@ -84,3 +96,3 @@ * @returns {Promise<Response>}

request.callback = request.callback || {};
callbackName = registerCallback(request.callback.prefix || 'jsonp', d.resolver, response);
callbackName = registerCallback(request.callback.prefix || 'jsonp', d.resolver, response, request.callback.name);
callbackParams = {};

@@ -101,4 +113,4 @@ callbackParams[request.callback.param || 'callback'] = callbackName;

script.onerror = function () {
if (global[callbackName]) {
function handlePossibleError() {
if (typeof global[callbackName] === 'function') {
response.error = 'loaderror';

@@ -109,7 +121,11 @@ clearProperty(global, callbackName);

}
}
script.onerror = function () {
handlePossibleError();
};
script.onload = script.onreadystatechange = function (e) {
// script tag load callbacks are completely non-standard
// handle case where onreadystatechange is fired for an error instead of onerror
if ((e && (e.type === 'load' || e.type === 'error')) || script.readyState === 'loaded') {
script.onerror(e);
handlePossibleError();
}

@@ -116,0 +132,0 @@ };

{
"name": "rest",
"version": "0.9.2",
"version": "0.9.3",
"main": "./rest.js",

@@ -5,0 +5,0 @@ "dependencies": {

{
"name": "rest",
"version": "0.9.2",
"version": "0.9.3",
"description": "RESTful HTTP client library",

@@ -12,8 +12,6 @@ "keywords": ["rest", "http", "client", "rest-template", "spring", "cujojs"],

],
"repositories": [
{
"type": "git",
"url": "https://github.com/cujojs/rest"
}
],
"repository": {
"type": "git",
"url": "https://github.com/cujojs/rest.git"
},
"bugs": "https://github.com/cujojs/rest/issues",

@@ -39,3 +37,3 @@ "maintainers": [

"dojo": "https://github.com/dojo/dojo/tarball/1.7.2",
"test-support": "~0.2",
"test-support": "~0.3",
"curl": "https://github.com/cujojs/curl/tarball/0.7.3",

@@ -42,0 +40,0 @@ "poly": "https://github.com/cujojs/poly/tarball/0.5.1"

@@ -231,2 +231,5 @@ rest.js

0.9.3
- fixes issues with uglified JSONP client in IE 8
0.9.2

@@ -233,0 +236,0 @@ - allow strings to represent request objects, the string value is treated as the path property

@@ -38,2 +38,3 @@ /*

'node_modules/wire/**/*.js',
'test/**/fixtures/**',
{ path: '/wait', backend: 'http://example.com' }

@@ -40,0 +41,0 @@ ],

@@ -27,3 +27,3 @@ /*

buster.testCase('rest/client/jsonp', {
'should make a GET by default': function () {
'should make a cross origin request': function () {
var request = { path: 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0', params: { q: 'javascript' } };

@@ -38,5 +38,5 @@ return client(request).then(function (response) {

'should use the jsonp client from the jsonp interceptor by default': function () {
var request = { path: 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0', params: { q: 'html5' } };
var request = { path: '/test/client/fixtures/data.js', callback: { name: 'callback' } };
return jsonpInterceptor()(request).then(function (response) {
assert(response.entity.responseData);
assert(response.entity.data);
assert.same(request, response.request);

@@ -49,3 +49,3 @@ refute(request.canceled);

var request, response;
request = { path: 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0', params: { q: 'html5' } };
request = { path: 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0', params: { q: 'jsonp' } };
response = client(request).then(

@@ -73,3 +73,3 @@ fail,

'should not make a request that has already been canceled': function () {
var request = { canceled: true, path: 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0', params: { q: 'javascript' } };
var request = { canceled: true, path: 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0', params: { q: 'html5' } };
return client(request).then(

@@ -84,2 +84,20 @@ fail,

},
'should error if callback not invoked': function () {
var request = { path: '/test/client/fixtures/noop.js' };
return client(request).then(
fail,
failOnThrow(function (response) {
assert.same('loaderror', response.error);
})
);
},
'should error if script throws': function () {
var request = { path: '/test/client/fixtures/throw.js' };
return client(request).then(
fail,
failOnThrow(function (response) {
assert.same('loaderror', response.error);
})
);
},
'should normalize a string to a request object': function () {

@@ -86,0 +104,0 @@ var request = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=javascript';

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