@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 +2 -1
- package/dist/light.js +44 -40
- package/dist/light.umd.cjs +1 -1
- package/dist/mutation.d.ts +2 -1
- package/dist/toQuery.d.ts +2 -1
- package/package.json +1 -1
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
|
|
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
|
|
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
|
|
10
|
-
i.mutation[t][l] =
|
|
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
|
-
}),
|
|
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
|
-
|
|
33
|
+
if (typeof n == "boolean") {
|
|
34
|
+
e[r] = n;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
e[r] = f(n);
|
|
34
38
|
}), e);
|
|
35
|
-
},
|
|
39
|
+
}, b = (t) => f(t), y = async (t) => {
|
|
36
40
|
const e = h.create({
|
|
37
41
|
withCredentials: !0
|
|
38
42
|
});
|
|
39
|
-
let r = w(
|
|
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
|
-
},
|
|
50
|
+
}, M = (t) => {
|
|
47
51
|
localStorage.setItem("light-api-url", t);
|
|
48
52
|
};
|
|
49
|
-
async function
|
|
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
|
|
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
|
|
75
|
-
function
|
|
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
|
|
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
|
|
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([
|
|
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([
|
|
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(
|
|
224
|
+
return p(O, R, t);
|
|
221
225
|
}
|
|
222
|
-
function
|
|
226
|
+
function j(t) {
|
|
223
227
|
return p(
|
|
224
|
-
|
|
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
|
-
|
|
238
|
+
S,
|
|
235
239
|
J,
|
|
236
240
|
t
|
|
237
241
|
);
|
|
238
242
|
}
|
|
239
|
-
async function
|
|
243
|
+
async function U(t) {
|
|
240
244
|
const e = await navigator.credentials.create(
|
|
241
245
|
t
|
|
242
246
|
);
|
|
243
|
-
return e.toJSON = () =>
|
|
247
|
+
return e.toJSON = () => j(e), e;
|
|
244
248
|
}
|
|
245
|
-
async function
|
|
249
|
+
async function D(t) {
|
|
246
250
|
const e = await navigator.credentials.get(
|
|
247
251
|
t
|
|
248
252
|
);
|
|
249
|
-
return e.toJSON = () =>
|
|
253
|
+
return e.toJSON = () => K(e), e;
|
|
250
254
|
}
|
|
251
|
-
async function
|
|
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 =
|
|
262
|
+
})).webAuthnRequestOptions, n = T({
|
|
259
263
|
publicKey: r
|
|
260
|
-
}), i = await
|
|
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
|
|
270
|
+
async function W() {
|
|
267
271
|
const t = await y({ webAuthnCreationOptions: !0 }), e = N({
|
|
268
272
|
publicKey: t.webAuthnCreationOptions
|
|
269
|
-
}), r = await
|
|
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
|
-
|
|
281
|
+
B as logout,
|
|
278
282
|
d as mutation,
|
|
279
283
|
y as query,
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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
|
};
|
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,w){"use strict";const h=()=>localStorage.getItem("light-api-url")===null?"/api/":localStorage.getItem("light-api-url"),p=async(e,t=null,n=[])=>{const
|
|
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"})});
|
package/dist/mutation.d.ts
CHANGED
package/dist/toQuery.d.ts
CHANGED