@hostlink/light 0.0.15 → 0.0.17
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 +89 -85
- package/dist/light.umd.cjs +1 -1
- package/package.json +2 -2
package/dist/light.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { jsonToGraphQLQuery as w, VariableType as
|
|
1
|
+
import { jsonToGraphQLQuery as w, VariableType as A } 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
|
-
const
|
|
4
|
+
const n = h.create({
|
|
5
5
|
withCredentials: !0
|
|
6
6
|
}), i = {
|
|
7
7
|
mutation: {}
|
|
@@ -9,40 +9,44 @@ 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 u = await
|
|
12
|
+
const u = await n.post(m(), {
|
|
13
13
|
query: w(i)
|
|
14
14
|
});
|
|
15
15
|
if (u.data.errors)
|
|
16
16
|
throw new Error(u.data.errors[0].message);
|
|
17
17
|
return u.data.data;
|
|
18
|
-
},
|
|
18
|
+
}, I = async (t, e, r = "") => await d("login", {
|
|
19
19
|
username: t,
|
|
20
20
|
password: e,
|
|
21
21
|
code: r
|
|
22
|
-
}),
|
|
22
|
+
}), V = 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
|
-
Object.entries(f(r)).forEach(([
|
|
26
|
-
e[
|
|
25
|
+
Object.entries(f(r)).forEach(([n, i]) => {
|
|
26
|
+
e[n] = i;
|
|
27
27
|
});
|
|
28
|
-
}), e) : (Object.entries(t).forEach(([r,
|
|
29
|
-
if (r == "__args") {
|
|
30
|
-
e[r] =
|
|
28
|
+
}), e) : (Object.entries(t).forEach(([r, n]) => {
|
|
29
|
+
if (r == "__args" || r == "__aliasFor" || r == "__variables" || r == "__directives" || r == "__all_on" || r == "__name") {
|
|
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
|
+
}, C = (t) => f(t), b = async (t) => {
|
|
36
40
|
const e = h.create({
|
|
37
41
|
withCredentials: !0
|
|
38
42
|
});
|
|
39
|
-
let r = w(
|
|
40
|
-
const
|
|
43
|
+
let r = w(C(t));
|
|
44
|
+
const n = await e.post(m(), {
|
|
41
45
|
query: `{ ${r} }`
|
|
42
46
|
});
|
|
43
|
-
if (
|
|
44
|
-
throw new Error(
|
|
45
|
-
return
|
|
47
|
+
if (n.data.errors)
|
|
48
|
+
throw new Error(n.data.errors[0].message);
|
|
49
|
+
return n.data.data;
|
|
46
50
|
}, B = (t) => {
|
|
47
51
|
localStorage.setItem("light-api-url", t);
|
|
48
52
|
};
|
|
@@ -55,27 +59,27 @@ async function M(t) {
|
|
|
55
59
|
},
|
|
56
60
|
fsUploadTempFile: {
|
|
57
61
|
__args: {
|
|
58
|
-
file: new
|
|
62
|
+
file: new A("file")
|
|
59
63
|
},
|
|
60
64
|
name: !0,
|
|
61
65
|
path: !0,
|
|
62
66
|
size: !0,
|
|
63
67
|
mime: !0
|
|
64
68
|
}
|
|
65
|
-
},
|
|
66
|
-
|
|
69
|
+
}, n = new FormData();
|
|
70
|
+
n.append("operations", JSON.stringify({
|
|
67
71
|
query: w({ mutation: r })
|
|
68
|
-
})),
|
|
69
|
-
const i = await e.post(m(),
|
|
72
|
+
})), n.append("map", JSON.stringify({ 0: ["variables.file"] })), n.append("0", t);
|
|
73
|
+
const i = await e.post(m(), n);
|
|
70
74
|
if (i.data.errors)
|
|
71
75
|
throw new Error(i.data.errors[0].message);
|
|
72
76
|
return i.data.data.fsUploadTempFile;
|
|
73
77
|
}
|
|
74
78
|
const P = (t, e, r) => d("sendMail", { email: t, subject: e, message: r });
|
|
75
|
-
function
|
|
76
|
-
const e = "==".slice(0, (4 - t.length % 4) % 4), r = t.replace(/-/g, "+").replace(/_/g, "/") + e,
|
|
77
|
-
for (let l = 0; l <
|
|
78
|
-
u[l] =
|
|
79
|
+
function y(t) {
|
|
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
|
+
for (let l = 0; l < n.length; l++)
|
|
82
|
+
u[l] = n.charCodeAt(l);
|
|
79
83
|
return i;
|
|
80
84
|
}
|
|
81
85
|
function O(t) {
|
|
@@ -88,16 +92,16 @@ function O(t) {
|
|
|
88
92
|
"_"
|
|
89
93
|
).replace(/=/g, "");
|
|
90
94
|
}
|
|
91
|
-
var
|
|
95
|
+
var a = "copy", c = "convert";
|
|
92
96
|
function p(t, e, r) {
|
|
93
|
-
if (e ===
|
|
97
|
+
if (e === a)
|
|
94
98
|
return r;
|
|
95
99
|
if (e === c)
|
|
96
100
|
return t(r);
|
|
97
101
|
if (e instanceof Array)
|
|
98
|
-
return r.map((
|
|
102
|
+
return r.map((n) => p(t, e[0], n));
|
|
99
103
|
if (e instanceof Object) {
|
|
100
|
-
const
|
|
104
|
+
const n = {};
|
|
101
105
|
for (const [i, u] of Object.entries(e)) {
|
|
102
106
|
if (u.derive) {
|
|
103
107
|
const l = u.derive(r);
|
|
@@ -109,16 +113,16 @@ function p(t, e, r) {
|
|
|
109
113
|
continue;
|
|
110
114
|
}
|
|
111
115
|
if (r[i] == null) {
|
|
112
|
-
|
|
116
|
+
n[i] = null;
|
|
113
117
|
continue;
|
|
114
118
|
}
|
|
115
|
-
|
|
119
|
+
n[i] = p(
|
|
116
120
|
t,
|
|
117
121
|
u.schema,
|
|
118
122
|
r[i]
|
|
119
123
|
);
|
|
120
124
|
}
|
|
121
|
-
return
|
|
125
|
+
return n;
|
|
122
126
|
}
|
|
123
127
|
}
|
|
124
128
|
function g(t, e) {
|
|
@@ -141,44 +145,44 @@ function s(t) {
|
|
|
141
145
|
};
|
|
142
146
|
}
|
|
143
147
|
var S = {
|
|
144
|
-
type: o(
|
|
148
|
+
type: o(a),
|
|
145
149
|
id: o(c),
|
|
146
|
-
transports: s(
|
|
150
|
+
transports: s(a)
|
|
151
|
+
}, _ = {
|
|
152
|
+
appid: s(a),
|
|
153
|
+
appidExclude: s(a),
|
|
154
|
+
credProps: s(a)
|
|
147
155
|
}, v = {
|
|
148
|
-
appid: s(
|
|
149
|
-
appidExclude: s(
|
|
150
|
-
credProps: s(
|
|
151
|
-
},
|
|
152
|
-
appid: s(n),
|
|
153
|
-
appidExclude: s(n),
|
|
154
|
-
credProps: s(n)
|
|
155
|
-
}, R = {
|
|
156
|
+
appid: s(a),
|
|
157
|
+
appidExclude: s(a),
|
|
158
|
+
credProps: s(a)
|
|
159
|
+
}, E = {
|
|
156
160
|
publicKey: o({
|
|
157
|
-
rp: o(
|
|
161
|
+
rp: o(a),
|
|
158
162
|
user: o({
|
|
159
163
|
id: o(c),
|
|
160
|
-
name: o(
|
|
161
|
-
displayName: o(
|
|
164
|
+
name: o(a),
|
|
165
|
+
displayName: o(a)
|
|
162
166
|
}),
|
|
163
167
|
challenge: o(c),
|
|
164
|
-
pubKeyCredParams: o(
|
|
165
|
-
timeout: s(
|
|
168
|
+
pubKeyCredParams: o(a),
|
|
169
|
+
timeout: s(a),
|
|
166
170
|
excludeCredentials: s([S]),
|
|
167
|
-
authenticatorSelection: s(
|
|
168
|
-
attestation: s(
|
|
169
|
-
extensions: s(
|
|
171
|
+
authenticatorSelection: s(a),
|
|
172
|
+
attestation: s(a),
|
|
173
|
+
extensions: s(_)
|
|
170
174
|
}),
|
|
171
|
-
signal: s(
|
|
172
|
-
},
|
|
173
|
-
type: o(
|
|
174
|
-
id: o(
|
|
175
|
+
signal: s(a)
|
|
176
|
+
}, R = {
|
|
177
|
+
type: o(a),
|
|
178
|
+
id: o(a),
|
|
175
179
|
rawId: o(c),
|
|
176
|
-
authenticatorAttachment: s(
|
|
180
|
+
authenticatorAttachment: s(a),
|
|
177
181
|
response: o({
|
|
178
182
|
clientDataJSON: o(c),
|
|
179
183
|
attestationObject: o(c),
|
|
180
184
|
transports: g(
|
|
181
|
-
|
|
185
|
+
a,
|
|
182
186
|
(t) => {
|
|
183
187
|
var e;
|
|
184
188
|
return ((e = t.getTransports) == null ? void 0 : e.call(t)) || [];
|
|
@@ -186,25 +190,25 @@ var S = {
|
|
|
186
190
|
)
|
|
187
191
|
}),
|
|
188
192
|
clientExtensionResults: g(
|
|
189
|
-
|
|
193
|
+
v,
|
|
190
194
|
(t) => t.getClientExtensionResults()
|
|
191
195
|
)
|
|
192
|
-
},
|
|
193
|
-
mediation: s(
|
|
196
|
+
}, q = {
|
|
197
|
+
mediation: s(a),
|
|
194
198
|
publicKey: o({
|
|
195
199
|
challenge: o(c),
|
|
196
|
-
timeout: s(
|
|
197
|
-
rpId: s(
|
|
200
|
+
timeout: s(a),
|
|
201
|
+
rpId: s(a),
|
|
198
202
|
allowCredentials: s([S]),
|
|
199
|
-
userVerification: s(
|
|
200
|
-
extensions: s(
|
|
203
|
+
userVerification: s(a),
|
|
204
|
+
extensions: s(_)
|
|
201
205
|
}),
|
|
202
|
-
signal: s(
|
|
203
|
-
},
|
|
204
|
-
type: o(
|
|
205
|
-
id: o(
|
|
206
|
+
signal: s(a)
|
|
207
|
+
}, x = {
|
|
208
|
+
type: o(a),
|
|
209
|
+
id: o(a),
|
|
206
210
|
rawId: o(c),
|
|
207
|
-
authenticatorAttachment: s(
|
|
211
|
+
authenticatorAttachment: s(a),
|
|
208
212
|
response: o({
|
|
209
213
|
clientDataJSON: o(c),
|
|
210
214
|
authenticatorData: o(c),
|
|
@@ -212,27 +216,27 @@ var S = {
|
|
|
212
216
|
userHandle: o(c)
|
|
213
217
|
}),
|
|
214
218
|
clientExtensionResults: g(
|
|
215
|
-
|
|
219
|
+
v,
|
|
216
220
|
(t) => t.getClientExtensionResults()
|
|
217
221
|
)
|
|
218
222
|
};
|
|
219
|
-
function
|
|
220
|
-
return p(
|
|
223
|
+
function J(t) {
|
|
224
|
+
return p(y, E, t);
|
|
221
225
|
}
|
|
222
|
-
function
|
|
226
|
+
function N(t) {
|
|
223
227
|
return p(
|
|
224
228
|
O,
|
|
225
|
-
|
|
229
|
+
R,
|
|
226
230
|
t
|
|
227
231
|
);
|
|
228
232
|
}
|
|
229
233
|
function j(t) {
|
|
230
|
-
return p(
|
|
234
|
+
return p(y, q, t);
|
|
231
235
|
}
|
|
232
236
|
function T(t) {
|
|
233
237
|
return p(
|
|
234
238
|
O,
|
|
235
|
-
|
|
239
|
+
x,
|
|
236
240
|
t
|
|
237
241
|
);
|
|
238
242
|
}
|
|
@@ -240,7 +244,7 @@ async function K(t) {
|
|
|
240
244
|
const e = await navigator.credentials.create(
|
|
241
245
|
t
|
|
242
246
|
);
|
|
243
|
-
return e.toJSON = () =>
|
|
247
|
+
return e.toJSON = () => N(e), e;
|
|
244
248
|
}
|
|
245
249
|
async function U(t) {
|
|
246
250
|
const e = await navigator.credentials.get(
|
|
@@ -249,22 +253,22 @@ async function U(t) {
|
|
|
249
253
|
return e.toJSON = () => T(e), e;
|
|
250
254
|
}
|
|
251
255
|
async function Q(t) {
|
|
252
|
-
const r = (await
|
|
256
|
+
const r = (await b({
|
|
253
257
|
webAuthnRequestOptions: {
|
|
254
258
|
__args: {
|
|
255
259
|
username: t
|
|
256
260
|
}
|
|
257
261
|
}
|
|
258
|
-
})).webAuthnRequestOptions,
|
|
262
|
+
})).webAuthnRequestOptions, n = j({
|
|
259
263
|
publicKey: r
|
|
260
|
-
}), i = await U(
|
|
264
|
+
}), i = await U(n);
|
|
261
265
|
await d("webAuthnAssertion", {
|
|
262
266
|
username: t,
|
|
263
267
|
assertion: i.toJSON()
|
|
264
268
|
});
|
|
265
269
|
}
|
|
266
270
|
async function L() {
|
|
267
|
-
const t = await
|
|
271
|
+
const t = await b({ webAuthnCreationOptions: !0 }), e = J({
|
|
268
272
|
publicKey: t.webAuthnCreationOptions
|
|
269
273
|
}), r = await K(e);
|
|
270
274
|
await d("webAuthnRegister", {
|
|
@@ -273,13 +277,13 @@ async function L() {
|
|
|
273
277
|
}
|
|
274
278
|
export {
|
|
275
279
|
m as getApiUrl,
|
|
276
|
-
|
|
277
|
-
|
|
280
|
+
I as login,
|
|
281
|
+
V as logout,
|
|
278
282
|
d as mutation,
|
|
279
|
-
|
|
283
|
+
b as query,
|
|
280
284
|
P as sendMail,
|
|
281
285
|
B as setApiUrl,
|
|
282
|
-
|
|
286
|
+
C as toQuery,
|
|
283
287
|
M as uploadFile,
|
|
284
288
|
Q as webauthnLogin,
|
|
285
289
|
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,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>0&&(o.mutation[e]={}),n.forEach(d=>{o.mutation[e][d]=!0});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"),m=e=>{let t={};return typeof e=="string"?(t[e]=!0,t):e instanceof Array?(e.forEach(n=>{Object.entries(m(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]=m(r)}),t)},S=e=>m(e),b=async e=>{const t=w.create({withCredentials:!0});let n=f.jsonToGraphQLQuery(S(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 O(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 y(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:y(i,e=>{var t;return((t=e.getTransports)==null?void 0:t.call(e))||[]})}),clientExtensionResults:y(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:y(C,e=>e.getClientExtensionResults())};function F(e){return g(O,N,e)}function D(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=()=>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 b({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 b({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=b,u.sendMail=J,u.setApiUrl=R,u.toQuery=S,u.uploadFile=j,u.webauthnLogin=M,u.webauthnRegister=x,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hostlink/light",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dev": "vite --host",
|
|
18
18
|
"build": "tsc && vite build",
|
|
19
19
|
"preview": "vite preview",
|
|
20
|
-
"release": "npm version patch && npm publish --access public && git push --follow-tags"
|
|
20
|
+
"release": "npm run build && npm version patch && npm publish --access public && git push --follow-tags"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"typescript": "^5.0.2",
|