UNPKG

autogram-sdk

Version:
3 lines 13.3 kB
var AutogramSDK=(()=>{var re=Object.create;var S=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames,M=Object.getOwnPropertySymbols,se=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty,ie=Object.prototype.propertyIsEnumerable;var N=(o,s,r)=>s in o?S(o,s,{enumerable:!0,configurable:!0,writable:!0,value:r}):o[s]=r,H=(o,s)=>{for(var r in s||(s={}))k.call(s,r)&&N(o,r,s[r]);if(M)for(var r of M(s))ie.call(s,r)&&N(o,r,s[r]);return o};var ae=(o,s)=>()=>(s||o((s={exports:{}}).exports,s),s.exports),fe=(o,s)=>{for(var r in s)S(o,r,{get:s[r],enumerable:!0})},V=(o,s,r,u)=>{if(s&&typeof s=="object"||typeof s=="function")for(let i of ne(s))!k.call(o,i)&&i!==r&&S(o,i,{get:()=>s[i],enumerable:!(u=oe(s,i))||u.enumerable});return o};var ue=(o,s,r)=>(r=o!=null?re(se(o)):{},V(s||!o||!o.__esModule?S(r,"default",{value:o,enumerable:!0}):r,o)),ce=o=>V(S({},"__esModule",{value:!0}),o);var $=(o,s,r)=>new Promise((u,i)=>{var h=d=>{try{g(r.next(d))}catch(p){i(p)}},m=d=>{try{g(r.throw(d))}catch(p){i(p)}},g=d=>d.done?u(d.value):Promise.resolve(d.value).then(h,m);g((r=r.apply(o,s)).next())});var z=ae((A,G)=>{var U=typeof globalThis!="undefined"&&globalThis||typeof self!="undefined"&&self||typeof global!="undefined"&&global,I=function(){function o(){this.fetch=!1,this.DOMException=U.DOMException}return o.prototype=U,new o}();(function(o){var s=function(r){var u=typeof o!="undefined"&&o||typeof self!="undefined"&&self||typeof u!="undefined"&&u,i={searchParams:"URLSearchParams"in u,iterable:"Symbol"in u&&"iterator"in Symbol,blob:"FileReader"in u&&"Blob"in u&&function(){try{return new Blob,!0}catch(e){return!1}}(),formData:"FormData"in u,arrayBuffer:"ArrayBuffer"in u};function h(e){return e&&DataView.prototype.isPrototypeOf(e)}if(i.arrayBuffer)var m=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],g=ArrayBuffer.isView||function(e){return e&&m.indexOf(Object.prototype.toString.call(e))>-1};function d(e){if(typeof e!="string"&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(e)||e==="")throw new TypeError('Invalid character in header field name: "'+e+'"');return e.toLowerCase()}function p(e){return typeof e!="string"&&(e=String(e)),e}function w(e){var t={next:function(){var n=e.shift();return{done:n===void 0,value:n}}};return i.iterable&&(t[Symbol.iterator]=function(){return t}),t}function a(e){this.map={},e instanceof a?e.forEach(function(t,n){this.append(n,t)},this):Array.isArray(e)?e.forEach(function(t){this.append(t[0],t[1])},this):e&&Object.getOwnPropertyNames(e).forEach(function(t){this.append(t,e[t])},this)}a.prototype.append=function(e,t){e=d(e),t=p(t);var n=this.map[e];this.map[e]=n?n+", "+t:t},a.prototype.delete=function(e){delete this.map[d(e)]},a.prototype.get=function(e){return e=d(e),this.has(e)?this.map[e]:null},a.prototype.has=function(e){return this.map.hasOwnProperty(d(e))},a.prototype.set=function(e,t){this.map[d(e)]=p(t)},a.prototype.forEach=function(e,t){for(var n in this.map)this.map.hasOwnProperty(n)&&e.call(t,this.map[n],n,this)},a.prototype.keys=function(){var e=[];return this.forEach(function(t,n){e.push(n)}),w(e)},a.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),w(e)},a.prototype.entries=function(){var e=[];return this.forEach(function(t,n){e.push([n,t])}),w(e)},i.iterable&&(a.prototype[Symbol.iterator]=a.prototype.entries);function T(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function P(e){return new Promise(function(t,n){e.onload=function(){t(e.result)},e.onerror=function(){n(e.error)}})}function B(e){var t=new FileReader,n=P(t);return t.readAsArrayBuffer(e),n}function q(e){var t=new FileReader,n=P(t);return t.readAsText(e),n}function R(e){for(var t=new Uint8Array(e),n=new Array(t.length),c=0;c<t.length;c++)n[c]=String.fromCharCode(t[c]);return n.join("")}function E(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function F(){return this.bodyUsed=!1,this._initBody=function(e){this.bodyUsed=this.bodyUsed,this._bodyInit=e,e?typeof e=="string"?this._bodyText=e:i.blob&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:i.formData&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:i.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():i.arrayBuffer&&i.blob&&h(e)?(this._bodyArrayBuffer=E(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):i.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(e)||g(e))?this._bodyArrayBuffer=E(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||(typeof e=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):i.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i.blob&&(this.blob=function(){var e=T(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){if(this._bodyArrayBuffer){var e=T(this);return e||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}else return this.blob().then(B)}),this.text=function(){var e=T(this);if(e)return e;if(this._bodyBlob)return q(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(R(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i.formData&&(this.formData=function(){return this.text().then(Y)}),this.json=function(){return this.text().then(JSON.parse)},this}var Q=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function W(e){var t=e.toUpperCase();return Q.indexOf(t)>-1?t:e}function v(e,t){if(!(this instanceof v))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');t=t||{};var n=t.body;if(e instanceof v){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new a(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,!n&&e._bodyInit!=null&&(n=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",(t.headers||!this.headers)&&(this.headers=new a(t.headers)),this.method=W(t.method||this.method||"GET"),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&n)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(n),(this.method==="GET"||this.method==="HEAD")&&(t.cache==="no-store"||t.cache==="no-cache")){var c=/([?&])_=[^&]*/;if(c.test(this.url))this.url=this.url.replace(c,"$1_="+new Date().getTime());else{var l=/\?/;this.url+=(l.test(this.url)?"&":"?")+"_="+new Date().getTime()}}}v.prototype.clone=function(){return new v(this,{body:this._bodyInit})};function Y(e){var t=new FormData;return e.trim().split("&").forEach(function(n){if(n){var c=n.split("="),l=c.shift().replace(/\+/g," "),f=c.join("=").replace(/\+/g," ");t.append(decodeURIComponent(l),decodeURIComponent(f))}}),t}function Z(e){var t=new a,n=e.replace(/\r?\n[\t ]+/g," ");return n.split("\r").map(function(c){return c.indexOf(` `)===0?c.substr(1,c.length):c}).forEach(function(c){var l=c.split(":"),f=l.shift().trim();if(f){var O=l.join(":").trim();t.append(f,O)}}),t}F.call(v.prototype);function b(e,t){if(!(this instanceof b))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');t||(t={}),this.type="default",this.status=t.status===void 0?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText=t.statusText===void 0?"":""+t.statusText,this.headers=new a(t.headers),this.url=t.url||"",this._initBody(e)}F.call(b.prototype),b.prototype.clone=function(){return new b(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new a(this.headers),url:this.url})},b.error=function(){var e=new b(null,{status:0,statusText:""});return e.type="error",e};var ee=[301,302,303,307,308];b.redirect=function(e,t){if(ee.indexOf(t)===-1)throw new RangeError("Invalid status code");return new b(null,{status:t,headers:{location:e}})},r.DOMException=u.DOMException;try{new r.DOMException}catch(e){r.DOMException=function(t,n){this.message=t,this.name=n;var c=Error(t);this.stack=c.stack},r.DOMException.prototype=Object.create(Error.prototype),r.DOMException.prototype.constructor=r.DOMException}function j(e,t){return new Promise(function(n,c){var l=new v(e,t);if(l.signal&&l.signal.aborted)return c(new r.DOMException("Aborted","AbortError"));var f=new XMLHttpRequest;function O(){f.abort()}f.onload=function(){var y={status:f.status,statusText:f.statusText,headers:Z(f.getAllResponseHeaders()||"")};y.url="responseURL"in f?f.responseURL:y.headers.get("X-Request-URL");var D="response"in f?f.response:f.responseText;setTimeout(function(){n(new b(D,y))},0)},f.onerror=function(){setTimeout(function(){c(new TypeError("Network request failed"))},0)},f.ontimeout=function(){setTimeout(function(){c(new TypeError("Network request failed"))},0)},f.onabort=function(){setTimeout(function(){c(new r.DOMException("Aborted","AbortError"))},0)};function te(y){try{return y===""&&u.location.href?u.location.href:y}catch(D){return y}}f.open(l.method,te(l.url),!0),l.credentials==="include"?f.withCredentials=!0:l.credentials==="omit"&&(f.withCredentials=!1),"responseType"in f&&(i.blob?f.responseType="blob":i.arrayBuffer&&l.headers.get("Content-Type")&&l.headers.get("Content-Type").indexOf("application/octet-stream")!==-1&&(f.responseType="arraybuffer")),t&&typeof t.headers=="object"&&!(t.headers instanceof a)?Object.getOwnPropertyNames(t.headers).forEach(function(y){f.setRequestHeader(y,p(t.headers[y]))}):l.headers.forEach(function(y,D){f.setRequestHeader(D,y)}),l.signal&&(l.signal.addEventListener("abort",O),f.onreadystatechange=function(){f.readyState===4&&l.signal.removeEventListener("abort",O)}),f.send(typeof l._bodyInit=="undefined"?null:l._bodyInit)})}return j.polyfill=!0,u.fetch||(u.fetch=j,u.Headers=a,u.Request=v,u.Response=b),r.Headers=a,r.Request=v,r.Response=b,r.fetch=j,r}({})})(I);I.fetch.ponyfill=!0;delete I.fetch.polyfill;var _=U.fetch?U:I;A=_.fetch;A.default=_.fetch;A.fetch=_.fetch;A.Headers=_.Headers;A.Request=_.Request;A.Response=_.Response;G.exports=A});var he={};fe(he,{UserCancelledSigningException:()=>x,apiClient:()=>J});var C=ue(z());var le=Array.from(Array(256).keys()).map(o=>o.toString(16).padStart(2,"0"));function K(o){return Array.prototype.map.call(o,s=>le[s]).join("")}function X(o){return new DataView(o.buffer,0).getUint32(0)}function L(o){return crypto.getRandomValues(new Uint8Array(o))}function J(o){let s={serverProtocol:"http",serverHost:"localhost",serverPort:37200,customProtocol:"autogram",disableSecurity:!1,requestsOrigin:typeof location!="undefined"?location.origin:"*",secretKey:K(L(32)),secretInitialNonce:X(L(4)),language:"sk"},r=H(H({},s),o),u=new URL(`${r.serverProtocol}://${r.serverHost}:${r.serverPort}`);return{getLaunchURL(i="listen"){let h=new URLSearchParams;return h.set("protocol",r.serverProtocol),h.set("port",r.serverPort.toString()),h.set("host",r.serverHost),h.set("origin",r.requestsOrigin),r.language&&h.set("language",r.language),r.disableSecurity||(r.secretKey&&h.set("key",r.secretKey),r.secretInitialNonce&&h.set("nonce",r.secretInitialNonce.toString())),`${r.customProtocol}://${i}?${h}`},info(){let i=new URL("info",u),h={cache:"no-store"};return(0,C.default)(i.toString(),h).then(m=>m.json())},waitForStatus(i,h=60,m=4,g){let d=new URL("info",u);return new Promise((p,w)=>$(this,null,function*(){let a,T,P=new Error("No request ever finished"),B=!1;g&&g.signal.addEventListener("abort",()=>{a.signal.aborted||a.abort(),B=!0,w(new Error("Aborted"))});let q=setTimeout(()=>{a.signal.aborted||a.abort(),B=!0,w(P)},h*1e3);for(;!B;){a=new AbortController;let R=setTimeout(()=>{a.signal.aborted||a.abort()},(m+1)*1e3);try{if(T=yield(yield(0,C.default)(d.toString(),{cache:"no-store",signal:a.signal})).json(),T.status===i){B=!0,clearTimeout(q),clearTimeout(R),p(T);break}}catch(E){clearTimeout(R),E.name!=="AbortError"&&(P=E)}yield new Promise(E=>setTimeout(E,m*1e3))}}))},sign(i,h={level:"XAdES_BASELINE_B",checkPDFACompliance:!0},m="application/xml"){let g=new URL("sign",u),p={method:"POST",headers:{"Content-Type":"text/plain"},cache:"no-store",body:JSON.stringify({document:i,parameters:h,payloadMimeType:m})};return(0,C.default)(g.toString(),p).then(w=>{if(w.status==204)throw new x;return w.json()})}}}var x=class{};return ce(he);})(); //# sourceMappingURL=index.global.js.map