@hostlink/light 2.0.1 → 2.0.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/README.md +37 -0
- package/dist/auth.d.ts +3 -3
- package/dist/light.js +5 -4
- package/dist/light.umd.cjs +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# HostLink Light Cient
|
|
2
|
+
|
|
3
|
+
A javascript library for Light Framework.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @hostlink/light
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```javascript
|
|
15
|
+
import { createClient } from '@hostlink/light';
|
|
16
|
+
|
|
17
|
+
const api=createClient('https://example.com/api');
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Login
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
await api.auth.login('username','password');
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Logout
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
await api.auth.logout();
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
package/dist/auth.d.ts
CHANGED
|
@@ -8,9 +8,9 @@ declare const _default: (axios: AxiosInstance) => {
|
|
|
8
8
|
login: (username: string, password: string, code?: string) => Promise<boolean>;
|
|
9
9
|
logout: () => Promise<boolean>;
|
|
10
10
|
updatePassword: (oldPassword: string, newPassword: string) => Promise<boolean>;
|
|
11
|
-
resetPassword: (
|
|
12
|
-
forgetPassword: (email: string) => Promise<boolean>;
|
|
13
|
-
verifyCode(
|
|
11
|
+
resetPassword: (username: string, password: string, code: string) => Promise<boolean>;
|
|
12
|
+
forgetPassword: (username: string, email: string) => Promise<boolean>;
|
|
13
|
+
verifyCode(username: string, code: string): Promise<boolean>;
|
|
14
14
|
granted: (rights: string[]) => Promise<string[]>;
|
|
15
15
|
};
|
|
16
16
|
export default _default;
|
package/dist/light.js
CHANGED
|
@@ -216,16 +216,17 @@ const H = (t) => ({
|
|
|
216
216
|
new_password: r
|
|
217
217
|
}),
|
|
218
218
|
resetPassword: (e, r, n) => c(t, "resetPassword", {
|
|
219
|
-
|
|
219
|
+
username: e,
|
|
220
220
|
password: r,
|
|
221
221
|
code: n
|
|
222
222
|
}),
|
|
223
|
-
forgetPassword: (e) => c(t, "forgetPassword", {
|
|
224
|
-
|
|
223
|
+
forgetPassword: (e, r) => c(t, "forgetPassword", {
|
|
224
|
+
username: e,
|
|
225
|
+
email: r
|
|
225
226
|
}),
|
|
226
227
|
verifyCode(e, r) {
|
|
227
228
|
return c(t, "verifyCode", {
|
|
228
|
-
|
|
229
|
+
username: e,
|
|
229
230
|
code: r
|
|
230
231
|
});
|
|
231
232
|
},
|
package/dist/light.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(h,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("json-to-graphql-query"),require("axios")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","axios"],y):(h=typeof globalThis<"u"?globalThis:h||self,y(h.light={},h.jsonToGraphqlQuery,h.axios))})(this,function(h,y,T){"use strict";function E(t){const e="==".slice(0,(4-t.length%4)%4),r=t.replace(/-/g,"+").replace(/_/g,"/")+e,n=atob(r),s=new ArrayBuffer(n.length),a=new Uint8Array(s);for(let u=0;u<n.length;u++)a[u]=n.charCodeAt(u);return s}function N(t){const e=new Uint8Array(t);let r="";for(const a of e)r+=String.fromCharCode(a);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var o="copy",m="convert";function O(t,e,r){if(e===o)return r;if(e===m)return t(r);if(e instanceof Array)return r.map(n=>O(t,e[0],n));if(e instanceof Object){const n={};for(const[s,a]of Object.entries(e)){if(a.derive){const u=a.derive(r);u!==void 0&&(r[s]=u)}if(!(s in r)){if(a.required)throw new Error(`Missing key: ${s}`);continue}if(r[s]==null){n[s]=null;continue}n[s]=O(t,a.schema,r[s])}return n}}function j(t,e){return{required:!0,schema:t,derive:e}}function l(t){return{required:!0,schema:t}}function d(t){return{required:!1,schema:t}}var J={type:l(o),id:l(m),transports:d(o)},L={appid:d(o),appidExclude:d(o),credProps:d(o)},P={appid:d(o),appidExclude:d(o),credProps:d(o)},U={publicKey:l({rp:l(o),user:l({id:l(m),name:l(o),displayName:l(o)}),challenge:l(m),pubKeyCredParams:l(o),timeout:d(o),excludeCredentials:d([J]),authenticatorSelection:d(o),attestation:d(o),extensions:d(L)}),signal:d(o)},V={type:l(o),id:l(o),rawId:l(m),authenticatorAttachment:d(o),response:l({clientDataJSON:l(m),attestationObject:l(m),transports:j(o,t=>{var e;return((e=t.getTransports)==null?void 0:e.call(t))||[]})}),clientExtensionResults:j(P,t=>t.getClientExtensionResults())},K={mediation:d(o),publicKey:l({challenge:l(m),timeout:d(o),rpId:d(o),allowCredentials:d([J]),userVerification:d(o),extensions:d(L)}),signal:d(o)},D={type:l(o),id:l(o),rawId:l(m),authenticatorAttachment:d(o),response:l({clientDataJSON:l(m),authenticatorData:l(m),signature:l(m),userHandle:l(m)}),clientExtensionResults:j(P,t=>t.getClientExtensionResults())};function B(t){return O(E,U,t)}function Q(t){return O(N,V,t)}function W(t){return O(E,K,t)}function M(t){return O(N,D,t)}async function $(t){const e=await navigator.credentials.create(t);return e.toJSON=()=>Q(e),e}async function z(t){const e=await navigator.credentials.get(t);return e.toJSON=()=>M(e),e}const H=t=>({login:async e=>{const n=(await w(t,{webAuthnRequestOptions:{__args:{username:e}}})).webAuthnRequestOptions,s=W({publicKey:n}),a=await z(s);await c(t,"webAuthnAssertion",{username:e,assertion:a.toJSON()})},register:async()=>{const e=await w(t,{webAuthnCreationOptions:!0}),r=B({publicKey:e.webAuthnCreationOptions}),n=await $(r);await c(t,"webAuthnRegister",{registration:n.toJSON()})}}),I=t=>({WebAuthn:H(t),googleLogin:e=>c(t,"googleLogin",{credential:e}),login:(e,r,n="")=>c(t,"login",{username:e,password:r,code:n}),logout:()=>c(t,"logout"),updatePassword:(e,r)=>c(t,"updatePassword",{old_password:e,new_password:r}),resetPassword:(e,r,n)=>c(t,"resetPassword",{
|
|
1
|
+
(function(h,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("json-to-graphql-query"),require("axios")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","axios"],y):(h=typeof globalThis<"u"?globalThis:h||self,y(h.light={},h.jsonToGraphqlQuery,h.axios))})(this,function(h,y,T){"use strict";function E(t){const e="==".slice(0,(4-t.length%4)%4),r=t.replace(/-/g,"+").replace(/_/g,"/")+e,n=atob(r),s=new ArrayBuffer(n.length),a=new Uint8Array(s);for(let u=0;u<n.length;u++)a[u]=n.charCodeAt(u);return s}function N(t){const e=new Uint8Array(t);let r="";for(const a of e)r+=String.fromCharCode(a);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var o="copy",m="convert";function O(t,e,r){if(e===o)return r;if(e===m)return t(r);if(e instanceof Array)return r.map(n=>O(t,e[0],n));if(e instanceof Object){const n={};for(const[s,a]of Object.entries(e)){if(a.derive){const u=a.derive(r);u!==void 0&&(r[s]=u)}if(!(s in r)){if(a.required)throw new Error(`Missing key: ${s}`);continue}if(r[s]==null){n[s]=null;continue}n[s]=O(t,a.schema,r[s])}return n}}function j(t,e){return{required:!0,schema:t,derive:e}}function l(t){return{required:!0,schema:t}}function d(t){return{required:!1,schema:t}}var J={type:l(o),id:l(m),transports:d(o)},L={appid:d(o),appidExclude:d(o),credProps:d(o)},P={appid:d(o),appidExclude:d(o),credProps:d(o)},U={publicKey:l({rp:l(o),user:l({id:l(m),name:l(o),displayName:l(o)}),challenge:l(m),pubKeyCredParams:l(o),timeout:d(o),excludeCredentials:d([J]),authenticatorSelection:d(o),attestation:d(o),extensions:d(L)}),signal:d(o)},V={type:l(o),id:l(o),rawId:l(m),authenticatorAttachment:d(o),response:l({clientDataJSON:l(m),attestationObject:l(m),transports:j(o,t=>{var e;return((e=t.getTransports)==null?void 0:e.call(t))||[]})}),clientExtensionResults:j(P,t=>t.getClientExtensionResults())},K={mediation:d(o),publicKey:l({challenge:l(m),timeout:d(o),rpId:d(o),allowCredentials:d([J]),userVerification:d(o),extensions:d(L)}),signal:d(o)},D={type:l(o),id:l(o),rawId:l(m),authenticatorAttachment:d(o),response:l({clientDataJSON:l(m),authenticatorData:l(m),signature:l(m),userHandle:l(m)}),clientExtensionResults:j(P,t=>t.getClientExtensionResults())};function B(t){return O(E,U,t)}function Q(t){return O(N,V,t)}function W(t){return O(E,K,t)}function M(t){return O(N,D,t)}async function $(t){const e=await navigator.credentials.create(t);return e.toJSON=()=>Q(e),e}async function z(t){const e=await navigator.credentials.get(t);return e.toJSON=()=>M(e),e}const H=t=>({login:async e=>{const n=(await w(t,{webAuthnRequestOptions:{__args:{username:e}}})).webAuthnRequestOptions,s=W({publicKey:n}),a=await z(s);await c(t,"webAuthnAssertion",{username:e,assertion:a.toJSON()})},register:async()=>{const e=await w(t,{webAuthnCreationOptions:!0}),r=B({publicKey:e.webAuthnCreationOptions}),n=await $(r);await c(t,"webAuthnRegister",{registration:n.toJSON()})}}),I=t=>({WebAuthn:H(t),googleLogin:e=>c(t,"googleLogin",{credential:e}),login:(e,r,n="")=>c(t,"login",{username:e,password:r,code:n}),logout:()=>c(t,"logout"),updatePassword:(e,r)=>c(t,"updatePassword",{old_password:e,new_password:r}),resetPassword:(e,r,n)=>c(t,"resetPassword",{username:e,password:r,code:n}),forgetPassword:(e,r)=>c(t,"forgetPassword",{username:e,email:r}),verifyCode(e,r){return c(t,"verifyCode",{username:e,code:r})},granted:async e=>(await w(t,{granted:{__args:{rights:e}}})).granted}),G=(t,e,r)=>{const n=e,s=t,a=r,u=i=>a[i]?a[i]():null;return{field:u,$fields:a,gqlFields(i){const p=[];for(const f of i)if(typeof f=="string"){const g=u(f);g&&p.push(g.getGQLField())}else typeof f=="object"&&p.push(f);return p},async update(i,p){return await c(s,"update"+n,{id:i,data:p})},async delete(i){return await c(s,"delete"+n,{id:i})},async add(i){return await c(s,"add"+n,{data:i})},fields(i){let p=[];for(let f of i){const g=u(f);g&&p.push(g)}return p},async get(i,p){return(await w(s,{["list"+n]:{__args:{filters:i},data:{__args:{limit:1},...S(p)}}}))["list"+n].data[0]},async list(i,p){return(await w(s,{["list"+n]:{__args:{filters:i},data:{...S(p)}}}))["list"+n].data}}};function X(t){t="<~"+t+"~>";var e,r,n,s,a,u=String,i=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,n=[],s=0,a=t.length;a>s;s+=5)r=52200625*(t.charCodeAt(s)-33)+614125*(t.charCodeAt(s+1)-33)+7225*(t.charCodeAt(s+2)-33)+85*(t.charCodeAt(s+3)-33)+(t.charCodeAt(s+4)-33),n.push(i&r>>24,i&r>>16,i&r>>8,i&r);return function(p,f){for(var g=f;g>0;g--)p.pop()}(n,e.length),u.fromCharCode.apply(u,n)}const q=(t="")=>{const e=t,r=(n="application/octet-stream")=>{const s=new Uint8Array(e.length);for(let i=0;i<e.length;i++)s[i]=e.charCodeAt(i);const a=new Blob([s],{type:n});return URL.createObjectURL(a)};return{getContent:()=>e,getURL:r,download:n=>{const s=document.createElement("a");s.download=n,s.href=r(),document.body.appendChild(s),s.click(),document.body.removeChild(s)},open:n=>{window.open(r(n),"_blank")}}},Y={fromBase85:t=>q(X(t)),fromBase64:t=>q(atob(t)),fromString:t=>q(t)},R=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(R(r)).forEach(([n,s])=>{e[n]=s})}),e):(Object.entries(t).forEach(([r,n])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=n;return}if(typeof n=="boolean"){e[r]=n;return}e[r]=R(n)}),e)},S=t=>R(t),w=async(t,e)=>{let r=y.jsonToGraphQLQuery(S(e));const n=await t.post("",{query:`{ ${r} }`});if(n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data};function Z(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function x(t){for(let e in t)if(t[e]instanceof File)return!0;return!1}const c=async(t,e,r=null,n=[])=>{let s={[e]:{}};const a=new FormData;let u=!1;if(r){const f={},g={},v={};let C=0;Object.entries(r).forEach(([b,_])=>{if(_ instanceof Array&&Z(_)){u=!0;let F=0;_.forEach(A=>{A instanceof File&&(f[b]=new y.VariableType(b),g[C]=["variables."+b+"."+F],a.append(C.toString(),A),C++)}),v[b]="[Upload!]!"}else _ instanceof File?(u=!0,f[b]=new y.VariableType(b),g[C]=["variables."+b],a.append(C.toString(),_),v[b]="Upload!",C++):_ instanceof Object&&x(_)?(u=!0,f[b]={},Object.entries(_).forEach(([F,A])=>{A instanceof File?(f[b][F]=new y.VariableType(F),g[C]=["variables."+F],a.append(C.toString(),A),v[F]="Upload!",C++):f[b][F]=A})):_!==void 0&&(f[b]=_)}),s[e].__args=f,s.__variables=v,u&&a.append("map",JSON.stringify(g))}Object.entries(S(n)).forEach(([f,g])=>{s[e][f]=g}),Object.entries(s[e]).length===0&&(s[e]=!0);let i=null;const p=y.jsonToGraphQLQuery({mutation:s});if(u?(a.append("operations",JSON.stringify({query:p})),i=await t.post("",a)):i=await t.post("",{query:p}),i.data.errors)throw new Error(i.data.errors[0].message);return i.data.data[e]},k=t=>({uploadTempFile:e=>c(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=>c(t,"fsCreateFolder",{path:e}),delete:e=>c(t,"fsDeleteFolder",{path:e}),rename:(e,r)=>c(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)=>c(t,"fsWriteFile",{path:e,content:r}),delete:e=>c(t,"fsDeleteFile",{path:e}),rename:(e,r)=>c(t,"fsRenameFile",{path:e,name:r}),move:(e,r)=>c(t,"fsMoveFile",{source:e,target:r})}}),ee=t=>({get:async e=>(await t({config:{__args:{name:e}}})).config}),te=t=>({send:(e,r,n)=>c(t,"sendMail",{email:e,subject:r,message:n})}),re=t=>({list:async()=>(await w(t,{listUser:{data:{user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0}}})).listUser.data}),ne=()=>{const t={};return{create(e,r){t[e]={};for(const n of Object.entries(r)){const[s,a]=n;t[e][s]=()=>({name:a.name?a.name:s,raw:a,getName:()=>a.name?a.name:s,getGQLField:()=>a.gqlField!==void 0?a.gqlField:a.name||s,getRaw(){return a},getValue(u){return a.field&&typeof a.field=="function"?a.field(u):a.field&&typeof a.field=="string"?u[a.field]:u[this.getName()]},getFormattedValue(u){const i=this.getValue(u);return a.format?a.format(i):i}})}return t[e]},get(e){return t[e]}}},se=t=>({list:async()=>(await w(t,{listRole:{name:!0}})).listRole}),ae=t=>{const e=T.create({baseURL:t,withCredentials:!0}),r=(a,u=null,i=[])=>c(e,a,u,i),n=a=>w(e,a),s=ne();return{baseURL:t,axios:e,auth:I(e),mutation:r,query:n,config:ee(n),mail:te(e),users:re(e),fs:k(e),models:s,model(a){return G(e,a,s.get(a))},roles:se(e)}};h.File=Y,h.createClient=ae,h.file=q,h.mutation=c,h.query=w,h.toQuery=S,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|