UNPKG

@codemaster138/authy-client

Version:
1 lines 4.49 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.authy=t():e.authy=t()}(this,(function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t,n){"use strict";e.exports=n(1)},function(e,t,n){"use strict";function o(e){for(var t=document.cookie?document.cookie.split("; "):[],n={},o=0;o<t.length;o++){var r=t[o].split("=");n[decodeURIComponent(r[0])]=decodeURIComponent(r[1])}return e?n[e]:n}function r(e,t,n){n=n||{},null===t&&(n.expires=-1),"number"==typeof n.expires&&(n.expires=new Date((new Date).getTime()+1e3*n.expires)),document.cookie=[encodeURIComponent(e)+"="+encodeURIComponent(t),n.expires?"; expires="+n.expires.toUTCString():"",n.domain?"; domain="+n.domain:"",n.path?"; path="+n.path:"",n.secure?"; secure":""].join("")}e.exports=function(e,t,n){return 0===arguments.length?o():1===arguments.length?o(e):void r(e,t,n)}},function(e,t,n){"use strict";async function o(e,{username:t,email:n,password:o}){return new Promise((r,i)=>{e.app||i("Must define app before using authy"),t||i("Missing required argument: config.username"),n||i("Missing required argument: config.email"),o||i("Missing required argument: config.password"),fetch(`${e.protocol}://${e.host}:${e.port}/create`,{headers:[["content-type","application/json"]],method:"post",body:JSON.stringify({app:e.app,name:t,email:n,pass:o})}).then(e=>"2"===e.status.toString()[0]?e.text().then(e=>r(e)):e.text().then(e=>i(e))).catch(e=>{i(e)})})}n.r(t),n.d(t,"core",(function(){return a})),n.d(t,"init",(function(){return u})),n.d(t,"createUser",(function(){return l})),n.d(t,"login",(function(){return d}));class r{constructor(e){this.globals=e}async read(e){let t=await fetch(`${this.globals.protocol}://${this.globals.host}:${this.globals.port}/fromSession`,{credentials:"include",headers:[["content-type","application/json"]],method:"post",body:JSON.stringify({path:e})});return await t.json()}async write(e){await fetch(`${this.globals.protocol}://${this.globals.host}:${this.globals.port}/toSession`,{credentials:"include",headers:[["content-type","application/json"]],method:"post",body:JSON.stringify({data:e})})}async writeUser(e){await fetch(`${this.globals.protocol}://${this.globals.host}:${this.globals.port}/toAccount`,{credentials:"include",headers:[["content-type","application/json"]],method:"post",body:JSON.stringify({data:e})})}async readUser(e){let t=await fetch(`${this.globals.protocol}://${this.globals.host}:${this.globals.port}/fromAccount`,{credentials:"include",headers:[["content-type","application/json"]],method:"post",body:JSON.stringify({path:e})});return await t.json()}}function i(e){return new r(e)}async function s(e,t){return new Promise((n,o)=>{e.app||o("Must define app before using authy"),t.username||o("Missing required argument: config.username"),t.password||o("Missing required argument: config.password"),t.setCookie=t.setCookie||!0,fetch(`${e.protocol}://${e.host}:${e.port}/login`,{headers:[["content-type","application/json"]],method:"post",credentials:"include",body:JSON.stringify({app:e.app,name:t.username,pass:t.password})}).then(t=>"2"===t.status.toString()[0]?t.text().then(t=>{e.setSession(i(e)),n(t)}):t.text().then(e=>o(e))).catch(e=>{o(e)})})}n(0);var a={},c={host:"localhost",port:"8080",protocol:"http",setSession:e=>{a.session=e}};function u(e){e=e||{},c={...c,...e}}function p(e,...t){if(!c.app)throw"Error: Must define app before using authy";return e(...t)}function l(...e){return p(o,c,...e)}function d(...e){return p(s,c,...e)}a.session=i(c)}])}));