@hostlink/light 0.0.16 → 0.0.18

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/index.d.ts CHANGED
@@ -9,4 +9,5 @@ import uploadFile from './uploadFile';
9
9
  import sendMail from './sendMail';
10
10
  import webauthnLogin from './webauthnLogin';
11
11
  import webauthnRegister from './webauthnRegister';
12
- export { toQuery, login, logout, query, mutation, getApiUrl, setApiUrl, uploadFile, sendMail, webauthnLogin, webauthnRegister };
12
+ export type Fields = Object | Array<string | Object> | string;
13
+ export { toQuery, login, logout, query, mutation, getApiUrl, setApiUrl, uploadFile, sendMail, webauthnLogin, webauthnRegister, };
package/dist/light.js CHANGED
@@ -1,4 +1,4 @@
1
- import { jsonToGraphQLQuery as w, VariableType as C } from "json-to-graphql-query";
1
+ import { jsonToGraphQLQuery as w, VariableType as E } from "json-to-graphql-query";
2
2
  import h from "axios";
3
3
  const m = () => localStorage.getItem("light-api-url") === null ? "/api/" : localStorage.getItem("light-api-url"), d = async (t, e = null, r = []) => {
4
4
  const n = h.create({
@@ -6,8 +6,8 @@ const m = () => localStorage.getItem("light-api-url") === null ? "/api/" : local
6
6
  }), i = {
7
7
  mutation: {}
8
8
  };
9
- i.mutation[t] = !0, e && (i.mutation[t] = {}, i.mutation[t].__args = e), r.length > 0 && (i.mutation[t] = {}), r.forEach((l) => {
10
- i.mutation[t][l] = !0;
9
+ i.mutation[t] = !0, e && (i.mutation[t] = {}, i.mutation[t].__args = e), r instanceof Array && r.length == 0 && (i.mutation[t] = {}), Object.entries(b(r)).forEach(([l, C]) => {
10
+ i.mutation[t][l] = C;
11
11
  });
12
12
  const u = await n.post(m(), {
13
13
  query: w(i)
@@ -19,34 +19,38 @@ const m = () => localStorage.getItem("light-api-url") === null ? "/api/" : local
19
19
  username: t,
20
20
  password: e,
21
21
  code: r
22
- }), F = async () => await d("logout"), f = (t) => {
22
+ }), B = async () => await d("logout"), f = (t) => {
23
23
  let e = {};
24
24
  return typeof t == "string" ? (e[t] = !0, e) : t instanceof Array ? (t.forEach((r) => {
25
25
  Object.entries(f(r)).forEach(([n, i]) => {
26
26
  e[n] = i;
27
27
  });
28
28
  }), e) : (Object.entries(t).forEach(([r, n]) => {
29
- if (r == "__args") {
29
+ if (r == "__args" || r == "__aliasFor" || r == "__variables" || r == "__directives" || r == "__all_on" || r == "__name") {
30
30
  e[r] = n;
31
31
  return;
32
32
  }
33
- n === !0 ? e[r] = !0 : e[r] = f(n);
33
+ if (typeof n == "boolean") {
34
+ e[r] = n;
35
+ return;
36
+ }
37
+ e[r] = f(n);
34
38
  }), e);
35
- }, E = (t) => f(t), y = async (t) => {
39
+ }, b = (t) => f(t), y = async (t) => {
36
40
  const e = h.create({
37
41
  withCredentials: !0
38
42
  });
39
- let r = w(E(t));
43
+ let r = w(b(t));
40
44
  const n = await e.post(m(), {
41
45
  query: `{ ${r} }`
42
46
  });
43
47
  if (n.data.errors)
44
48
  throw new Error(n.data.errors[0].message);
45
49
  return n.data.data;
46
- }, B = (t) => {
50
+ }, M = (t) => {
47
51
  localStorage.setItem("light-api-url", t);
48
52
  };
49
- async function M(t) {
53
+ async function P(t) {
50
54
  const e = h.create({
51
55
  withCredentials: !0
52
56
  }), r = {
@@ -55,7 +59,7 @@ async function M(t) {
55
59
  },
56
60
  fsUploadTempFile: {
57
61
  __args: {
58
- file: new C("file")
62
+ file: new E("file")
59
63
  },
60
64
  name: !0,
61
65
  path: !0,
@@ -71,14 +75,14 @@ async function M(t) {
71
75
  throw new Error(i.data.errors[0].message);
72
76
  return i.data.data.fsUploadTempFile;
73
77
  }
74
- const P = (t, e, r) => d("sendMail", { email: t, subject: e, message: r });
75
- function b(t) {
78
+ const Q = (t, e, r) => d("sendMail", { email: t, subject: e, message: r });
79
+ function O(t) {
76
80
  const e = "==".slice(0, (4 - t.length % 4) % 4), r = t.replace(/-/g, "+").replace(/_/g, "/") + e, n = atob(r), i = new ArrayBuffer(n.length), u = new Uint8Array(i);
77
81
  for (let l = 0; l < n.length; l++)
78
82
  u[l] = n.charCodeAt(l);
79
83
  return i;
80
84
  }
81
- function O(t) {
85
+ function S(t) {
82
86
  const e = new Uint8Array(t);
83
87
  let r = "";
84
88
  for (const u of e)
@@ -140,7 +144,7 @@ function s(t) {
140
144
  schema: t
141
145
  };
142
146
  }
143
- var S = {
147
+ var _ = {
144
148
  type: o(a),
145
149
  id: o(c),
146
150
  transports: s(a)
@@ -163,7 +167,7 @@ var S = {
163
167
  challenge: o(c),
164
168
  pubKeyCredParams: o(a),
165
169
  timeout: s(a),
166
- excludeCredentials: s([S]),
170
+ excludeCredentials: s([_]),
167
171
  authenticatorSelection: s(a),
168
172
  attestation: s(a),
169
173
  extensions: s(v)
@@ -195,7 +199,7 @@ var S = {
195
199
  challenge: o(c),
196
200
  timeout: s(a),
197
201
  rpId: s(a),
198
- allowCredentials: s([S]),
202
+ allowCredentials: s([_]),
199
203
  userVerification: s(a),
200
204
  extensions: s(v)
201
205
  }),
@@ -217,56 +221,56 @@ var S = {
217
221
  )
218
222
  };
219
223
  function N(t) {
220
- return p(b, R, t);
224
+ return p(O, R, t);
221
225
  }
222
- function _(t) {
226
+ function j(t) {
223
227
  return p(
224
- O,
228
+ S,
225
229
  q,
226
230
  t
227
231
  );
228
232
  }
229
- function j(t) {
230
- return p(b, x, t);
231
- }
232
233
  function T(t) {
234
+ return p(O, x, t);
235
+ }
236
+ function K(t) {
233
237
  return p(
234
- O,
238
+ S,
235
239
  J,
236
240
  t
237
241
  );
238
242
  }
239
- async function K(t) {
243
+ async function U(t) {
240
244
  const e = await navigator.credentials.create(
241
245
  t
242
246
  );
243
- return e.toJSON = () => _(e), e;
247
+ return e.toJSON = () => j(e), e;
244
248
  }
245
- async function U(t) {
249
+ async function D(t) {
246
250
  const e = await navigator.credentials.get(
247
251
  t
248
252
  );
249
- return e.toJSON = () => T(e), e;
253
+ return e.toJSON = () => K(e), e;
250
254
  }
251
- async function Q(t) {
255
+ async function L(t) {
252
256
  const r = (await y({
253
257
  webAuthnRequestOptions: {
254
258
  __args: {
255
259
  username: t
256
260
  }
257
261
  }
258
- })).webAuthnRequestOptions, n = j({
262
+ })).webAuthnRequestOptions, n = T({
259
263
  publicKey: r
260
- }), i = await U(n);
264
+ }), i = await D(n);
261
265
  await d("webAuthnAssertion", {
262
266
  username: t,
263
267
  assertion: i.toJSON()
264
268
  });
265
269
  }
266
- async function L() {
270
+ async function W() {
267
271
  const t = await y({ webAuthnCreationOptions: !0 }), e = N({
268
272
  publicKey: t.webAuthnCreationOptions
269
- }), r = await K(e);
273
+ }), r = await U(e);
270
274
  await d("webAuthnRegister", {
271
275
  registration: r.toJSON()
272
276
  });
@@ -274,13 +278,13 @@ async function L() {
274
278
  export {
275
279
  m as getApiUrl,
276
280
  V as login,
277
- F as logout,
281
+ B as logout,
278
282
  d as mutation,
279
283
  y as query,
280
- P as sendMail,
281
- B as setApiUrl,
282
- E as toQuery,
283
- M as uploadFile,
284
- Q as webauthnLogin,
285
- L as webauthnRegister
284
+ Q as sendMail,
285
+ M as setApiUrl,
286
+ b as toQuery,
287
+ P as uploadFile,
288
+ L as webauthnLogin,
289
+ W as webauthnRegister
286
290
  };
@@ -1 +1 @@
1
- (function(u,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("json-to-graphql-query"),require("axios")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","axios"],f):(u=typeof globalThis<"u"?globalThis:u||self,f(u.light={},u.jsonToGraphqlQuery,u.axios))})(this,function(u,f,w){"use strict";const h=()=>localStorage.getItem("light-api-url")===null?"/api/":localStorage.getItem("light-api-url"),p=async(e,t=null,n=[])=>{const i=w.create({withCredentials:!0}),o={mutation:{}};o.mutation[e]=!0,t&&(o.mutation[e]={},o.mutation[e].__args=t),n.length>0&&(o.mutation[e]={}),n.forEach(d=>{o.mutation[e][d]=!0});const l=await i.post(h(),{query:f.jsonToGraphQLQuery(o)});if(l.data.errors)throw new Error(l.data.errors[0].message);return l.data.data},E=async(e,t,n="")=>await p("login",{username:e,password:t,code:n}),R=async()=>await p("logout"),y=e=>{let t={};return typeof e=="string"?(t[e]=!0,t):e instanceof Array?(e.forEach(n=>{Object.entries(y(n)).forEach(([i,o])=>{t[i]=o})}),t):(Object.entries(e).forEach(([n,i])=>{if(n=="__args"){t[n]=i;return}i===!0?t[n]=!0:t[n]=y(i)}),t)},S=e=>y(e),m=async e=>{const t=w.create({withCredentials:!0});let n=f.jsonToGraphQLQuery(S(e));const i=await t.post(h(),{query:`{ ${n} }`});if(i.data.errors)throw new Error(i.data.errors[0].message);return i.data.data},j=e=>{localStorage.setItem("light-api-url",e)};async function J(e){const t=w.create({withCredentials:!0}),n={__variables:{file:"Upload!"},fsUploadTempFile:{__args:{file:new f.VariableType("file")},name:!0,path:!0,size:!0,mime:!0}},i=new FormData;i.append("operations",JSON.stringify({query:f.jsonToGraphQLQuery({mutation:n})})),i.append("map",JSON.stringify({0:["variables.file"]})),i.append("0",e);const o=await t.post(h(),i);if(o.data.errors)throw new Error(o.data.errors[0].message);return o.data.data.fsUploadTempFile}const N=(e,t,n)=>p("sendMail",{email:e,subject:t,message:n});function O(e){const t="==".slice(0,(4-e.length%4)%4),n=e.replace(/-/g,"+").replace(/_/g,"/")+t,i=atob(n),o=new ArrayBuffer(i.length),l=new Uint8Array(o);for(let d=0;d<i.length;d++)l[d]=i.charCodeAt(d);return o}function v(e){const t=new Uint8Array(e);let n="";for(const l of t)n+=String.fromCharCode(l);return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var r="copy",c="convert";function g(e,t,n){if(t===r)return n;if(t===c)return e(n);if(t instanceof Array)return n.map(i=>g(e,t[0],i));if(t instanceof Object){const i={};for(const[o,l]of Object.entries(t)){if(l.derive){const d=l.derive(n);d!==void 0&&(n[o]=d)}if(!(o in n)){if(l.required)throw new Error(`Missing key: ${o}`);continue}if(n[o]==null){i[o]=null;continue}i[o]=g(e,l.schema,n[o])}return i}}function b(e,t){return{required:!0,schema:e,derive:t}}function a(e){return{required:!0,schema:e}}function s(e){return{required:!1,schema:e}}var A={type:a(r),id:a(c),transports:s(r)},C={appid:s(r),appidExclude:s(r),credProps:s(r)},q={appid:s(r),appidExclude:s(r),credProps:s(r)},_={publicKey:a({rp:a(r),user:a({id:a(c),name:a(r),displayName:a(r)}),challenge:a(c),pubKeyCredParams:a(r),timeout:s(r),excludeCredentials:s([A]),authenticatorSelection:s(r),attestation:s(r),extensions:s(C)}),signal:s(r)},T={type:a(r),id:a(r),rawId:a(c),authenticatorAttachment:s(r),response:a({clientDataJSON:a(c),attestationObject:a(c),transports:b(r,e=>{var t;return((t=e.getTransports)==null?void 0:t.call(e))||[]})}),clientExtensionResults:b(q,e=>e.getClientExtensionResults())},U={mediation:s(r),publicKey:a({challenge:a(c),timeout:s(r),rpId:s(r),allowCredentials:s([A]),userVerification:s(r),extensions:s(C)}),signal:s(r)},K={type:a(r),id:a(r),rawId:a(c),authenticatorAttachment:s(r),response:a({clientDataJSON:a(c),authenticatorData:a(c),signature:a(c),userHandle:a(c)}),clientExtensionResults:b(q,e=>e.getClientExtensionResults())};function D(e){return g(O,_,e)}function F(e){return g(v,T,e)}function I(e){return g(O,U,e)}function Q(e){return g(v,K,e)}async function V(e){const t=await navigator.credentials.create(e);return t.toJSON=()=>F(t),t}async function L(e){const t=await navigator.credentials.get(e);return t.toJSON=()=>Q(t),t}async function M(e){const n=(await m({webAuthnRequestOptions:{__args:{username:e}}})).webAuthnRequestOptions,i=I({publicKey:n}),o=await L(i);await p("webAuthnAssertion",{username:e,assertion:o.toJSON()})}async function x(){const e=await m({webAuthnCreationOptions:!0}),t=D({publicKey:e.webAuthnCreationOptions}),n=await V(t);await p("webAuthnRegister",{registration:n.toJSON()})}u.getApiUrl=h,u.login=E,u.logout=R,u.mutation=p,u.query=m,u.sendMail=N,u.setApiUrl=j,u.toQuery=S,u.uploadFile=J,u.webauthnLogin=M,u.webauthnRegister=x,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
1
+ (function(u,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("json-to-graphql-query"),require("axios")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","axios"],f):(u=typeof globalThis<"u"?globalThis:u||self,f(u.light={},u.jsonToGraphqlQuery,u.axios))})(this,function(u,f,w){"use strict";const h=()=>localStorage.getItem("light-api-url")===null?"/api/":localStorage.getItem("light-api-url"),p=async(e,t=null,n=[])=>{const r=w.create({withCredentials:!0}),o={mutation:{}};o.mutation[e]=!0,t&&(o.mutation[e]={},o.mutation[e].__args=t),n instanceof Array&&n.length==0&&(o.mutation[e]={}),Object.entries(m(n)).forEach(([d,P])=>{o.mutation[e][d]=P});const l=await r.post(h(),{query:f.jsonToGraphQLQuery(o)});if(l.data.errors)throw new Error(l.data.errors[0].message);return l.data.data},q=async(e,t,n="")=>await p("login",{username:e,password:t,code:n}),E=async()=>await p("logout"),b=e=>{let t={};return typeof e=="string"?(t[e]=!0,t):e instanceof Array?(e.forEach(n=>{Object.entries(b(n)).forEach(([r,o])=>{t[r]=o})}),t):(Object.entries(e).forEach(([n,r])=>{if(n=="__args"||n=="__aliasFor"||n=="__variables"||n=="__directives"||n=="__all_on"||n=="__name"){t[n]=r;return}if(typeof r=="boolean"){t[n]=r;return}t[n]=b(r)}),t)},m=e=>b(e),y=async e=>{const t=w.create({withCredentials:!0});let n=f.jsonToGraphQLQuery(m(e));const r=await t.post(h(),{query:`{ ${n} }`});if(r.data.errors)throw new Error(r.data.errors[0].message);return r.data.data},R=e=>{localStorage.setItem("light-api-url",e)};async function j(e){const t=w.create({withCredentials:!0}),n={__variables:{file:"Upload!"},fsUploadTempFile:{__args:{file:new f.VariableType("file")},name:!0,path:!0,size:!0,mime:!0}},r=new FormData;r.append("operations",JSON.stringify({query:f.jsonToGraphQLQuery({mutation:n})})),r.append("map",JSON.stringify({0:["variables.file"]})),r.append("0",e);const o=await t.post(h(),r);if(o.data.errors)throw new Error(o.data.errors[0].message);return o.data.data.fsUploadTempFile}const J=(e,t,n)=>p("sendMail",{email:e,subject:t,message:n});function S(e){const t="==".slice(0,(4-e.length%4)%4),n=e.replace(/-/g,"+").replace(/_/g,"/")+t,r=atob(n),o=new ArrayBuffer(r.length),l=new Uint8Array(o);for(let d=0;d<r.length;d++)l[d]=r.charCodeAt(d);return o}function v(e){const t=new Uint8Array(e);let n="";for(const l of t)n+=String.fromCharCode(l);return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var i="copy",c="convert";function g(e,t,n){if(t===i)return n;if(t===c)return e(n);if(t instanceof Array)return n.map(r=>g(e,t[0],r));if(t instanceof Object){const r={};for(const[o,l]of Object.entries(t)){if(l.derive){const d=l.derive(n);d!==void 0&&(n[o]=d)}if(!(o in n)){if(l.required)throw new Error(`Missing key: ${o}`);continue}if(n[o]==null){r[o]=null;continue}r[o]=g(e,l.schema,n[o])}return r}}function O(e,t){return{required:!0,schema:e,derive:t}}function a(e){return{required:!0,schema:e}}function s(e){return{required:!1,schema:e}}var _={type:a(i),id:a(c),transports:s(i)},A={appid:s(i),appidExclude:s(i),credProps:s(i)},C={appid:s(i),appidExclude:s(i),credProps:s(i)},N={publicKey:a({rp:a(i),user:a({id:a(c),name:a(i),displayName:a(i)}),challenge:a(c),pubKeyCredParams:a(i),timeout:s(i),excludeCredentials:s([_]),authenticatorSelection:s(i),attestation:s(i),extensions:s(A)}),signal:s(i)},T={type:a(i),id:a(i),rawId:a(c),authenticatorAttachment:s(i),response:a({clientDataJSON:a(c),attestationObject:a(c),transports:O(i,e=>{var t;return((t=e.getTransports)==null?void 0:t.call(e))||[]})}),clientExtensionResults:O(C,e=>e.getClientExtensionResults())},U={mediation:s(i),publicKey:a({challenge:a(c),timeout:s(i),rpId:s(i),allowCredentials:s([_]),userVerification:s(i),extensions:s(A)}),signal:s(i)},K={type:a(i),id:a(i),rawId:a(c),authenticatorAttachment:s(i),response:a({clientDataJSON:a(c),authenticatorData:a(c),signature:a(c),userHandle:a(c)}),clientExtensionResults:O(C,e=>e.getClientExtensionResults())};function F(e){return g(S,N,e)}function D(e){return g(v,T,e)}function I(e){return g(S,U,e)}function Q(e){return g(v,K,e)}async function V(e){const t=await navigator.credentials.create(e);return t.toJSON=()=>D(t),t}async function L(e){const t=await navigator.credentials.get(e);return t.toJSON=()=>Q(t),t}async function M(e){const n=(await y({webAuthnRequestOptions:{__args:{username:e}}})).webAuthnRequestOptions,r=I({publicKey:n}),o=await L(r);await p("webAuthnAssertion",{username:e,assertion:o.toJSON()})}async function x(){const e=await y({webAuthnCreationOptions:!0}),t=F({publicKey:e.webAuthnCreationOptions}),n=await V(t);await p("webAuthnRegister",{registration:n.toJSON()})}u.getApiUrl=h,u.login=q,u.logout=E,u.mutation=p,u.query=y,u.sendMail=J,u.setApiUrl=R,u.toQuery=m,u.uploadFile=j,u.webauthnLogin=M,u.webauthnRegister=x,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
@@ -1,2 +1,3 @@
1
- declare const _default: (operation: string, args?: any, fields?: Array<any>) => Promise<any>;
1
+ import { Fields } from '.';
2
+ declare const _default: (operation: string, args?: any, fields?: Fields) => Promise<any>;
2
3
  export default _default;
package/dist/toQuery.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- declare const _default: (query: Object | Array<string | Object> | string) => any;
1
+ import { Fields } from ".";
2
+ declare const _default: (query: Fields) => any;
2
3
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/light",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"