@hostlink/light 0.0.20 → 0.0.22

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