@hostlink/light 0.0.17 → 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 +56 -56
- 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)
|
|
@@ -15,11 +15,11 @@ const m = () => localStorage.getItem("light-api-url") === null ? "/api/" : local
|
|
|
15
15
|
if (u.data.errors)
|
|
16
16
|
throw new Error(u.data.errors[0].message);
|
|
17
17
|
return u.data.data;
|
|
18
|
-
},
|
|
18
|
+
}, V = async (t, e, r = "") => await d("login", {
|
|
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]) => {
|
|
@@ -36,21 +36,21 @@ const m = () => localStorage.getItem("light-api-url") === null ? "/api/" : local
|
|
|
36
36
|
}
|
|
37
37
|
e[r] = f(n);
|
|
38
38
|
}), e);
|
|
39
|
-
},
|
|
39
|
+
}, b = (t) => f(t), y = async (t) => {
|
|
40
40
|
const e = h.create({
|
|
41
41
|
withCredentials: !0
|
|
42
42
|
});
|
|
43
|
-
let r = w(
|
|
43
|
+
let r = w(b(t));
|
|
44
44
|
const n = await e.post(m(), {
|
|
45
45
|
query: `{ ${r} }`
|
|
46
46
|
});
|
|
47
47
|
if (n.data.errors)
|
|
48
48
|
throw new Error(n.data.errors[0].message);
|
|
49
49
|
return n.data.data;
|
|
50
|
-
},
|
|
50
|
+
}, M = (t) => {
|
|
51
51
|
localStorage.setItem("light-api-url", t);
|
|
52
52
|
};
|
|
53
|
-
async function
|
|
53
|
+
async function P(t) {
|
|
54
54
|
const e = h.create({
|
|
55
55
|
withCredentials: !0
|
|
56
56
|
}), r = {
|
|
@@ -59,7 +59,7 @@ async function M(t) {
|
|
|
59
59
|
},
|
|
60
60
|
fsUploadTempFile: {
|
|
61
61
|
__args: {
|
|
62
|
-
file: new
|
|
62
|
+
file: new E("file")
|
|
63
63
|
},
|
|
64
64
|
name: !0,
|
|
65
65
|
path: !0,
|
|
@@ -75,14 +75,14 @@ async function M(t) {
|
|
|
75
75
|
throw new Error(i.data.errors[0].message);
|
|
76
76
|
return i.data.data.fsUploadTempFile;
|
|
77
77
|
}
|
|
78
|
-
const
|
|
79
|
-
function
|
|
78
|
+
const Q = (t, e, r) => d("sendMail", { email: t, subject: e, message: r });
|
|
79
|
+
function O(t) {
|
|
80
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);
|
|
81
81
|
for (let l = 0; l < n.length; l++)
|
|
82
82
|
u[l] = n.charCodeAt(l);
|
|
83
83
|
return i;
|
|
84
84
|
}
|
|
85
|
-
function
|
|
85
|
+
function S(t) {
|
|
86
86
|
const e = new Uint8Array(t);
|
|
87
87
|
let r = "";
|
|
88
88
|
for (const u of e)
|
|
@@ -144,19 +144,19 @@ function s(t) {
|
|
|
144
144
|
schema: t
|
|
145
145
|
};
|
|
146
146
|
}
|
|
147
|
-
var
|
|
147
|
+
var _ = {
|
|
148
148
|
type: o(a),
|
|
149
149
|
id: o(c),
|
|
150
150
|
transports: s(a)
|
|
151
|
-
},
|
|
151
|
+
}, v = {
|
|
152
152
|
appid: s(a),
|
|
153
153
|
appidExclude: s(a),
|
|
154
154
|
credProps: s(a)
|
|
155
|
-
},
|
|
155
|
+
}, A = {
|
|
156
156
|
appid: s(a),
|
|
157
157
|
appidExclude: s(a),
|
|
158
158
|
credProps: s(a)
|
|
159
|
-
},
|
|
159
|
+
}, R = {
|
|
160
160
|
publicKey: o({
|
|
161
161
|
rp: o(a),
|
|
162
162
|
user: o({
|
|
@@ -167,13 +167,13 @@ var S = {
|
|
|
167
167
|
challenge: o(c),
|
|
168
168
|
pubKeyCredParams: o(a),
|
|
169
169
|
timeout: s(a),
|
|
170
|
-
excludeCredentials: s([
|
|
170
|
+
excludeCredentials: s([_]),
|
|
171
171
|
authenticatorSelection: s(a),
|
|
172
172
|
attestation: s(a),
|
|
173
|
-
extensions: s(
|
|
173
|
+
extensions: s(v)
|
|
174
174
|
}),
|
|
175
175
|
signal: s(a)
|
|
176
|
-
},
|
|
176
|
+
}, q = {
|
|
177
177
|
type: o(a),
|
|
178
178
|
id: o(a),
|
|
179
179
|
rawId: o(c),
|
|
@@ -190,21 +190,21 @@ var S = {
|
|
|
190
190
|
)
|
|
191
191
|
}),
|
|
192
192
|
clientExtensionResults: g(
|
|
193
|
-
|
|
193
|
+
A,
|
|
194
194
|
(t) => t.getClientExtensionResults()
|
|
195
195
|
)
|
|
196
|
-
},
|
|
196
|
+
}, x = {
|
|
197
197
|
mediation: s(a),
|
|
198
198
|
publicKey: o({
|
|
199
199
|
challenge: o(c),
|
|
200
200
|
timeout: s(a),
|
|
201
201
|
rpId: s(a),
|
|
202
|
-
allowCredentials: s([
|
|
202
|
+
allowCredentials: s([_]),
|
|
203
203
|
userVerification: s(a),
|
|
204
|
-
extensions: s(
|
|
204
|
+
extensions: s(v)
|
|
205
205
|
}),
|
|
206
206
|
signal: s(a)
|
|
207
|
-
},
|
|
207
|
+
}, J = {
|
|
208
208
|
type: o(a),
|
|
209
209
|
id: o(a),
|
|
210
210
|
rawId: o(c),
|
|
@@ -216,75 +216,75 @@ var S = {
|
|
|
216
216
|
userHandle: o(c)
|
|
217
217
|
}),
|
|
218
218
|
clientExtensionResults: g(
|
|
219
|
-
|
|
219
|
+
A,
|
|
220
220
|
(t) => t.getClientExtensionResults()
|
|
221
221
|
)
|
|
222
222
|
};
|
|
223
|
-
function J(t) {
|
|
224
|
-
return p(y, E, t);
|
|
225
|
-
}
|
|
226
223
|
function N(t) {
|
|
224
|
+
return p(O, R, t);
|
|
225
|
+
}
|
|
226
|
+
function j(t) {
|
|
227
227
|
return p(
|
|
228
|
-
|
|
229
|
-
|
|
228
|
+
S,
|
|
229
|
+
q,
|
|
230
230
|
t
|
|
231
231
|
);
|
|
232
232
|
}
|
|
233
|
-
function j(t) {
|
|
234
|
-
return p(y, q, t);
|
|
235
|
-
}
|
|
236
233
|
function T(t) {
|
|
234
|
+
return p(O, x, t);
|
|
235
|
+
}
|
|
236
|
+
function K(t) {
|
|
237
237
|
return p(
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
S,
|
|
239
|
+
J,
|
|
240
240
|
t
|
|
241
241
|
);
|
|
242
242
|
}
|
|
243
|
-
async function
|
|
243
|
+
async function U(t) {
|
|
244
244
|
const e = await navigator.credentials.create(
|
|
245
245
|
t
|
|
246
246
|
);
|
|
247
|
-
return e.toJSON = () =>
|
|
247
|
+
return e.toJSON = () => j(e), e;
|
|
248
248
|
}
|
|
249
|
-
async function
|
|
249
|
+
async function D(t) {
|
|
250
250
|
const e = await navigator.credentials.get(
|
|
251
251
|
t
|
|
252
252
|
);
|
|
253
|
-
return e.toJSON = () =>
|
|
253
|
+
return e.toJSON = () => K(e), e;
|
|
254
254
|
}
|
|
255
|
-
async function
|
|
256
|
-
const r = (await
|
|
255
|
+
async function L(t) {
|
|
256
|
+
const r = (await y({
|
|
257
257
|
webAuthnRequestOptions: {
|
|
258
258
|
__args: {
|
|
259
259
|
username: t
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
|
-
})).webAuthnRequestOptions, n =
|
|
262
|
+
})).webAuthnRequestOptions, n = T({
|
|
263
263
|
publicKey: r
|
|
264
|
-
}), i = await
|
|
264
|
+
}), i = await D(n);
|
|
265
265
|
await d("webAuthnAssertion", {
|
|
266
266
|
username: t,
|
|
267
267
|
assertion: i.toJSON()
|
|
268
268
|
});
|
|
269
269
|
}
|
|
270
|
-
async function
|
|
271
|
-
const t = await
|
|
270
|
+
async function W() {
|
|
271
|
+
const t = await y({ webAuthnCreationOptions: !0 }), e = N({
|
|
272
272
|
publicKey: t.webAuthnCreationOptions
|
|
273
|
-
}), r = await
|
|
273
|
+
}), r = await U(e);
|
|
274
274
|
await d("webAuthnRegister", {
|
|
275
275
|
registration: r.toJSON()
|
|
276
276
|
});
|
|
277
277
|
}
|
|
278
278
|
export {
|
|
279
279
|
m as getApiUrl,
|
|
280
|
-
|
|
281
|
-
|
|
280
|
+
V as login,
|
|
281
|
+
B as logout,
|
|
282
282
|
d as mutation,
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
283
|
+
y as query,
|
|
284
|
+
Q as sendMail,
|
|
285
|
+
M as setApiUrl,
|
|
286
|
+
b as toQuery,
|
|
287
|
+
P as uploadFile,
|
|
288
|
+
L as webauthnLogin,
|
|
289
|
+
W as webauthnRegister
|
|
290
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 r=w.create({withCredentials:!0}),o={mutation:{}};o.mutation[e]=!0,t&&(o.mutation[e]={},o.mutation[e].__args=t),n.length
|
|
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