@hostlink/light 0.0.3
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/lib/login.d.ts +2 -0
- package/dist/lib/logout.d.ts +2 -0
- package/dist/lib/mutation.d.ts +2 -0
- package/dist/lib/query.d.ts +2 -0
- package/dist/lib/toQuery.d.ts +2 -0
- package/dist/light.js +53 -0
- package/dist/light.umd.cjs +1 -0
- package/package.json +31 -0
package/dist/light.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsonToGraphQLQuery as i } from "json-to-graphql-query";
|
|
2
|
+
import u from "axios";
|
|
3
|
+
const f = async (r, a = null, o = []) => {
|
|
4
|
+
const n = u.create({
|
|
5
|
+
withCredentials: !0
|
|
6
|
+
}), t = {
|
|
7
|
+
mutation: {}
|
|
8
|
+
};
|
|
9
|
+
t.mutation[r] = !0, a && (t.mutation[r] = {}, t.mutation[r].__args = a), o.length > 0 && (t.mutation[r] = {}), o.forEach((m) => {
|
|
10
|
+
t.mutation[r][m] = !0;
|
|
11
|
+
});
|
|
12
|
+
const s = "/api/", e = await n.post(s, {
|
|
13
|
+
query: i(t)
|
|
14
|
+
});
|
|
15
|
+
if (e.data.errors)
|
|
16
|
+
throw new Error(e.data.errors[0].message);
|
|
17
|
+
return e.data.data;
|
|
18
|
+
}, g = async (r, a, o = "") => await f("login", {
|
|
19
|
+
username: r,
|
|
20
|
+
password: a,
|
|
21
|
+
code: o
|
|
22
|
+
}), d = async () => await f("logout"), c = function(r) {
|
|
23
|
+
let a = {};
|
|
24
|
+
return Object.entries(r).forEach(([o, n]) => {
|
|
25
|
+
if (o == "__args") {
|
|
26
|
+
a[o] = n;
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
n instanceof Array ? (a[o] = {}, n.forEach((t) => {
|
|
30
|
+
t instanceof Object ? Object.entries(c(t)).forEach(([s, e]) => {
|
|
31
|
+
a[o][s] = e;
|
|
32
|
+
}) : a[o][t] = !0;
|
|
33
|
+
})) : a[o] = c(n);
|
|
34
|
+
}), a;
|
|
35
|
+
}, h = (r) => c(r), p = async (r) => {
|
|
36
|
+
const a = u.create({
|
|
37
|
+
withCredentials: !0
|
|
38
|
+
});
|
|
39
|
+
let o = i(h(r));
|
|
40
|
+
const n = "/api/", t = await a.post(n, {
|
|
41
|
+
query: `{ ${o} }`
|
|
42
|
+
});
|
|
43
|
+
if (t.data.errors)
|
|
44
|
+
throw new Error(t.data.errors[0].message);
|
|
45
|
+
return t.data.data;
|
|
46
|
+
};
|
|
47
|
+
export {
|
|
48
|
+
g as login,
|
|
49
|
+
d as logout,
|
|
50
|
+
f as mutation,
|
|
51
|
+
p as query,
|
|
52
|
+
h as toQuery
|
|
53
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(o,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):(o=typeof globalThis<"u"?globalThis:o||self,i(o.light={},o.jsonToGraphqlQuery,o.axios))})(this,function(o,i,d){"use strict";const u=async(e,r=null,n=[])=>{const a=d.create({withCredentials:!0}),t={mutation:{}};t.mutation[e]=!0,r&&(t.mutation[e]={},t.mutation[e].__args=r),n.length>0&&(t.mutation[e]={}),n.forEach(g=>{t.mutation[e][g]=!0});const f="/api/",s=await a.post(f,{query:i.jsonToGraphQLQuery(t)});if(s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data},l=async(e,r,n="")=>await u("login",{username:e,password:r,code:n}),y=async()=>await u("logout"),c=function(e){let r={};return Object.entries(e).forEach(([n,a])=>{if(n=="__args"){r[n]=a;return}a instanceof Array?(r[n]={},a.forEach(t=>{t instanceof Object?Object.entries(c(t)).forEach(([f,s])=>{r[n][f]=s}):r[n][t]=!0})):r[n]=c(a)}),r},h=e=>c(e),m=async e=>{const r=d.create({withCredentials:!0});let n=i.jsonToGraphQLQuery(h(e));const a="/api/",t=await r.post(a,{query:`{ ${n} }`});if(t.data.errors)throw new Error(t.data.errors[0].message);return t.data.data};o.login=l,o.logout=y,o.mutation=u,o.query=m,o.toQuery=h,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hostlink/light",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"main": "./dist/light.umd.cjs",
|
|
9
|
+
"module": "./dist/light.js",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/light.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"types": "./dist/light.d.ts",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"dev": "vite --host",
|
|
18
|
+
"build": "tsc && vite build",
|
|
19
|
+
"preview": "vite preview",
|
|
20
|
+
"release": "npm version patch && npm publish --access public && git push --follow-tags"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"typescript": "^5.0.2",
|
|
24
|
+
"vite": "^4.3.0",
|
|
25
|
+
"vite-plugin-dts": "^3.6.0"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"axios": "^1.5.1",
|
|
29
|
+
"json-to-graphql-query": "^2.2.5"
|
|
30
|
+
}
|
|
31
|
+
}
|