@hostlink/light 0.0.10 → 0.0.12

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