Socket
Socket
Sign inDemoInstall

@commercetools/checkout-browser-sdk

Package Overview
Dependencies
Maintainers
12
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commercetools/checkout-browser-sdk - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

16

browser/sdk.js

@@ -1,8 +0,8 @@

!function(){function e(e,t,n,o,r,c,i){try{var a=e[c](i),l=a.value}catch(e){n(e);return}a.done?t(l):Promise.resolve(l).then(o,r)}function t(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function n(e,t){return(n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function o(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function r(e,t,c){return(r=o()?Reflect.construct:function(e,t,o){var r=[null];r.push.apply(r,t);var c=new(Function.bind.apply(e,r));return o&&n(c,o.prototype),c}).apply(null,arguments)}function c(e){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function i(e){var t="function"==typeof Map?new Map:void 0;return(i=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,o)}function o(){return r(e,arguments,c(this).constructor)}return o.prototype=Object.create(e.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),n(o,e)})(e)}"function"==typeof SuppressedError&&SuppressedError;var a,l,u,s,f={},p=/*#__PURE__*/function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&n(e,t)}(a,e);var r,i=(r=o(),function(){var e,n,o=c(a);if(r){var i=c(this).constructor;n=Reflect.construct(o,arguments,i)}else n=o.apply(this,arguments);return(e=n)&&("object"==(e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)||"function"==typeof e)?e:t(this)});function a(e){var n;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,a),Object.setPrototypeOf(t(n=i.call(this,"Missing field in the configuration: ".concat(e))),a.prototype),n}return a}(i(Error)),d=function(){if(!f.host)throw new p("host");return f.host},y=function(){return h()?d():window.location.origin},h=function(){return!!f.iframe},v=function(){return f},w=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return t&&(f={}),// if ('callbackUrl' in newConfig) announceDeprecatedField('callbackUrl', 'returnUrl')
f={//not documented
iframe:"iframe"in e?!!e.iframe:f.iframe,// deprecated
applicationId:"applicationId"in e?e.applicationId:f.applicationId,callbackUrl:"callbackUrl"in e?e.callbackUrl:f.callbackUrl,sellerId:"sellerId"in e?e.sellerId:f.sellerId,// documented
accessToken:"accessToken"in e?e.accessToken:f.accessToken,applicationKey:"applicationKey"in e?e.applicationKey:f.applicationKey,returnUrl:"callbackUrl"in e?e.returnUrl:f.returnUrl,cartId:"cartId"in e?e.cartId:f.cartId,locale:"locale"in e?e.locale:f.locale,projectKey:"sellerId"in e?e.projectKey:f.projectKey,storeKey:"storeKey"in e?e.storeKey:f.storeKey,host:"host"in e?e.host:f.host,skipShipping:"skipShipping"in e?e.skipShipping:f.skipShipping,styles:"styles"in e?e.styles:f.styles,languageOverrides:"languageOverrides"in e?e.languageOverrides:f.languageOverrides,forms:"forms"in e?e.forms:f.forms,currencyLocale:"currencyLocale"in e?e.currencyLocale:f.currencyLocale,showTaxes:"showTaxes"in e?e.showTaxes:f.showTaxes}},b="commercetools-checkout",m=document.body.style.overflow,g=function(){var e=document.querySelectorAll("[".concat("data-ctc","]"));return e.length>0&&(e[0]instanceof HTMLDivElement||e[0]instanceof HTMLSpanElement)?e[0]:null};(s||(s={})).InitCheckout="init_checkout";var k=function(){var e=document.getElementById(b);e&&(document.body.style.overflow=m,e.remove());var t=g();t&&(t.innerHTML=""),u&&window.removeEventListener("message",u)},E=function(e){u=function(t){var n=t.origin,o=t.data;if(n===y()){if((null==o?void 0:o.code)==="checkout_cancelled"&&k(),(null==o?void 0:o.code)==="checkout_loaded"){var r=Object.assign({},v());delete r.callbackUrl,(e?e.contentWindow:window).postMessage({code:s.InitCheckout,payload:r},y())}if((null==o?void 0:o.code)==="checkout_completed"){k();var c,i=((null==o?void 0:null===(c=o.payload)||void 0===c?void 0:c.order)||{}).id,a=v().callbackUrl;a&&(window.location.href="".concat(a,"?orderId=").concat(i))}}},window.addEventListener("message",u)},I=function(){// create the iframe and append to the document body
var e=document.createElement("iframe");return E(e),e.src=d(),e.title="Checkout",e.setAttribute("id",b),e.setAttribute("style","display: none; top: 0; position: fixed; height: 100%; width: 100%; z-index: 100000;"),e.onload=function(){// scroll to the iframe
e.scrollIntoView({behavior:"smooth",block:"center"})},document.body.appendChild(e),document.body.style.overflow="hidden",e},O=(a=function(){var e,t,n,o,r,c,i,a,l,u,s;return n=this,o=function(n){return k(),E(),g()||((e=document.createElement("div")).setAttribute("id",b),document.body.appendChild(e),document.body.style.overflow="hidden"),"object"==typeof window.commercetoolsCheckout&&"function"==typeof window.commercetoolsCheckout.render?window.commercetoolsCheckout.render():((t=document.createElement("script")).src="".concat(d(),"/main.js"),document.head.appendChild(t)),[2]},r=function(e){return function(t){return c([e,t])}},c=function(e){if(i)throw TypeError("Generator is already executing.");for(;u&&(u=0,e[0]&&(s=0)),s;)try{if(i=1,a&&(l=2&e[0]?a.return:e[0]?a.throw||((l=a.return)&&l.call(a),0):a.next)&&!(l=l.call(a,e[1])).done)return l;switch(a=0,l&&(e=[2&e[0],l.value]),e[0]){case 0:case 1:l=e;break;case 4:return s.label++,{value:e[1],done:!1};case 5:s.label++,a=e[1],e=[0];continue;case 7:e=s.ops.pop(),s.trys.pop();continue;default:if(!(l=(l=s.trys).length>0&&l[l.length-1])&&(6===e[0]||2===e[0])){s=0;continue}if(3===e[0]&&(!l||e[1]>l[0]&&e[1]<l[3])){s.label=e[1];break}if(6===e[0]&&s.label<l[1]){s.label=l[1],l=e;break}if(l&&s.label<l[2]){s.label=l[2],s.ops.push(e);break}l[2]&&s.ops.pop(),s.trys.pop();continue}e=o.call(n,s)}catch(t){e=[6,t],a=0}finally{i=l=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}},s={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},u={next:r(0),throw:r(1),return:r(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u},l=function(){var t=this,n=arguments;return new Promise(function(o,r){var c=a.apply(t,n);function i(t){e(c,o,r,i,l,"next",t)}function l(t){e(c,o,r,i,l,"throw",t)}i(void 0)})},function(){return l.apply(this,arguments)}),j=function(e){return function(t){if(!e||!t)return!1;if("*"===e||t===e)return!0;var n=e.split(":"),o=t.split(":");return!!o[0]&&n[0]===o[0]&&j(n.slice(1).join(":"))(o.slice(1).join(":"))}},S={},T=function(e,t){var n="".concat(e,"_").concat(Math.round(1e15*Math.random())),o=function(n){var o=n.origin,r=n.data;if(o===y()){var c=r||{};j(e)(c.type)&&t(c)}};return window.addEventListener("message",o),S[n]=o,n},x=function(e){return window.removeEventListener("message",S[e])},_={},C=function(e){[["info","onInfo"],["warn","onWarn"],["error","onError"]].forEach(function(t){var n=t[0],o=t[1];"function"==typeof e[o]&&(_[o]&&x(_[o]),_[o]=T("".concat(n,":*"),e[o]))})},K=function(e){[["info","logInfo"],["warn","logWarn"],["error","logError"]].forEach(function(t){var n=t[0],o=t[1];!0===e[o]&&(_[o]&&x(_[o]),_[o]=T("".concat(n,":*"),function(e){console[n]("[ctc]",e.type,e.code,e.payload||{})}))})},L={checkout:function(e){w(e),h()?(document.getElementById(b)||I()).style.display="block":O()},init:function(e){if("object"!=typeof e)throw Error("Bad config, please review docs");"object"==typeof e.checkoutConfig&&w(e.checkoutConfig),C(e),K(e)},subscribe:T,unsubscribe:x};function U(e){// eslint-disable-next-line prefer-rest-params
return L[e]&&L[e].apply(null,Array.prototype.slice.call(arguments,1))}window.ctc&&Array.isArray(window.ctc.queue)&&window.ctc.queue.forEach(function(e){return U.apply(null,e)}),window.ctc&&Array.isArray(window.ctc.q)&&window.ctc.q.forEach(function(e){return U.apply(null,e)}),window.ctc=U}();
!function(){var e;let o,t={};class n extends Error{constructor(e){super(`Missing field in the configuration: ${e}`),Object.setPrototypeOf(this,n.prototype)}}let c=()=>{if(!t.host)throw new n("host");return t.host},r=()=>i()?c():window.location.origin,i=()=>!!t.iframe,l=()=>t,a=(e,o=!1)=>(o&&(t={}),// if ('callbackUrl' in newConfig) announceDeprecatedField('callbackUrl', 'returnUrl')
t={//not documented
iframe:"iframe"in e?!!e.iframe:t.iframe,// deprecated
applicationId:"applicationId"in e?e.applicationId:t.applicationId,callbackUrl:"callbackUrl"in e?e.callbackUrl:t.callbackUrl,sellerId:"sellerId"in e?e.sellerId:t.sellerId,// documented
accessToken:"accessToken"in e?e.accessToken:t.accessToken,applicationKey:"applicationKey"in e?e.applicationKey:t.applicationKey,returnUrl:"callbackUrl"in e?e.returnUrl:t.returnUrl,cartId:"cartId"in e?e.cartId:t.cartId,locale:"locale"in e?e.locale:t.locale,projectKey:"projectKey"in e?e.projectKey:t.projectKey,storeKey:"storeKey"in e?e.storeKey:t.storeKey,host:"host"in e?e.host:t.host,skipShipping:"skipShipping"in e?e.skipShipping:t.skipShipping,styles:"styles"in e?e.styles:t.styles,languageOverrides:"languageOverrides"in e?e.languageOverrides:t.languageOverrides,forms:"forms"in e?e.forms:t.forms,currencyLocale:"currencyLocale"in e?e.currencyLocale:t.currencyLocale,showTaxes:"showTaxes"in e?e.showTaxes:t.showTaxes}),s="commercetools-checkout",d=document.body.style.overflow,u=()=>{let e=document.querySelectorAll("[data-ctc]");return e.length>0&&(e[0]instanceof HTMLDivElement||e[0]instanceof HTMLSpanElement)?e[0]:null};(e||(e={})).InitCheckout="init_checkout";let p=()=>{let e=document.getElementById(s);e&&(document.body.style.overflow=d,e.remove());let t=u();t&&(t.innerHTML=""),o&&window.removeEventListener("message",o)},y=e=>{o=({origin:o,data:t})=>{if(o===r()){if((null==t?void 0:t.code)==="checkout_cancelled"&&p(),(null==t?void 0:t.code)==="checkout_loaded"){let o=Object.assign({},l());delete o.callbackUrl;let t=e?e.contentWindow:window;t.postMessage({code:"init_checkout",payload:o},r())}if((null==t?void 0:t.code)==="checkout_completed"){var n;p();let{id:e}=(null==t?void 0:null===(n=t.payload)||void 0===n?void 0:n.order)||{},{callbackUrl:o}=l();o&&(window.location.href=`${o}?orderId=${e}`)}}},window.addEventListener("message",o)},f=()=>{// create the iframe and append to the document body
let e=document.createElement("iframe");return y(e),e.src=c(),e.title="Checkout",e.setAttribute("id",s),e.setAttribute("style","display: none; top: 0; position: fixed; height: 100%; width: 100%; z-index: 100000;"),e.onload=()=>{// scroll to the iframe
e.scrollIntoView({behavior:"smooth",block:"center"})},document.body.appendChild(e),document.body.style.overflow="hidden",e},h=async()=>{if(p(),y(),!u()){let e=document.createElement("div");e.setAttribute("id",s),document.body.appendChild(e),document.body.style.overflow="hidden"}if("object"==typeof window.commercetoolsCheckout&&"function"==typeof window.commercetoolsCheckout.render)window.commercetoolsCheckout.render();else{let e=document.createElement("script");e.src=`${c()}/main.js`,document.head.appendChild(e)}},m=e=>o=>{if(!e||!o)return!1;if("*"===e||o===e)return!0;let t=e.split(":"),n=o.split(":");return!!n[0]&&t[0]===n[0]&&m(t.slice(1).join(":"))(n.slice(1).join(":"))},w={},g=(e,o)=>{let t=`${e}_${Math.round(1e15*Math.random())}`,n=({origin:t,data:n})=>{if(t!==r()||"commercetoolsCheckout"!==n.source)return;let c=n||{};m(e)(c.type)&&o(c)};return window.addEventListener("message",n),w[t]=n,t},k=e=>window.removeEventListener("message",w[e]),b={},v=e=>{[["info","onInfo"],["warn","onWarn"],["error","onError"]].forEach(o=>{let t=o[0],n=o[1];"function"==typeof e[n]&&(b[n]&&k(b[n]),b[n]=g(`${t}:*`,e[n]))})},E=e=>{[["info","logInfo"],["warn","logWarn"],["error","logError"]].forEach(o=>{let t=o[0],n=o[1];!0===e[n]&&(b[n]&&k(b[n]),b[n]=g(`${t}:*`,function(e){console[t]("[ctc]",e.type,e.code,e.payload||{})}))})},I={checkout:e=>{if(a(e),i()){let e=document.getElementById(s)||f();e.style.display="block"}else h()},init:e=>{if("object"!=typeof e)throw Error("Bad config, please review docs");"object"==typeof e.checkoutConfig&&a(e.checkoutConfig),v(e),E(e)},subscribe:g,unsubscribe:k};function j(e){// eslint-disable-next-line prefer-rest-params
return I[e]&&I[e].apply(null,Array.prototype.slice.call(arguments,1))}window.ctc&&Array.isArray(window.ctc.queue)&&window.ctc.queue.forEach(e=>j.apply(null,e)),window.ctc&&Array.isArray(window.ctc.q)&&window.ctc.q.forEach(e=>j.apply(null,e)),window.ctc=j}();
# @commercetools/checkout-browser-sdk
## 0.4.0
### Minor Changes
- 427ec82fc7: Added new origin field to seller messages
### Patch Changes
- 6bacadd7cd: Patch bump for CI/CD testing purposes
## 0.3.0

@@ -4,0 +14,0 @@

@@ -45,3 +45,3 @@ "use strict";

locale: 'locale' in newConfig ? newConfig.locale : checkoutConfig.locale,
projectKey: 'sellerId' in newConfig ? newConfig.projectKey : checkoutConfig.projectKey,
projectKey: 'projectKey' in newConfig ? newConfig.projectKey : checkoutConfig.projectKey,
storeKey: 'storeKey' in newConfig ? newConfig.storeKey : checkoutConfig.storeKey,

@@ -48,0 +48,0 @@ host: 'host' in newConfig ? newConfig.host : checkoutConfig.host,

export type Message = {
source: string;
type: string;

@@ -3,0 +4,0 @@ code: string;

@@ -27,2 +27,4 @@ "use strict";

return;
if (data.source !== 'commercetoolsCheckout')
return;
const message = data || {};

@@ -29,0 +31,0 @@ if ((0, exports.typeMatches)(pattern)(message.type)) {

{
"private": false,
"name": "@commercetools/checkout-browser-sdk",
"version": "0.3.0",
"version": "0.4.0",
"main": "dist/index.js",

@@ -6,0 +6,0 @@ "types": "dist/index.d.ts",

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