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

@commercetools/checkout-browser-sdk

Package Overview
Dependencies
Maintainers
12
Versions
23
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.7.0 to 0.7.1

2

browser/sdk.js

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

(function(o){typeof define=="function"&&define.amd?define(o):o()})(function(){"use strict";let o={};class p extends Error{constructor(c){super(`Missing field in the configuration: ${c}`),Object.setPrototypeOf(this,p.prototype)}}const M=()=>{if(!o.region&&!o.host)throw new p("region");return o.region&&o.region.startsWith("http")?o.region:o.region?`https://app.checkout.${o.region}.commercetools.com`:o.host},b=()=>o,d=(e,c=!1)=>(c&&(o={}),o={skipConfirmationPages:"skipConfirmationPages"in e?e.skipConfirmationPages:o.skipConfirmationPages,accessToken:"accessToken"in e?e.accessToken:o.accessToken,applicationId:"applicationId"in e?e.applicationId:o.applicationId,applicationKey:"applicationKey"in e?e.applicationKey:o.applicationKey,callbackUrl:"callbackUrl"in e?e.callbackUrl:o.callbackUrl,returnUrl:"returnUrl"in e?e.returnUrl:o.returnUrl,sellerId:"sellerId"in e?e.sellerId:o.sellerId,cartId:"cartId"in e?e.cartId:o.cartId,host:"host"in e?e.host:o.host,paymentReference:"paymentReference"in e?e.paymentReference:o.paymentReference,locale:"locale"in e?e.locale:o.locale,projectKey:"projectKey"in e?e.projectKey:o.projectKey,storeKey:"storeKey"in e?e.storeKey:o.storeKey,styles:"styles"in e?e.styles:o.styles,languageOverrides:"languageOverrides"in e?e.languageOverrides:o.languageOverrides,forms:"forms"in e?e.forms:o.forms,currencyLocale:"currencyLocale"in e?e.currencyLocale:o.currencyLocale,showTaxes:"showTaxes"in e?e.showTaxes:o.showTaxes,sessionId:"sessionId"in e?e.sessionId:o.sessionId,region:"region"in e?e.region:o.region,browserSdkVersion:"0.7.0"},o),E=e=>c=>{if(!e||!c)return!1;if(e==="*"||c===e)return!0;const t=e.split(":"),s=c.split(":");return!s[0]||t[0]!==s[0]?!1:E(t.slice(1).join(":"))(s.slice(1).join(":"))},v={},m=(e,c)=>{const t=`${e}_${Math.round(Math.random()*1e15)}`,s=({origin:r,data:i})=>{if(r!==window.location.origin||i.source!=="commercetoolsCheckout")return;const a=i||{};E(e)(a.type)&&c(a)};return window.addEventListener("message",s),v[t]=s,t},l=e=>window.removeEventListener("message",v[e]),n={},h=(e,c)=>{[["info","onInfo"],["warn","onWarn"],["error","onError"]].forEach(t=>{const s=t[0],r=t[1];c&&n[r]&&l(n[r]),typeof e[r]=="function"&&(n[r]&&l(n[r]),n[r]=m(`${s}:*`,e[r]))})},y=(e,c)=>{[["info","logInfo"],["warn","logWarn"],["error","logError"]].forEach(t=>{const s=t[0],r=t[1];c&&n[r]&&l(n[r]),e[r]===!0&&(n[r]&&l(n[r]),n[r]=m(`${s}:*`,function(i){i.payload!==void 0?console[s]("[ctc]",i.code,i.payload):console[s]("[ctc]",i.code)}))})},$=e=>{if(typeof e!="object")throw new Error("Bad config, please review docs");typeof e.checkoutConfig=="object"&&d(e.checkoutConfig),h(e),y(e)},I="commercetools-checkout",K="data-ctc";let u;const U=document.body.style.overflow,j=()=>{const e=document.querySelectorAll(`[${K}]`);return e.length>0&&(e[0]instanceof HTMLDivElement||e[0]instanceof HTMLSpanElement)?e[0]:null},f=()=>{if(window.commercetoolsCheckout&&window.commercetoolsCheckout.root&&window.commercetoolsCheckout.root.unmount)window.commercetoolsCheckout.root.unmount();else{const t=j();t&&(t.innerHTML="")}const c=document.getElementById(I);c&&(document.body.style.overflow=U,c.remove()),u&&window.removeEventListener("message",u)},A=e=>{u=({origin:c,data:t})=>{var s;if(c===window.location.origin){if((t==null?void 0:t.code)==="checkout_cancelled"&&f(),(t==null?void 0:t.code)==="checkout_loaded"){const r=Object.assign({},b());window.postMessage({code:"init_checkout",payload:{...r,checkoutMode:e}},window.location.origin)}if((t==null?void 0:t.code)==="checkout_completed"){f();const{id:r}=((s=t==null?void 0:t.payload)==null?void 0:s.order)||{},{callbackUrl:i,returnUrl:a}=b();a?window.location.href=`${a}?orderId=${r}`:i&&(window.location.href=`${i}?orderId=${r}`)}}},window.addEventListener("message",u)},k=async(e="complete-flow")=>{if(f(),A(e),!j()){const c=document.createElement("div");c.setAttribute("id",I),document.body.appendChild(c),document.body.style.overflow="hidden"}if(typeof window.commercetoolsCheckout=="object"&&typeof window.commercetoolsCheckout.render=="function")window.commercetoolsCheckout.render();else{const c=document.createElement("script");c.src=`${M()}/main.js`,c.onerror=()=>console.log(`[ctc] Error loading checkout script on ${c.src}`),document.head.appendChild(c)}},L={checkout:e=>{d(e),k()},checkoutFlow:e=>{if(typeof e!="object")throw new Error("Bad config, please review docs");d(e,!0),h(e,!0),y(e,!0),k()},init:$,paymentFlow:e=>{if(typeof e!="object")throw new Error("Bad config, please review docs");d(e,!0),h(e,!0),y(e,!0),k("payment-only")},subscribe:m,unsubscribe:l};function w(e){return L[e]&&L[e].apply(null,Array.prototype.slice.call(arguments,1))}window.ctc&&Array.isArray(window.ctc.queue)&&window.ctc.queue.forEach(e=>w.apply(null,e)),window.ctc&&Array.isArray(window.ctc.q)&&window.ctc.q.forEach(e=>w.apply(null,e)),window.ctc=w});
(function(o){typeof define=="function"&&define.amd?define(o):o()})(function(){"use strict";let o={};class p extends Error{constructor(c){super(`Missing field in the configuration: ${c}`),Object.setPrototypeOf(this,p.prototype)}}const M=()=>{if(!o.region&&!o.host)throw new p("region");return o.region&&o.region.startsWith("http")?o.region:o.region?`https://app.checkout.${o.region}.commercetools.com`:o.host},b=()=>o,d=(e,c=!1)=>(c&&(o={}),o={skipConfirmationPages:"skipConfirmationPages"in e?e.skipConfirmationPages:o.skipConfirmationPages,accessToken:"accessToken"in e?e.accessToken:o.accessToken,applicationId:"applicationId"in e?e.applicationId:o.applicationId,applicationKey:"applicationKey"in e?e.applicationKey:o.applicationKey,callbackUrl:"callbackUrl"in e?e.callbackUrl:o.callbackUrl,returnUrl:"returnUrl"in e?e.returnUrl:o.returnUrl,sellerId:"sellerId"in e?e.sellerId:o.sellerId,cartId:"cartId"in e?e.cartId:o.cartId,host:"host"in e?e.host:o.host,paymentReference:"paymentReference"in e?e.paymentReference:o.paymentReference,locale:"locale"in e?e.locale:o.locale,projectKey:"projectKey"in e?e.projectKey:o.projectKey,storeKey:"storeKey"in e?e.storeKey:o.storeKey,styles:"styles"in e?e.styles:o.styles,languageOverrides:"languageOverrides"in e?e.languageOverrides:o.languageOverrides,forms:"forms"in e?e.forms:o.forms,currencyLocale:"currencyLocale"in e?e.currencyLocale:o.currencyLocale,showTaxes:"showTaxes"in e?e.showTaxes:o.showTaxes,sessionId:"sessionId"in e?e.sessionId:o.sessionId,region:"region"in e?e.region:o.region,browserSdkVersion:"0.7.1"},o),E=e=>c=>{if(!e||!c)return!1;if(e==="*"||c===e)return!0;const t=e.split(":"),s=c.split(":");return!s[0]||t[0]!==s[0]?!1:E(t.slice(1).join(":"))(s.slice(1).join(":"))},v={},m=(e,c)=>{const t=`${e}_${Math.round(Math.random()*1e15)}`,s=({origin:r,data:i})=>{if(r!==window.location.origin||i.source!=="commercetoolsCheckout")return;const a=i||{};E(e)(a.type)&&c(a)};return window.addEventListener("message",s),v[t]=s,t},l=e=>window.removeEventListener("message",v[e]),n={},h=(e,c)=>{[["info","onInfo"],["warn","onWarn"],["error","onError"]].forEach(t=>{const s=t[0],r=t[1];c&&n[r]&&l(n[r]),typeof e[r]=="function"&&(n[r]&&l(n[r]),n[r]=m(`${s}:*`,e[r]))})},y=(e,c)=>{[["info","logInfo"],["warn","logWarn"],["error","logError"]].forEach(t=>{const s=t[0],r=t[1];c&&n[r]&&l(n[r]),e[r]===!0&&(n[r]&&l(n[r]),n[r]=m(`${s}:*`,function(i){i.payload!==void 0?console[s]("[ctc]",i.code,i.payload):console[s]("[ctc]",i.code)}))})},$=e=>{if(typeof e!="object")throw new Error("Bad config, please review docs");typeof e.checkoutConfig=="object"&&d(e.checkoutConfig),h(e),y(e)},I="commercetools-checkout",K="data-ctc";let u;const U=document.body.style.overflow,j=()=>{const e=document.querySelectorAll(`[${K}]`);return e.length>0&&(e[0]instanceof HTMLDivElement||e[0]instanceof HTMLSpanElement)?e[0]:null},f=()=>{if(window.commercetoolsCheckout&&window.commercetoolsCheckout.root&&window.commercetoolsCheckout.root.unmount)window.commercetoolsCheckout.root.unmount();else{const t=j();t&&(t.innerHTML="")}const c=document.getElementById(I);c&&(document.body.style.overflow=U,c.remove()),u&&window.removeEventListener("message",u)},A=e=>{u=({origin:c,data:t})=>{var s;if(c===window.location.origin){if((t==null?void 0:t.code)==="checkout_cancelled"&&f(),(t==null?void 0:t.code)==="checkout_loaded"){const r=Object.assign({},b());window.postMessage({code:"init_checkout",payload:{...r,checkoutMode:e}},window.location.origin)}if((t==null?void 0:t.code)==="checkout_completed"){f();const{id:r}=((s=t==null?void 0:t.payload)==null?void 0:s.order)||{},{callbackUrl:i,returnUrl:a}=b();a?window.location.href=`${a}?orderId=${r}`:i&&(window.location.href=`${i}?orderId=${r}`)}}},window.addEventListener("message",u)},k=async(e="complete-flow")=>{if(f(),A(e),!j()){const c=document.createElement("div");c.setAttribute("id",I),document.body.appendChild(c),document.body.style.overflow="hidden"}if(typeof window.commercetoolsCheckout=="object"&&typeof window.commercetoolsCheckout.render=="function")window.commercetoolsCheckout.render();else{const c=document.createElement("script");c.src=`${M()}/main.js`,c.onerror=()=>console.log(`[ctc] Error loading checkout script on ${c.src}`),document.head.appendChild(c)}},L={checkout:e=>{d(e),k()},checkoutFlow:e=>{if(typeof e!="object")throw new Error("Bad config, please review docs");d(e,!0),h(e,!0),y(e,!0),k()},init:$,paymentFlow:e=>{if(typeof e!="object")throw new Error("Bad config, please review docs");d(e,!0),h(e,!0),y(e,!0),k("payment-only")},subscribe:m,unsubscribe:l};function w(e){return L[e]&&L[e].apply(null,Array.prototype.slice.call(arguments,1))}window.ctc&&Array.isArray(window.ctc.queue)&&window.ctc.queue.forEach(e=>w.apply(null,e)),window.ctc&&Array.isArray(window.ctc.q)&&window.ctc.q.forEach(e=>w.apply(null,e)),window.ctc=w});
# @commercetools/checkout-browser-sdk
## 0.7.1
### Patch Changes
- 09072bf: Fix README.md file
## 0.7.0

@@ -4,0 +10,0 @@

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

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

# Commercetools Checkout Typescript SDK
## Usage examples
## Installation
### Browser environment
### Use as script in the browser

@@ -11,50 +11,21 @@ ```

### Install as module
`npm`
```
<script>
(function(w, d, s){
if (w.ctc) {return;}
var js, fjs = d.getElementsByTagName(s)[0];
var q = [];
w.ctc = w.ctc || function() { q.push(arguments); }
w.ctc.q = q;
js = d.createElement(s);
js.type = 'text/javascript';
js.async = true;
js.src = 'https://cdn.checkout.europe-west1.gcp.commercetools.com/sdk.js';
fjs.parentNode.insertBefore(js, fjs);
}(window, document, 'script'));
ctc('init', {
checkoutConfig: {
sellerId: '{sellerId}',
applicationId: '{applicationId}',
host: 'https://app.checkout.{region}.commercetools.com',
callbackUrl: '{callbackUrl}',
cartId: '{cartId}',
accessToken: '{accessToken}',
locale: '{locale}'
}
});
</script>
npm install @commercetools/checkout-browser-sdk
```
### Node environment
`yarn`
```
yarn add @commercetools/checkout-browser-sdk
```
`pnpm`
```
import sdk from '@commercetools/checkout-browser-sdk';
pnpm add @commercetools/checkout-browser-sdk
```
sdk.init({
checkoutConfig: {
sellerId: '{sellerId}',
applicationId: '{applicationId}',
host: 'https://app.checkout.{region}.commercetools.com',
callbackUrl: '{callbackUrl}',
cartId: '{cartId}',
accessToken: '{accessToken}',
locale: '{locale}'
}
logInfo: true,
logWarn: true,
logError: true,
onInfo: m => console.log('[Info]', m),
});
```
## Documentation
[commercetools Checkout documentation](https://docs.commercetools.com/checkout/sdk)

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