@hostlink/light 3.1.0 → 3.2.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.
@@ -0,0 +1,11 @@
1
+ export declare const createFolder: (location: string) => Promise<any>;
2
+ export declare const deleteFolder: (location: string) => Promise<any>;
3
+ export declare const renameFolder: (location: string, newName: string) => Promise<any>;
4
+ export declare const renameFile: (location: string, newName: string) => Promise<any>;
5
+ export declare const writeFile: (location: string, content: string) => Promise<any>;
6
+ export declare const uploadFile: (location: string, file: File) => Promise<any>;
7
+ export declare const deleteFile: (location: string) => Promise<any>;
8
+ export declare const move: (from: string, to: string) => Promise<any>;
9
+ export declare const exists: (location: string) => Promise<any>;
10
+ export declare const list: (location: string) => Promise<any>;
11
+ export declare const read: (location: string) => Promise<any>;
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -25,9 +25,12 @@ export type { RoleFields } from './role';
25
25
  export { setApiClient, getApiClient, getApiClientOptional } from './apiClient';
26
26
  export interface GraphQLQuery {
27
27
  [key: string]: boolean | GraphQLQuery | {
28
- __args: Record<string, any>;
28
+ __args?: Record<string, any>;
29
29
  __aliasFor?: string;
30
30
  __variables?: Record<string, string>;
31
31
  __name?: string;
32
+ __on?: Array<GraphQLQuery>;
33
+ __typeName?: string;
34
+ [key: string]: any;
32
35
  };
33
36
  }
package/dist/light.js CHANGED
@@ -946,7 +946,7 @@ const p = async (t) => {
946
946
  const c = o.config;
947
947
  return i ? new Promise((h, d) => {
948
948
  u.push({ resolve: h, reject: d });
949
- }).then(() => s(c)).catch((h) => Promise.reject(h)) : (i = !0, f().then(() => (i = !1, l(null), s(c))).catch((h) => (i = !1, l(h), window.location.href = "/login", Promise.reject(h))));
949
+ }).then(() => s(c)).catch((h) => Promise.reject(h)) : (i = !0, f().then(() => (i = !1, l(null), s(c))).catch((h) => (i = !1, l(h), Promise.reject(h))));
950
950
  }
951
951
  return o;
952
952
  },
@@ -1 +1 @@
1
- (function(h,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("json-to-graphql-query"),require("collect.js"),require("axios")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","collect.js","axios"],b):(h=typeof globalThis<"u"?globalThis:h||self,b(h.light={},h.jsonToGraphqlQuery,h.collect,h.axios))})(this,(function(h,b,E,bt){"use strict";function v(t){if(t===null||typeof t!="object")return!1;const e=Object.getPrototypeOf(t);return e!==null&&e!==Object.prototype&&Object.getPrototypeOf(e)!==null||Symbol.iterator in t?!1:Symbol.toStringTag in t?Object.prototype.toString.call(t)==="[object Module]":!0}function S(t,e,r=".",s){if(!v(e))return S(t,{},r,s);const o=Object.assign({},e);for(const u in t){if(u==="__proto__"||u==="constructor")continue;const l=t[u];l!=null&&(s&&s(o,u,l,r)||(Array.isArray(l)&&Array.isArray(o[u])?o[u]=[...l,...o[u]]:v(l)&&v(o[u])?o[u]=S(l,o[u],(r?`${r}.`:"")+u.toString(),s):o[u]=l))}return o}function mt(t){return(...e)=>e.reduce((r,s)=>S(r,s,"",t),{})}const C=mt();let j=null;const T=t=>{j=t},M=()=>{if(!j)throw new Error("Api client not initialized. Call setApiClient() first.");return j},Ft=()=>j;function D(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function B(t){for(let e in t)if(t[e]instanceof File||t[e]instanceof Array&&D(t[e]))return!0;return!1}function At(t){t="<~"+t+"~>";var e,r,s,o,u,l=String,p=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=[],o=0,u=t.length;u>o;o+=5)r=52200625*(t.charCodeAt(o)-33)+614125*(t.charCodeAt(o+1)-33)+7225*(t.charCodeAt(o+2)-33)+85*(t.charCodeAt(o+3)-33)+(t.charCodeAt(o+4)-33),s.push(p&r>>24,p&r>>16,p&r>>8,p&r);return(function(n,i){for(var a=i;a>0;a--)n.pop()})(s,e.length),l.fromCharCode.apply(l,s)}const q=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const o=new Uint8Array(e.length);for(let p=0;p<e.length;p++)o[p]=e.charCodeAt(p);const u=new Blob([o],{type:s});return URL.createObjectURL(u)};return{getContent:()=>e,getURL:r,download:s=>{const o=document.createElement("a");o.download=s,o.href=r(),document.body.appendChild(o),o.click(),document.body.removeChild(o)},open:s=>{window.open(r(s),"_blank")}}},Ct=t=>q(atob(t)),Ot=t=>q(At(t));function $(t,e,r,s,o){if(!(!t||typeof t!="object"))for(let u in t){const l=t[u];if(l&&typeof l=="object"){if("__args"in l){const p=l.__args,n={};Object.entries(p).forEach(([i,a])=>{if(a instanceof Array&&D(a)){n[i]=new b.VariableType(i);let c=0;a.forEach(f=>{f instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+i+"."+c),s.append(o.current.toString(),f),o.current++,c++)}),e[i]="[Upload!]!"}else a instanceof File?(n[i]=new b.VariableType(i),r[o.current]=["variables."+i],s.append(o.current.toString(),a),e[i]="Upload!",o.current++):a instanceof Object&&B(a)?(n[i]={},Object.entries(a).forEach(([c,f])=>{if(f instanceof Array&&D(f)){n[i][c]=new b.VariableType(c);let g=0;f.forEach(_=>{_ instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+c+"."+g),s.append(o.current.toString(),_),o.current++,g++)}),e[c]="[Upload!]!"}else f instanceof File?(n[i][c]=new b.VariableType(c),r[o.current]=["variables."+c],s.append(o.current.toString(),f),e[c]="Upload!",o.current++):n[i][c]=f})):a!=null&&(n[i]=a)}),l.__args=n}$(l,e,r,s,o)}}}const w=async t=>{const{axios:e}=M(),r=t,s=new FormData;let o=!1;const u={},l={};$(r,u,l,s,{current:0}),o=Object.keys(u).length>0,o&&(r.__variables=u);let n=null;const i={query:r},a=b.jsonToGraphQLQuery(i);if(o?(s.append("map",JSON.stringify(l)),s.append("operations",JSON.stringify({query:a})),n=await e.post("",s)):n=await e.post("",{query:a}),n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data};function P(t,e){let r,s=[],o,u;const l=n=>!n||typeof n!="object"?!1:Object.values(n).some(i=>i&&typeof i=="object"&&Object.keys(i).some(a=>a.startsWith("_"))),p=()=>s.length===0?(s.unshift({}),s[0]):(l(s[0])&&s.unshift({}),s[0]);return{first(){return this.fetchFirst()},all(){return this.fetch()},async fetchFirst(){const i=await this.limit(1).fetch();return Array.isArray(i)&&i.length>0?i[0]:null},async fetchWithMeta(){let i=await w(this.toQuery(!0));if(u){const a=u.split(".");for(const c of a)i=i[c];return i}return i[`list${t}`]},async fetch(){let i=await w(this.toQuery());if(u){const a=u.split(".");for(const c of a)i=i[c];return i.data}return i[`list${t}`].data},dataPath(n){return n&&typeof n=="string"&&(u=n),this},sort(n){return n&&typeof n=="string"&&(o=n),this},filters(n){return n&&typeof n=="object"&&(s=[n]),this},where(n,i,a){const c=(f,g,_)=>{const F={">":"_gt","<":"_lt",">=":"_gte","<=":"_lte","!=":"_ne",in:"_in",contains:"_contains"}[g];F&&s.push({[f]:{[F]:_}})};if(a!==void 0)c(n,String(i),a);else{const f=p(),g=C(f,{[n]:i});s[0]=g}return this},whereContains(n,i){if(n&&typeof n=="string"){const a=p(),c={_contains:i};a[n]?Array.isArray(a[n])?a[n].push(c):a[n]=[a[n],c]:a[n]=[c],s[0]=a}return this},whereIn(n,i){if(n&&typeof n=="string"&&Array.isArray(i)){const a=p(),c={_in:i};a[n]?Array.isArray(a[n])?a[n].push(c):a[n]=[a[n],c]:a[n]=[c],s[0]=a}return this},whereBetween(n,i,a){if(n&&typeof n=="string"){const c=p(),f={_between:[i,a]};c[n]?Array.isArray(c[n])?c[n].push(f):c[n]=[c[n],f]:c[n]=f,s[0]=c}return this},limit(n){return typeof n=="number"&&Number.isFinite(n)&&(r=C(r||{},{limit:n})),this},offset(n){return typeof n=="number"&&Number.isFinite(n)&&(r=C(r||{},{offset:n})),this},toQuery(n=!1){let i;const a=s.length>0&&Object.keys(s[0]||{}).length>0,c=a?1:0,f=s.length>c;a&&f?i=s:f?i=s.slice(c):a&&(i=s[0]);const g=C(o?{sort:o}:{},i?{filters:i}:{}),_={data:{...e}};if(r&&(_.data.__args=r),Object.keys(g).length>0&&(_.__args=g),n&&(_.meta={total:!0,key:!0,name:!0}),u){const A=u.split(".");let F=_;for(let m=A.length-1;m>=0;m--)F={[A[m]]:F};return F}return{[`list${t}`]:_}}}}const Dt="list",Pt=["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"],jt=["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"];class y{_batchData=null;data_path="";filters;steps;fields;already_limit=!1;already_offset=!1;limit=null;offset=null;_sort=null;_sortDesc=!1;meta={};constructor(e){this.filters={},this.steps=[],this.fields=e}}y.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}},y.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},y.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},y.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},E().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),y.prototype.fetchData=async function(){try{if(this._batchData){const p=this._batchData;return this.meta=p.meta,E(p.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,o=e[e.length-1];for(const p of e){if(p===o){s[p]=t;break}s[p]={},s=s[p]}let l=await w(r);for(const p of e)l=l[p];return this.meta=l.meta,E(l.data)}catch(t){throw console.error("Error fetching collection data:",t),t}},y.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},y.prototype.all=async function(){return(await this.processData()).all()};for(const t of Pt)y.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of jt)y.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};y.prototype.average=y.prototype.avg,y.prototype.first=async function(){return this.take(1),(await this.processData()).first()},y.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},y.prototype.where=function(...t){const e=this._handleBatchData("where",t);if(e)return e;if(t.length===2)this.filters[t[0]]=t[1];else if(t.length===3){const r=t[0],s=t[1],o=t[2];switch(s){case"==":this.filters[r]=o;break;case"<":this.filters[r]={lt:o};break;case"<=":this.filters[r]={lte:o};break;case">":this.filters[r]={gt:o};break;case">=":this.filters[r]={gte:o};break;case"!==":this.filters[r]={ne:o};break;default:throw new Error(`Unsupported operator: ${s}`)}}return this},y.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},y.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)},y.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},y.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},y.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},y.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},y.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},y.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},y.prototype.skip=function(t){if(t<0)throw new Error("Offset must be non-negative");return this.already_offset&&this.steps.push({type:"skip",args:[t]}),this.offset=t,this.already_offset=!0,this},y.prototype.take=function(t){if(t<0)throw new Error("Length must be non-negative");return this.already_limit?(this.steps.push({type:"take",args:[t]}),this):(this.limit=t,this.already_limit=!0,this)},y.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 N=(t,e)=>{const r=new y(e);return r.data_path=Dt+t,r},kt=(t,e={})=>{const r=e;let s="list"+t;const o=u=>r[u]?r[u]:null;return{field:o,$fields:r,setDataPath(u){return s=u,s},getDataPath(){return s},gqlFields(u){let l={};for(const p of u)if(typeof p=="string"){const n=o(p);n&&(l=C(l,n.gqlField?typeof n.gqlField=="string"?{[n.gqlField]:!0}:n.gqlField:{[n.name||p]:!0}))}else typeof p=="object"&&(l=C(l,p));return l},update(u,l){return d({["update"+t]:{__args:{id:u,data:l}}}).then(p=>p["update"+t])},async delete(u){return d({["delete"+t]:{__args:{id:u}}}).then(l=>l["delete"+t])},add(u){return d({["add"+t]:{__args:{data:u}}}).then(l=>l["add"+t])},fields(u){let l=[];for(let p of u){const n=o(p);n&&l.push(n)}return l},async get(u,l){const p=N(t,wt(l));for(const[n,i]of Object.entries(u))p.where(n,"==",i);return await p.first()},list(u){let l=u;const p={};Object.entries(u).forEach(([a])=>{r[a]&&(p[a]=r[a],r[a].gqlField&&(delete l[a],l=C(l,r[a].gqlField)),r[a].gql&&(delete l[a],l=C(l,r[a].gql)))});const n=P(t,l).dataPath(s),i=n.fetch.bind(n);return{...n,async fetch(){return(await i()).map(c=>{const f={...c};return Object.entries(p).forEach(([g,_])=>{_.field&&typeof _.field=="function"&&(f[g]=_.field(c[g],c))}),f})},async fetchFirst(){const c=await n.fetchFirst.bind(n)();if(!c)return c;const f={...c};return Object.entries(p).forEach(([g,_])=>{_.field&&typeof _.field=="function"&&(f[g]=_.field(c[g],c))}),f}}}}},O={},L=(t,e)=>{const r=kt(t,e);return O[t]=r,r},k=t=>O[t]?O[t]:L(t,{}),Ut=t=>!!O[t],Et=()=>Object.keys(O),vt=()=>{Object.keys(O).forEach(t=>delete O[t])},St=t=>{Object.entries(t).forEach(([e,r])=>{L(e,r)})},Mt=()=>w({app:{permissions:!0}}).then(t=>t.app.permissions),Q=async()=>{const{app:t}=await w({app:{auth:{webAuthnRequestOptions:!0}}}),e=t.auth.webAuthnRequestOptions,r=PublicKeyCredential.parseRequestOptionsFromJSON(e);return await navigator.credentials.get({publicKey:r})},W=async()=>{const{app:t}=await w({app:{auth:{webAuthnCreationOptions:!0}}}),e=PublicKeyCredential.parseCreationOptionsFromJSON(t.auth.webAuthnCreationOptions);return await navigator.credentials.create({publicKey:e})},z=Object.freeze(Object.defineProperty({__proto__:null,assertion:Q,attestation:W,login:async()=>{const t=await Q();return await d({webAuthnAssertion:{__args:{assertion:t.toJSON()}}}).then(e=>e.webAuthnAssertion)},register:async()=>{const t=await W();return await d({webAuthnRegister:{__args:{registration:t.toJSON()}}}).then(e=>e.webAuthnRegister)}},Symbol.toStringTag,{value:"Module"})),G=(t=J)=>w({my:t}).then(e=>e.my),H=(t,e,r="")=>d({login:{__args:{username:t,password:e,code:r}}}).then(s=>s.login),V=()=>d({logout:!0}).then(t=>t.logout),X=(t,e,r)=>d({changeExpiredPassword:{__args:{username:t,old_password:e,new_password:r}}}).then(s=>s.changeExpiredPassword),Y=(t,e)=>d({changeUserPassword:{__args:{old_password:t,new_password:e}}}).then(r=>r.changeUserPassword),Z=(t,e,r)=>d({resetPassword:{__args:{jwt:t,password:e,code:r}}}).then(s=>s.resetPassword),I=(t,e)=>d({forgetPassword:{__args:{username:t,email:e}}}).then(r=>r.forgetPassword),K=(t,e)=>d({forgetPasswordVerifyCode:{__args:{jwt:t,code:e}}}).then(r=>r.forgetPasswordVerifyCode),x=t=>w({my:{granted:{__args:{right:t}}}}).then(e=>e.my.granted),tt=t=>w({my:{grantedRights:{__args:{rights:t}}}}).then(e=>e.my.grantedRights),et={getCurrentUser:G,webAuthn:z,google:{unlink:()=>d({lightAuthUnlinkGoogle:!0}).then(t=>t.lightAuthUnlinkGoogle),login:t=>d({lightAuthLoginGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthLoginGoogle),register:t=>d({lightAuthRegisterGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthRegisterGoogle)},facebook:{unlink:()=>d({lightAuthUnlinkFacebook:!0}).then(t=>t.lightAuthUnlinkFacebook),login:t=>d({lightAuthLoginFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginFacebook),register:t=>d({lightAuthRegisterFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthRegisterFacebook)},microsoft:{unlink:()=>d({lightAuthUnlinkMicrosoft:!0}).then(t=>t.lightAuthUnlinkMicrosoft),login:t=>d({lightAuthLoginMicrosoft:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginMicrosoft),register:t=>d({lightAuthRegisterMicrosoft:{__args:{account_id:t}}}).then(e=>e.lightAuthRegisterMicrosoft)},login:H,logout:V,changeExpiredPassword:X,updatePassword:Y,resetPassword:Z,forgetPassword:I,verifyCode:K,grantedRights:tt,isGranted:x},rt={name:!0,path:!0,size:!0,mime:!0,url:!0},st=(t,e,r=rt)=>w({app:{drive:{__args:{index:t},files:{__args:{path:e},...r}}}}).then(s=>s.app.drive.files),nt=(t,e)=>w({app:{drive:{__args:{index:t},file:{__args:{path:e},base64Content:!0}}}}).then(r=>r.app.drive?.file?.base64Content),Bt=t=>({list:(e,r=rt)=>st(t,e,r),get:(e,r={name:!0,path:!0,size:!0,mime:!0,url:!0})=>w({app:{drive:{__args:{index:t},file:{__args:{path:e},...r}}}}).then(s=>s.app.drive.file),readFileAsBase64(e){return nt(t,e)},read:async e=>{let r=await w({app:{drive:{__args:{index:t},file:{__args:{path:e},base64Content:!0}}}});if(!r.app.drive.file||!r.app.drive.file.base64Content)throw new Error(`File not found or cannot read content: ${e}`);return typeof window<"u"&&window.atob?window.atob(r.app.drive.file.base64Content):r.app.drive.file.base64Content},write:(e,r)=>d({lightDriveWriteFile:{__args:{index:t,path:e,content:r}}}).then(s=>s.lightDriveWriteFile),delete:e=>d({lightDriveDeleteFile:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFile),rename:(e,r)=>d({lightDriveRenameFile:{__args:{index:t,path:e,name:r}}}).then(s=>s.lightDriveRenameFile),move:(e,r)=>d({lightDriveMoveFile:{__args:{index:t,source:e,destination:r}}}).then(s=>s.lightDriveMoveFile)}),it={name:!0,path:!0},ot=(t,e,r=it)=>w({app:{drive:{__args:{index:t},folders:{__args:{path:e},...r}}}}).then(s=>s.app.drive.folders),qt=t=>({list:(e,r=it)=>ot(t,e,r),create:e=>d({lightDriveCreateFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveCreateFolder),delete:e=>d({lightDriveDeleteFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFolder),rename:(e,r)=>d({lightDriveRenameFolder:{__args:{index:t,path:e,name:r}}}).then(s=>s.lightDriveRenameFolder)}),Nt=()=>w({app:{drives:{index:!0,name:!0}}}).then(t=>t.app.drives),at=t=>{const e=Bt(t),r=qt(t);return{folders:r,files:e,listFiles:e.list,getFile:e.get,readFile:e.read,writeFile:e.write,deleteFile:e.delete,renameFile:e.rename,moveFile:e.move,listFolders:r.list,createFolder:r.create,deleteFolder:r.delete,renameFolder:r.rename,uploadTempFile:s=>d({lightDriveUploadTempFile:{__args:{index:t,file:s},name:!0,path:!0,size:!0,mime:!0}}).then(o=>o.lightDriveUploadTempFile)}},J={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0},ct=t=>d({addUser:{__args:t}}).then(e=>e.addUser),lt=t=>d({deleteUser:{__args:{id:t}}}).then(e=>e.deleteUser),ut=(t=J)=>P("Users",t).dataPath("app.listUser").fetch(),ht=(t,e)=>d({updateUser:{__args:{id:t,data:e}}}).then(r=>r.updateUser),Lt={list:ut,create:ct,delete:lt,update:ht},ft=t=>w({app:{listConfig:{__args:{filters:{name:t}},data:{name:!0,value:!0}}}}).then(e=>e.app.listConfig.data[0]?.value),Jt={name:!0},pt=(t=Jt)=>w({app:{roles:t}}).then(e=>e.app.roles),dt=(t,e)=>d({addRole:{__args:{data:{name:t,childs:e}}}}).then(r=>r.addRole),gt=t=>d({deleteRole:{__args:{name:t}}}).then(e=>e.deleteRole),Rt=()=>({list:pt,create:dt,delete:gt});function _t(t,e,r,s,o){if(!(!t||typeof t!="object"))for(let u in t){const l=t[u];if(l&&typeof l=="object"){if("__args"in l){const p=l.__args,n={};Object.entries(p).forEach(([i,a])=>{if(a instanceof Array&&D(a)){n[i]=new b.VariableType(i);let c=0;a.forEach(f=>{f instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+i+"."+c),s.append(o.current.toString(),f),o.current++,c++)}),e[i]="[Upload!]!"}else a instanceof File?(n[i]=new b.VariableType(i),r[o.current]=["variables."+i],s.append(o.current.toString(),a),e[i]="Upload!",o.current++):a instanceof Object&&B(a)?(n[i]={},Object.entries(a).forEach(([c,f])=>{if(f instanceof Array&&D(f)){n[i][c]=new b.VariableType(c);let g=0;f.forEach(_=>{_ instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+c+"."+g),s.append(o.current.toString(),_),o.current++,g++)}),e[c]="[Upload!]!"}else f instanceof File?(n[i][c]=new b.VariableType(c),r[o.current]=["variables."+c],s.append(o.current.toString(),f),e[c]="Upload!",o.current++):n[i][c]=f})):a!=null&&(n[i]=a)}),l.__args=n}_t(l,e,r,s,o)}}}const d=async t=>{const{axios:e}=M(),r=t,s=new FormData;let o=!1;const u={},l={};_t(r,u,l,s,{current:0}),o=Object.keys(u).length>0,o&&(r.__variables=u);let n=null;const i={mutation:r},a=b.jsonToGraphQLQuery(i);if(o?(s.append("map",JSON.stringify(l)),s.append("operations",JSON.stringify({query:a})),n=await e.post("",s)):n=await e.post("",{query:a}),n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data},yt=(t,e,r)=>d({sendMail:{__args:{email:t,subject:e,message:r}}}).then(s=>s.sendMail),Tt={send:yt},R=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(R(r)).forEach(([s,o])=>{e[s]=o})}),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)},wt=t=>R(t),$t=t=>{const e=typeof window>"u";let r=[];const s=bt.create({baseURL:t,withCredentials:!0});let o=!1,u=[];const l=(i,a=null)=>{u.forEach(c=>{i?c.reject(i):c.resolve(a)}),u=[]};s.interceptors.response.use(i=>{const a=i.data.errors;if(a&&a.some(c=>c.extensions?.code==="TOKEN_EXPIRED")){const c=i.config;return o?new Promise((f,g)=>{u.push({resolve:f,reject:g})}).then(()=>s(c)).catch(f=>Promise.reject(f)):(o=!0,p().then(()=>(o=!1,l(null),s(c))).catch(f=>(o=!1,l(f),window.location.href="/login",Promise.reject(f))))}return i},i=>Promise.reject(i));function p(){return s.post("/refresh_token")}e&&(s.interceptors.request.use(i=>(i.withCredentials=!0,r.length>0&&(i.headers.Cookie=r.join("; ")),i)),s.interceptors.response.use(i=>{if(i.headers["set-cookie"]){const a=i.headers["set-cookie"].map(f=>f.split(";")[0]),c=new Map;r.forEach(f=>{const g=f.split("=")[0];c.set(g,f)}),a.forEach(f=>{const g=f.split("=")[0];c.set(g,f)}),r=Array.from(c.values())}return i}));const n={post:s.post,baseURL:t,axios:s,auth:et,mutation:d,query:w,config:ft,mail:Tt,users:Lt,model(i){return k(i)},roles:Rt(),collect:(i,a)=>{const c=N(i,a);return c.data_path=k(i).getDataPath(),c},list:(i,a)=>P(i,a).dataPath(k(i).getDataPath()),drive:at,async collects(i){const a={},c={};for(const g in i){const _=i[g].getQueryPayload();c[g]=_.data_path,a[g]={};const A=_.data_path.split(".");let F=A[A.length-1],m=a[g];for(const U of A){if(U===F){m[U]=_.query;break}m[U]=m[U]||{}}a[g].__aliasFor=A[0]}const f=await w(a);for(const g in i){const _=c[g].split(".");let A=_[_.length-1],F=f[g];for(const m of _){if(m===A){i[g]._batchData=f[g][m];break}F[m]=F[m]||{}}}return i}};return T(n),n},Qt=P;h.arrayHasFile=D,h.auth=et,h.changeExpiredPassword=X,h.clearModels=vt,h.createClient=$t,h.createCollection=N,h.createFileFromBase64=Ct,h.createFileFromBase85=Ot,h.createFileFromString=q,h.createList=P,h.createRole=dt,h.createUser=ct,h.defaultUserFields=J,h.defineModel=L,h.defineModels=St,h.deleteRole=gt,h.deleteUser=lt,h.forgetPassword=I,h.getApiClient=M,h.getApiClientOptional=Ft,h.getConfig=ft,h.getCurrentUser=G,h.getDrive=at,h.getGrantedRights=tt,h.getModel=k,h.hasModel=Ut,h.isGranted=x,h.list=Qt,h.listDrives=Nt,h.listFiles=st,h.listFolders=ot,h.listModels=Et,h.listPermissions=Mt,h.listRoles=pt,h.listUsers=ut,h.login=H,h.logout=V,h.mutation=d,h.objectHasFile=B,h.query=w,h.readFileAsBase64=nt,h.resetPassword=Z,h.sendMail=yt,h.setApiClient=T,h.toQuery=wt,h.updatePassword=Y,h.updateUser=ht,h.verifyCode=K,h.webAuthn=z,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(h,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("json-to-graphql-query"),require("collect.js"),require("axios")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","collect.js","axios"],b):(h=typeof globalThis<"u"?globalThis:h||self,b(h.light={},h.jsonToGraphqlQuery,h.collect,h.axios))})(this,(function(h,b,E,bt){"use strict";function v(t){if(t===null||typeof t!="object")return!1;const e=Object.getPrototypeOf(t);return e!==null&&e!==Object.prototype&&Object.getPrototypeOf(e)!==null||Symbol.iterator in t?!1:Symbol.toStringTag in t?Object.prototype.toString.call(t)==="[object Module]":!0}function S(t,e,r=".",s){if(!v(e))return S(t,{},r,s);const o=Object.assign({},e);for(const u in t){if(u==="__proto__"||u==="constructor")continue;const l=t[u];l!=null&&(s&&s(o,u,l,r)||(Array.isArray(l)&&Array.isArray(o[u])?o[u]=[...l,...o[u]]:v(l)&&v(o[u])?o[u]=S(l,o[u],(r?`${r}.`:"")+u.toString(),s):o[u]=l))}return o}function mt(t){return(...e)=>e.reduce((r,s)=>S(r,s,"",t),{})}const C=mt();let j=null;const T=t=>{j=t},M=()=>{if(!j)throw new Error("Api client not initialized. Call setApiClient() first.");return j},Ft=()=>j;function D(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function B(t){for(let e in t)if(t[e]instanceof File||t[e]instanceof Array&&D(t[e]))return!0;return!1}function At(t){t="<~"+t+"~>";var e,r,s,o,u,l=String,p=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=[],o=0,u=t.length;u>o;o+=5)r=52200625*(t.charCodeAt(o)-33)+614125*(t.charCodeAt(o+1)-33)+7225*(t.charCodeAt(o+2)-33)+85*(t.charCodeAt(o+3)-33)+(t.charCodeAt(o+4)-33),s.push(p&r>>24,p&r>>16,p&r>>8,p&r);return(function(n,i){for(var a=i;a>0;a--)n.pop()})(s,e.length),l.fromCharCode.apply(l,s)}const q=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const o=new Uint8Array(e.length);for(let p=0;p<e.length;p++)o[p]=e.charCodeAt(p);const u=new Blob([o],{type:s});return URL.createObjectURL(u)};return{getContent:()=>e,getURL:r,download:s=>{const o=document.createElement("a");o.download=s,o.href=r(),document.body.appendChild(o),o.click(),document.body.removeChild(o)},open:s=>{window.open(r(s),"_blank")}}},Ct=t=>q(atob(t)),Ot=t=>q(At(t));function $(t,e,r,s,o){if(!(!t||typeof t!="object"))for(let u in t){const l=t[u];if(l&&typeof l=="object"){if("__args"in l){const p=l.__args,n={};Object.entries(p).forEach(([i,a])=>{if(a instanceof Array&&D(a)){n[i]=new b.VariableType(i);let c=0;a.forEach(f=>{f instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+i+"."+c),s.append(o.current.toString(),f),o.current++,c++)}),e[i]="[Upload!]!"}else a instanceof File?(n[i]=new b.VariableType(i),r[o.current]=["variables."+i],s.append(o.current.toString(),a),e[i]="Upload!",o.current++):a instanceof Object&&B(a)?(n[i]={},Object.entries(a).forEach(([c,f])=>{if(f instanceof Array&&D(f)){n[i][c]=new b.VariableType(c);let g=0;f.forEach(_=>{_ instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+c+"."+g),s.append(o.current.toString(),_),o.current++,g++)}),e[c]="[Upload!]!"}else f instanceof File?(n[i][c]=new b.VariableType(c),r[o.current]=["variables."+c],s.append(o.current.toString(),f),e[c]="Upload!",o.current++):n[i][c]=f})):a!=null&&(n[i]=a)}),l.__args=n}$(l,e,r,s,o)}}}const w=async t=>{const{axios:e}=M(),r=t,s=new FormData;let o=!1;const u={},l={};$(r,u,l,s,{current:0}),o=Object.keys(u).length>0,o&&(r.__variables=u);let n=null;const i={query:r},a=b.jsonToGraphQLQuery(i);if(o?(s.append("map",JSON.stringify(l)),s.append("operations",JSON.stringify({query:a})),n=await e.post("",s)):n=await e.post("",{query:a}),n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data};function P(t,e){let r,s=[],o,u;const l=n=>!n||typeof n!="object"?!1:Object.values(n).some(i=>i&&typeof i=="object"&&Object.keys(i).some(a=>a.startsWith("_"))),p=()=>s.length===0?(s.unshift({}),s[0]):(l(s[0])&&s.unshift({}),s[0]);return{first(){return this.fetchFirst()},all(){return this.fetch()},async fetchFirst(){const i=await this.limit(1).fetch();return Array.isArray(i)&&i.length>0?i[0]:null},async fetchWithMeta(){let i=await w(this.toQuery(!0));if(u){const a=u.split(".");for(const c of a)i=i[c];return i}return i[`list${t}`]},async fetch(){let i=await w(this.toQuery());if(u){const a=u.split(".");for(const c of a)i=i[c];return i.data}return i[`list${t}`].data},dataPath(n){return n&&typeof n=="string"&&(u=n),this},sort(n){return n&&typeof n=="string"&&(o=n),this},filters(n){return n&&typeof n=="object"&&(s=[n]),this},where(n,i,a){const c=(f,g,_)=>{const F={">":"_gt","<":"_lt",">=":"_gte","<=":"_lte","!=":"_ne",in:"_in",contains:"_contains"}[g];F&&s.push({[f]:{[F]:_}})};if(a!==void 0)c(n,String(i),a);else{const f=p(),g=C(f,{[n]:i});s[0]=g}return this},whereContains(n,i){if(n&&typeof n=="string"){const a=p(),c={_contains:i};a[n]?Array.isArray(a[n])?a[n].push(c):a[n]=[a[n],c]:a[n]=[c],s[0]=a}return this},whereIn(n,i){if(n&&typeof n=="string"&&Array.isArray(i)){const a=p(),c={_in:i};a[n]?Array.isArray(a[n])?a[n].push(c):a[n]=[a[n],c]:a[n]=[c],s[0]=a}return this},whereBetween(n,i,a){if(n&&typeof n=="string"){const c=p(),f={_between:[i,a]};c[n]?Array.isArray(c[n])?c[n].push(f):c[n]=[c[n],f]:c[n]=f,s[0]=c}return this},limit(n){return typeof n=="number"&&Number.isFinite(n)&&(r=C(r||{},{limit:n})),this},offset(n){return typeof n=="number"&&Number.isFinite(n)&&(r=C(r||{},{offset:n})),this},toQuery(n=!1){let i;const a=s.length>0&&Object.keys(s[0]||{}).length>0,c=a?1:0,f=s.length>c;a&&f?i=s:f?i=s.slice(c):a&&(i=s[0]);const g=C(o?{sort:o}:{},i?{filters:i}:{}),_={data:{...e}};if(r&&(_.data.__args=r),Object.keys(g).length>0&&(_.__args=g),n&&(_.meta={total:!0,key:!0,name:!0}),u){const A=u.split(".");let F=_;for(let m=A.length-1;m>=0;m--)F={[A[m]]:F};return F}return{[`list${t}`]:_}}}}const Dt="list",Pt=["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"],jt=["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"];class y{_batchData=null;data_path="";filters;steps;fields;already_limit=!1;already_offset=!1;limit=null;offset=null;_sort=null;_sortDesc=!1;meta={};constructor(e){this.filters={},this.steps=[],this.fields=e}}y.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}},y.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},y.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},y.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},E().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),y.prototype.fetchData=async function(){try{if(this._batchData){const p=this._batchData;return this.meta=p.meta,E(p.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,o=e[e.length-1];for(const p of e){if(p===o){s[p]=t;break}s[p]={},s=s[p]}let l=await w(r);for(const p of e)l=l[p];return this.meta=l.meta,E(l.data)}catch(t){throw console.error("Error fetching collection data:",t),t}},y.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},y.prototype.all=async function(){return(await this.processData()).all()};for(const t of Pt)y.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of jt)y.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};y.prototype.average=y.prototype.avg,y.prototype.first=async function(){return this.take(1),(await this.processData()).first()},y.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},y.prototype.where=function(...t){const e=this._handleBatchData("where",t);if(e)return e;if(t.length===2)this.filters[t[0]]=t[1];else if(t.length===3){const r=t[0],s=t[1],o=t[2];switch(s){case"==":this.filters[r]=o;break;case"<":this.filters[r]={lt:o};break;case"<=":this.filters[r]={lte:o};break;case">":this.filters[r]={gt:o};break;case">=":this.filters[r]={gte:o};break;case"!==":this.filters[r]={ne:o};break;default:throw new Error(`Unsupported operator: ${s}`)}}return this},y.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},y.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)},y.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},y.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},y.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},y.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},y.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},y.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},y.prototype.skip=function(t){if(t<0)throw new Error("Offset must be non-negative");return this.already_offset&&this.steps.push({type:"skip",args:[t]}),this.offset=t,this.already_offset=!0,this},y.prototype.take=function(t){if(t<0)throw new Error("Length must be non-negative");return this.already_limit?(this.steps.push({type:"take",args:[t]}),this):(this.limit=t,this.already_limit=!0,this)},y.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 N=(t,e)=>{const r=new y(e);return r.data_path=Dt+t,r},kt=(t,e={})=>{const r=e;let s="list"+t;const o=u=>r[u]?r[u]:null;return{field:o,$fields:r,setDataPath(u){return s=u,s},getDataPath(){return s},gqlFields(u){let l={};for(const p of u)if(typeof p=="string"){const n=o(p);n&&(l=C(l,n.gqlField?typeof n.gqlField=="string"?{[n.gqlField]:!0}:n.gqlField:{[n.name||p]:!0}))}else typeof p=="object"&&(l=C(l,p));return l},update(u,l){return d({["update"+t]:{__args:{id:u,data:l}}}).then(p=>p["update"+t])},async delete(u){return d({["delete"+t]:{__args:{id:u}}}).then(l=>l["delete"+t])},add(u){return d({["add"+t]:{__args:{data:u}}}).then(l=>l["add"+t])},fields(u){let l=[];for(let p of u){const n=o(p);n&&l.push(n)}return l},async get(u,l){const p=N(t,wt(l));for(const[n,i]of Object.entries(u))p.where(n,"==",i);return await p.first()},list(u){let l=u;const p={};Object.entries(u).forEach(([a])=>{r[a]&&(p[a]=r[a],r[a].gqlField&&(delete l[a],l=C(l,r[a].gqlField)),r[a].gql&&(delete l[a],l=C(l,r[a].gql)))});const n=P(t,l).dataPath(s),i=n.fetch.bind(n);return{...n,async fetch(){return(await i()).map(c=>{const f={...c};return Object.entries(p).forEach(([g,_])=>{_.field&&typeof _.field=="function"&&(f[g]=_.field(c[g],c))}),f})},async fetchFirst(){const c=await n.fetchFirst.bind(n)();if(!c)return c;const f={...c};return Object.entries(p).forEach(([g,_])=>{_.field&&typeof _.field=="function"&&(f[g]=_.field(c[g],c))}),f}}}}},O={},L=(t,e)=>{const r=kt(t,e);return O[t]=r,r},k=t=>O[t]?O[t]:L(t,{}),Ut=t=>!!O[t],Et=()=>Object.keys(O),vt=()=>{Object.keys(O).forEach(t=>delete O[t])},St=t=>{Object.entries(t).forEach(([e,r])=>{L(e,r)})},Mt=()=>w({app:{permissions:!0}}).then(t=>t.app.permissions),Q=async()=>{const{app:t}=await w({app:{auth:{webAuthnRequestOptions:!0}}}),e=t.auth.webAuthnRequestOptions,r=PublicKeyCredential.parseRequestOptionsFromJSON(e);return await navigator.credentials.get({publicKey:r})},W=async()=>{const{app:t}=await w({app:{auth:{webAuthnCreationOptions:!0}}}),e=PublicKeyCredential.parseCreationOptionsFromJSON(t.auth.webAuthnCreationOptions);return await navigator.credentials.create({publicKey:e})},z=Object.freeze(Object.defineProperty({__proto__:null,assertion:Q,attestation:W,login:async()=>{const t=await Q();return await d({webAuthnAssertion:{__args:{assertion:t.toJSON()}}}).then(e=>e.webAuthnAssertion)},register:async()=>{const t=await W();return await d({webAuthnRegister:{__args:{registration:t.toJSON()}}}).then(e=>e.webAuthnRegister)}},Symbol.toStringTag,{value:"Module"})),G=(t=J)=>w({my:t}).then(e=>e.my),H=(t,e,r="")=>d({login:{__args:{username:t,password:e,code:r}}}).then(s=>s.login),V=()=>d({logout:!0}).then(t=>t.logout),X=(t,e,r)=>d({changeExpiredPassword:{__args:{username:t,old_password:e,new_password:r}}}).then(s=>s.changeExpiredPassword),Y=(t,e)=>d({changeUserPassword:{__args:{old_password:t,new_password:e}}}).then(r=>r.changeUserPassword),Z=(t,e,r)=>d({resetPassword:{__args:{jwt:t,password:e,code:r}}}).then(s=>s.resetPassword),I=(t,e)=>d({forgetPassword:{__args:{username:t,email:e}}}).then(r=>r.forgetPassword),K=(t,e)=>d({forgetPasswordVerifyCode:{__args:{jwt:t,code:e}}}).then(r=>r.forgetPasswordVerifyCode),x=t=>w({my:{granted:{__args:{right:t}}}}).then(e=>e.my.granted),tt=t=>w({my:{grantedRights:{__args:{rights:t}}}}).then(e=>e.my.grantedRights),et={getCurrentUser:G,webAuthn:z,google:{unlink:()=>d({lightAuthUnlinkGoogle:!0}).then(t=>t.lightAuthUnlinkGoogle),login:t=>d({lightAuthLoginGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthLoginGoogle),register:t=>d({lightAuthRegisterGoogle:{__args:{credential:t}}}).then(e=>e.lightAuthRegisterGoogle)},facebook:{unlink:()=>d({lightAuthUnlinkFacebook:!0}).then(t=>t.lightAuthUnlinkFacebook),login:t=>d({lightAuthLoginFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginFacebook),register:t=>d({lightAuthRegisterFacebook:{__args:{access_token:t}}}).then(e=>e.lightAuthRegisterFacebook)},microsoft:{unlink:()=>d({lightAuthUnlinkMicrosoft:!0}).then(t=>t.lightAuthUnlinkMicrosoft),login:t=>d({lightAuthLoginMicrosoft:{__args:{access_token:t}}}).then(e=>e.lightAuthLoginMicrosoft),register:t=>d({lightAuthRegisterMicrosoft:{__args:{account_id:t}}}).then(e=>e.lightAuthRegisterMicrosoft)},login:H,logout:V,changeExpiredPassword:X,updatePassword:Y,resetPassword:Z,forgetPassword:I,verifyCode:K,grantedRights:tt,isGranted:x},rt={name:!0,path:!0,size:!0,mime:!0,url:!0},st=(t,e,r=rt)=>w({app:{drive:{__args:{index:t},files:{__args:{path:e},...r}}}}).then(s=>s.app.drive.files),nt=(t,e)=>w({app:{drive:{__args:{index:t},file:{__args:{path:e},base64Content:!0}}}}).then(r=>r.app.drive?.file?.base64Content),Bt=t=>({list:(e,r=rt)=>st(t,e,r),get:(e,r={name:!0,path:!0,size:!0,mime:!0,url:!0})=>w({app:{drive:{__args:{index:t},file:{__args:{path:e},...r}}}}).then(s=>s.app.drive.file),readFileAsBase64(e){return nt(t,e)},read:async e=>{let r=await w({app:{drive:{__args:{index:t},file:{__args:{path:e},base64Content:!0}}}});if(!r.app.drive.file||!r.app.drive.file.base64Content)throw new Error(`File not found or cannot read content: ${e}`);return typeof window<"u"&&window.atob?window.atob(r.app.drive.file.base64Content):r.app.drive.file.base64Content},write:(e,r)=>d({lightDriveWriteFile:{__args:{index:t,path:e,content:r}}}).then(s=>s.lightDriveWriteFile),delete:e=>d({lightDriveDeleteFile:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFile),rename:(e,r)=>d({lightDriveRenameFile:{__args:{index:t,path:e,name:r}}}).then(s=>s.lightDriveRenameFile),move:(e,r)=>d({lightDriveMoveFile:{__args:{index:t,source:e,destination:r}}}).then(s=>s.lightDriveMoveFile)}),it={name:!0,path:!0},ot=(t,e,r=it)=>w({app:{drive:{__args:{index:t},folders:{__args:{path:e},...r}}}}).then(s=>s.app.drive.folders),qt=t=>({list:(e,r=it)=>ot(t,e,r),create:e=>d({lightDriveCreateFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveCreateFolder),delete:e=>d({lightDriveDeleteFolder:{__args:{index:t,path:e}}}).then(r=>r.lightDriveDeleteFolder),rename:(e,r)=>d({lightDriveRenameFolder:{__args:{index:t,path:e,name:r}}}).then(s=>s.lightDriveRenameFolder)}),Nt=()=>w({app:{drives:{index:!0,name:!0}}}).then(t=>t.app.drives),at=t=>{const e=Bt(t),r=qt(t);return{folders:r,files:e,listFiles:e.list,getFile:e.get,readFile:e.read,writeFile:e.write,deleteFile:e.delete,renameFile:e.rename,moveFile:e.move,listFolders:r.list,createFolder:r.create,deleteFolder:r.delete,renameFolder:r.rename,uploadTempFile:s=>d({lightDriveUploadTempFile:{__args:{index:t,file:s},name:!0,path:!0,size:!0,mime:!0}}).then(o=>o.lightDriveUploadTempFile)}},J={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0},ct=t=>d({addUser:{__args:t}}).then(e=>e.addUser),lt=t=>d({deleteUser:{__args:{id:t}}}).then(e=>e.deleteUser),ut=(t=J)=>P("Users",t).dataPath("app.listUser").fetch(),ht=(t,e)=>d({updateUser:{__args:{id:t,data:e}}}).then(r=>r.updateUser),Lt={list:ut,create:ct,delete:lt,update:ht},ft=t=>w({app:{listConfig:{__args:{filters:{name:t}},data:{name:!0,value:!0}}}}).then(e=>e.app.listConfig.data[0]?.value),Jt={name:!0},pt=(t=Jt)=>w({app:{roles:t}}).then(e=>e.app.roles),dt=(t,e)=>d({addRole:{__args:{data:{name:t,childs:e}}}}).then(r=>r.addRole),gt=t=>d({deleteRole:{__args:{name:t}}}).then(e=>e.deleteRole),Rt=()=>({list:pt,create:dt,delete:gt});function _t(t,e,r,s,o){if(!(!t||typeof t!="object"))for(let u in t){const l=t[u];if(l&&typeof l=="object"){if("__args"in l){const p=l.__args,n={};Object.entries(p).forEach(([i,a])=>{if(a instanceof Array&&D(a)){n[i]=new b.VariableType(i);let c=0;a.forEach(f=>{f instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+i+"."+c),s.append(o.current.toString(),f),o.current++,c++)}),e[i]="[Upload!]!"}else a instanceof File?(n[i]=new b.VariableType(i),r[o.current]=["variables."+i],s.append(o.current.toString(),a),e[i]="Upload!",o.current++):a instanceof Object&&B(a)?(n[i]={},Object.entries(a).forEach(([c,f])=>{if(f instanceof Array&&D(f)){n[i][c]=new b.VariableType(c);let g=0;f.forEach(_=>{_ instanceof File&&(r[o.current]||(r[o.current]=[]),r[o.current].push("variables."+c+"."+g),s.append(o.current.toString(),_),o.current++,g++)}),e[c]="[Upload!]!"}else f instanceof File?(n[i][c]=new b.VariableType(c),r[o.current]=["variables."+c],s.append(o.current.toString(),f),e[c]="Upload!",o.current++):n[i][c]=f})):a!=null&&(n[i]=a)}),l.__args=n}_t(l,e,r,s,o)}}}const d=async t=>{const{axios:e}=M(),r=t,s=new FormData;let o=!1;const u={},l={};_t(r,u,l,s,{current:0}),o=Object.keys(u).length>0,o&&(r.__variables=u);let n=null;const i={mutation:r},a=b.jsonToGraphQLQuery(i);if(o?(s.append("map",JSON.stringify(l)),s.append("operations",JSON.stringify({query:a})),n=await e.post("",s)):n=await e.post("",{query:a}),n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data},yt=(t,e,r)=>d({sendMail:{__args:{email:t,subject:e,message:r}}}).then(s=>s.sendMail),Tt={send:yt},R=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(R(r)).forEach(([s,o])=>{e[s]=o})}),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)},wt=t=>R(t),$t=t=>{const e=typeof window>"u";let r=[];const s=bt.create({baseURL:t,withCredentials:!0});let o=!1,u=[];const l=(i,a=null)=>{u.forEach(c=>{i?c.reject(i):c.resolve(a)}),u=[]};s.interceptors.response.use(i=>{const a=i.data.errors;if(a&&a.some(c=>c.extensions?.code==="TOKEN_EXPIRED")){const c=i.config;return o?new Promise((f,g)=>{u.push({resolve:f,reject:g})}).then(()=>s(c)).catch(f=>Promise.reject(f)):(o=!0,p().then(()=>(o=!1,l(null),s(c))).catch(f=>(o=!1,l(f),Promise.reject(f))))}return i},i=>Promise.reject(i));function p(){return s.post("/refresh_token")}e&&(s.interceptors.request.use(i=>(i.withCredentials=!0,r.length>0&&(i.headers.Cookie=r.join("; ")),i)),s.interceptors.response.use(i=>{if(i.headers["set-cookie"]){const a=i.headers["set-cookie"].map(f=>f.split(";")[0]),c=new Map;r.forEach(f=>{const g=f.split("=")[0];c.set(g,f)}),a.forEach(f=>{const g=f.split("=")[0];c.set(g,f)}),r=Array.from(c.values())}return i}));const n={post:s.post,baseURL:t,axios:s,auth:et,mutation:d,query:w,config:ft,mail:Tt,users:Lt,model(i){return k(i)},roles:Rt(),collect:(i,a)=>{const c=N(i,a);return c.data_path=k(i).getDataPath(),c},list:(i,a)=>P(i,a).dataPath(k(i).getDataPath()),drive:at,async collects(i){const a={},c={};for(const g in i){const _=i[g].getQueryPayload();c[g]=_.data_path,a[g]={};const A=_.data_path.split(".");let F=A[A.length-1],m=a[g];for(const U of A){if(U===F){m[U]=_.query;break}m[U]=m[U]||{}}a[g].__aliasFor=A[0]}const f=await w(a);for(const g in i){const _=c[g].split(".");let A=_[_.length-1],F=f[g];for(const m of _){if(m===A){i[g]._batchData=f[g][m];break}F[m]=F[m]||{}}}return i}};return T(n),n},Qt=P;h.arrayHasFile=D,h.auth=et,h.changeExpiredPassword=X,h.clearModels=vt,h.createClient=$t,h.createCollection=N,h.createFileFromBase64=Ct,h.createFileFromBase85=Ot,h.createFileFromString=q,h.createList=P,h.createRole=dt,h.createUser=ct,h.defaultUserFields=J,h.defineModel=L,h.defineModels=St,h.deleteRole=gt,h.deleteUser=lt,h.forgetPassword=I,h.getApiClient=M,h.getApiClientOptional=Ft,h.getConfig=ft,h.getCurrentUser=G,h.getDrive=at,h.getGrantedRights=tt,h.getModel=k,h.hasModel=Ut,h.isGranted=x,h.list=Qt,h.listDrives=Nt,h.listFiles=st,h.listFolders=ot,h.listModels=Et,h.listPermissions=Mt,h.listRoles=pt,h.listUsers=ut,h.login=H,h.logout=V,h.mutation=d,h.objectHasFile=B,h.query=w,h.readFileAsBase64=nt,h.resetPassword=Z,h.sendMail=yt,h.setApiClient=T,h.toQuery=wt,h.updatePassword=Y,h.updateUser=ht,h.verifyCode=K,h.webAuthn=z,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/light",
3
- "version": "3.1.0",
3
+ "version": "3.2.2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"