UNPKG

kite-publisher

Version:

The Kite Publisher Javascript plugin lets you add one-click trade buttons to your webpage. It works like a basket combined with a payment gateway, where an inline popup opens on your webpage, guides the user through a trade, and lands the user back on you

1 lines 4.69 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.KitePublisher=e():t.KitePublisher=e()}(self,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var o in n)t.o(n,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:n[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{KiteConnect:()=>o,KitePublisher:()=>r,default:()=>i});var n=function(){return n=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},n.apply(this,arguments)},o=function(){function t(t,e){this.basket=[],this.finishedCallback=null,this.options={api_key:t,redirect_url:null!=e?e:"#"}}return t.prototype.add=function(t){if(this.basket.length>=50)return!1;var e={};return["variety","exchange","tradingsymbol","transaction_type","quantity","order_type","price","trigger_price","product","validity","readonly","tag","stoploss","squareoff","trailing_stoploss","disclosed_quantity"].forEach((function(n){void 0!==t[n]&&(e[n]=t[n])})),this.basket.push(e),!0},t.prototype.connect=function(){if(0!==this.basket.length){var t=n({data:JSON.stringify(this.basket)},this.options),e=this.createForm(t,"https://kite.zerodha.com/connect/basket","post");this.showPopup(e)}},t.prototype.renderButton=function(t){var e,n=this,o=jQuery(t),r=jQuery("<button>").addClass("kite-trade-button").text("Trade with Kite");if(1===this.basket.length){var i=this.basket[0];r.addClass("kite-".concat(null===(e=null==i?void 0:i.transaction_type)||void 0===e?void 0:e.toLowerCase())),r.attr("title","".concat(i.transaction_type," ").concat(i.tradingsymbol))}r.on("click",(function(t){t.preventDefault(),n.connect()})),o.append(r)},t.prototype.createForm=function(t,e,n){var o=jQuery("<form>").attr({method:n,action:e});return Object.entries(t).forEach((function(t){var e=t[0],n=t[1];return o.append(jQuery("<input>").attr({name:e,type:"hidden",value:n}))})),o[0]},t.prototype.showPopup=function(t){var e=Math.min(window.screen.width/2,500),n=Math.min(window.screen.height/1.5,500),o=(window.screen.width-e)/2,r=(window.screen.height-n)/2,i=window.open("","Kite","width=".concat(e,",height=").concat(n,",left=").concat(o,",top=").concat(r));if(!i)throw new Error("Popup blocked");var a=i.document.body;jQuery(a).empty().append(t),setTimeout((function(){return t.submit()}),500)},t}(),r=function(){function t(t,e){this.apiKey=t,this.redirectUrl=e,this.kite=null}return t.prototype.initialize=function(){return t=this,e=void 0,r=function(){var t=this;return function(t,e){var n,o,r,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=c(0),a.throw=c(1),a.return=c(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function c(c){return function(u){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(i=0)),i;)try{if(n=1,o&&(r=2&c[0]?o.return:c[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,c[1])).done)return r;switch(o=0,r&&(c=[2&c[0],r.value]),c[0]){case 0:case 1:r=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,o=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!((r=(r=i.trys).length>0&&r[r.length-1])||6!==c[0]&&2!==c[0])){i=0;continue}if(3===c[0]&&(!r||c[1]>r[0]&&c[1]<r[3])){i.label=c[1];break}if(6===c[0]&&i.label<r[1]){i.label=r[1],r=c;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(c);break}r[2]&&i.ops.pop(),i.trys.pop();continue}c=e.call(t,i)}catch(t){c=[6,t],o=0}finally{n=r=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,u])}}}(this,(function(e){return[2,new Promise((function(e){jQuery((function(){t.kite=new o(t.apiKey,t.redirectUrl),e(t.kite)}))}))]}))},new((n=void 0)||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function c(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,c)}u((r=r.apply(t,e||[])).next())}));var t,e,n,r},t.prototype.addStockToBasket=function(t){if(!this.kite)throw new Error("Kite not initialized. Call initialize() first.");this.kite.add(t)},t.prototype.renderButton=function(t){if(!this.kite)throw new Error("Kite not initialized. Call initialize() first.");this.kite.renderButton(t)},t}();const i=r;return e})()));