@hostlink/light 2.7.1 → 2.7.2

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.
package/dist/light.js CHANGED
@@ -249,7 +249,7 @@ const Z = (t) => ({
249
249
  old_password: r,
250
250
  new_password: s
251
251
  }),
252
- updatePassword: (e, r) => u(t, "updatePassword", {
252
+ updatePassword: (e, r) => u(t, "changeUserPassword", {
253
253
  old_password: e,
254
254
  new_password: r
255
255
  }),
@@ -1 +1 @@
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 D=(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",A="convert";function S(t,e,r){if(e===f)return r;if(e===A)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(A),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(A),name:h(f),displayName:h(f)}),challenge:h(A),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(A),authenticatorAttachment:g(f),response:h({clientDataJSON:h(A),attestationObject:h(A),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(A),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(A),authenticatorAttachment:g(f),response:h({clientDataJSON:h(A),authenticatorData:h(A),signature:h(A),userHandle:h(A)}),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 v=0;C.forEach(q=>{q instanceof File&&(l[_]=new m.VariableType(_),p[F]=["variables."+_+"."+v],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(([v,q])=>{q instanceof File?(l[_][v]=new m.VariableType(v),p[F]=["variables."+v],i.append(F.toString(),q),b[v]="Upload!",F++):l[_][v]=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){D(this,"_batchData",null);D(this,"data_path","");D(this,"axios");D(this,"filters");D(this,"steps");D(this,"fields");D(this,"already_limit",!1);D(this,"already_offset",!1);D(this,"limit",null);D(this,"offset",null);D(this,"_sort",null);D(this,"_sortDesc",!1);D(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(this._batchData)return this.steps.push({type:"where",args:t}),this;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},d.prototype.whereContains=function(t,e){return this._batchData?(this.steps.push({type:"whereContains",args:[t,e]}),this):(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._batchData?(this.steps.push({type:"whereIn",args:[t,e]}),this):(this.filters[t]={in:e},this)},d.prototype.whereNotIn=function(t,e){return this._batchData?(this.steps.push({type:"whereNotIn",args:[t,e]}),this):(this.filters[t]={nin:e},this)},d.prototype.whereNotBetween=function(t,e){return this._batchData?(this.steps.push({type:"whereNotBetween",args:[t,e]}),this):(this.filters[t]={notBetween:e},this)},d.prototype.whereBetween=function(t,e){return this._batchData?(this.steps.push({type:"whereBetween",args:[t,e]}),this):(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
+ (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 D=(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",A="convert";function S(t,e,r){if(e===f)return r;if(e===A)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 U={type:h(f),id:h(A),transports:g(f)},T={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(A),name:h(f),displayName:h(f)}),challenge:h(A),pubKeyCredParams:h(f),timeout:g(f),excludeCredentials:g([U]),authenticatorSelection:g(f),attestation:g(f),extensions:g(T)}),signal:g(f)},M={type:h(f),id:h(f),rawId:h(A),authenticatorAttachment:g(f),response:h({clientDataJSON:h(A),attestationObject:h(A),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(A),timeout:g(f),rpId:g(f),allowCredentials:g([U]),userVerification:g(f),extensions:g(T)}),signal:g(f)},K={type:h(f),id:h(f),rawId:h(A),authenticatorAttachment:g(f),response:h({clientDataJSON:h(A),authenticatorData:h(A),signature:h(A),userHandle:h(A)}),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,"changeUserPassword",{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 v=0;C.forEach(q=>{q instanceof File&&(l[_]=new m.VariableType(_),p[F]=["variables."+_+"."+v],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(([v,q])=>{q instanceof File?(l[_][v]=new m.VariableType(v),p[F]=["variables."+v],i.append(F.toString(),q),b[v]="Upload!",F++):l[_][v]=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){D(this,"_batchData",null);D(this,"data_path","");D(this,"axios");D(this,"filters");D(this,"steps");D(this,"fields");D(this,"already_limit",!1);D(this,"already_offset",!1);D(this,"limit",null);D(this,"offset",null);D(this,"_sort",null);D(this,"_sortDesc",!1);D(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(this._batchData)return this.steps.push({type:"where",args:t}),this;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},d.prototype.whereContains=function(t,e){return this._batchData?(this.steps.push({type:"whereContains",args:[t,e]}),this):(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._batchData?(this.steps.push({type:"whereIn",args:[t,e]}),this):(this.filters[t]={in:e},this)},d.prototype.whereNotIn=function(t,e){return this._batchData?(this.steps.push({type:"whereNotIn",args:[t,e]}),this):(this.filters[t]={nin:e},this)},d.prototype.whereNotBetween=function(t,e){return this._batchData?(this.steps.push({type:"whereNotBetween",args:[t,e]}),this):(this.filters[t]={notBetween:e},this)},d.prototype.whereBetween=function(t,e){return this._batchData?(this.steps.push({type:"whereBetween",args:[t,e]}),this):(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"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/light",
3
- "version": "2.7.1",
3
+ "version": "2.7.2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"