@hostlink/light 0.0.4 → 0.0.6
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/getApiUrl.d.ts +2 -0
- package/dist/index.d.ts +3 -1
- package/dist/light.js +43 -39
- package/dist/light.umd.cjs +1 -1
- package/dist/setApiUrl.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,6 @@ import logout from './logout';
|
|
|
3
3
|
import query from './query';
|
|
4
4
|
import mutation from './mutation';
|
|
5
5
|
import toQuery from './toQuery';
|
|
6
|
-
|
|
6
|
+
import getApiUrl from './getApiUrl';
|
|
7
|
+
import setApiUrl from './setApiUrl';
|
|
8
|
+
export { toQuery, login, logout, query, mutation, getApiUrl, setApiUrl };
|
package/dist/light.js
CHANGED
|
@@ -1,53 +1,57 @@
|
|
|
1
|
-
import { jsonToGraphQLQuery as
|
|
1
|
+
import { jsonToGraphQLQuery as c } from "json-to-graphql-query";
|
|
2
2
|
import u from "axios";
|
|
3
|
-
const
|
|
4
|
-
const
|
|
3
|
+
const l = async (t, e = null, a = []) => {
|
|
4
|
+
const o = u.create({
|
|
5
5
|
withCredentials: !0
|
|
6
|
-
}),
|
|
6
|
+
}), r = {
|
|
7
7
|
mutation: {}
|
|
8
8
|
};
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
r.mutation[t] = !0, e && (r.mutation[t] = {}, r.mutation[t].__args = e), a.length > 0 && (r.mutation[t] = {}), a.forEach((g) => {
|
|
10
|
+
r.mutation[t][g] = !0;
|
|
11
11
|
});
|
|
12
|
-
const s = "/api/",
|
|
13
|
-
query:
|
|
12
|
+
const s = {}.VITE_API_URL ?? "/api/", n = await o.post(s, {
|
|
13
|
+
query: c(r)
|
|
14
14
|
});
|
|
15
|
-
if (
|
|
16
|
-
throw new Error(
|
|
17
|
-
return
|
|
18
|
-
},
|
|
19
|
-
username:
|
|
20
|
-
password:
|
|
21
|
-
code:
|
|
22
|
-
}),
|
|
23
|
-
let
|
|
24
|
-
return Object.entries(
|
|
25
|
-
if (
|
|
26
|
-
a
|
|
15
|
+
if (n.data.errors)
|
|
16
|
+
throw new Error(n.data.errors[0].message);
|
|
17
|
+
return n.data.data;
|
|
18
|
+
}, p = async (t, e, a = "") => await l("login", {
|
|
19
|
+
username: t,
|
|
20
|
+
password: e,
|
|
21
|
+
code: a
|
|
22
|
+
}), w = async () => await l("logout"), i = function(t) {
|
|
23
|
+
let e = {};
|
|
24
|
+
return Object.entries(t).forEach(([a, o]) => {
|
|
25
|
+
if (a == "__args") {
|
|
26
|
+
e[a] = o;
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
a
|
|
32
|
-
}) : a
|
|
33
|
-
})) : a
|
|
34
|
-
}),
|
|
35
|
-
},
|
|
36
|
-
const
|
|
29
|
+
o instanceof Array ? (e[a] = {}, o.forEach((r) => {
|
|
30
|
+
r instanceof Object ? Object.entries(i(r)).forEach(([s, n]) => {
|
|
31
|
+
e[a][s] = n;
|
|
32
|
+
}) : e[a][r] = !0;
|
|
33
|
+
})) : e[a] = i(o);
|
|
34
|
+
}), e;
|
|
35
|
+
}, m = (t) => i(t), E = async (t) => {
|
|
36
|
+
const e = u.create({
|
|
37
37
|
withCredentials: !0
|
|
38
38
|
});
|
|
39
|
-
let
|
|
40
|
-
const
|
|
41
|
-
query: `{ ${
|
|
39
|
+
let a = c(m(t));
|
|
40
|
+
const o = {}.VITE_API_URL ?? "/api/", r = await e.post(o, {
|
|
41
|
+
query: `{ ${a} }`
|
|
42
42
|
});
|
|
43
|
-
if (
|
|
44
|
-
throw new Error(
|
|
45
|
-
return
|
|
43
|
+
if (r.data.errors)
|
|
44
|
+
throw new Error(r.data.errors[0].message);
|
|
45
|
+
return r.data.data;
|
|
46
|
+
}, _ = () => localStorage.getItem("light-api-url") === null ? "/api/" : localStorage.getItem("light-api-url"), d = (t) => {
|
|
47
|
+
localStorage.setItem("light-api-url", t);
|
|
46
48
|
};
|
|
47
49
|
export {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
_ as getApiUrl,
|
|
51
|
+
p as login,
|
|
52
|
+
w as logout,
|
|
53
|
+
l as mutation,
|
|
54
|
+
E as query,
|
|
55
|
+
d as setApiUrl,
|
|
56
|
+
m as toQuery
|
|
53
57
|
};
|
package/dist/light.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(e,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("json-to-graphql-query"),require("axios")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","axios"],i):(e=typeof globalThis<"u"?globalThis:e||self,i(e.light={},e.jsonToGraphqlQuery,e.axios))})(this,function(e,i,f){"use strict";const u=async(t,n=null,o=[])=>{const a=f.create({withCredentials:!0}),r={mutation:{}};r.mutation[t]=!0,n&&(r.mutation[t]={},r.mutation[t].__args=n),o.length>0&&(r.mutation[t]={}),o.forEach(q=>{r.mutation[t][q]=!0});const l={}.VITE_API_URL??"/api/",s=await a.post(l,{query:i.jsonToGraphQLQuery(r)});if(s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data},h=async(t,n,o="")=>await u("login",{username:t,password:n,code:o}),d=async()=>await u("logout"),c=function(t){let n={};return Object.entries(t).forEach(([o,a])=>{if(o=="__args"){n[o]=a;return}a instanceof Array?(n[o]={},a.forEach(r=>{r instanceof Object?Object.entries(c(r)).forEach(([l,s])=>{n[o][l]=s}):n[o][r]=!0})):n[o]=c(a)}),n},g=t=>c(t),m=async t=>{const n=f.create({withCredentials:!0});let o=i.jsonToGraphQLQuery(g(t));const a={}.VITE_API_URL??"/api/",r=await n.post(a,{query:`{ ${o} }`});if(r.data.errors)throw new Error(r.data.errors[0].message);return r.data.data},p=()=>localStorage.getItem("light-api-url")===null?"/api/":localStorage.getItem("light-api-url"),y=t=>{localStorage.setItem("light-api-url",t)};e.getApiUrl=p,e.login=h,e.logout=d,e.mutation=u,e.query=m,e.setApiUrl=y,e.toQuery=g,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|