@hostlink/light 0.0.19 → 0.0.21

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
+ export declare const setApiUrl: (url: string) => void;
2
+ export declare const getApiUrl: () => string;
package/dist/auth.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export declare const login: (username: string, password: string, code?: string) => Promise<boolean>;
2
+ export declare const logout: () => Promise<boolean>;
3
+ /**
4
+ * Updates the user's password.
5
+ * @param oldPassword The user's current password.
6
+ * @param newPassword The user's new password.
7
+ * @returns A Promise that resolves to a boolean indicating whether the password was successfully updated.
8
+ */
9
+ export declare const updatePassword: (oldPassword: string, newPassword: string) => Promise<boolean>;
10
+ export declare const resetPassword: (email: string, password: string, code: string) => Promise<boolean>;
11
+ export declare const forgetPassword: (email: string) => Promise<boolean>;
package/dist/fs.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ export type File = {
2
+ name: string;
3
+ path: string;
4
+ size: number;
5
+ mime: string;
6
+ canPreview: boolean;
7
+ imagePath: string;
8
+ };
9
+ export type Folder = {
10
+ name: String;
11
+ path: String;
12
+ };
13
+ export declare const fsListFiles: (path: string) => Promise<Array<File>>;
14
+ export declare const fsListFolders: (path: string) => Promise<Array<Folder>>;
15
+ export declare const fsReadFile: (path: string) => Promise<string>;
16
+ export declare const fsWriteFile: (path: string, content: string) => Promise<boolean>;
17
+ export declare const fsDeleteFile: (path: string) => Promise<boolean>;
18
+ export declare const fsCreateFolder: (path: string) => Promise<boolean>;
19
+ export declare const fsDeleteFolder: (path: string) => Promise<boolean>;
20
+ export declare const fsRenameFile: (path: string, name: string) => Promise<boolean>;
21
+ export declare const fsRenameFolder: (path: string, name: string) => Promise<boolean>;
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,14 +1,13 @@
1
- import login from './login';
2
- import logout from './logout';
1
+ export * from './auth';
3
2
  import query from './query';
4
3
  import mutation from './mutation';
5
4
  import toQuery from './toQuery';
6
- import getApiUrl from './getApiUrl';
7
- import setApiUrl from './setApiUrl';
5
+ export * from './apiUrl';
8
6
  import uploadFile from './uploadFile';
9
7
  import sendMail from './sendMail';
10
8
  import getConfig from './getConfig';
11
9
  import webauthnLogin from './webauthnLogin';
12
10
  import webauthnRegister from './webauthnRegister';
13
11
  export type Fields = Object | Array<string | Object> | string;
14
- export { toQuery, login, logout, query, mutation, getApiUrl, setApiUrl, uploadFile, sendMail, webauthnLogin, webauthnRegister, getConfig };
12
+ export * from './fs';
13
+ export { toQuery, query, mutation, uploadFile, sendMail, webauthnLogin, webauthnRegister, getConfig, };
package/dist/light.js CHANGED
@@ -1,295 +1,367 @@
1
- import { jsonToGraphQLQuery as h, VariableType as x } from "json-to-graphql-query";
2
- import y from "axios";
3
- let d;
4
- const _ = () => (d || (d = y.create({
5
- withCredentials: !0
6
- })), d), m = () => typeof localStorage > "u" ? "http://127.0.0.1:8888/api/" : localStorage.getItem("light-api-url") === null ? "/api/" : localStorage.getItem("light-api-url"), f = async (t, e = null, r = []) => {
7
- const n = {
8
- mutation: {}
9
- };
10
- n.mutation[t] = !0, r instanceof Array && r.length != 0 && (n.mutation[t] = {}), e && (n.mutation[t] = {}, n.mutation[t].__args = e), Object.entries(O(r)).forEach(([u, l]) => {
11
- n.mutation[t][u] = l;
12
- });
13
- const o = await _().post(m(), {
14
- query: h(n)
15
- });
16
- if (o.data.errors)
17
- throw new Error(o.data.errors[0].message);
18
- return o.data.data[t];
19
- }, B = async (t, e, r = "") => await f("login", {
20
- username: t,
21
- password: e,
1
+ import { jsonToGraphQLQuery as b, VariableType as R } from "json-to-graphql-query";
2
+ import E from "axios";
3
+ const V = (e, t, r = "") => u("login", {
4
+ username: e,
5
+ password: t,
22
6
  code: r
23
- }), M = async () => await f("logout"), g = (t) => {
24
- let e = {};
25
- return typeof t == "string" ? (e[t] = !0, e) : t instanceof Array ? (t.forEach((r) => {
26
- Object.entries(g(r)).forEach(([n, o]) => {
27
- e[n] = o;
7
+ }), W = () => u("logout"), I = (e, t) => u("updatePassword", {
8
+ old_password: e,
9
+ new_password: t
10
+ }), M = (e, t, r) => u("resetPassword", {
11
+ email: e,
12
+ password: t,
13
+ code: r
14
+ }), Q = (e) => u("forgetPassword", {
15
+ email: e
16
+ }), w = (e) => {
17
+ let t = {};
18
+ return typeof e == "string" ? (t[e] = !0, t) : e instanceof Array ? (e.forEach((r) => {
19
+ Object.entries(w(r)).forEach(([n, i]) => {
20
+ t[n] = i;
28
21
  });
29
- }), e) : (Object.entries(t).forEach(([r, n]) => {
22
+ }), t) : (Object.entries(e).forEach(([r, n]) => {
30
23
  if (r == "__args" || r == "__aliasFor" || r == "__variables" || r == "__directives" || r == "__all_on" || r == "__name") {
31
- e[r] = n;
24
+ t[r] = n;
32
25
  return;
33
26
  }
34
27
  if (typeof n == "boolean") {
35
- e[r] = n;
28
+ t[r] = n;
36
29
  return;
37
30
  }
38
- e[r] = g(n);
39
- }), e);
40
- }, O = (t) => g(t), b = async (t) => {
41
- let e = h(O(t));
42
- const r = await _().post(m(), {
43
- query: `{ ${e} }`
31
+ t[r] = w(n);
32
+ }), t);
33
+ }, _ = (e) => w(e);
34
+ let g;
35
+ const h = () => (g || (g = E.create({
36
+ withCredentials: !0
37
+ })), g), p = async (e) => {
38
+ let t = b(_(e));
39
+ const r = await h().post(y(), {
40
+ query: `{ ${t} }`
44
41
  });
45
42
  if (r.data.errors)
46
43
  throw new Error(r.data.errors[0].message);
47
44
  return r.data.data;
48
- }, P = (t) => {
49
- localStorage.setItem("light-api-url", t);
45
+ }, u = async (e, t = null, r = []) => {
46
+ const n = {
47
+ mutation: {}
48
+ };
49
+ n.mutation[e] = !0, r instanceof Array && r.length != 0 && (n.mutation[e] = {}), t && (n.mutation[e] = {}, n.mutation[e].__args = t), Object.entries(_(r)).forEach(([l, f]) => {
50
+ n.mutation[e][l] = f;
51
+ });
52
+ const i = await h().post(y(), {
53
+ query: b(n)
54
+ });
55
+ if (i.data.errors)
56
+ throw new Error(i.data.errors[0].message);
57
+ return i.data.data[e];
50
58
  };
51
- async function Q(t) {
52
- const e = y.create({
53
- withCredentials: !0
54
- }), r = {
59
+ let F = "/api/";
60
+ const z = (e) => {
61
+ F = e;
62
+ }, y = () => F;
63
+ async function $(e) {
64
+ const t = {
55
65
  __variables: {
56
66
  file: "Upload!"
57
67
  },
58
68
  fsUploadTempFile: {
59
69
  __args: {
60
- file: new x("file")
70
+ file: new R("file")
61
71
  },
62
72
  name: !0,
63
73
  path: !0,
64
74
  size: !0,
65
75
  mime: !0
66
76
  }
67
- }, n = new FormData();
68
- n.append("operations", JSON.stringify({
69
- query: h({ mutation: r })
70
- })), n.append("map", JSON.stringify({ 0: ["variables.file"] })), n.append("0", t);
71
- const o = await e.post(m(), n);
72
- if (o.data.errors)
73
- throw new Error(o.data.errors[0].message);
74
- return o.data.data.fsUploadTempFile;
77
+ }, r = new FormData();
78
+ r.append("operations", JSON.stringify({
79
+ query: b({ mutation: t })
80
+ })), r.append("map", JSON.stringify({ 0: ["variables.file"] })), r.append("0", e);
81
+ const n = await h().post(y(), r);
82
+ if (n.data.errors)
83
+ throw new Error(n.data.errors[0].message);
84
+ return n.data.data.fsUploadTempFile;
75
85
  }
76
- const L = (t, e, r) => f("sendMail", { email: t, subject: e, message: r }), W = async (t) => (await b({
86
+ const G = (e, t, r) => u("sendMail", {
87
+ email: e,
88
+ subject: t,
89
+ message: r
90
+ }), H = async (e) => (await p({
77
91
  config: {
78
92
  __args: {
79
- name: t
93
+ name: e
80
94
  }
81
95
  }
82
96
  })).config;
83
- function S(t) {
84
- const e = "==".slice(0, (4 - t.length % 4) % 4), r = t.replace(/-/g, "+").replace(/_/g, "/") + e, n = atob(r), o = new ArrayBuffer(n.length), u = new Uint8Array(o);
85
- for (let l = 0; l < n.length; l++)
86
- u[l] = n.charCodeAt(l);
87
- return o;
97
+ function O(e) {
98
+ const t = "==".slice(0, (4 - e.length % 4) % 4), r = e.replace(/-/g, "+").replace(/_/g, "/") + t, n = atob(r), i = new ArrayBuffer(n.length), l = new Uint8Array(i);
99
+ for (let f = 0; f < n.length; f++)
100
+ l[f] = n.charCodeAt(f);
101
+ return i;
88
102
  }
89
- function A(t) {
90
- const e = new Uint8Array(t);
103
+ function S(e) {
104
+ const t = new Uint8Array(e);
91
105
  let r = "";
92
- for (const u of e)
93
- r += String.fromCharCode(u);
106
+ for (const l of t)
107
+ r += String.fromCharCode(l);
94
108
  return btoa(r).replace(/\+/g, "-").replace(
95
109
  /\//g,
96
110
  "_"
97
111
  ).replace(/=/g, "");
98
112
  }
99
- var a = "copy", c = "convert";
100
- function p(t, e, r) {
101
- if (e === a)
113
+ var s = "copy", c = "convert";
114
+ function d(e, t, r) {
115
+ if (t === s)
102
116
  return r;
103
- if (e === c)
104
- return t(r);
105
- if (e instanceof Array)
106
- return r.map((n) => p(t, e[0], n));
107
- if (e instanceof Object) {
117
+ if (t === c)
118
+ return e(r);
119
+ if (t instanceof Array)
120
+ return r.map((n) => d(e, t[0], n));
121
+ if (t instanceof Object) {
108
122
  const n = {};
109
- for (const [o, u] of Object.entries(e)) {
110
- if (u.derive) {
111
- const l = u.derive(r);
112
- l !== void 0 && (r[o] = l);
123
+ for (const [i, l] of Object.entries(t)) {
124
+ if (l.derive) {
125
+ const f = l.derive(r);
126
+ f !== void 0 && (r[i] = f);
113
127
  }
114
- if (!(o in r)) {
115
- if (u.required)
116
- throw new Error(`Missing key: ${o}`);
128
+ if (!(i in r)) {
129
+ if (l.required)
130
+ throw new Error(`Missing key: ${i}`);
117
131
  continue;
118
132
  }
119
- if (r[o] == null) {
120
- n[o] = null;
133
+ if (r[i] == null) {
134
+ n[i] = null;
121
135
  continue;
122
136
  }
123
- n[o] = p(
124
- t,
125
- u.schema,
126
- r[o]
137
+ n[i] = d(
138
+ e,
139
+ l.schema,
140
+ r[i]
127
141
  );
128
142
  }
129
143
  return n;
130
144
  }
131
145
  }
132
- function w(t, e) {
146
+ function m(e, t) {
133
147
  return {
134
148
  required: !0,
135
- schema: t,
136
- derive: e
149
+ schema: e,
150
+ derive: t
137
151
  };
138
152
  }
139
- function i(t) {
153
+ function a(e) {
140
154
  return {
141
155
  required: !0,
142
- schema: t
156
+ schema: e
143
157
  };
144
158
  }
145
- function s(t) {
159
+ function o(e) {
146
160
  return {
147
161
  required: !1,
148
- schema: t
162
+ schema: e
149
163
  };
150
164
  }
151
- var v = {
152
- type: i(a),
153
- id: i(c),
154
- transports: s(a)
165
+ var A = {
166
+ type: a(s),
167
+ id: a(c),
168
+ transports: o(s)
169
+ }, v = {
170
+ appid: o(s),
171
+ appidExclude: o(s),
172
+ credProps: o(s)
155
173
  }, C = {
156
- appid: s(a),
157
- appidExclude: s(a),
158
- credProps: s(a)
159
- }, E = {
160
- appid: s(a),
161
- appidExclude: s(a),
162
- credProps: s(a)
163
- }, R = {
164
- publicKey: i({
165
- rp: i(a),
166
- user: i({
167
- id: i(c),
168
- name: i(a),
169
- displayName: i(a)
174
+ appid: o(s),
175
+ appidExclude: o(s),
176
+ credProps: o(s)
177
+ }, x = {
178
+ publicKey: a({
179
+ rp: a(s),
180
+ user: a({
181
+ id: a(c),
182
+ name: a(s),
183
+ displayName: a(s)
170
184
  }),
171
- challenge: i(c),
172
- pubKeyCredParams: i(a),
173
- timeout: s(a),
174
- excludeCredentials: s([v]),
175
- authenticatorSelection: s(a),
176
- attestation: s(a),
177
- extensions: s(C)
185
+ challenge: a(c),
186
+ pubKeyCredParams: a(s),
187
+ timeout: o(s),
188
+ excludeCredentials: o([A]),
189
+ authenticatorSelection: o(s),
190
+ attestation: o(s),
191
+ extensions: o(v)
178
192
  }),
179
- signal: s(a)
193
+ signal: o(s)
180
194
  }, q = {
181
- type: i(a),
182
- id: i(a),
183
- rawId: i(c),
184
- authenticatorAttachment: s(a),
185
- response: i({
186
- clientDataJSON: i(c),
187
- attestationObject: i(c),
188
- transports: w(
189
- a,
190
- (t) => {
191
- var e;
192
- return ((e = t.getTransports) == null ? void 0 : e.call(t)) || [];
195
+ type: a(s),
196
+ id: a(s),
197
+ rawId: a(c),
198
+ authenticatorAttachment: o(s),
199
+ response: a({
200
+ clientDataJSON: a(c),
201
+ attestationObject: a(c),
202
+ transports: m(
203
+ s,
204
+ (e) => {
205
+ var t;
206
+ return ((t = e.getTransports) == null ? void 0 : t.call(e)) || [];
193
207
  }
194
208
  )
195
209
  }),
196
- clientExtensionResults: w(
197
- E,
198
- (t) => t.getClientExtensionResults()
210
+ clientExtensionResults: m(
211
+ C,
212
+ (e) => e.getClientExtensionResults()
199
213
  )
200
214
  }, J = {
201
- mediation: s(a),
202
- publicKey: i({
203
- challenge: i(c),
204
- timeout: s(a),
205
- rpId: s(a),
206
- allowCredentials: s([v]),
207
- userVerification: s(a),
208
- extensions: s(C)
215
+ mediation: o(s),
216
+ publicKey: a({
217
+ challenge: a(c),
218
+ timeout: o(s),
219
+ rpId: o(s),
220
+ allowCredentials: o([A]),
221
+ userVerification: o(s),
222
+ extensions: o(v)
209
223
  }),
210
- signal: s(a)
224
+ signal: o(s)
211
225
  }, N = {
212
- type: i(a),
213
- id: i(a),
214
- rawId: i(c),
215
- authenticatorAttachment: s(a),
216
- response: i({
217
- clientDataJSON: i(c),
218
- authenticatorData: i(c),
219
- signature: i(c),
220
- userHandle: i(c)
226
+ type: a(s),
227
+ id: a(s),
228
+ rawId: a(c),
229
+ authenticatorAttachment: o(s),
230
+ response: a({
231
+ clientDataJSON: a(c),
232
+ authenticatorData: a(c),
233
+ signature: a(c),
234
+ userHandle: a(c)
221
235
  }),
222
- clientExtensionResults: w(
223
- E,
224
- (t) => t.getClientExtensionResults()
236
+ clientExtensionResults: m(
237
+ C,
238
+ (e) => e.getClientExtensionResults()
225
239
  )
226
240
  };
227
- function j(t) {
228
- return p(S, R, t);
241
+ function P(e) {
242
+ return d(O, x, e);
229
243
  }
230
- function T(t) {
231
- return p(
232
- A,
244
+ function j(e) {
245
+ return d(
246
+ S,
233
247
  q,
234
- t
248
+ e
235
249
  );
236
250
  }
237
- function K(t) {
238
- return p(S, J, t);
251
+ function D(e) {
252
+ return d(O, J, e);
239
253
  }
240
- function U(t) {
241
- return p(
242
- A,
254
+ function T(e) {
255
+ return d(
256
+ S,
243
257
  N,
244
- t
258
+ e
245
259
  );
246
260
  }
247
- async function D(t) {
248
- const e = await navigator.credentials.create(
249
- t
261
+ async function K(e) {
262
+ const t = await navigator.credentials.create(
263
+ e
250
264
  );
251
- return e.toJSON = () => T(e), e;
265
+ return t.toJSON = () => j(t), t;
252
266
  }
253
- async function F(t) {
254
- const e = await navigator.credentials.get(
255
- t
267
+ async function L(e) {
268
+ const t = await navigator.credentials.get(
269
+ e
256
270
  );
257
- return e.toJSON = () => U(e), e;
271
+ return t.toJSON = () => T(t), t;
258
272
  }
259
- async function $(t) {
260
- const r = (await b({
273
+ async function X(e) {
274
+ const r = (await p({
261
275
  webAuthnRequestOptions: {
262
276
  __args: {
263
- username: t
277
+ username: e
264
278
  }
265
279
  }
266
- })).webAuthnRequestOptions, n = K({
280
+ })).webAuthnRequestOptions, n = D({
267
281
  publicKey: r
268
- }), o = await F(n);
269
- await f("webAuthnAssertion", {
270
- username: t,
271
- assertion: o.toJSON()
282
+ }), i = await L(n);
283
+ await u("webAuthnAssertion", {
284
+ username: e,
285
+ assertion: i.toJSON()
272
286
  });
273
287
  }
274
- async function z() {
275
- const t = await b({ webAuthnCreationOptions: !0 }), e = j({
276
- publicKey: t.webAuthnCreationOptions
277
- }), r = await D(e);
278
- await f("webAuthnRegister", {
288
+ async function Y() {
289
+ const e = await p({ webAuthnCreationOptions: !0 }), t = P({
290
+ publicKey: e.webAuthnCreationOptions
291
+ }), r = await K(t);
292
+ await u("webAuthnRegister", {
279
293
  registration: r.toJSON()
280
294
  });
281
295
  }
296
+ const Z = async (e) => (await p({
297
+ fsListFiles: {
298
+ __args: {
299
+ path: e
300
+ },
301
+ name: !0,
302
+ path: !0,
303
+ size: !0,
304
+ mime: !0,
305
+ canPreview: !0,
306
+ imagePath: !0
307
+ }
308
+ })).fsListFiles, k = async (e) => (await p({
309
+ fsListFolders: {
310
+ __args: {
311
+ path: e
312
+ },
313
+ name: !0,
314
+ path: !0
315
+ }
316
+ })).fsListFolders, ee = async (e) => {
317
+ let t = await p({
318
+ fsFile: {
319
+ __args: {
320
+ path: e
321
+ },
322
+ content: !0
323
+ }
324
+ });
325
+ return Buffer.from(t.fsFile.content, "base64").toString("utf-8");
326
+ }, te = (e, t) => (t = Buffer.from(t).toString("base64"), u("fsWriteFileBase64", {
327
+ path: e,
328
+ content: t
329
+ })), re = (e) => u("fsDeleteFile", {
330
+ path: e
331
+ }), ne = (e) => u("fsCreateFolder", {
332
+ path: e
333
+ }), se = (e) => u("fsDeleteFolder", {
334
+ path: e
335
+ }), ae = (e, t) => u("fsRenameFile", {
336
+ path: e,
337
+ name: t
338
+ }), oe = (e, t) => u("fsRenameFolder", {
339
+ path: e,
340
+ name: t
341
+ });
282
342
  export {
283
- m as getApiUrl,
284
- W as getConfig,
285
- B as login,
286
- M as logout,
287
- f as mutation,
288
- b as query,
289
- L as sendMail,
290
- P as setApiUrl,
291
- O as toQuery,
292
- Q as uploadFile,
293
- $ as webauthnLogin,
294
- z as webauthnRegister
343
+ Q as forgetPassword,
344
+ ne as fsCreateFolder,
345
+ re as fsDeleteFile,
346
+ se as fsDeleteFolder,
347
+ Z as fsListFiles,
348
+ k as fsListFolders,
349
+ ee as fsReadFile,
350
+ ae as fsRenameFile,
351
+ oe as fsRenameFolder,
352
+ te as fsWriteFile,
353
+ y as getApiUrl,
354
+ H as getConfig,
355
+ V as login,
356
+ W as logout,
357
+ u as mutation,
358
+ p as query,
359
+ M as resetPassword,
360
+ G as sendMail,
361
+ z as setApiUrl,
362
+ _ as toQuery,
363
+ I as updatePassword,
364
+ $ as uploadFile,
365
+ X as webauthnLogin,
366
+ Y as webauthnRegister
295
367
  };
@@ -1 +1 @@
1
- (function(u,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("json-to-graphql-query"),require("axios")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","axios"],d):(u=typeof globalThis<"u"?globalThis:u||self,d(u.light={},u.jsonToGraphqlQuery,u.axios))})(this,function(u,d,O){"use strict";let y;const _=()=>(y||(y=O.create({withCredentials:!0})),y),h=()=>typeof localStorage>"u"?"http://127.0.0.1:8888/api/":localStorage.getItem("light-api-url")===null?"/api/":localStorage.getItem("light-api-url"),p=async(t,e=null,n=[])=>{const r={mutation:{}};r.mutation[t]=!0,n instanceof Array&&n.length!=0&&(r.mutation[t]={}),e&&(r.mutation[t]={},r.mutation[t].__args=e),Object.entries(m(n)).forEach(([l,f])=>{r.mutation[t][l]=f});const o=await _().post(h(),{query:d.jsonToGraphQLQuery(r)});if(o.data.errors)throw new Error(o.data.errors[0].message);return o.data.data[t]},R=async(t,e,n="")=>await p("login",{username:t,password:e,code:n}),j=async()=>await p("logout"),b=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(n=>{Object.entries(b(n)).forEach(([r,o])=>{e[r]=o})}),e):(Object.entries(t).forEach(([n,r])=>{if(n=="__args"||n=="__aliasFor"||n=="__variables"||n=="__directives"||n=="__all_on"||n=="__name"){e[n]=r;return}if(typeof r=="boolean"){e[n]=r;return}e[n]=b(r)}),e)},m=t=>b(t),w=async t=>{let e=d.jsonToGraphQLQuery(m(t));const n=await _().post(h(),{query:`{ ${e} }`});if(n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data},J=t=>{localStorage.setItem("light-api-url",t)};async function N(t){const e=O.create({withCredentials:!0}),n={__variables:{file:"Upload!"},fsUploadTempFile:{__args:{file:new d.VariableType("file")},name:!0,path:!0,size:!0,mime:!0}},r=new FormData;r.append("operations",JSON.stringify({query:d.jsonToGraphQLQuery({mutation:n})})),r.append("map",JSON.stringify({0:["variables.file"]})),r.append("0",t);const o=await e.post(h(),r);if(o.data.errors)throw new Error(o.data.errors[0].message);return o.data.data.fsUploadTempFile}const T=(t,e,n)=>p("sendMail",{email:t,subject:e,message:n}),U=async t=>(await w({config:{__args:{name:t}}})).config;function A(t){const e="==".slice(0,(4-t.length%4)%4),n=t.replace(/-/g,"+").replace(/_/g,"/")+e,r=atob(n),o=new ArrayBuffer(r.length),l=new Uint8Array(o);for(let f=0;f<r.length;f++)l[f]=r.charCodeAt(f);return o}function v(t){const e=new Uint8Array(t);let n="";for(const l of e)n+=String.fromCharCode(l);return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var i="copy",c="convert";function g(t,e,n){if(e===i)return n;if(e===c)return t(n);if(e instanceof Array)return n.map(r=>g(t,e[0],r));if(e instanceof Object){const r={};for(const[o,l]of Object.entries(e)){if(l.derive){const f=l.derive(n);f!==void 0&&(n[o]=f)}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(t,l.schema,n[o])}return r}}function S(t,e){return{required:!0,schema:t,derive:e}}function a(t){return{required:!0,schema:t}}function s(t){return{required:!1,schema:t}}var C={type:a(i),id:a(c),transports:s(i)},q={appid:s(i),appidExclude:s(i),credProps:s(i)},E={appid:s(i),appidExclude:s(i),credProps:s(i)},K={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([C]),authenticatorSelection:s(i),attestation:s(i),extensions:s(q)}),signal:s(i)},F={type:a(i),id:a(i),rawId:a(c),authenticatorAttachment:s(i),response:a({clientDataJSON:a(c),attestationObject:a(c),transports:S(i,t=>{var e;return((e=t.getTransports)==null?void 0:e.call(t))||[]})}),clientExtensionResults:S(E,t=>t.getClientExtensionResults())},x={mediation:s(i),publicKey:a({challenge:a(c),timeout:s(i),rpId:s(i),allowCredentials:s([C]),userVerification:s(i),extensions:s(q)}),signal:s(i)},D={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:S(E,t=>t.getClientExtensionResults())};function I(t){return g(A,K,t)}function Q(t){return g(v,F,t)}function V(t){return g(A,x,t)}function L(t){return g(v,D,t)}async function M(t){const e=await navigator.credentials.create(t);return e.toJSON=()=>Q(e),e}async function P(t){const e=await navigator.credentials.get(t);return e.toJSON=()=>L(e),e}async function B(t){const n=(await w({webAuthnRequestOptions:{__args:{username:t}}})).webAuthnRequestOptions,r=V({publicKey:n}),o=await P(r);await p("webAuthnAssertion",{username:t,assertion:o.toJSON()})}async function W(){const t=await w({webAuthnCreationOptions:!0}),e=I({publicKey:t.webAuthnCreationOptions}),n=await M(e);await p("webAuthnRegister",{registration:n.toJSON()})}u.getApiUrl=h,u.getConfig=U,u.login=R,u.logout=j,u.mutation=p,u.query=w,u.sendMail=T,u.setApiUrl=J,u.toQuery=m,u.uploadFile=N,u.webauthnLogin=B,u.webauthnRegister=W,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
1
+ (function(n,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("json-to-graphql-query"),require("axios")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","axios"],p):(n=typeof globalThis<"u"?globalThis:n||self,p(n.light={},n.jsonToGraphqlQuery,n.axios))})(this,function(n,p,q){"use strict";const E=(e,t,r="")=>l("login",{username:e,password:t,code:r}),P=()=>l("logout"),j=(e,t)=>l("updatePassword",{old_password:e,new_password:t}),J=(e,t,r)=>l("resetPassword",{email:e,password:t,code:r}),L=e=>l("forgetPassword",{email:e}),h=e=>{let t={};return typeof e=="string"?(t[e]=!0,t):e instanceof Array?(e.forEach(r=>{Object.entries(h(r)).forEach(([s,u])=>{t[s]=u})}),t):(Object.entries(e).forEach(([r,s])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){t[r]=s;return}if(typeof s=="boolean"){t[r]=s;return}t[r]=h(s)}),t)},b=e=>h(e);let y;const F=()=>(y||(y=q.create({withCredentials:!0})),y),g=async e=>{let t=p.jsonToGraphQLQuery(b(e));const r=await F().post(m(),{query:`{ ${t} }`});if(r.data.errors)throw new Error(r.data.errors[0].message);return r.data.data},l=async(e,t=null,r=[])=>{const s={mutation:{}};s.mutation[e]=!0,r instanceof Array&&r.length!=0&&(s.mutation[e]={}),t&&(s.mutation[e]={},s.mutation[e].__args=t),Object.entries(b(r)).forEach(([f,d])=>{s.mutation[e][f]=d});const u=await F().post(m(),{query:p.jsonToGraphQLQuery(s)});if(u.data.errors)throw new Error(u.data.errors[0].message);return u.data.data[e]};let O="/api/";const N=e=>{O=e},m=()=>O;async function D(e){const t={__variables:{file:"Upload!"},fsUploadTempFile:{__args:{file:new p.VariableType("file")},name:!0,path:!0,size:!0,mime:!0}},r=new FormData;r.append("operations",JSON.stringify({query:p.jsonToGraphQLQuery({mutation:t})})),r.append("map",JSON.stringify({0:["variables.file"]})),r.append("0",e);const s=await F().post(m(),r);if(s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data.fsUploadTempFile}const T=(e,t,r)=>l("sendMail",{email:e,subject:t,message:r}),U=async e=>(await g({config:{__args:{name:e}}})).config;function S(e){const t="==".slice(0,(4-e.length%4)%4),r=e.replace(/-/g,"+").replace(/_/g,"/")+t,s=atob(r),u=new ArrayBuffer(s.length),f=new Uint8Array(u);for(let d=0;d<s.length;d++)f[d]=s.charCodeAt(d);return u}function A(e){const t=new Uint8Array(e);let r="";for(const f of t)r+=String.fromCharCode(f);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var a="copy",c="convert";function w(e,t,r){if(t===a)return r;if(t===c)return e(r);if(t instanceof Array)return r.map(s=>w(e,t[0],s));if(t instanceof Object){const s={};for(const[u,f]of Object.entries(t)){if(f.derive){const d=f.derive(r);d!==void 0&&(r[u]=d)}if(!(u in r)){if(f.required)throw new Error(`Missing key: ${u}`);continue}if(r[u]==null){s[u]=null;continue}s[u]=w(e,f.schema,r[u])}return s}}function _(e,t){return{required:!0,schema:e,derive:t}}function i(e){return{required:!0,schema:e}}function o(e){return{required:!1,schema:e}}var R={type:i(a),id:i(c),transports:o(a)},v={appid:o(a),appidExclude:o(a),credProps:o(a)},C={appid:o(a),appidExclude:o(a),credProps:o(a)},K={publicKey:i({rp:i(a),user:i({id:i(c),name:i(a),displayName:i(a)}),challenge:i(c),pubKeyCredParams:i(a),timeout:o(a),excludeCredentials:o([R]),authenticatorSelection:o(a),attestation:o(a),extensions:o(v)}),signal:o(a)},B={type:i(a),id:i(a),rawId:i(c),authenticatorAttachment:o(a),response:i({clientDataJSON:i(c),attestationObject:i(c),transports:_(a,e=>{var t;return((t=e.getTransports)==null?void 0:t.call(e))||[]})}),clientExtensionResults:_(C,e=>e.getClientExtensionResults())},Q={mediation:o(a),publicKey:i({challenge:i(c),timeout:o(a),rpId:o(a),allowCredentials:o([R]),userVerification:o(a),extensions:o(v)}),signal:o(a)},V={type:i(a),id:i(a),rawId:i(c),authenticatorAttachment:o(a),response:i({clientDataJSON:i(c),authenticatorData:i(c),signature:i(c),userHandle:i(c)}),clientExtensionResults:_(C,e=>e.getClientExtensionResults())};function M(e){return w(S,K,e)}function W(e){return w(A,B,e)}function I(e){return w(S,Q,e)}function z(e){return w(A,V,e)}async function $(e){const t=await navigator.credentials.create(e);return t.toJSON=()=>W(t),t}async function G(e){const t=await navigator.credentials.get(e);return t.toJSON=()=>z(t),t}async function H(e){const r=(await g({webAuthnRequestOptions:{__args:{username:e}}})).webAuthnRequestOptions,s=I({publicKey:r}),u=await G(s);await l("webAuthnAssertion",{username:e,assertion:u.toJSON()})}async function X(){const e=await g({webAuthnCreationOptions:!0}),t=M({publicKey:e.webAuthnCreationOptions}),r=await $(t);await l("webAuthnRegister",{registration:r.toJSON()})}const Y=async e=>(await g({fsListFiles:{__args:{path:e},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}})).fsListFiles,Z=async e=>(await g({fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,x=async e=>{let t=await g({fsFile:{__args:{path:e},content:!0}});return Buffer.from(t.fsFile.content,"base64").toString("utf-8")},k=(e,t)=>(t=Buffer.from(t).toString("base64"),l("fsWriteFileBase64",{path:e,content:t})),ee=e=>l("fsDeleteFile",{path:e}),te=e=>l("fsCreateFolder",{path:e}),re=e=>l("fsDeleteFolder",{path:e}),ne=(e,t)=>l("fsRenameFile",{path:e,name:t}),se=(e,t)=>l("fsRenameFolder",{path:e,name:t});n.forgetPassword=L,n.fsCreateFolder=te,n.fsDeleteFile=ee,n.fsDeleteFolder=re,n.fsListFiles=Y,n.fsListFolders=Z,n.fsReadFile=x,n.fsRenameFile=ne,n.fsRenameFolder=se,n.fsWriteFile=k,n.getApiUrl=m,n.getConfig=U,n.login=E,n.logout=P,n.mutation=l,n.query=g,n.resetPassword=J,n.sendMail=T,n.setApiUrl=N,n.toQuery=b,n.updatePassword=j,n.uploadFile=D,n.webauthnLogin=H,n.webauthnRegister=X,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/light",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -1,2 +0,0 @@
1
- declare const _default: () => string;
2
- export default _default;
package/dist/login.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare const _default: (username: string, password: string, code?: string) => Promise<boolean>;
2
- export default _default;
package/dist/logout.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare const _default: () => Promise<boolean>;
2
- export default _default;