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.0.8 to 0.0.9

2

browser/sdk.js

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

!function(){var o,e,n,t=["dev","stg","prod"],c={},i=function(){return e||!o||"prod"===o?e||"https://app.checkout.europe-west1.gcp.commercetools.com":"https://app.".concat(o,".checkout.europe-west1.gcp.commercetools.com")},r=function(){return c},a=function(o){return arguments.length>1&&void 0!==arguments[1]&&arguments[1]&&(c={}),c={accessToken:"accessToken"in o?o.accessToken:c.accessToken,applicationId:"applicationId"in o?o.applicationId:c.applicationId,callbackUrl:"callbackUrl"in o?o.callbackUrl:c.callbackUrl,cartId:"cartId"in o?o.cartId:c.cartId,locale:"locale"in o?o.locale:c.locale,sellerId:"sellerId"in o?o.sellerId:c.sellerId,storeKey:"storeKey"in o?o.storeKey:c.storeKey,skipShipping:"skipShipping"in o?o.skipShipping:c.skipShipping}},l="ctc-wrapper";(n||(n={})).InitCheckout="init_checkout";var d=function(o){var e=document.body.style.top;window.scrollTo({left:0,top:-1*parseInt(e||"0",10),behavior:"instant"}),document.body.style.overflow="visible";var n=document.getElementById(l);n&&n.remove(),window.removeEventListener("message",o)},s=function(){var o=document.createElement("iframe");return function(o){var e=function(t){var c=t.origin,a=t.data;if(c===i()){if("checkout_cancelled"===(null==a?void 0:a.code)&&d(e),"checkout_loaded"===(null==a?void 0:a.code)){document.body.style.overflow="hidden",document.body.style.top="-".concat(window.scrollY,"px");var l=Object.assign({},r());delete l.callbackUrl,o.contentWindow.postMessage({code:n.InitCheckout,payload:l},i())}if("checkout_completed"===(null==a?void 0:a.code)){var s;d(e);var u=((null==a||null===(s=a.payload)||void 0===s?void 0:s.order)||{}).id,p=r().callbackUrl;p&&(window.location.href="".concat(p,"?orderId=").concat(u))}}};window.addEventListener("message",e)}(o),o.src=i(),o.title="Checkout",o.setAttribute("id",l),o.setAttribute("style","display: none; top: 0; position: fixed; height: 100vh; width: 100vw; z-index: 100000;"),o.onload=function(){o.scrollIntoView({behavior:"smooth",block:"center"})},document.body.appendChild(o),o},u=function(o){return function(e){if(!o||!e)return!1;if("*"===o||e===o)return!0;var n=o.split(":"),t=e.split(":");return!(!t[0]||n[0]!==t[0])&&u(n.slice(1).join(":"))(t.slice(1).join(":"))}},p={},f=function(o,e){var n="".concat(o,"_").concat(Math.round(1e15*Math.random())),t=function(n){var t=n.origin,c=n.data;if(t===i()){var r=c||{};u(o)(r.type)&&e(r)}};return window.addEventListener("message",t),p[n]=t,n},w=function(o){return window.removeEventListener("message",p[o])},v={},y={checkout:function(o){a(o),(document.getElementById(l)||s()).style.display="block"},init:function(n){if("object"!=typeof n)throw new Error("Bad config, please review docs");var c,i;t.includes(n.env)&&(c=n.env,o=c),"string"==typeof n.appHost&&(i=n.appHost,e=i),"object"==typeof n.checkoutConfig&&a(n.checkoutConfig),function(o){[["info","onInfo"],["warn","onWarn"],["error","onError"]].forEach((function(e){var n=e[0],t=e[1];"function"==typeof o[t]&&(v[t]&&w(v[t]),v[t]=f("".concat(n,":*"),o[t]))}))}(n),function(o){[["info","logInfo"],["warn","logWarn"],["error","logError"]].forEach((function(e){var n=e[0],t=e[1];!0===o[t]&&(v[t]&&w(v[t]),v[t]=f("".concat(n,":*"),(function(o){console[n]("[ctc]",o.type,o.code,o.payload||{})})))}))}(n)},subscribe:f,unsubscribe:w};function h(o){return y[o]&&y[o].apply(null,Array.prototype.slice.call(arguments,1))}window.ctc&&Array.isArray(window.ctc.queue)&&window.ctc.queue.forEach((function(o){return h.apply(null,o)})),window.ctc&&Array.isArray(window.ctc.q)&&window.ctc.q.forEach((function(o){return h.apply(null,o)})),window.ctc=h}();
!function(){function t(t){if(void 0===t)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function e(t,n){return(e=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,n)}function n(){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(t){return!1}}function o(t,r,c){return(o=n()?Reflect.construct:function(t,n,o){var r=[null];r.push.apply(r,n);var c=new(Function.bind.apply(t,r));return o&&e(c,o.prototype),c}).apply(null,arguments)}function r(t){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function c(t){var n="function"==typeof Map?new Map:void 0;return(c=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(t))return n.get(t);n.set(t,c)}function c(){return o(t,arguments,r(this).constructor)}return c.prototype=Object.create(t.prototype,{constructor:{value:c,enumerable:!1,writable:!0,configurable:!0}}),e(c,t)})(t)}var i,a={},l=function(o){"use strict";!function(t,n){if("function"!=typeof n&&null!==n)throw TypeError("Super expression must either be null or a function");t.prototype=Object.create(n&&n.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),n&&e(t,n)}(a,o);var c,i=(c=n(),function(){var e,n,o=r(a);if(c){var i=r(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(t,e){if(!(t instanceof e))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}(c(Error)),u=function(){if(!a.host)throw new l("host");return a.host},s=function(){return a},f=function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return e&&(a={}),a={accessToken:"accessToken"in t?t.accessToken:a.accessToken,applicationId:"applicationId"in t?t.applicationId:a.applicationId,callbackUrl:"callbackUrl"in t?t.callbackUrl:a.callbackUrl,cartId:"cartId"in t?t.cartId:a.cartId,locale:"locale"in t?t.locale:a.locale,sellerId:"sellerId"in t?t.sellerId:a.sellerId,storeKey:"storeKey"in t?t.storeKey:a.storeKey,host:"host"in t?t.host:a.host,skipShipping:"skipShipping"in t?t.skipShipping:a.skipShipping,styles:"styles"in t?t.styles:a.styles,languageOverrides:"languageOverrides"in t?t.languageOverrides:a.languageOverrides}},d="ctc-wrapper";(i||(i={})).InitCheckout="init_checkout";var p=function(t){var e=document.body.style.top;window.scrollTo({left:0,top:-1*parseInt(e||"0",10),behavior:"instant"}),document.body.style.overflow="visible";var n=document.getElementById(d);n&&n.remove(),window.removeEventListener("message",t)},y=function(t){var e=function(n){var o=n.origin,r=n.data;if(o===u()){if((null==r?void 0:r.code)==="checkout_cancelled"&&p(e),(null==r?void 0:r.code)==="checkout_loaded"){document.body.style.overflow="hidden",document.body.style.top="-".concat(window.scrollY,"px");var c=Object.assign({},s());delete c.callbackUrl,t.contentWindow.postMessage({code:i.InitCheckout,payload:c},u())}if((null==r?void 0:r.code)==="checkout_completed"){p(e);var a,l=((null==r?void 0:null===(a=r.payload)||void 0===a?void 0:a.order)||{}).id,f=s().callbackUrl;f&&(window.location.href="".concat(f,"?orderId=").concat(l))}}};window.addEventListener("message",e)},h=function(){var t=document.createElement("iframe");return y(t),t.src=u(),t.title="Checkout",t.setAttribute("id",d),t.setAttribute("style","display: none; top: 0; position: fixed; height: 100vh; width: 100vw; z-index: 100000;"),t.onload=function(){t.scrollIntoView({behavior:"smooth",block:"center"})},document.body.appendChild(t),t},v=function(t){return function(e){if(!t||!e)return!1;if("*"===t||e===t)return!0;var n=t.split(":"),o=e.split(":");return!!o[0]&&n[0]===o[0]&&v(n.slice(1).join(":"))(o.slice(1).join(":"))}},w={},b=function(t,e){var n="".concat(t,"_").concat(Math.round(1e15*Math.random())),o=function(n){var o=n.origin,r=n.data;if(o===u()){var c=r||{};v(t)(c.type)&&e(c)}};return window.addEventListener("message",o),w[n]=o,n},g=function(t){return window.removeEventListener("message",w[t])},m={},k=function(t){[["info","onInfo"],["warn","onWarn"],["error","onError"]].forEach(function(e){var n=e[0],o=e[1];"function"==typeof t[o]&&(m[o]&&g(m[o]),m[o]=b("".concat(n,":*"),t[o]))})},I=function(t){[["info","logInfo"],["warn","logWarn"],["error","logError"]].forEach(function(e){var n=e[0],o=e[1];!0===t[o]&&(m[o]&&g(m[o]),m[o]=b("".concat(n,":*"),function(t){console[n]("[ctc]",t.type,t.code,t.payload||{})}))})},E={checkout:function(t){f(t),(document.getElementById(d)||h()).style.display="block"},init:function(t){if("object"!=typeof t)throw Error("Bad config, please review docs");"object"==typeof t.checkoutConfig&&f(t.checkoutConfig),k(t),I(t)},subscribe:b,unsubscribe:g};function O(t){return E[t]&&E[t].apply(null,Array.prototype.slice.call(arguments,1))}window.ctc&&Array.isArray(window.ctc.queue)&&window.ctc.queue.forEach(function(t){return O.apply(null,t)}),window.ctc&&Array.isArray(window.ctc.q)&&window.ctc.q.forEach(function(t){return O.apply(null,t)}),window.ctc=O}();

@@ -16,3 +16,2 @@ "use strict";

top: parseInt(scrollY || '0', 10) * -1,
// @ts-expect-error - https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1195
behavior: 'instant',

@@ -19,0 +18,0 @@ });

@@ -1,6 +0,5 @@

import { CheckoutData, Env } from './services/config';
import { CheckoutData } from './services/config';
import { Handler } from './subscriptions';
type Config = {
checkoutConfig: CheckoutData;
env?: Env;
onInfo?: Handler;

@@ -7,0 +6,0 @@ onWarn?: Handler;

@@ -42,10 +42,2 @@ "use strict";

throw new Error('Bad config, please review docs');
if (config_1.ENVS.includes(config.env))
(0, config_1.setEnv)(config.env);
// We don't want to expose appHost as part of the public config but we still want to
// be able to override this value during development
if (process.env.APP_HOST)
(0, config_1.setAppHost)(process.env.APP_HOST);
if (typeof config['appHost'] === 'string')
(0, config_1.setAppHost)(config['appHost']);
if (typeof config.checkoutConfig === 'object')

@@ -52,0 +44,0 @@ (0, config_1.updateCheckoutConfig)(config.checkoutConfig);

@@ -1,3 +0,4 @@

export declare const ENVS: readonly ["dev", "stg", "prod"];
export type Env = (typeof ENVS)[number];
type Definitions = Record<string, string> | {
[key: string]: Definitions;
};
export type CheckoutData = {

@@ -12,8 +13,12 @@ accessToken?: string;

skipShipping?: boolean;
host?: string;
styles?: Record<string, string>;
languageOverrides?: Definitions;
};
export declare const getEnv: () => Env;
export declare const setEnv: (newEnv: Env) => void;
export declare const setAppHost: (newAppHost: string) => void;
export declare class MissingConfigurationField extends Error {
constructor(fieldName: string);
}
export declare const getAppHost: () => string;
export declare const getCheckoutConfig: () => CheckoutData;
export declare const updateCheckoutConfig: (newConfig: CheckoutData, reset?: boolean) => CheckoutData;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateCheckoutConfig = exports.getCheckoutConfig = exports.getAppHost = exports.setAppHost = exports.setEnv = exports.getEnv = exports.ENVS = void 0;
exports.ENVS = ['dev', 'stg', 'prod'];
let env;
let appHost;
exports.updateCheckoutConfig = exports.getCheckoutConfig = exports.getAppHost = exports.MissingConfigurationField = void 0;
let checkoutConfig = {};
const getEnv = () => env;
exports.getEnv = getEnv;
const setEnv = (newEnv) => {
env = newEnv;
class MissingConfigurationField extends Error {
constructor(fieldName) {
super(`Missing field in the configuration: ${fieldName}`);
Object.setPrototypeOf(this, MissingConfigurationField.prototype);
}
}
exports.MissingConfigurationField = MissingConfigurationField;
const getAppHost = () => {
if (!checkoutConfig.host) {
throw new MissingConfigurationField('host');
}
return checkoutConfig.host;
};
exports.setEnv = setEnv;
const setAppHost = (newAppHost) => {
appHost = newAppHost;
};
exports.setAppHost = setAppHost;
const getAppHost = () => appHost || !env || env === 'prod'
? appHost || 'https://app.checkout.europe-west1.gcp.commercetools.com'
: `https://app.${env}.checkout.europe-west1.gcp.commercetools.com`;
exports.getAppHost = getAppHost;

@@ -35,3 +32,8 @@ const getCheckoutConfig = () => checkoutConfig;

storeKey: 'storeKey' in newConfig ? newConfig.storeKey : checkoutConfig.storeKey,
host: 'host' in newConfig ? newConfig.host : checkoutConfig.host,
skipShipping: 'skipShipping' in newConfig ? newConfig.skipShipping : checkoutConfig.skipShipping,
styles: 'styles' in newConfig ? newConfig.styles : checkoutConfig.styles,
languageOverrides: 'languageOverrides' in newConfig
? newConfig.languageOverrides
: checkoutConfig.languageOverrides,
};

@@ -38,0 +40,0 @@ return checkoutConfig;

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

@@ -11,4 +11,4 @@ "types": "dist/index.d.ts",

"dependencies": {
"@swc/helpers": "0.5.0"
"@swc/helpers": "0.5.1"
}
}

@@ -29,2 +29,3 @@ # Commercetools Checkout Typescript SDK

applicationId: '{applicationId}',
host: 'https://app.checkout.{region}.commercetools.com',
callbackUrl: '{callbackUrl}',

@@ -45,17 +46,16 @@ cartId: '{cartId}',

sdk.init({
logInfo: true,
logWarn: true,
logError: true,
onInfo: m => console.log('[Info]', m),
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),
});
sdk.checkout({
sellerId: 'some-seller-id',
applicationId: 'some-application-id',
callbackUrl: window.location.origin + "/confirmation",
cartId: 'some-id',
accessToken: 'some-access-token',
locale: 'en'
});
```

Sorry, the diff of this file is not supported yet

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