@pay-com/js 1.1.7 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -441,7 +441,7 @@ declare module '@pay-com/js' {
441
441
  export function loadScript(
442
442
  options: PayComScriptOptions,
443
443
  PromisePonyfill?: PromiseConstructor
444
- ): Promise<PayComNamespace | null>
444
+ ): Promise<PayComNamespace>
445
445
 
446
446
  export function loadCustomScript(options: {
447
447
  url: string
@@ -1,11 +1,19 @@
1
1
  type StringMap = Record<string, string>;
2
- export declare function findScript(url: string, attributes?: StringMap): HTMLScriptElement | null;
2
+ export declare const findScript: (url: string, attributes?: StringMap) => HTMLScriptElement | null;
3
3
  export interface ScriptElement {
4
4
  url: string;
5
5
  attributes?: StringMap;
6
6
  onSuccess: () => void;
7
- onError: OnErrorEventHandler;
7
+ onError: () => void;
8
8
  }
9
- export declare function insertScriptElement({ url, attributes, onSuccess, onError }: ScriptElement): void;
10
- export declare function objectToQueryString(params: StringMap): string;
9
+ export declare const insertScriptElement: ({ url, attributes, onSuccess, onError }: ScriptElement) => void;
10
+ export declare const getDefaultPromiseImplementation: () => PromiseConstructor;
11
+ export declare const validateArguments: (options: unknown, PromisePonyfill?: unknown) => void;
12
+ export declare const objectToQueryString: (params: StringMap) => string;
13
+ export interface AttachScriptListenersI {
14
+ script: HTMLScriptElement;
15
+ onSuccess: () => void;
16
+ onError: () => void;
17
+ }
18
+ export declare const attachScriptListeners: ({ script, onSuccess, onError }: AttachScriptListenersI) => void;
11
19
  export {};
package/lib/index.d.ts CHANGED
@@ -440,7 +440,7 @@ declare module '@pay-com/js' {
440
440
  export function loadScript(
441
441
  options: PayComScriptOptions,
442
442
  PromisePonyfill?: PromiseConstructor
443
- ): Promise<PayComNamespace | null>
443
+ ): Promise<PayComNamespace>
444
444
 
445
445
  export function loadCustomScript(options: {
446
446
  url: string
package/lib/index.esm.js CHANGED
@@ -1 +1 @@
1
- var e=function(){return e=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};function t(e,t,r,n){return new(r||(r=Promise))((function(o,i){function u(e){try{a(n.next(e))}catch(e){i(e)}}function c(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(u,c)}a((n=n.apply(e,t||[])).next())}))}function r(e,t){var r,n,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,n=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=t.call(e,u)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}function n(e,t){void 0===t&&(t={});var r=document.createElement("script");return r.src=e,Object.keys(t).forEach((function(e){r.setAttribute(e,t[e]),"data-csp-nonce"===e&&r.setAttribute("nonce",t["data-csp-nonce"])})),r}function o(t,r){if(u(t,r),"undefined"==typeof window)return r.resolve(null);var o=t.live,c=t.sdkUrlOverride,a=o?"https://js.pay.com/v1.js":"https://js.staging.pay.com/v1.js";c&&(a=c);var l="Pay",s=i(l);return function(t,r){var o=document.querySelector('script[src="'.concat(t,'"]'));if(null===o)return null;var i=n(t,r),u=e({},o.dataset);if(delete u.uidAuto,Object.keys(u).length!==Object.keys(i.dataset).length)return null;var c=!0;return Object.keys(u).forEach((function(e){u[e]!==i.dataset[e]&&(c=!1)})),c?o:null}(a)&&s?r.resolve(s):function(e,t){u(e,t);var r=e.url,o=e.attributes;if("string"!=typeof r||0===r.length)throw new Error("Invalid url.");if(void 0!==o&&"object"!=typeof o)throw new Error("Expected attributes to be an object.");return new t((function(e,t){return"undefined"==typeof window?e():function(e){var t=e.url,r=e.attributes,o=e.onSuccess,i=e.onError,u=n(t,r);u.onerror=i,u.onload=o,document.head.insertBefore(u,document.head.firstElementChild)}({url:r,attributes:o,onSuccess:function(){return e()},onError:function(){return t(new Error('The script "'.concat(r,'" failed to load.')))}})}))}({url:a},r).then((function(){var e=i(l);if(e)return e;throw new Error("The window.".concat(l," global variable is not available."))}))}function i(e){return window[e]}function u(e,t){if("object"!=typeof e||null===e)throw new Error("Expected an options object.");if(void 0!==t&&"function"!=typeof t)throw new Error("Expected PromisePonyfill to be a function.")}"function"==typeof SuppressedError&&SuppressedError;var c={com:function(e,n){return void 0===n&&(n=function(){if("undefined"==typeof Promise)throw new Error("Promise is undefined. To resolve the issue, use a Promise polyfill.");return Promise}()),t(void 0,void 0,void 0,(function(){var t;return r(this,(function(r){switch(r.label){case 0:return[4,o(e,n)];case 1:if(!(t=r.sent()))throw new Error("Wrong script URL provided");return[2,t.com(e)]}}))}))}};export{c as default};
1
+ var e=function(){return e=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e},e.apply(this,arguments)};function r(e,r,t,n){return new(t||(t=Promise))((function(o,i){function c(e){try{a(n.next(e))}catch(e){i(e)}}function u(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var r;e.done?o(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(c,u)}a((n=n.apply(e,r||[])).next())}))}function t(e,r){var t,n,o,i,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(a){return function(u){if(t)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(c=0)),c;)try{if(t=1,n&&(o=2&u[0]?n.return:u[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;switch(n=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return c.label++,{value:u[1],done:!1};case 5:c.label++,n=u[1],u=[0];continue;case 7:u=c.ops.pop(),c.trys.pop();continue;default:if(!(o=c.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){c=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){c.label=u[1];break}if(6===u[0]&&c.label<o[1]){c.label=o[1],o=u;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(u);break}o[2]&&c.ops.pop(),c.trys.pop();continue}u=r.call(e,c)}catch(e){u=[6,e],n=0}finally{t=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,a])}}}"function"==typeof SuppressedError&&SuppressedError;var n=function(e,r){if("object"!=typeof e||null===e)throw new Error("Expected an options object.");if(void 0!==r&&"function"!=typeof r)throw new Error("Expected PromisePonyfill to be a function.")},o=function(e){var r=e.script,t=e.onSuccess,n=e.onError;r.addEventListener("load",t,!1),r.addEventListener("error",n,!1)},i=function(e,r){void 0===r&&(r={});var t=document.createElement("script");return t.src=e,Object.keys(r).forEach((function(e){t.setAttribute(e,r[e]),"data-csp-nonce"===e&&t.setAttribute("nonce",r["data-csp-nonce"])})),t},c=function(r,t){n(r,t);var c=r.live,a=r.sdkUrlOverride,s=c?"https://js.pay.com/v1.js":"https://js.staging.pay.com/v1.js";a&&(s=a);var l=window.Pay,f=function(r,t){var n=document.querySelector('script[src="'.concat(r,'"]'));if(!n)return null;var o=i(r,t),c=e({},n.dataset);return delete c.uidAuto,Object.keys(c).length!==Object.keys(o.dataset).length?null:Object.entries(c).every((function(e){var r=e[0];return e[1]===o.dataset[r]}))?n:null}(s);return f&&l?t.resolve(l):f?new t((function(e,r){o({script:f,onSuccess:function(){var t=window.Pay;if(t)return e(t);r(new Error("The script failed to load."))},onError:function(){return r(new Error("The script failed to load."))}})})):u({url:s},t).then((function(){var e=window.Pay;if(e)return e;throw new Error("The window.Pay global variable is not available.")}))},u=function(e,r){n(e,r);var t=e.url,c=e.attributes;if("string"!=typeof t||0===t.length)throw new Error("Invalid url.");if(void 0!==c&&"object"!=typeof c)throw new Error("Expected attributes to be an object.");return new r((function(e,r){return function(e){var r=e.url,t=e.attributes,n=e.onSuccess,c=e.onError,u=i(r,t);o({script:u,onSuccess:n,onError:c}),document.head.insertBefore(u,document.head.firstElementChild)}({url:t,attributes:c,onSuccess:function(){return e()},onError:function(){return r(new Error('The script "'.concat(t,'" failed to load.')))}})}))},a={com:function(e,n){return void 0===n&&(n=function(){if("undefined"==typeof Promise)throw new Error("Promise is undefined. To resolve the issue, use a Promise polyfill.");return Promise}()),r(void 0,void 0,void 0,(function(){return t(this,(function(r){switch(r.label){case 0:return[4,c(e,n)];case 1:return[2,r.sent().com(e)]}}))}))}};export{a as default};
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Pay=t()}(this,(function(){"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};function t(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,c)}a((r=r.apply(e,t||[])).next())}))}function n(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=t.call(e,u)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}function r(e,t){void 0===t&&(t={});var n=document.createElement("script");return n.src=e,Object.keys(t).forEach((function(e){n.setAttribute(e,t[e]),"data-csp-nonce"===e&&n.setAttribute("nonce",t["data-csp-nonce"])})),n}function o(t,n){if(u(t,n),"undefined"==typeof window)return n.resolve(null);var o=t.live,c=t.sdkUrlOverride,a=o?"https://js.pay.com/v1.js":"https://js.staging.pay.com/v1.js";c&&(a=c);var l="Pay",f=i(l);return function(t,n){var o=document.querySelector('script[src="'.concat(t,'"]'));if(null===o)return null;var i=r(t,n),u=e({},o.dataset);if(delete u.uidAuto,Object.keys(u).length!==Object.keys(i.dataset).length)return null;var c=!0;return Object.keys(u).forEach((function(e){u[e]!==i.dataset[e]&&(c=!1)})),c?o:null}(a)&&f?n.resolve(f):function(e,t){u(e,t);var n=e.url,o=e.attributes;if("string"!=typeof n||0===n.length)throw new Error("Invalid url.");if(void 0!==o&&"object"!=typeof o)throw new Error("Expected attributes to be an object.");return new t((function(e,t){return"undefined"==typeof window?e():function(e){var t=e.url,n=e.attributes,o=e.onSuccess,i=e.onError,u=r(t,n);u.onerror=i,u.onload=o,document.head.insertBefore(u,document.head.firstElementChild)}({url:n,attributes:o,onSuccess:function(){return e()},onError:function(){return t(new Error('The script "'.concat(n,'" failed to load.')))}})}))}({url:a},n).then((function(){var e=i(l);if(e)return e;throw new Error("The window.".concat(l," global variable is not available."))}))}function i(e){return window[e]}function u(e,t){if("object"!=typeof e||null===e)throw new Error("Expected an options object.");if(void 0!==t&&"function"!=typeof t)throw new Error("Expected PromisePonyfill to be a function.")}"function"==typeof SuppressedError&&SuppressedError;return{com:function(e,r){return void 0===r&&(r=function(){if("undefined"==typeof Promise)throw new Error("Promise is undefined. To resolve the issue, use a Promise polyfill.");return Promise}()),t(void 0,void 0,void 0,(function(){var t;return n(this,(function(n){switch(n.label){case 0:return[4,o(e,r)];case 1:if(!(t=n.sent()))throw new Error("Wrong script URL provided");return[2,t.com(e)]}}))}))}}}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Pay=t()}(this,(function(){"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};function t(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,c)}a((r=r.apply(e,t||[])).next())}))}function n(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=t.call(e,u)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}"function"==typeof SuppressedError&&SuppressedError;var r=function(e,t){if("object"!=typeof e||null===e)throw new Error("Expected an options object.");if(void 0!==t&&"function"!=typeof t)throw new Error("Expected PromisePonyfill to be a function.")},o=function(e){var t=e.script,n=e.onSuccess,r=e.onError;t.addEventListener("load",n,!1),t.addEventListener("error",r,!1)},i=function(e,t){void 0===t&&(t={});var n=document.createElement("script");return n.src=e,Object.keys(t).forEach((function(e){n.setAttribute(e,t[e]),"data-csp-nonce"===e&&n.setAttribute("nonce",t["data-csp-nonce"])})),n},u=function(t,n){r(t,n);var u=t.live,a=t.sdkUrlOverride,s=u?"https://js.pay.com/v1.js":"https://js.staging.pay.com/v1.js";a&&(s=a);var l=window.Pay,f=function(t,n){var r=document.querySelector('script[src="'.concat(t,'"]'));if(!r)return null;var o=i(t,n),u=e({},r.dataset);return delete u.uidAuto,Object.keys(u).length!==Object.keys(o.dataset).length?null:Object.entries(u).every((function(e){var t=e[0];return e[1]===o.dataset[t]}))?r:null}(s);return f&&l?n.resolve(l):f?new n((function(e,t){o({script:f,onSuccess:function(){var n=window.Pay;if(n)return e(n);t(new Error("The script failed to load."))},onError:function(){return t(new Error("The script failed to load."))}})})):c({url:s},n).then((function(){var e=window.Pay;if(e)return e;throw new Error("The window.Pay global variable is not available.")}))},c=function(e,t){r(e,t);var n=e.url,u=e.attributes;if("string"!=typeof n||0===n.length)throw new Error("Invalid url.");if(void 0!==u&&"object"!=typeof u)throw new Error("Expected attributes to be an object.");return new t((function(e,t){return function(e){var t=e.url,n=e.attributes,r=e.onSuccess,u=e.onError,c=i(t,n);o({script:c,onSuccess:r,onError:u}),document.head.insertBefore(c,document.head.firstElementChild)}({url:n,attributes:u,onSuccess:function(){return e()},onError:function(){return t(new Error('The script "'.concat(n,'" failed to load.')))}})}))};return{com:function(e,r){return void 0===r&&(r=function(){if("undefined"==typeof Promise)throw new Error("Promise is undefined. To resolve the issue, use a Promise polyfill.");return Promise}()),t(void 0,void 0,void 0,(function(){return n(this,(function(t){switch(t.label){case 0:return[4,u(e,r)];case 1:return[2,t.sent().com(e)]}}))}))}}}));
package/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "@pay-com/js",
3
- "version": "1.1.7",
4
- "description": "",
3
+ "version": "1.1.8",
4
+ "description": "Pay.com JS loading utility",
5
5
  "keywords": [
6
- "payments"
6
+ "Pay.com",
7
+ "Pay.com js",
8
+ "Pay Components"
7
9
  ],
8
10
  "license": "MIT",
9
11
  "author": "Pay.com",