@hostlink/light 2.5.4 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- (function(d,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("json-to-graphql-query"),require("axios"),require("collect.js")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","axios","collect.js"],y):(d=typeof globalThis<"u"?globalThis:d||self,y(d.light={},d.jsonToGraphqlQuery,d.axios,d.collect))})(this,function(d,y,O,k){"use strict";var de=Object.defineProperty;var ge=(d,y,O)=>y in d?de(d,y,{enumerable:!0,configurable:!0,writable:!0,value:O}):d[y]=O;var b=(d,y,O)=>ge(d,typeof y!="symbol"?y+"":y,O);function N(e){const t="==".slice(0,(4-e.length%4)%4),r=e.replace(/-/g,"+").replace(/_/g,"/")+t,s=atob(r),n=new ArrayBuffer(s.length),i=new Uint8Array(n);for(let u=0;u<s.length;u++)i[u]=s.charCodeAt(u);return n}function L(e){const t=new Uint8Array(e);let r="";for(const i of t)r+=String.fromCharCode(i);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var f="copy",m="convert";function S(e,t,r){if(t===f)return r;if(t===m)return e(r);if(t instanceof Array)return r.map(s=>S(e,t[0],s));if(t instanceof Object){const s={};for(const[n,i]of Object.entries(t)){if(i.derive){const u=i.derive(r);u!==void 0&&(r[n]=u)}if(!(n in r)){if(i.required)throw new Error(`Missing key: ${n}`);continue}if(r[n]==null){s[n]=null;continue}s[n]=S(e,i.schema,r[n])}return s}}function E(e,t){return{required:!0,schema:e,derive:t}}function p(e){return{required:!0,schema:e}}function h(e){return{required:!1,schema:e}}var T={type:p(f),id:p(m),transports:h(f)},U={appid:h(f),appidExclude:h(f),credProps:h(f)},J={appid:h(f),appidExclude:h(f),credProps:h(f)},I={publicKey:p({rp:p(f),user:p({id:p(m),name:p(f),displayName:p(f)}),challenge:p(m),pubKeyCredParams:p(f),timeout:h(f),excludeCredentials:h([T]),authenticatorSelection:h(f),attestation:h(f),extensions:h(U)}),signal:h(f)},W={type:p(f),id:p(f),rawId:p(m),authenticatorAttachment:h(f),response:p({clientDataJSON:p(m),attestationObject:p(m),transports:E(f,e=>{var t;return((t=e.getTransports)==null?void 0:t.call(e))||[]})}),clientExtensionResults:E(J,e=>e.getClientExtensionResults())},K={mediation:h(f),publicKey:p({challenge:p(m),timeout:h(f),rpId:h(f),allowCredentials:h([T]),userVerification:h(f),extensions:h(U)}),signal:h(f)},M={type:p(f),id:p(f),rawId:p(m),authenticatorAttachment:h(f),response:p({clientDataJSON:p(m),authenticatorData:p(m),signature:p(m),userHandle:p(m)}),clientExtensionResults:E(J,e=>e.getClientExtensionResults())};function z(e){return S(N,I,e)}function Q(e){return S(L,W,e)}function G(e){return S(N,K,e)}function $(e){return S(L,M,e)}async function H(e){const t=await navigator.credentials.create(e);return t.toJSON=()=>Q(t),t}async function X(e){const t=await navigator.credentials.get(e);return t.toJSON=()=>$(t),t}const Y=e=>({login:async t=>{const{app:r}=await w(e,{app:{auth:{webAuthnRequestOptions:{__args:{username:t}}}}}),s=r.auth.webAuthnRequestOptions,n=G({publicKey:s}),i=await X(n);await o(e,"webAuthnAssertion",{username:t,assertion:i.toJSON()})},register:async()=>{const{app:t}=await w(e,{app:{auth:{webAuthnCreationOptions:!0}}}),r=z({publicKey:t.auth.webAuthnCreationOptions}),s=await H(r);await o(e,"webAuthnRegister",{registration:s.toJSON()})}}),Z=e=>({WebAuthn:Y(e),google:{unlink:()=>o(e,"lightAuthUnlinkGoogle"),login:t=>o(e,"lightAuthLoginGoogle",{credential:t}),register:t=>o(e,"lightAuthRegisterGoogle",{credential:t})},facebook:{unlink:()=>o(e,"lightAuthUnlinkFacebook"),login:t=>o(e,"lightAuthLoginFacebook",{access_token:t}),register:t=>o(e,"lightAuthRegisterFacebook",{access_token:t})},microsoft:{unlink:()=>o(e,"lightAuthUnlinkMicrosoft"),login:t=>o(e,"lightAuthLoginMicrosoft",{access_token:t}),register:t=>o(e,"lightAuthRegisterMicrosoft",{account_id:t})},login:(t,r,s="")=>o(e,"login",{username:t,password:r,code:s}),logout:()=>o(e,"logout"),changeExpiredPassword:(t,r,s)=>o(e,"changeExpiredPassword",{username:t,old_password:r,new_password:s}),updatePassword:(t,r)=>o(e,"updatePassword",{old_password:t,new_password:r}),resetPassword:(t,r,s)=>o(e,"resetPassword",{username:t,password:r,code:s}),forgetPassword:(t,r)=>o(e,"forgetPassword",{username:t,email:r}),verifyCode(t,r){return o(e,"forgetPasswordVerifyCode",{username:t,code:r})},granted:async t=>(await w(e,{granted:{__args:{rights:t}}})).granted}),x=(e,t,r)=>{const s=t,n=e,i=r;let u="list"+t;const l=a=>i[a]?i[a]():null;return{field:l,$fields:i,setDataPath(a){return u=a,u},getDataPath(){return u},gqlFields(a){const c=[];for(const g of a)if(typeof g=="string"){const C=l(g);C&&c.push(C.getGQLField())}else typeof g=="object"&&c.push(g);return c},async update(a,c){return await o(n,"update"+s,{id:a,data:c})},async delete(a){return await o(n,"delete"+s,{id:a})},async add(a){return await o(n,"add"+s,{data:a})},fields(a){let c=[];for(let g of a){const C=l(g);C&&c.push(C)}return c},async get(a,c){return(await w(n,{["list"+s]:{__args:{filters:a},data:{__args:{limit:1},...B(c)}}}))["list"+s].data[0]},async list(a,c){return(await w(n,{["list"+s]:{__args:{filters:a},data:{...B(c)}}}))["list"+s].data}}};function ee(e){e="<~"+e+"~>";var t,r,s,n,i,u=String,l=255;for(e.slice(0,2)==="<~"&&e.slice(-2),e=e.slice(2,-2).replace(/\s/g,"").replace("z","!!!!!"),t="uuuuu".slice(e.length%5||5),e+=t,s=[],n=0,i=e.length;i>n;n+=5)r=52200625*(e.charCodeAt(n)-33)+614125*(e.charCodeAt(n+1)-33)+7225*(e.charCodeAt(n+2)-33)+85*(e.charCodeAt(n+3)-33)+(e.charCodeAt(n+4)-33),s.push(l&r>>24,l&r>>16,l&r>>8,l&r);return function(a,c){for(var g=c;g>0;g--)a.pop()}(s,t.length),u.fromCharCode.apply(u,s)}const P=(e="")=>{const t=e,r=(s="application/octet-stream")=>{const n=new Uint8Array(t.length);for(let l=0;l<t.length;l++)n[l]=t.charCodeAt(l);const i=new Blob([n],{type:s});return URL.createObjectURL(i)};return{getContent:()=>t,getURL:r,download:s=>{const n=document.createElement("a");n.download=s,n.href=r(),document.body.appendChild(n),n.click(),document.body.removeChild(n)},open:s=>{window.open(r(s),"_blank")}}},te={fromBase85:e=>P(ee(e)),fromBase64:e=>P(atob(e)),fromString:e=>P(e)},R=e=>{let t={};return typeof e=="string"?(t[e]=!0,t):e instanceof Array?(e.forEach(r=>{Object.entries(R(r)).forEach(([s,n])=>{t[s]=n})}),t):(Object.entries(e).forEach(([r,s])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){t[r]=s;return}if(typeof s=="boolean"){t[r]=s;return}t[r]=R(s)}),t)},B=e=>R(e),w=async(e,t)=>{let r=y.jsonToGraphQLQuery(B(t));const s=await e.post("",{query:`{ ${r} }`});if(s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function re(e){for(let t=0;t<e.length;t++)if(e[t]instanceof File)return!0;return!1}function se(e){for(let t in e)if(e[t]instanceof File)return!0;return!1}const o=async(e,t,r=null,s=[])=>{let n={[t]:{}};const i=new FormData;let u=!1;if(r){const c={},g={},C={};let D=0;Object.entries(r).forEach(([v,F])=>{if(F instanceof Array&&re(F)){u=!0;let A=0;F.forEach(q=>{q instanceof File&&(c[v]=new y.VariableType(v),g[D]=["variables."+v+"."+A],i.append(D.toString(),q),D++)}),C[v]="[Upload!]!"}else F instanceof File?(u=!0,c[v]=new y.VariableType(v),g[D]=["variables."+v],i.append(D.toString(),F),C[v]="Upload!",D++):F instanceof Object&&se(F)?(u=!0,c[v]={},Object.entries(F).forEach(([A,q])=>{q instanceof File?(c[v][A]=new y.VariableType(A),g[D]=["variables."+A],i.append(D.toString(),q),C[A]="Upload!",D++):c[v][A]=q})):F!==void 0&&(c[v]=F)}),n[t].__args=c,n.__variables=C,u&&i.append("map",JSON.stringify(g))}Object.entries(B(s)).forEach(([c,g])=>{n[t][c]=g}),Object.entries(n[t]).length===0&&(n[t]=!0);let l=null;const a=y.jsonToGraphQLQuery({mutation:n});if(u?(i.append("operations",JSON.stringify({query:a})),l=await e.post("",i)):l=await e.post("",{query:a}),l.data.errors)throw new Error(l.data.errors[0].message);return l.data.data[t]},ne=e=>({uploadTempFile:t=>o(e,"fsUploadTempFile",{file:t},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async t=>(await w(e,{fsListFolders:{__args:{path:t},name:!0,path:!0}})).fsListFolders,create:t=>o(e,"fsCreateFolder",{path:t}),delete:t=>o(e,"fsDeleteFolder",{path:t}),rename:(t,r)=>o(e,"fsRenameFolder",{path:t,name:r})},files:{list:async t=>(await w(e,{fsListFiles:{__args:{path:t},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}})).fsListFiles,read:async t=>{let r=await w(e,{fsFile:{__args:{path:t},base64Content:!0}});return window.atob(r.fsFile.base64Content)},write:(t,r)=>o(e,"fsWriteFile",{path:t,content:r}),delete:t=>o(e,"fsDeleteFile",{path:t}),rename:(t,r)=>o(e,"fsRenameFile",{path:t,name:r}),move:(t,r)=>o(e,"fsMoveFile",{source:t,target:r})}}),ie=e=>({get:async t=>(await e({config:{__args:{name:t}}})).config}),ae=e=>({send:(t,r,s)=>o(e,"sendMail",{email:t,subject:r,message:s})}),oe=e=>({list:async(t={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0})=>{const r=j("Users",e,t);return r.data_path="app.users",r.all()}}),le=e=>{const t=e,r={};return{create(s,n){r[s]=null;let i={};for(const u of Object.entries(n)){const[l,a]=u;i[l]=()=>({name:a.name?a.name:l,raw:a,getName:()=>a.name?a.name:l,getGQLField:()=>a.gqlField!==void 0?a.gqlField:a.name||l,getRaw(){return a},getValue(c){return a.field&&typeof a.field=="function"?a.field(c):a.field&&typeof a.field=="string"?c[a.field]:c[this.getName()]},getFormattedValue(c){const g=this.getValue(c);return a.format?a.format(g):g}})}r[s]=x(t,s,i)},get(s){return r[s]||this.create(s,{}),r[s]}}},ue=e=>({list:async(t={name:!0})=>{const{app:{roles:r}}=await w(e,{app:{roles:t}});return r}}),V=["flatMap","chunk","shuffle","splice","sortBy","map","reverse","groupBy","keyBy","keys","mapToDictionary","mapWithKeys","nth","skipUntil","skipWhile","takeUntil","takeWhile","unique","pluck","push","only","pad","slice","tap"],ce=["forPage","sortByDesc","sortBy","skip","take","splice","whereBetween","whereIn","whereNotBetween","whereNotIn","first","where","whereContains"],fe=["avg","count","countBy","dd","each","every","filter","firstWhere","isEmpty","isNotEmpty","last","mapToGroups","max","median","min","mode","contains","sole","sort","split","sum","toJson","get","has","implode","partition","sole"];class _{constructor(t,r){b(this,"data_path","");b(this,"axios");b(this,"filters");b(this,"steps");b(this,"fields");b(this,"already_limit",!1);b(this,"already_offset",!1);b(this,"limit",null);b(this,"offset",null);b(this,"_sort",null);b(this,"_sortDesc",!1);b(this,"meta",{});this.axios=r,this.filters={},this.steps=[],this.fields=t}}_.prototype.dataPath=function(e){const t=this.clone();return t.data_path=e,t},_.prototype.buildArgs=function(){let e={};return Object.keys(this.filters).length>0&&(e.filters=this.filters),this._sort&&(e.sort=this._sort,this._sortDesc&&(e.sort+=":desc")),e},_.prototype.clone=function(){const e=Object.create(this);return e.steps=[...this.steps],e},k().macro("whereContains",function(e,t){return this.filter(r=>r[e].toLowerCase().includes(t.toLowerCase()))}),_.prototype.fetchData=async function(){let e={meta:{total:!0,key:!0,name:!0}};e.__args=this.buildArgs(),e.data=this.fields,this.already_limit&&(e.data.__args=e.data.__args||{},e.data.__args.limit=this.limit),this.already_offset&&(e.data.__args=e.data.__args||{},e.data.__args.offset=this.offset);const t=this.data_path.split(".");let r={},s=r,n=t[t.length-1];for(const l of t){if(l===n){s[l]=e;break}s[l]={},s=s[l]}let u=await w(this.axios,r);for(const l of t)u=u[l];return this.meta=u.meta,k(u.data)},_.prototype.processData=async function(){let e=null;for(const t of this.steps){if(V.includes(t.type)){e||(e=await this.fetchData()),e=e[t.type](...t.args);continue}if(t.type==="forPage"&&(e?e=e.forPage(t.args[0],t.args[1]):this.already_limit||this.already_offset?(e=await this.fetchData(),e=e.forPage(t.args[0],t.args[1])):(this.offset=(t.args[0]-1)*t.args[1],this.limit=t.args[1]),this.already_limit=!0,this.already_offset=!0),t.type==="where")if(e)e=e.where(...t.args);else{const r=t.args[0];let s="==",n=null;t.args.length==2&&(n=t.args[1]),t.args.length==3&&(s=t.args[1],n=t.args[2]),s==="=="&&(this.filters[r]=n),s==="<"&&(this.filters[r]={lt:n}),s==="<="&&(this.filters[r]={lte:n}),s===">"&&(this.filters[r]={gt:n}),s===">="&&(this.filters[r]={gte:n}),s==="!=="&&(this.filters[r]={ne:n})}t.type==="whereContains"&&(e?e=e.whereContains(...t.args):this.filters[t.args[0]]={contains:t.args[1]}),t.type==="whereIn"&&(e?e=e.whereIn(...t.args):this.filters[t.args[0]]={in:t.args[1]}),t.type==="whereNotBetween"&&(e?e=e.whereNotBetween(...t.args):this.filters[t.args[0]]={notBetween:t.args[1]}),t.type==="whereNotIn"&&(e?e=e.whereNotIn(...t.args):this.filters[t.args[0]]={notIn:t.args[1]}),t.type=="whereBetween"&&(e?e=e.whereBetween(...t.args):this.filters[t.args[0]]={between:t.args[1]}),t.type==="sortByDesc"&&(e?e=e.sortByDesc(t.args[0]):this.already_limit||this.already_offset?(e=await this.fetchData(),e=e.sortByDesc(t.args[0])):(this._sort=t.args[0],this._sortDesc=!0)),t.type==="sortBy"&&(e?e=e.sortBy(t.args[0]):this.already_limit||this.already_offset?(e=await this.fetchData(),e=e.sortBy(t.args[0])):this._sort=t.args[0]),t.type==="skip"&&(e?e=e.skip(t.args[0]):this.already_offset||this.already_limit?(e=await this.fetchData(),e=e.skip(t.args[0])):this.offset=t.args[0],this.already_offset=!0),t.type==="take"&&(e?e=e.take(...t.args):this.already_offset||this.already_limit?(e=await this.fetchData(),e=e.take(t.args[0])):this.limit=t.args[0],this.already_limit=!0),t.type==="splice"&&(e?e=e.splice(...t.args):(this.offset=t.args[0],this.limit=t.args[1]),this.already_limit=!0,this.already_offset=!0),t.type==="pop"&&(e?e=e.pop(...t.args):(e=await this.fetchData(),e.pop(...t.args))),t.type==="prepend"&&(e?e=e.prepend(...t.args):(e=await this.fetchData(),e.prepend(...t.args)))}return e||(e=await this.fetchData()),e},_.prototype.all=async function(){return(await this.processData()).all()};for(const e of[...V,...ce])_.prototype[e]=function(...t){const r=this.clone();return r.steps.push({type:e,args:t}),r};for(const e of fe)_.prototype[e]=async function(...t){return(await this.clone().processData())[e](...t)};_.prototype.average=_.prototype.avg,_.prototype.first=async function(){return this.take(1),(await this.processData()).first()},_.prototype.push=function(e){return this.steps.push({type:"push",args:[e]}),this},_.prototype.pop=async function(...e){const r=(await this.clone().processData()).pop(...e);return this.steps.push({type:"pop",args:e}),r},_.prototype.prepend=function(...e){return this.steps.push({type:"prepend",args:e}),this},_.prototype.shift=async function(...e){const r=(await this.clone().processData()).shift(...e);return this.steps.push({type:"shift",args:e}),r},_.prototype.transform=function(...e){return this.steps.push({type:"transform",args:e}),this};const j=(e,t,r)=>{const s=new _(r,t);return s.data_path="list"+e,s},pe=(e,t)=>({uploadTempFile:r=>o(t,"lightDriveUploadTempFile",{index:e,file:r},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async(r,s={name:!0,path:!0})=>(await w(t,{app:{drive:{__args:{index:e},folders:{__args:{path:r},...s}}}})).app.drive.folders,create:r=>o(t,"lightDriveCreateFolder",{index:e,path:r}),delete:r=>o(t,"lightDriveDeleteFolder",{index:e,path:r}),rename:(r,s)=>o(t,"lightDriveRenameFolder",{index:e,path:r,name:s})},files:{list:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await w(t,{app:{drive:{__args:{index:e},files:{__args:{path:r},...s}}}})).app.drive.files,get:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await w(t,{app:{drive:{__args:{index:e},file:{__args:{path:r},...s}}}})).app.drive.file,read:async r=>{let s=await w(t,{app:{drive:{__args:{index:e},file:{__args:{path:r},base64Content:!0}}}});return window.atob(s.app.drive.file.base64Content)},write:(r,s)=>o(t,"lightDriveWriteFile",{index:e,path:r,content:s}),delete:r=>o(t,"lightDriveDeleteFile",{index:e,path:r}),rename:(r,s)=>o(t,"lightDriveRenameFile",{index:e,path:r,name:s}),move:(r,s)=>o(t,"lightDriveMoveFile",{index:e,source:r,destination:s})}}),he=e=>{const t=O.create({baseURL:e,withCredentials:!0}),r=(i,u=null,l=[])=>o(t,i,u,l),s=i=>w(t,i),n=le(t);return{baseURL:e,axios:t,auth:Z(t),mutation:r,query:s,config:ie(s),mail:ae(t),users:oe(t),fs:ne(t),models:n,model(i){return n.get(i)},roles:ue(t),collect:(i,u)=>{const l=j(i,t,u);return l.data_path=n.get(i).getDataPath(),l},drive(i){return pe(i,t)}}};d.File=te,d.createClient=he,d.createCollection=j,d.file=P,d.mutation=o,d.query=w,d.toQuery=B,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
1
+ (function(y,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("json-to-graphql-query"),require("axios"),require("collect.js")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","axios","collect.js"],m):(y=typeof globalThis<"u"?globalThis:y||self,m(y.light={},y.jsonToGraphqlQuery,y.axios,y.collect))})(this,function(y,m,O,P){"use strict";var ht=Object.defineProperty;var dt=(y,m,O)=>m in y?ht(y,m,{enumerable:!0,configurable:!0,writable:!0,value:O}):y[m]=O;var A=(y,m,O)=>dt(y,typeof m!="symbol"?m+"":m,O);function J(t){const e="==".slice(0,(4-t.length%4)%4),r=t.replace(/-/g,"+").replace(/_/g,"/")+e,s=atob(r),n=new ArrayBuffer(s.length),i=new Uint8Array(n);for(let c=0;c<s.length;c++)i[c]=s.charCodeAt(c);return n}function B(t){const e=new Uint8Array(t);let r="";for(const i of e)r+=String.fromCharCode(i);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var f="copy",v="convert";function S(t,e,r){if(e===f)return r;if(e===v)return t(r);if(e instanceof Array)return r.map(s=>S(t,e[0],s));if(e instanceof Object){const s={};for(const[n,i]of Object.entries(e)){if(i.derive){const c=i.derive(r);c!==void 0&&(r[n]=c)}if(!(n in r)){if(i.required)throw new Error(`Missing key: ${n}`);continue}if(r[n]==null){s[n]=null;continue}s[n]=S(t,i.schema,r[n])}return s}}function E(t,e){return{required:!0,schema:t,derive:e}}function h(t){return{required:!0,schema:t}}function g(t){return{required:!1,schema:t}}var T={type:h(f),id:h(v),transports:g(f)},U={appid:g(f),appidExclude:g(f),credProps:g(f)},L={appid:g(f),appidExclude:g(f),credProps:g(f)},V={publicKey:h({rp:h(f),user:h({id:h(v),name:h(f),displayName:h(f)}),challenge:h(v),pubKeyCredParams:h(f),timeout:g(f),excludeCredentials:g([T]),authenticatorSelection:g(f),attestation:g(f),extensions:g(U)}),signal:g(f)},M={type:h(f),id:h(f),rawId:h(v),authenticatorAttachment:g(f),response:h({clientDataJSON:h(v),attestationObject:h(v),transports:E(f,t=>{var e;return((e=t.getTransports)==null?void 0:e.call(t))||[]})}),clientExtensionResults:E(L,t=>t.getClientExtensionResults())},W={mediation:g(f),publicKey:h({challenge:h(v),timeout:g(f),rpId:g(f),allowCredentials:g([T]),userVerification:g(f),extensions:g(U)}),signal:g(f)},K={type:h(f),id:h(f),rawId:h(v),authenticatorAttachment:g(f),response:h({clientDataJSON:h(v),authenticatorData:h(v),signature:h(v),userHandle:h(v)}),clientExtensionResults:E(L,t=>t.getClientExtensionResults())};function I(t){return S(J,V,t)}function Q(t){return S(B,M,t)}function z(t){return S(J,W,t)}function G(t){return S(B,K,t)}async function $(t){const e=await navigator.credentials.create(t);return e.toJSON=()=>Q(e),e}async function H(t){const e=await navigator.credentials.get(t);return e.toJSON=()=>G(e),e}const X=t=>({login:async()=>{const{app:e}=await w(t,{app:{auth:{webAuthnRequestOptions:!0}}}),r=e.auth.webAuthnRequestOptions,s=z({publicKey:r}),n=await H(s);await u(t,"webAuthnAssertion",{assertion:n.toJSON()})},register:async()=>{const{app:e}=await w(t,{app:{auth:{webAuthnCreationOptions:!0}}}),r=I({publicKey:e.auth.webAuthnCreationOptions}),s=await $(r);await u(t,"webAuthnRegister",{registration:s.toJSON()})}}),Y=t=>({WebAuthn:X(t),google:{unlink:()=>u(t,"lightAuthUnlinkGoogle"),login:e=>u(t,"lightAuthLoginGoogle",{credential:e}),register:e=>u(t,"lightAuthRegisterGoogle",{credential:e})},facebook:{unlink:()=>u(t,"lightAuthUnlinkFacebook"),login:e=>u(t,"lightAuthLoginFacebook",{access_token:e}),register:e=>u(t,"lightAuthRegisterFacebook",{access_token:e})},microsoft:{unlink:()=>u(t,"lightAuthUnlinkMicrosoft"),login:e=>u(t,"lightAuthLoginMicrosoft",{access_token:e}),register:e=>u(t,"lightAuthRegisterMicrosoft",{account_id:e})},login:(e,r,s="")=>u(t,"login",{username:e,password:r,code:s}),logout:()=>u(t,"logout"),changeExpiredPassword:(e,r,s)=>u(t,"changeExpiredPassword",{username:e,old_password:r,new_password:s}),updatePassword:(e,r)=>u(t,"updatePassword",{old_password:e,new_password:r}),resetPassword:(e,r,s)=>u(t,"resetPassword",{jwt:e,password:r,code:s}),forgetPassword:(e,r)=>u(t,"forgetPassword",{username:e,email:r}),verifyCode(e,r){return u(t,"forgetPasswordVerifyCode",{jwt:e,code:r})},granted:async e=>(await w(t,{granted:{__args:{rights:e}}})).granted}),Z=(t,e,r)=>{const s=e,n=t,i=r;let c="list"+e;const o=a=>i[a]?i[a]():null;return{field:o,$fields:i,setDataPath(a){return c=a,c},getDataPath(){return c},gqlFields(a){const l=[];for(const p of a)if(typeof p=="string"){const b=o(p);b&&l.push(b.getGQLField())}else typeof p=="object"&&l.push(p);return l},async update(a,l){return await u(n,"update"+s,{id:a,data:l})},async delete(a){return await u(n,"delete"+s,{id:a})},async add(a){return await u(n,"add"+s,{data:a})},fields(a){let l=[];for(let p of a){const b=o(p);b&&l.push(b)}return l},async get(a,l){return(await w(n,{["list"+s]:{__args:{filters:a},data:{__args:{limit:1},...k(l)}}}))["list"+s].data[0]},async list(a,l){return(await w(n,{["list"+s]:{__args:{filters:a},data:{...k(l)}}}))["list"+s].data}}};function x(t){t="<~"+t+"~>";var e,r,s,n,i,c=String,o=255;for(t.slice(0,2)==="<~"&&t.slice(-2),t=t.slice(2,-2).replace(/\s/g,"").replace("z","!!!!!"),e="uuuuu".slice(t.length%5||5),t+=e,s=[],n=0,i=t.length;i>n;n+=5)r=52200625*(t.charCodeAt(n)-33)+614125*(t.charCodeAt(n+1)-33)+7225*(t.charCodeAt(n+2)-33)+85*(t.charCodeAt(n+3)-33)+(t.charCodeAt(n+4)-33),s.push(o&r>>24,o&r>>16,o&r>>8,o&r);return function(a,l){for(var p=l;p>0;p--)a.pop()}(s,e.length),c.fromCharCode.apply(c,s)}const N=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const n=new Uint8Array(e.length);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);const i=new Blob([n],{type:s});return URL.createObjectURL(i)};return{getContent:()=>e,getURL:r,download:s=>{const n=document.createElement("a");n.download=s,n.href=r(),document.body.appendChild(n),n.click(),document.body.removeChild(n)},open:s=>{window.open(r(s),"_blank")}}},tt={fromBase85:t=>N(x(t)),fromBase64:t=>N(atob(t)),fromString:t=>N(t)},R=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(R(r)).forEach(([s,n])=>{e[s]=n})}),e):(Object.entries(t).forEach(([r,s])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=s;return}if(typeof s=="boolean"){e[r]=s;return}e[r]=R(s)}),e)},k=t=>R(t),w=async(t,e)=>{let r=m.jsonToGraphQLQuery(k(e));const s=await t.post("",{query:`{ ${r} }`});if(s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function et(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function rt(t){for(let e in t)if(t[e]instanceof File)return!0;return!1}const u=async(t,e,r=null,s=[])=>{let n={[e]:{}};const i=new FormData;let c=!1;if(r){const l={},p={},b={};let F=0;Object.entries(r).forEach(([_,C])=>{if(C instanceof Array&&et(C)){c=!0;let D=0;C.forEach(q=>{q instanceof File&&(l[_]=new m.VariableType(_),p[F]=["variables."+_+"."+D],i.append(F.toString(),q),F++)}),b[_]="[Upload!]!"}else C instanceof File?(c=!0,l[_]=new m.VariableType(_),p[F]=["variables."+_],i.append(F.toString(),C),b[_]="Upload!",F++):C instanceof Object&&rt(C)?(c=!0,l[_]={},Object.entries(C).forEach(([D,q])=>{q instanceof File?(l[_][D]=new m.VariableType(D),p[F]=["variables."+D],i.append(F.toString(),q),b[D]="Upload!",F++):l[_][D]=q})):C!==void 0&&(l[_]=C)}),n[e].__args=l,n.__variables=b,c&&i.append("map",JSON.stringify(p))}Object.entries(k(s)).forEach(([l,p])=>{n[e][l]=p}),Object.entries(n[e]).length===0&&(n[e]=!0);let o=null;const a=m.jsonToGraphQLQuery({mutation:n});if(c?(i.append("operations",JSON.stringify({query:a})),o=await t.post("",i)):o=await t.post("",{query:a}),o.data.errors)throw new Error(o.data.errors[0].message);return o.data.data[e]},st=t=>({uploadTempFile:e=>u(t,"fsUploadTempFile",{file:e},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async e=>(await w(t,{fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,create:e=>u(t,"fsCreateFolder",{path:e}),delete:e=>u(t,"fsDeleteFolder",{path:e}),rename:(e,r)=>u(t,"fsRenameFolder",{path:e,name:r})},files:{list:async e=>(await w(t,{fsListFiles:{__args:{path:e},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}})).fsListFiles,read:async e=>{let r=await w(t,{fsFile:{__args:{path:e},base64Content:!0}});return window.atob(r.fsFile.base64Content)},write:(e,r)=>u(t,"fsWriteFile",{path:e,content:r}),delete:e=>u(t,"fsDeleteFile",{path:e}),rename:(e,r)=>u(t,"fsRenameFile",{path:e,name:r}),move:(e,r)=>u(t,"fsMoveFile",{source:e,target:r})}}),nt=t=>({get:async e=>(await t({config:{__args:{name:e}}})).config}),it=t=>({send:(e,r,s)=>u(t,"sendMail",{email:e,subject:r,message:s})}),at=t=>({list:async(e={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0})=>{const r=j("Users",t,e);return r.data_path="app.users",r.all()}}),ot=t=>{const e=t,r={};return{create(s,n){r[s]=null;let i={};for(const c of Object.entries(n)){const[o,a]=c;i[o]=()=>({name:a.name?a.name:o,raw:a,getName:()=>a.name?a.name:o,getGQLField:()=>a.gqlField!==void 0?a.gqlField:a.name||o,getRaw(){return a},getValue(l){return a.field&&typeof a.field=="function"?a.field(l):a.field&&typeof a.field=="string"?l[a.field]:l[this.getName()]},getFormattedValue(l){const p=this.getValue(l);return a.format?a.format(p):p}})}r[s]=Z(e,s,i)},get(s){return r[s]||this.create(s,{}),r[s]}}},lt=t=>({list:async(e={name:!0})=>{const{app:{roles:r}}=await w(t,{app:{roles:e}});return r}}),ut=["flatMap","chunk","shuffle","splice","sortBy","map","reverse","groupBy","keyBy","keys","mapToDictionary","mapWithKeys","nth","skipUntil","skipWhile","takeUntil","takeWhile","unique","pluck","push","only","pad","slice","tap","sort"],ct=["avg","count","countBy","dd","each","every","filter","firstWhere","isEmpty","isNotEmpty","last","mapToGroups","max","median","min","mode","contains","sole","sort","split","sum","toJson","get","has","implode","partition","sole"];class d{constructor(e,r){A(this,"_batchData",null);A(this,"data_path","");A(this,"axios");A(this,"filters");A(this,"steps");A(this,"fields");A(this,"already_limit",!1);A(this,"already_offset",!1);A(this,"limit",null);A(this,"offset",null);A(this,"_sort",null);A(this,"_sortDesc",!1);A(this,"meta",{});this.axios=r,this.filters={},this.steps=[],this.fields=e}}d.prototype.getQueryPayload=function(){let t={meta:{total:!0,key:!0,name:!0}};return t.__args=this.buildArgs(),t.data=this.fields,t.data.__args=t.data.__args||{},this.limit&&(t.data.__args.limit=this.limit),this.offset&&(t.data.__args.offset=this.offset),{data_path:this.data_path,query:t,steps:this.steps}},d.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},d.prototype.buildArgs=function(){let t={};return Object.keys(this.filters).length>0&&(t.filters=this.filters),this._sort&&(t.sort=this._sort,this._sortDesc&&(t.sort+=":desc")),t},d.prototype.clone=function(){const t=Object.create(this);return t.steps=JSON.parse(JSON.stringify(this.steps)),t.filters=JSON.parse(JSON.stringify(this.filters)),t.fields=JSON.parse(JSON.stringify(this.fields)),t},P().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),d.prototype.fetchData=async function(){if(this._batchData){const o=this._batchData;return this.meta=o.meta,P(o.data)}let t={meta:{total:!0,key:!0,name:!0}};t.__args=this.buildArgs(),t.data=this.fields,this.already_limit&&(t.data.__args=t.data.__args||{},t.data.__args.limit=this.limit),this.already_offset&&(t.data.__args=t.data.__args||{},t.data.__args.offset=this.offset);const e=this.data_path.split(".");let r={},s=r,n=e[e.length-1];for(const o of e){if(o===n){s[o]=t;break}s[o]={},s=s[o]}let c=await w(this.axios,r);for(const o of e)c=c[o];return this.meta=c.meta,P(c.data)},d.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},d.prototype.all=async function(){return(await this.processData()).all()};for(const t of ut)d.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of ct)d.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};d.prototype.average=d.prototype.avg,d.prototype.first=async function(){return this.take(1),(await this.processData()).first()},d.prototype.where=function(...t){if(t.length==2)this.filters[t[0]]=t[1];else if(t.length==3){let e="==",r=t[0],s=null;t.length==3&&(e=t[1],s=t[2]),e==="=="&&(this.filters[r]=s),e==="<"&&(this.filters[r]={lt:s}),e==="<="&&(this.filters[r]={lte:s}),e===">"&&(this.filters[r]={gt:s}),e===">="&&(this.filters[r]={gte:s}),e==="!=="&&(this.filters[r]={ne:s})}return this.steps.push({type:"where",args:t}),this},d.prototype.whereContains=function(t,e){return this.steps.push({type:"whereContains",args:[t,e]}),this.filters[t]={contains:e},this},d.prototype.forPage=function(t,e){return t=Math.max(1,t),this.already_limit?(this.steps.push({type:"forPage",args:[t,e]}),this):(this.limit=e,this.offset=(t-1)*e,this.already_limit=!0,this.already_offset=!0,this)},d.prototype.whereIn=function(t,e){return this.steps.push({type:"whereIn",args:[t,e]}),this.filters[t]={in:e},this},d.prototype.whereNotIn=function(t,e){return this.steps.push({type:"whereNotIn",args:[t,e]}),this.filters[t]={nin:e},this},d.prototype.whereNotBetween=function(t,e){return this.steps.push({type:"whereNotBetween",args:[t,e]}),this.filters[t]={notBetween:e},this},d.prototype.whereBetween=function(t,e){return this.steps.push({type:"whereBetween",args:[t,e]}),this.filters[t]={between:e},this},d.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},d.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},d.prototype.skip=function(t){return this.already_offset&&this.steps.push({type:"skip",args:[t]}),this.offset=t,this.already_offset=!0,this},d.prototype.take=function(t){return this.already_limit?(this.steps.push({type:"take",args:[t]}),this):(this.limit=t,this.already_limit=!0,this)},d.prototype.splice=function(t,e){return this.steps.push({type:"splice",args:[t,e]}),this.offset=t,this.limit=e,this.already_limit=!0,this.already_offset=!0,this};const j=(t,e,r)=>{const s=new d(r,e);return s.data_path="list"+t,s},ft=(t,e)=>({uploadTempFile:r=>u(e,"lightDriveUploadTempFile",{index:t,file:r},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async(r,s={name:!0,path:!0})=>(await w(e,{app:{drive:{__args:{index:t},folders:{__args:{path:r},...s}}}})).app.drive.folders,create:r=>u(e,"lightDriveCreateFolder",{index:t,path:r}),delete:r=>u(e,"lightDriveDeleteFolder",{index:t,path:r}),rename:(r,s)=>u(e,"lightDriveRenameFolder",{index:t,path:r,name:s})},files:{list:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await w(e,{app:{drive:{__args:{index:t},files:{__args:{path:r},...s}}}})).app.drive.files,get:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await w(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},...s}}}})).app.drive.file,read:async r=>{let s=await w(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},base64Content:!0}}}});return window.atob(s.app.drive.file.base64Content)},write:(r,s)=>u(e,"lightDriveWriteFile",{index:t,path:r,content:s}),delete:r=>u(e,"lightDriveDeleteFile",{index:t,path:r}),rename:(r,s)=>u(e,"lightDriveRenameFile",{index:t,path:r,name:s}),move:(r,s)=>u(e,"lightDriveMoveFile",{index:t,source:r,destination:s})}}),pt=t=>{const e=O.create({baseURL:t,withCredentials:!0}),r=(i,c=null,o=[])=>u(e,i,c,o),s=i=>w(e,i),n=ot(e);return{baseURL:t,axios:e,auth:Y(e),mutation:r,query:s,config:nt(s),mail:it(e),users:at(e),fs:st(e),models:n,model(i){return n.get(i)},roles:lt(e),collect:(i,c)=>{const o=j(i,e,c);return o.data_path=n.get(i).getDataPath(),o},drive(i){return ft(i,e)},async collects(i){const c={},o={};for(const l in i){const p=i[l].getQueryPayload();o[l]=p.data_path,c[l]={};const b=p.data_path.split(".");let F=b[b.length-1],_=c[l];for(const C of b){if(C===F){_[C]=p.query;break}_[C]=_[C]||{}}c[l].__aliasFor=b[0]}const a=await w(e,c);for(const l in i){const p=o[l].split(".");let b=p[p.length-1],F=a[l];for(const _ of p){if(_===b){i[l]._batchData=a[l][_];break}F[_]=F[_]||{}}}return i}}};y.File=tt,y.createClient=pt,y.createCollection=j,y.file=N,y.mutation=u,y.query=w,y.toQuery=k,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
@@ -1,6 +1,6 @@
1
1
  import { AxiosInstance } from 'axios';
2
2
  declare const _default: (axios: AxiosInstance) => {
3
- login: (username: string) => Promise<void>;
3
+ login: () => Promise<void>;
4
4
  register: () => Promise<void>;
5
5
  };
6
6
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/light",
3
- "version": "2.5.4",
3
+ "version": "2.7.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"