UNPKG

@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) 3.71 kB
import c from"qrcode";class p{async generate(t){return new Promise((e,r)=>{c.toString(t,(a,s)=>{a&&r(a),e(s)})})}async generatex(t){return new Promise((e,r)=>{c.toString(t,(a,s)=>{a&&r(a),e(s)})})}}const n=async i=>{const t=i.headers.get("content-type");if(!i.ok)throw new Error(await i.text());return t&&t.includes("application/json")?i.json():i.text()};class d{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(n)}async update(t,e){return fetch(`${this.api}/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(n)}async delete(t){return fetch(`${this.api}/${t}`,{method:"DELETE"}).then(n)}}class y{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(n)}async findByIpAddress(){return fetch(`${this.api}`).then(n)}async findByPairingKey(t){return fetch(`${this.api}/${t}`).then(n)}async pair(t){return fetch(`${this.api}/${t}/pair`,{method:"PATCH"}).then(n)}async unpair(t){return fetch(`${this.api}/${t}/unpair`,{method:"PATCH"}).then(n)}async destroy(t){return fetch(`${this.api}/${t}`,{method:"DELETE"}).then(n)}}class f{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(n)}async findById(t){return fetch(`${this.api}/${t}`).then(n)}async update(t,e){return fetch(`${this.api}/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(n)}async loadMetadata(t,e){return fetch(`${this.api}/${t}/metadata/load`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(n)}async delete(t){return fetch(`${this.api}/${t}`,{method:"DELETE"}).then(n)}}class u{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(n)}async findById(t){return fetch(`${this.api}/${t}`).then(n)}async update(t,e){return fetch(`${this.api}/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(n)}async attach(t,e){return fetch(`${this.api}/${t}/signatures/attach`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(n)}async delete(t){return fetch(`${this.api}/${t}`,{method:"DELETE",headers:{}}).then(n)}async loadMetadata(t,e){return fetch(`${this.api}/${t}/metadata/load`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(n)}populateMetadata(t,e){let r=t;for(const[a,s]of Object.entries(e.ingest)){const o=new RegExp(`\\[metadata:${a}\\]`,"g");r=r.replace(o,s)}return r}extractSignatures(t){const e=/\[signature:(.+?)\]\((.+?)\)/g,r={},a=s=>{if(s===""||s.trim()==="")return!1;try{return atob(s.split(",")[1]),!0}catch{return!1}};for(const s of t.matchAll(e)){const o=s[1],h=s[2];r[o]=a(h)?h:""}return r}}const $=()=>{let i,t,e,r,a,s=!1;const o=()=>{if(!s)throw new Error("SdkClient is not initialized. Make sure to call the init(config) method first.")};return{init(h){return i=new y(h),t=new d(h),e=new f(h),r=new u(h),a=new p,s=!0,this},get sessions(){return o(),i},get references(){return o(),t},get signatures(){return o(),e},get documents(){return o(),r},get qr(){return o(),a}}},g=$();export{g as client};