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

@paypal/paypal-js

Package Overview
Dependencies
Maintainers
28
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@paypal/paypal-js - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

53

dist/paypal.browser.js
/*!
* paypal-js v1.0.1 (2020-09-11T20:27:05.885Z)
* paypal-js v1.0.2 (2020-09-30T18:10:04.928Z)
* Copyright 2020-present, PayPal, Inc. All rights reserved.

@@ -291,18 +291,28 @@ *

function findScript(url) {
return document.querySelector("script[src=\"".concat(url, "\"]"));
function findScript(url, dataAttributes) {
var currentScript = document.querySelector("script[src=\"".concat(url, "\"]"));
if (!currentScript) return null;
var nextScript = createScriptElement(url, dataAttributes); // check if the new script has the same number of data attributes
if (objectSize(currentScript.dataset) !== objectSize(nextScript.dataset)) {
return null;
}
var isExactMatch = true; // check if the data attribute values are the same
forEachObjectKey(currentScript.dataset, function (key) {
if (currentScript.dataset[key] !== nextScript.dataset[key]) {
isExactMatch = false;
}
});
return isExactMatch ? currentScript : null;
}
function insertScriptElement(_ref) {
var url = _ref.url,
_ref$dataAttributes = _ref.dataAttributes,
dataAttributes = _ref$dataAttributes === void 0 ? {} : _ref$dataAttributes,
dataAttributes = _ref.dataAttributes,
onSuccess = _ref.onSuccess,
onError = _ref.onError;
var newScript = document.createElement('script');
var newScript = createScriptElement(url, dataAttributes);
newScript.onerror = onError;
newScript.onload = onSuccess;
forEachObjectKey(dataAttributes, function (key) {
newScript.setAttribute(key, dataAttributes[key]);
});
newScript.src = url;
document.head.insertBefore(newScript, document.head.firstElementChild);

@@ -337,4 +347,15 @@ }

return queryString;
}
function createScriptElement(url) {
var dataAttributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var newScript = document.createElement('script');
newScript.src = url;
forEachObjectKey(dataAttributes, function (key) {
newScript.setAttribute(key, dataAttributes[key]);
});
return newScript;
} // uses es3 to avoid requiring polyfills for Array.prototype.forEach and Object.keys
function forEachObjectKey(obj, callback) {

@@ -348,2 +369,10 @@ for (var key in obj) {

function objectSize(obj) {
var size = 0;
forEachObjectKey(obj, function () {
return size++;
});
return size;
}
var SDK_BASE_URL = 'https://www.paypal.com/sdk/js';

@@ -365,3 +394,3 @@ var loadingPromise;

if (findScript(url) && window.paypal) return resolve(window.paypal);
if (findScript(url, dataAttributes) && window.paypal) return resolve(window.paypal);
isLoading = true;

@@ -384,3 +413,3 @@ insertScriptElement({

var version = '1.0.1';
var version = '1.0.2';

@@ -387,0 +416,0 @@ exports.loadScript = loadScript;

/*!
* paypal-js v1.0.1 (2020-09-11T20:27:05.885Z)
* paypal-js v1.0.2 (2020-09-30T18:10:04.928Z)
* Copyright 2020-present, PayPal, Inc. All rights reserved.

@@ -17,2 +17,2 @@ *

*/
var paypalLoadScript=function(t){"use strict";var n=setTimeout;function e(t){return Boolean(t&&void 0!==t.length)}function r(){}function o(t){if(!(this instanceof o))throw new TypeError("Promises must be constructed via new");if("function"!=typeof t)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],s(t,this)}function i(t,n){for(;3===t._state;)t=t._value;0!==t._state?(t._handled=!0,o._immediateFn((function(){var e=1===t._state?n.onFulfilled:n.onRejected;if(null!==e){var r;try{r=e(t._value)}catch(t){return void u(n.promise,t)}a(n.promise,r)}else(1===t._state?a:u)(n.promise,t._value)}))):t._deferreds.push(n)}function a(t,n){try{if(n===t)throw new TypeError("A promise cannot be resolved with itself.");if(n&&("object"==typeof n||"function"==typeof n)){var e=n.then;if(n instanceof o)return t._state=3,t._value=n,void c(t);if("function"==typeof e)return void s((r=e,i=n,function(){r.apply(i,arguments)}),t)}t._state=1,t._value=n,c(t)}catch(n){u(t,n)}var r,i}function u(t,n){t._state=2,t._value=n,c(t)}function c(t){2===t._state&&0===t._deferreds.length&&o._immediateFn((function(){t._handled||o._unhandledRejectionFn(t._value)}));for(var n=0,e=t._deferreds.length;n<e;n++)i(t,t._deferreds[n]);t._deferreds=null}function f(t,n,e){this.onFulfilled="function"==typeof t?t:null,this.onRejected="function"==typeof n?n:null,this.promise=e}function s(t,n){var e=!1;try{t((function(t){e||(e=!0,a(n,t))}),(function(t){e||(e=!0,u(n,t))}))}catch(t){if(e)return;e=!0,u(n,t)}}function l(t){var n="";return d(t,(function(e){0!==n.length&&(n+="&"),n+=e+"="+t[e]})),n}function d(t,n){for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&n(e)}o.prototype.catch=function(t){return this.then(null,t)},o.prototype.then=function(t,n){var e=new this.constructor(r);return i(this,new f(t,n,e)),e},o.prototype.finally=function(t){var n=this.constructor;return this.then((function(e){return n.resolve(t()).then((function(){return e}))}),(function(e){return n.resolve(t()).then((function(){return n.reject(e)}))}))},o.all=function(t){return new o((function(n,r){if(!e(t))return r(new TypeError("Promise.all accepts an array"));var o=Array.prototype.slice.call(t);if(0===o.length)return n([]);var i=o.length;function a(t,e){try{if(e&&("object"==typeof e||"function"==typeof e)){var u=e.then;if("function"==typeof u)return void u.call(e,(function(n){a(t,n)}),r)}o[t]=e,0==--i&&n(o)}catch(t){r(t)}}for(var u=0;u<o.length;u++)a(u,o[u])}))},o.resolve=function(t){return t&&"object"==typeof t&&t.constructor===o?t:new o((function(n){n(t)}))},o.reject=function(t){return new o((function(n,e){e(t)}))},o.race=function(t){return new o((function(n,r){if(!e(t))return r(new TypeError("Promise.race accepts an array"));for(var i=0,a=t.length;i<a;i++)o.resolve(t[i]).then(n,r)}))},o._immediateFn="function"==typeof setImmediate&&function(t){setImmediate(t)}||function(t){n(t,0)},o._unhandledRejectionFn=function(t){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",t)};var p,h=!1;return t.loadScript=function(t){return h?p:p=new o((function(n,e){if("undefined"==typeof window)return n(null);var r=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n={queryParams:{},dataAttributes:{}};d(t,(function(e){"data-"===e.substring(0,5)?n.dataAttributes[e]=t[e]:n.queryParams[e]=t[e]}));var e=n.queryParams,r=n.dataAttributes;return{queryString:l(e),dataAttributes:r}}(t),o=r.queryString,i=r.dataAttributes,a="".concat("https://www.paypal.com/sdk/js","?").concat(o);if(function(t){return document.querySelector('script[src="'.concat(t,'"]'))}(a)&&window.paypal)return n(window.paypal);h=!0,function(t){var n=t.url,e=t.dataAttributes,r=void 0===e?{}:e,o=t.onSuccess,i=t.onError,a=document.createElement("script");a.onerror=i,a.onload=o,d(r,(function(t){a.setAttribute(t,r[t])})),a.src=n,document.head.insertBefore(a,document.head.firstElementChild)}({url:a,dataAttributes:i,onSuccess:function(){return h=!1,window.paypal?n(window.paypal):e(new Error("The window.paypal global variable is not available."))},onError:function(){return h=!1,e(new Error('The script "'.concat(a,"\" didn't load correctly.")))}})}))},t.version="1.0.1",t}({});paypalLoadScript=paypalLoadScript.loadScript;
var paypalLoadScript=function(t){"use strict";var n=setTimeout;function e(t){return Boolean(t&&void 0!==t.length)}function r(){}function o(t){if(!(this instanceof o))throw new TypeError("Promises must be constructed via new");if("function"!=typeof t)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],s(t,this)}function i(t,n){for(;3===t._state;)t=t._value;0!==t._state?(t._handled=!0,o._immediateFn((function(){var e=1===t._state?n.onFulfilled:n.onRejected;if(null!==e){var r;try{r=e(t._value)}catch(t){return void u(n.promise,t)}a(n.promise,r)}else(1===t._state?a:u)(n.promise,t._value)}))):t._deferreds.push(n)}function a(t,n){try{if(n===t)throw new TypeError("A promise cannot be resolved with itself.");if(n&&("object"==typeof n||"function"==typeof n)){var e=n.then;if(n instanceof o)return t._state=3,t._value=n,void c(t);if("function"==typeof e)return void s((r=e,i=n,function(){r.apply(i,arguments)}),t)}t._state=1,t._value=n,c(t)}catch(n){u(t,n)}var r,i}function u(t,n){t._state=2,t._value=n,c(t)}function c(t){2===t._state&&0===t._deferreds.length&&o._immediateFn((function(){t._handled||o._unhandledRejectionFn(t._value)}));for(var n=0,e=t._deferreds.length;n<e;n++)i(t,t._deferreds[n]);t._deferreds=null}function f(t,n,e){this.onFulfilled="function"==typeof t?t:null,this.onRejected="function"==typeof n?n:null,this.promise=e}function s(t,n){var e=!1;try{t((function(t){e||(e=!0,a(n,t))}),(function(t){e||(e=!0,u(n,t))}))}catch(t){if(e)return;e=!0,u(n,t)}}function l(t){var n="";return p(t,(function(e){0!==n.length&&(n+="&"),n+=e+"="+t[e]})),n}function d(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=document.createElement("script");return e.src=t,p(n,(function(t){e.setAttribute(t,n[t])})),e}function p(t,n){for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&n(e)}function h(t){var n=0;return p(t,(function(){return n++})),n}o.prototype.catch=function(t){return this.then(null,t)},o.prototype.then=function(t,n){var e=new this.constructor(r);return i(this,new f(t,n,e)),e},o.prototype.finally=function(t){var n=this.constructor;return this.then((function(e){return n.resolve(t()).then((function(){return e}))}),(function(e){return n.resolve(t()).then((function(){return n.reject(e)}))}))},o.all=function(t){return new o((function(n,r){if(!e(t))return r(new TypeError("Promise.all accepts an array"));var o=Array.prototype.slice.call(t);if(0===o.length)return n([]);var i=o.length;function a(t,e){try{if(e&&("object"==typeof e||"function"==typeof e)){var u=e.then;if("function"==typeof u)return void u.call(e,(function(n){a(t,n)}),r)}o[t]=e,0==--i&&n(o)}catch(t){r(t)}}for(var u=0;u<o.length;u++)a(u,o[u])}))},o.resolve=function(t){return t&&"object"==typeof t&&t.constructor===o?t:new o((function(n){n(t)}))},o.reject=function(t){return new o((function(n,e){e(t)}))},o.race=function(t){return new o((function(n,r){if(!e(t))return r(new TypeError("Promise.race accepts an array"));for(var i=0,a=t.length;i<a;i++)o.resolve(t[i]).then(n,r)}))},o._immediateFn="function"==typeof setImmediate&&function(t){setImmediate(t)}||function(t){n(t,0)},o._unhandledRejectionFn=function(t){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",t)};var v,y=!1;return t.loadScript=function(t){return y?v:v=new o((function(n,e){if("undefined"==typeof window)return n(null);var r=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n={queryParams:{},dataAttributes:{}};p(t,(function(e){"data-"===e.substring(0,5)?n.dataAttributes[e]=t[e]:n.queryParams[e]=t[e]}));var e=n.queryParams,r=n.dataAttributes;return{queryString:l(e),dataAttributes:r}}(t),o=r.queryString,i=r.dataAttributes,a="".concat("https://www.paypal.com/sdk/js","?").concat(o);if(function(t,n){var e=document.querySelector('script[src="'.concat(t,'"]'));if(!e)return null;var r=d(t,n);if(h(e.dataset)!==h(r.dataset))return null;var o=!0;return p(e.dataset,(function(t){e.dataset[t]!==r.dataset[t]&&(o=!1)})),o?e:null}(a,i)&&window.paypal)return n(window.paypal);y=!0,function(t){var n=t.url,e=t.dataAttributes,r=t.onSuccess,o=t.onError,i=d(n,e);i.onerror=o,i.onload=r,document.head.insertBefore(i,document.head.firstElementChild)}({url:a,dataAttributes:i,onSuccess:function(){return y=!1,window.paypal?n(window.paypal):e(new Error("The window.paypal global variable is not available."))},onError:function(){return y=!1,e(new Error('The script "'.concat(a,"\" didn't load correctly.")))}})}))},t.version="1.0.2",t}({});paypalLoadScript=paypalLoadScript.loadScript;
/*!
* paypal-js v1.0.1 (2020-09-11T20:27:05.885Z)
* paypal-js v1.0.2 (2020-09-30T18:10:04.928Z)
* Copyright 2020-present, PayPal, Inc. All rights reserved.

@@ -288,18 +288,28 @@ *

function findScript(url) {
return document.querySelector("script[src=\"".concat(url, "\"]"));
function findScript(url, dataAttributes) {
var currentScript = document.querySelector("script[src=\"".concat(url, "\"]"));
if (!currentScript) return null;
var nextScript = createScriptElement(url, dataAttributes); // check if the new script has the same number of data attributes
if (objectSize(currentScript.dataset) !== objectSize(nextScript.dataset)) {
return null;
}
var isExactMatch = true; // check if the data attribute values are the same
forEachObjectKey(currentScript.dataset, function (key) {
if (currentScript.dataset[key] !== nextScript.dataset[key]) {
isExactMatch = false;
}
});
return isExactMatch ? currentScript : null;
}
function insertScriptElement(_ref) {
var url = _ref.url,
_ref$dataAttributes = _ref.dataAttributes,
dataAttributes = _ref$dataAttributes === void 0 ? {} : _ref$dataAttributes,
dataAttributes = _ref.dataAttributes,
onSuccess = _ref.onSuccess,
onError = _ref.onError;
var newScript = document.createElement('script');
var newScript = createScriptElement(url, dataAttributes);
newScript.onerror = onError;
newScript.onload = onSuccess;
forEachObjectKey(dataAttributes, function (key) {
newScript.setAttribute(key, dataAttributes[key]);
});
newScript.src = url;
document.head.insertBefore(newScript, document.head.firstElementChild);

@@ -334,4 +344,15 @@ }

return queryString;
}
function createScriptElement(url) {
var dataAttributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var newScript = document.createElement('script');
newScript.src = url;
forEachObjectKey(dataAttributes, function (key) {
newScript.setAttribute(key, dataAttributes[key]);
});
return newScript;
} // uses es3 to avoid requiring polyfills for Array.prototype.forEach and Object.keys
function forEachObjectKey(obj, callback) {

@@ -345,2 +366,10 @@ for (var key in obj) {

function objectSize(obj) {
var size = 0;
forEachObjectKey(obj, function () {
return size++;
});
return size;
}
var SDK_BASE_URL = 'https://www.paypal.com/sdk/js';

@@ -362,3 +391,3 @@ var loadingPromise;

if (findScript(url) && window.paypal) return resolve(window.paypal);
if (findScript(url, dataAttributes) && window.paypal) return resolve(window.paypal);
isLoading = true;

@@ -381,4 +410,4 @@ insertScriptElement({

var version = '1.0.1';
var version = '1.0.2';
export { loadScript, version };
/*!
* paypal-js v1.0.1 (2020-09-11T20:27:05.885Z)
* paypal-js v1.0.2 (2020-09-30T18:10:04.928Z)
* Copyright 2020-present, PayPal, Inc. All rights reserved.

@@ -292,18 +292,28 @@ *

function findScript(url) {
return document.querySelector("script[src=\"".concat(url, "\"]"));
function findScript(url, dataAttributes) {
var currentScript = document.querySelector("script[src=\"".concat(url, "\"]"));
if (!currentScript) return null;
var nextScript = createScriptElement(url, dataAttributes); // check if the new script has the same number of data attributes
if (objectSize(currentScript.dataset) !== objectSize(nextScript.dataset)) {
return null;
}
var isExactMatch = true; // check if the data attribute values are the same
forEachObjectKey(currentScript.dataset, function (key) {
if (currentScript.dataset[key] !== nextScript.dataset[key]) {
isExactMatch = false;
}
});
return isExactMatch ? currentScript : null;
}
function insertScriptElement(_ref) {
var url = _ref.url,
_ref$dataAttributes = _ref.dataAttributes,
dataAttributes = _ref$dataAttributes === void 0 ? {} : _ref$dataAttributes,
dataAttributes = _ref.dataAttributes,
onSuccess = _ref.onSuccess,
onError = _ref.onError;
var newScript = document.createElement('script');
var newScript = createScriptElement(url, dataAttributes);
newScript.onerror = onError;
newScript.onload = onSuccess;
forEachObjectKey(dataAttributes, function (key) {
newScript.setAttribute(key, dataAttributes[key]);
});
newScript.src = url;
document.head.insertBefore(newScript, document.head.firstElementChild);

@@ -338,4 +348,15 @@ }

return queryString;
}
function createScriptElement(url) {
var dataAttributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var newScript = document.createElement('script');
newScript.src = url;
forEachObjectKey(dataAttributes, function (key) {
newScript.setAttribute(key, dataAttributes[key]);
});
return newScript;
} // uses es3 to avoid requiring polyfills for Array.prototype.forEach and Object.keys
function forEachObjectKey(obj, callback) {

@@ -349,2 +370,10 @@ for (var key in obj) {

function objectSize(obj) {
var size = 0;
forEachObjectKey(obj, function () {
return size++;
});
return size;
}
var SDK_BASE_URL = 'https://www.paypal.com/sdk/js';

@@ -366,3 +395,3 @@ var loadingPromise;

if (findScript(url) && window.paypal) return resolve(window.paypal);
if (findScript(url, dataAttributes) && window.paypal) return resolve(window.paypal);
isLoading = true;

@@ -385,5 +414,5 @@ insertScriptElement({

var version = '1.0.1';
var version = '1.0.2';
exports.loadScript = loadScript;
exports.version = version;
{
"name": "@paypal/paypal-js",
"version": "1.0.2",
"description": "Async loader for the PayPal JS SDK",
"version": "1.0.3",
"description": "Client-side loader for the PayPal JS SDK",
"main": "dist/paypal.node.js",

@@ -6,0 +6,0 @@ "module": "dist/paypal.esm.js",

# PayPal JS
An async loader for the [PayPal JS SDK](https://developer.paypal.com/docs/checkout/).
A client-side loader for the [PayPal JS SDK](https://developer.paypal.com/docs/business/javascript-sdk/javascript-sdk-reference/).

@@ -11,2 +11,17 @@ <a href="https://www.npmjs.com/package/@paypal/paypal-js"><img src="https://img.shields.io/npm/v/@paypal/paypal-js?style=flat-square" alt="npm version"></a>

## Why use paypal-js?
The [default JS SDK code snippet](https://developer.paypal.com/docs/business/checkout/set-up-standard-payments/#sample-javascript-sdk-code) blocks page rendering:
```html
<script src="https://www.paypal.com/sdk/js?client-id=sb"></script>
<script>paypal.Buttons().render('body');</script>
```
The above snippet can be difficult to implement in a non-blocking way, especially in single page web apps. This is where the paypal-js library comes in. It provides the following benefits over the above snippet:
- Async script loading to ensure page rendering isn't blocked.
- A [Promise API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) to know when script loading is complete.
- A convenient way to reload the script when query parameters or data attributes change.
## Installation

@@ -55,3 +70,3 @@

View the [full list of supported query parameters](https://developer.paypal.com/docs/checkout/reference/customize-sdk/#query-parameters).
View the [full list of supported query parameters](https://developer.paypal.com/docs/business/javascript-sdk/javascript-sdk-configuration/#query-parameters).

@@ -71,3 +86,3 @@ #### Data Attributes

View the [full list of supported script parameters](https://developer.paypal.com/docs/checkout/reference/customize-sdk/#script-parameters).
View the [full list of supported script parameters](https://developer.paypal.com/docs/business/javascript-sdk/javascript-sdk-configuration/#script-parameters).

@@ -74,0 +89,0 @@ ### Using a CDN

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