@hostlink/light 0.0.14 → 0.0.15
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/light.js +98 -98
- package/dist/light.umd.cjs +1 -1
- package/dist/query.d.ts +1 -1
- package/dist/toQuery.d.ts +1 -1
- package/package.json +1 -1
package/dist/light.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsonToGraphQLQuery as w, VariableType as C } from "json-to-graphql-query";
|
|
2
2
|
import h from "axios";
|
|
3
|
-
const m = () => localStorage.getItem("light-api-url") === null ? "/api/" : localStorage.getItem("light-api-url"),
|
|
4
|
-
const
|
|
3
|
+
const m = () => localStorage.getItem("light-api-url") === null ? "/api/" : localStorage.getItem("light-api-url"), d = async (t, e = null, r = []) => {
|
|
4
|
+
const a = h.create({
|
|
5
5
|
withCredentials: !0
|
|
6
6
|
}), i = {
|
|
7
7
|
mutation: {}
|
|
@@ -9,41 +9,41 @@ const m = () => localStorage.getItem("light-api-url") === null ? "/api/" : local
|
|
|
9
9
|
i.mutation[t] = !0, e && (i.mutation[t] = {}, i.mutation[t].__args = e), r.length > 0 && (i.mutation[t] = {}), r.forEach((l) => {
|
|
10
10
|
i.mutation[t][l] = !0;
|
|
11
11
|
});
|
|
12
|
-
const
|
|
12
|
+
const u = await a.post(m(), {
|
|
13
13
|
query: w(i)
|
|
14
14
|
});
|
|
15
|
-
if (
|
|
16
|
-
throw new Error(
|
|
17
|
-
return
|
|
18
|
-
}, V = async (t, e, r = "") => await
|
|
15
|
+
if (u.data.errors)
|
|
16
|
+
throw new Error(u.data.errors[0].message);
|
|
17
|
+
return u.data.data;
|
|
18
|
+
}, V = async (t, e, r = "") => await d("login", {
|
|
19
19
|
username: t,
|
|
20
20
|
password: e,
|
|
21
21
|
code: r
|
|
22
|
-
}),
|
|
22
|
+
}), F = async () => await d("logout"), f = (t) => {
|
|
23
23
|
let e = {};
|
|
24
|
-
return
|
|
24
|
+
return typeof t == "string" ? (e[t] = !0, e) : t instanceof Array ? (t.forEach((r) => {
|
|
25
|
+
Object.entries(f(r)).forEach(([a, i]) => {
|
|
26
|
+
e[a] = i;
|
|
27
|
+
});
|
|
28
|
+
}), e) : (Object.entries(t).forEach(([r, a]) => {
|
|
25
29
|
if (r == "__args") {
|
|
26
|
-
e[r] =
|
|
30
|
+
e[r] = a;
|
|
27
31
|
return;
|
|
28
32
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}) : e[r][i] = !0;
|
|
33
|
-
})) : n instanceof Object ? e[r] = d(n) : e[r] = n;
|
|
34
|
-
}), e;
|
|
35
|
-
}, q = (t) => d(t), y = async (t) => {
|
|
33
|
+
e[r] = f(a);
|
|
34
|
+
}), e);
|
|
35
|
+
}, E = (t) => f(t), y = async (t) => {
|
|
36
36
|
const e = h.create({
|
|
37
37
|
withCredentials: !0
|
|
38
38
|
});
|
|
39
|
-
let r = w(
|
|
40
|
-
const
|
|
39
|
+
let r = w(E(t));
|
|
40
|
+
const a = await e.post(m(), {
|
|
41
41
|
query: `{ ${r} }`
|
|
42
42
|
});
|
|
43
|
-
if (
|
|
44
|
-
throw new Error(
|
|
45
|
-
return
|
|
46
|
-
},
|
|
43
|
+
if (a.data.errors)
|
|
44
|
+
throw new Error(a.data.errors[0].message);
|
|
45
|
+
return a.data.data;
|
|
46
|
+
}, B = (t) => {
|
|
47
47
|
localStorage.setItem("light-api-url", t);
|
|
48
48
|
};
|
|
49
49
|
async function M(t) {
|
|
@@ -62,63 +62,63 @@ async function M(t) {
|
|
|
62
62
|
size: !0,
|
|
63
63
|
mime: !0
|
|
64
64
|
}
|
|
65
|
-
},
|
|
66
|
-
|
|
65
|
+
}, a = new FormData();
|
|
66
|
+
a.append("operations", JSON.stringify({
|
|
67
67
|
query: w({ mutation: r })
|
|
68
|
-
})),
|
|
69
|
-
const i = await e.post(m(),
|
|
68
|
+
})), a.append("map", JSON.stringify({ 0: ["variables.file"] })), a.append("0", t);
|
|
69
|
+
const i = await e.post(m(), a);
|
|
70
70
|
if (i.data.errors)
|
|
71
71
|
throw new Error(i.data.errors[0].message);
|
|
72
72
|
return i.data.data.fsUploadTempFile;
|
|
73
73
|
}
|
|
74
|
-
const P = (t, e, r) =>
|
|
74
|
+
const P = (t, e, r) => d("sendMail", { email: t, subject: e, message: r });
|
|
75
75
|
function b(t) {
|
|
76
|
-
const e = "==".slice(0, (4 - t.length % 4) % 4), r = t.replace(/-/g, "+").replace(/_/g, "/") + e,
|
|
77
|
-
for (let l = 0; l <
|
|
78
|
-
|
|
76
|
+
const e = "==".slice(0, (4 - t.length % 4) % 4), r = t.replace(/-/g, "+").replace(/_/g, "/") + e, a = atob(r), i = new ArrayBuffer(a.length), u = new Uint8Array(i);
|
|
77
|
+
for (let l = 0; l < a.length; l++)
|
|
78
|
+
u[l] = a.charCodeAt(l);
|
|
79
79
|
return i;
|
|
80
80
|
}
|
|
81
81
|
function O(t) {
|
|
82
82
|
const e = new Uint8Array(t);
|
|
83
83
|
let r = "";
|
|
84
|
-
for (const
|
|
85
|
-
r += String.fromCharCode(
|
|
84
|
+
for (const u of e)
|
|
85
|
+
r += String.fromCharCode(u);
|
|
86
86
|
return btoa(r).replace(/\+/g, "-").replace(
|
|
87
87
|
/\//g,
|
|
88
88
|
"_"
|
|
89
89
|
).replace(/=/g, "");
|
|
90
90
|
}
|
|
91
|
-
var
|
|
91
|
+
var n = "copy", c = "convert";
|
|
92
92
|
function p(t, e, r) {
|
|
93
|
-
if (e ===
|
|
93
|
+
if (e === n)
|
|
94
94
|
return r;
|
|
95
|
-
if (e ===
|
|
95
|
+
if (e === c)
|
|
96
96
|
return t(r);
|
|
97
97
|
if (e instanceof Array)
|
|
98
|
-
return r.map((
|
|
98
|
+
return r.map((a) => p(t, e[0], a));
|
|
99
99
|
if (e instanceof Object) {
|
|
100
|
-
const
|
|
101
|
-
for (const [i,
|
|
102
|
-
if (
|
|
103
|
-
const l =
|
|
100
|
+
const a = {};
|
|
101
|
+
for (const [i, u] of Object.entries(e)) {
|
|
102
|
+
if (u.derive) {
|
|
103
|
+
const l = u.derive(r);
|
|
104
104
|
l !== void 0 && (r[i] = l);
|
|
105
105
|
}
|
|
106
106
|
if (!(i in r)) {
|
|
107
|
-
if (
|
|
107
|
+
if (u.required)
|
|
108
108
|
throw new Error(`Missing key: ${i}`);
|
|
109
109
|
continue;
|
|
110
110
|
}
|
|
111
111
|
if (r[i] == null) {
|
|
112
|
-
|
|
112
|
+
a[i] = null;
|
|
113
113
|
continue;
|
|
114
114
|
}
|
|
115
|
-
|
|
115
|
+
a[i] = p(
|
|
116
116
|
t,
|
|
117
|
-
|
|
117
|
+
u.schema,
|
|
118
118
|
r[i]
|
|
119
119
|
);
|
|
120
120
|
}
|
|
121
|
-
return
|
|
121
|
+
return a;
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
function g(t, e) {
|
|
@@ -141,44 +141,44 @@ function s(t) {
|
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
143
|
var S = {
|
|
144
|
-
type: o(
|
|
145
|
-
id: o(
|
|
146
|
-
transports: s(
|
|
144
|
+
type: o(n),
|
|
145
|
+
id: o(c),
|
|
146
|
+
transports: s(n)
|
|
147
147
|
}, v = {
|
|
148
|
-
appid: s(
|
|
149
|
-
appidExclude: s(
|
|
150
|
-
credProps: s(
|
|
148
|
+
appid: s(n),
|
|
149
|
+
appidExclude: s(n),
|
|
150
|
+
credProps: s(n)
|
|
151
151
|
}, A = {
|
|
152
|
-
appid: s(
|
|
153
|
-
appidExclude: s(
|
|
154
|
-
credProps: s(
|
|
155
|
-
},
|
|
152
|
+
appid: s(n),
|
|
153
|
+
appidExclude: s(n),
|
|
154
|
+
credProps: s(n)
|
|
155
|
+
}, R = {
|
|
156
156
|
publicKey: o({
|
|
157
|
-
rp: o(
|
|
157
|
+
rp: o(n),
|
|
158
158
|
user: o({
|
|
159
|
-
id: o(
|
|
160
|
-
name: o(
|
|
161
|
-
displayName: o(
|
|
159
|
+
id: o(c),
|
|
160
|
+
name: o(n),
|
|
161
|
+
displayName: o(n)
|
|
162
162
|
}),
|
|
163
|
-
challenge: o(
|
|
164
|
-
pubKeyCredParams: o(
|
|
165
|
-
timeout: s(
|
|
163
|
+
challenge: o(c),
|
|
164
|
+
pubKeyCredParams: o(n),
|
|
165
|
+
timeout: s(n),
|
|
166
166
|
excludeCredentials: s([S]),
|
|
167
|
-
authenticatorSelection: s(
|
|
168
|
-
attestation: s(
|
|
167
|
+
authenticatorSelection: s(n),
|
|
168
|
+
attestation: s(n),
|
|
169
169
|
extensions: s(v)
|
|
170
170
|
}),
|
|
171
|
-
signal: s(
|
|
172
|
-
},
|
|
173
|
-
type: o(
|
|
174
|
-
id: o(
|
|
175
|
-
rawId: o(
|
|
176
|
-
authenticatorAttachment: s(
|
|
171
|
+
signal: s(n)
|
|
172
|
+
}, q = {
|
|
173
|
+
type: o(n),
|
|
174
|
+
id: o(n),
|
|
175
|
+
rawId: o(c),
|
|
176
|
+
authenticatorAttachment: s(n),
|
|
177
177
|
response: o({
|
|
178
|
-
clientDataJSON: o(
|
|
179
|
-
attestationObject: o(
|
|
178
|
+
clientDataJSON: o(c),
|
|
179
|
+
attestationObject: o(c),
|
|
180
180
|
transports: g(
|
|
181
|
-
|
|
181
|
+
n,
|
|
182
182
|
(t) => {
|
|
183
183
|
var e;
|
|
184
184
|
return ((e = t.getTransports) == null ? void 0 : e.call(t)) || [];
|
|
@@ -190,26 +190,26 @@ var S = {
|
|
|
190
190
|
(t) => t.getClientExtensionResults()
|
|
191
191
|
)
|
|
192
192
|
}, x = {
|
|
193
|
-
mediation: s(
|
|
193
|
+
mediation: s(n),
|
|
194
194
|
publicKey: o({
|
|
195
|
-
challenge: o(
|
|
196
|
-
timeout: s(
|
|
197
|
-
rpId: s(
|
|
195
|
+
challenge: o(c),
|
|
196
|
+
timeout: s(n),
|
|
197
|
+
rpId: s(n),
|
|
198
198
|
allowCredentials: s([S]),
|
|
199
|
-
userVerification: s(
|
|
199
|
+
userVerification: s(n),
|
|
200
200
|
extensions: s(v)
|
|
201
201
|
}),
|
|
202
|
-
signal: s(
|
|
202
|
+
signal: s(n)
|
|
203
203
|
}, J = {
|
|
204
|
-
type: o(
|
|
205
|
-
id: o(
|
|
206
|
-
rawId: o(
|
|
207
|
-
authenticatorAttachment: s(
|
|
204
|
+
type: o(n),
|
|
205
|
+
id: o(n),
|
|
206
|
+
rawId: o(c),
|
|
207
|
+
authenticatorAttachment: s(n),
|
|
208
208
|
response: o({
|
|
209
|
-
clientDataJSON: o(
|
|
210
|
-
authenticatorData: o(
|
|
211
|
-
signature: o(
|
|
212
|
-
userHandle: o(
|
|
209
|
+
clientDataJSON: o(c),
|
|
210
|
+
authenticatorData: o(c),
|
|
211
|
+
signature: o(c),
|
|
212
|
+
userHandle: o(c)
|
|
213
213
|
}),
|
|
214
214
|
clientExtensionResults: g(
|
|
215
215
|
A,
|
|
@@ -217,12 +217,12 @@ var S = {
|
|
|
217
217
|
)
|
|
218
218
|
};
|
|
219
219
|
function N(t) {
|
|
220
|
-
return p(b,
|
|
220
|
+
return p(b, R, t);
|
|
221
221
|
}
|
|
222
222
|
function _(t) {
|
|
223
223
|
return p(
|
|
224
224
|
O,
|
|
225
|
-
|
|
225
|
+
q,
|
|
226
226
|
t
|
|
227
227
|
);
|
|
228
228
|
}
|
|
@@ -255,10 +255,10 @@ async function Q(t) {
|
|
|
255
255
|
username: t
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
|
-
})).webAuthnRequestOptions,
|
|
258
|
+
})).webAuthnRequestOptions, a = j({
|
|
259
259
|
publicKey: r
|
|
260
|
-
}), i = await U(
|
|
261
|
-
await
|
|
260
|
+
}), i = await U(a);
|
|
261
|
+
await d("webAuthnAssertion", {
|
|
262
262
|
username: t,
|
|
263
263
|
assertion: i.toJSON()
|
|
264
264
|
});
|
|
@@ -267,19 +267,19 @@ async function L() {
|
|
|
267
267
|
const t = await y({ webAuthnCreationOptions: !0 }), e = N({
|
|
268
268
|
publicKey: t.webAuthnCreationOptions
|
|
269
269
|
}), r = await K(e);
|
|
270
|
-
await
|
|
270
|
+
await d("webAuthnRegister", {
|
|
271
271
|
registration: r.toJSON()
|
|
272
272
|
});
|
|
273
273
|
}
|
|
274
274
|
export {
|
|
275
275
|
m as getApiUrl,
|
|
276
276
|
V as login,
|
|
277
|
-
|
|
278
|
-
|
|
277
|
+
F as logout,
|
|
278
|
+
d as mutation,
|
|
279
279
|
y as query,
|
|
280
280
|
P as sendMail,
|
|
281
|
-
|
|
282
|
-
|
|
281
|
+
B as setApiUrl,
|
|
282
|
+
E as toQuery,
|
|
283
283
|
M as uploadFile,
|
|
284
284
|
Q as webauthnLogin,
|
|
285
285
|
L as webauthnRegister
|
package/dist/light.umd.cjs
CHANGED
|
@@ -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,
|
|
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,y){"use strict";const h=()=>localStorage.getItem("light-api-url")===null?"/api/":localStorage.getItem("light-api-url"),p=async(e,t=null,n=[])=>{const i=y.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"),w=e=>{let t={};return typeof e=="string"?(t[e]=!0,t):e instanceof Array?(e.forEach(n=>{Object.entries(w(n)).forEach(([i,o])=>{t[i]=o})}),t):(Object.entries(e).forEach(([n,i])=>{if(n=="__args"){t[n]=i;return}t[n]=w(i)}),t)},S=e=>w(e),m=async e=>{const t=y.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=y.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"})});
|
package/dist/query.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: (q: Object) => Promise<any>;
|
|
1
|
+
declare const _default: (q: Object | Array<string | Object | string>) => Promise<any>;
|
|
2
2
|
export default _default;
|
package/dist/toQuery.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: (query:
|
|
1
|
+
declare const _default: (query: Object | Array<string | Object> | string) => any;
|
|
2
2
|
export default _default;
|