@ekisa-xsighub/sdk
Version:
SDK de emparejamiento que permite la integración de la aplicación móvil con el servidor centralizado para capturar y transferir las firmas de los usuarios en tiempo real.
2 lines (1 loc) • 4.23 kB
JavaScript
;const s=require("qrcode");function _interopDefaultCompat(n){return n&&typeof n=="object"&&"default"in n?n.default:n}const s__default=_interopDefaultCompat(s);class Qr{async generate(t){return new Promise((e,r)=>{s__default.toString(t,(o,i)=>{o&&r(o),e(i)})})}async generatex(t){return new Promise((e,r)=>{s__default.toString(t,(o,i)=>{o&&r(o),e(i)})})}}const handleResponse=async n=>{const t=n.headers.get("content-type");if(!n.ok)throw new Error(await n.text());return t&&t.includes("application/json")?n.json():n.text()};class References{constructor(t){this.config=t,this.api=`${this.config.api}/${this.config.version}/session-references`}async create(t){return fetch(`${this.api}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then(handleResponse)}async update(t,e){return fetch(`${this.api}/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(handleResponse)}async delete(t){return fetch(`${this.api}/${t}`,{method:"DELETE"}).then(handleResponse)}}class Sessions{constructor(t){this.config=t,this.api=`${this.config.api}/${this.config.version}/sessions`}async create(){return fetch(`${this.api}`,{method:"POST",headers:{"Content-Type":"application/json"}}).then(handleResponse)}async findByIpAddress(){return fetch(`${this.api}`).then(handleResponse)}async findByPairingKey(t){return fetch(`${this.api}/${t}`).then(handleResponse)}async pair(t){return fetch(`${this.api}/${t}/pair`,{method:"PATCH"}).then(handleResponse)}async unpair(t){return fetch(`${this.api}/${t}/unpair`,{method:"PATCH"}).then(handleResponse)}async destroy(t){return fetch(`${this.api}/${t}`,{method:"DELETE"}).then(handleResponse)}}class Signatures{constructor(t){this.config=t,this.api=`${this.config.api}/${this.config.version}/session-signatures`}async create(t){return fetch(`${this.api}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then(handleResponse)}async findById(t){return fetch(`${this.api}/${t}`).then(handleResponse)}async update(t,e){return fetch(`${this.api}/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(handleResponse)}async loadMetadata(t,e){return fetch(`${this.api}/${t}/metadata/load`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(handleResponse)}async delete(t){return fetch(`${this.api}/${t}`,{method:"DELETE"}).then(handleResponse)}}class Documents{constructor(t){this.config=t,this.api=`${this.config.api}/${this.config.version}/session-documents`}async create(t){return fetch(`${this.api}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then(handleResponse)}async findById(t){return fetch(`${this.api}/${t}`).then(handleResponse)}async update(t,e){return fetch(`${this.api}/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(handleResponse)}async attach(t,e){return fetch(`${this.api}/${t}/signatures/attach`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(handleResponse)}async delete(t){return fetch(`${this.api}/${t}`,{method:"DELETE",headers:{}}).then(handleResponse)}async loadMetadata(t,e){return fetch(`${this.api}/${t}/metadata/load`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(handleResponse)}populateMetadata(t,e){let r=t;for(const[o,i]of Object.entries(e.ingest)){const c=new RegExp(`\\[metadata:${o}\\]`,"g");r=r.replace(c,i)}return r}extractSignatures(t){const e=/\[signature:(.+?)\]\((.+?)\)/g,r={},o=i=>{if(i===""||i.trim()==="")return!1;try{return atob(i.split(",")[1]),!0}catch{return!1}};for(const i of t.matchAll(e)){const c=i[1],h=i[2];r[c]=o(h)?h:""}return r}}const a=()=>{let n,t,e,r,o,i=!1;const c=()=>{if(!i)throw new Error("SdkClient is not initialized. Make sure to call the init(config) method first.")};return{init(h){return n=new Sessions(h),t=new References(h),e=new Signatures(h),r=new Documents(h),o=new Qr,i=!0,this},get sessions(){return c(),n},get references(){return c(),t},get signatures(){return c(),e},get documents(){return c(),r},get qr(){return c(),o}}},client=a();exports.client=client;