@hostlink/light 1.2.0 → 1.2.1

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 CHANGED
@@ -1,35 +1,35 @@
1
- import K from "axios";
2
- import { VariableType as A, jsonToGraphQLQuery as x } from "json-to-graphql-query";
3
- const re = (e, t, r = "") => f("login", {
1
+ import T from "axios";
2
+ import { jsonToGraphQLQuery as N, VariableType as R } from "json-to-graphql-query";
3
+ const re = (e, t, r = "") => u("login", {
4
4
  username: e,
5
5
  password: t,
6
6
  code: r
7
- }), ne = () => f("logout"), se = (e, t) => f("updatePassword", {
7
+ }), ne = () => u("logout"), se = (e, t) => u("updatePassword", {
8
8
  old_password: e,
9
9
  new_password: t
10
- }), ae = (e, t, r) => f("resetPassword", {
10
+ }), ie = (e, t, r) => u("resetPassword", {
11
11
  email: e,
12
12
  password: t,
13
13
  code: r
14
- }), ie = (e) => f("forgetPassword", {
14
+ }), ae = (e) => u("forgetPassword", {
15
15
  email: e
16
16
  });
17
- let S;
17
+ let O;
18
18
  const oe = (e) => {
19
- S = e;
20
- }, v = () => (S || (S = K.create({
19
+ O = e;
20
+ }, E = () => (O || (O = T.create({
21
21
  withCredentials: !0
22
- })), S), le = async (e) => (await h({
22
+ })), O), ce = async (e) => (await b({
23
23
  granted: {
24
24
  __args: {
25
25
  rights: e
26
26
  }
27
27
  }
28
- })).granted, y = {}, ce = (e, t) => {
29
- y[e] = {};
28
+ })).granted, F = {}, le = (e, t) => {
29
+ F[e] = {};
30
30
  for (const r of Object.entries(t)) {
31
31
  const [s, n] = r;
32
- y[e][s] = () => ({
32
+ F[e][s] = () => ({
33
33
  name: n.name ? n.name : s,
34
34
  raw: n,
35
35
  getName: () => n.name ? n.name : s,
@@ -46,55 +46,39 @@ const oe = (e) => {
46
46
  }
47
47
  });
48
48
  }
49
- }, J = (e, t) => !y[e] || !y[e][t] ? null : y[e][t](), ue = (e, t) => {
49
+ }, L = (e, t) => !F[e] || !F[e][t] ? null : F[e][t](), ue = (e, t) => {
50
50
  const r = [];
51
51
  for (const s of t)
52
52
  if (typeof s == "string") {
53
- const n = J(e, s);
53
+ const n = L(e, s);
54
54
  n && r.push(n.getGQLField());
55
55
  } else
56
56
  typeof s == "object" && r.push(s);
57
57
  return r;
58
58
  }, fe = (e) => {
59
- const t = new FormData(), r = {}, s = {}, n = {};
60
- let a = 0, l = !1;
61
- return Object.entries(e).forEach(([u, d]) => {
62
- d instanceof File ? (l = !0, s[u] = "Upload!", n[u] = new A(u), t.append(a.toString(), d), r[a] = ["variables." + u], a++) : n[u] = d;
63
- }), l ? (t.append("map", JSON.stringify(r)), {
64
- data: n,
65
- formData: t,
66
- mutation: {
67
- __variables: s
68
- }
69
- }) : {
70
- data: n,
71
- formData: null,
72
- mutation: {}
73
- };
74
- }, de = (e) => {
75
59
  const t = e;
76
60
  return {
77
61
  name: t,
78
- $fields: y[e],
62
+ $fields: F[e],
79
63
  async update(r, s) {
80
- return await f("update" + t, { id: r, data: s });
64
+ return await u("update" + t, { id: r, data: s });
81
65
  },
82
66
  async delete(r) {
83
- return await f("delete" + t, { id: r });
67
+ return await u("delete" + t, { id: r });
84
68
  },
85
69
  async add(r) {
86
- return await f("add" + t, { data: r });
70
+ return await u("add" + t, { data: r });
87
71
  },
88
72
  fields(r) {
89
73
  let s = [];
90
74
  for (let n of r) {
91
- const a = J(t, n);
75
+ const a = L(t, n);
92
76
  a && s.push(a);
93
77
  }
94
78
  return s;
95
79
  },
96
80
  async get(r, s) {
97
- return (await h({
81
+ return (await b({
98
82
  ["list" + t]: {
99
83
  __args: {
100
84
  filters: r
@@ -103,19 +87,19 @@ const oe = (e) => {
103
87
  __args: {
104
88
  limit: 1
105
89
  },
106
- ...R(s)
90
+ ...S(s)
107
91
  }
108
92
  }
109
93
  }))["list" + t].data[0];
110
94
  },
111
95
  async list(r, s) {
112
- return (await h({
96
+ return (await b({
113
97
  ["list" + t]: {
114
98
  __args: {
115
99
  filters: r
116
100
  },
117
101
  data: {
118
- ...R(s)
102
+ ...S(s)
119
103
  }
120
104
  }
121
105
  }))["list" + t].data;
@@ -124,19 +108,19 @@ const oe = (e) => {
124
108
  };
125
109
  function M(e) {
126
110
  e = "<~" + e + "~>";
127
- var t, r, s, n, a, l = String, u = 255;
111
+ var t, r, s, n, a, l = String, d = 255;
128
112
  for (e.slice(0, 2) === "<~" && e.slice(-2), e = e.slice(2, -2).replace(/\s/g, "").replace("z", "!!!!!"), t = "uuuuu".slice(e.length % 5 || 5), e += t, s = [], n = 0, a = e.length; a > n; n += 5)
129
- r = 52200625 * (e.charCodeAt(n) - 33) + 614125 * (e.charCodeAt(n + 1) - 33) + 7225 * (e.charCodeAt(n + 2) - 33) + 85 * (e.charCodeAt(n + 3) - 33) + (e.charCodeAt(n + 4) - 33), s.push(u & r >> 24, u & r >> 16, u & r >> 8, u & r);
130
- return function(d, b) {
131
- for (var _ = b; _ > 0; _--)
132
- d.pop();
113
+ r = 52200625 * (e.charCodeAt(n) - 33) + 614125 * (e.charCodeAt(n + 1) - 33) + 7225 * (e.charCodeAt(n + 2) - 33) + 85 * (e.charCodeAt(n + 3) - 33) + (e.charCodeAt(n + 4) - 33), s.push(d & r >> 24, d & r >> 16, d & r >> 8, d & r);
114
+ return function(p, m) {
115
+ for (var _ = m; _ > 0; _--)
116
+ p.pop();
133
117
  }(s, t.length), l.fromCharCode.apply(l, s);
134
118
  }
135
- const j = (e = "") => {
119
+ const v = (e = "") => {
136
120
  const t = e, r = (s = "application/octet-stream") => {
137
121
  const n = new Uint8Array(t.length);
138
- for (let u = 0; u < t.length; u++)
139
- n[u] = t.charCodeAt(u);
122
+ for (let d = 0; d < t.length; d++)
123
+ n[d] = t.charCodeAt(d);
140
124
  const a = new Blob([n], { type: s });
141
125
  return URL.createObjectURL(a);
142
126
  };
@@ -151,14 +135,14 @@ const j = (e = "") => {
151
135
  window.open(r(s), "_blank");
152
136
  }
153
137
  };
154
- }, pe = {
155
- fromBase85: (e) => j(M(e)),
156
- fromBase64: (e) => j(atob(e)),
157
- fromString: (e) => j(e)
158
- }, q = (e) => {
138
+ }, de = {
139
+ fromBase85: (e) => v(M(e)),
140
+ fromBase64: (e) => v(atob(e)),
141
+ fromString: (e) => v(e)
142
+ }, j = (e) => {
159
143
  let t = {};
160
144
  return typeof e == "string" ? (t[e] = !0, t) : e instanceof Array ? (e.forEach((r) => {
161
- Object.entries(q(r)).forEach(([s, n]) => {
145
+ Object.entries(j(r)).forEach(([s, n]) => {
162
146
  t[s] = n;
163
147
  });
164
148
  }), t) : (Object.entries(e).forEach(([r, s]) => {
@@ -170,11 +154,11 @@ const j = (e = "") => {
170
154
  t[r] = s;
171
155
  return;
172
156
  }
173
- t[r] = q(s);
157
+ t[r] = j(s);
174
158
  }), t);
175
- }, R = (e) => q(e), h = async (e) => {
176
- let t = x(R(e));
177
- const r = await v().post(E(), {
159
+ }, S = (e) => j(e), b = async (e) => {
160
+ let t = N(S(e));
161
+ const r = await E().post(q(), {
178
162
  query: `{ ${t} }`
179
163
  });
180
164
  if (r.data.errors)
@@ -193,80 +177,67 @@ function Q(e) {
193
177
  return !0;
194
178
  return !1;
195
179
  }
196
- const f = async (e, t = null, r = []) => {
180
+ const u = async (e, t = null, r = []) => {
197
181
  let s = {
198
182
  [e]: {}
199
183
  };
200
184
  const n = new FormData();
201
185
  let a = !1;
202
186
  if (t) {
203
- const d = {}, b = {}, _ = {};
187
+ const p = {}, m = {}, _ = {};
204
188
  let w = 0;
205
- Object.entries(t).forEach(([m, g]) => {
189
+ Object.entries(t).forEach(([h, g]) => {
206
190
  if (g instanceof Array && B(g)) {
207
191
  a = !0;
208
- let F = 0;
209
- g.forEach((C) => {
210
- C instanceof File && (d[m] = new A(m), b[w] = ["variables." + m + "." + F], n.append(w.toString(), C), w++);
211
- }), _[m] = "[Upload!]!";
192
+ let y = 0;
193
+ g.forEach((A) => {
194
+ A instanceof File && (p[h] = new R(h), m[w] = ["variables." + h + "." + y], n.append(w.toString(), A), w++);
195
+ }), _[h] = "[Upload!]!";
212
196
  } else
213
- g instanceof File ? (a = !0, d[m] = new A(m), b[w] = ["variables." + m], n.append(w.toString(), g), _[m] = "Upload!", w++) : g instanceof Object && Q(g) ? (a = !0, Object.entries(g).forEach(([F, C]) => {
214
- C instanceof File ? (d[F] = new A(F), b[w] = ["variables." + F], n.append(w.toString(), C), w++) : d[F] = g;
215
- })) : d[m] = g;
216
- }), s[e].__args = d, s.__variables = _, a && n.append("map", JSON.stringify(b));
197
+ g instanceof File ? (a = !0, p[h] = new R(h), m[w] = ["variables." + h], n.append(w.toString(), g), _[h] = "Upload!", w++) : g instanceof Object && Q(g) ? (a = !0, Object.entries(g).forEach(([y, A]) => {
198
+ A instanceof File ? (p[y] = new R(y), m[w] = ["variables." + y], n.append(w.toString(), A), w++) : p[y] = g;
199
+ })) : p[h] = g;
200
+ }), s[e].__args = p, s.__variables = _, a && n.append("map", JSON.stringify(m));
217
201
  }
218
- Object.entries(R(r)).forEach(([d, b]) => {
219
- s[e][d] = b;
202
+ Object.entries(S(r)).forEach(([p, m]) => {
203
+ s[e][p] = m;
220
204
  }), Object.entries(s[e]).length === 0 && (s[e] = !0);
221
205
  let l = null;
222
- const u = x({ mutation: s });
206
+ const d = N({ mutation: s });
223
207
  if (a ? (n.append("operations", JSON.stringify({
224
- query: u
225
- })), l = await v().post(E(), n)) : l = await v().post(E(), {
226
- query: u
208
+ query: d
209
+ })), l = await E().post(q(), n)) : l = await E().post(q(), {
210
+ query: d
227
211
  }), l.data.errors)
228
212
  throw new Error(l.data.errors[0].message);
229
213
  return l.data.data[e];
230
214
  };
231
- let D = "/api/";
232
- const ge = (e) => {
233
- D = e;
234
- }, E = () => D;
235
- async function we(e) {
236
- const t = {
237
- __variables: {
238
- file: "Upload!"
239
- },
240
- fsUploadTempFile: {
241
- __args: {
242
- file: new A("file")
243
- },
244
- name: !0,
245
- path: !0,
246
- size: !0,
247
- mime: !0
248
- }
249
- }, r = new FormData();
250
- r.append("operations", JSON.stringify({
251
- query: x({ mutation: t })
252
- })), r.append("map", JSON.stringify({ 0: ["variables.file"] })), r.append("0", e);
253
- const s = await v().post(E(), r);
254
- if (s.data.errors)
255
- throw new Error(s.data.errors[0].message);
256
- return s.data.data.fsUploadTempFile;
215
+ let J = "/api/";
216
+ const pe = (e) => {
217
+ J = e;
218
+ }, q = () => J;
219
+ async function ge(e) {
220
+ return u("fsUploadTempFile", {
221
+ file: e
222
+ }, {
223
+ name: !0,
224
+ path: !0,
225
+ size: !0,
226
+ mime: !0
227
+ });
257
228
  }
258
- const me = (e, t, r) => f("sendMail", {
229
+ const we = (e, t, r) => u("sendMail", {
259
230
  email: e,
260
231
  subject: t,
261
232
  message: r
262
- }), he = async (e) => (await h({
233
+ }), he = async (e) => (await b({
263
234
  config: {
264
235
  __args: {
265
236
  name: e
266
237
  }
267
238
  }
268
239
  })).config;
269
- function L(e) {
240
+ function P(e) {
270
241
  const t = "==".slice(0, (4 - e.length % 4) % 4), r = e.replace(/-/g, "+").replace(/_/g, "/") + t, s = atob(r), n = new ArrayBuffer(s.length), a = new Uint8Array(n);
271
242
  for (let l = 0; l < s.length; l++)
272
243
  a[l] = s.charCodeAt(l);
@@ -282,14 +253,14 @@ function U(e) {
282
253
  "_"
283
254
  ).replace(/=/g, "");
284
255
  }
285
- var i = "copy", p = "convert";
286
- function O(e, t, r) {
256
+ var i = "copy", f = "convert";
257
+ function C(e, t, r) {
287
258
  if (t === i)
288
259
  return r;
289
- if (t === p)
260
+ if (t === f)
290
261
  return e(r);
291
262
  if (t instanceof Array)
292
- return r.map((s) => O(e, t[0], s));
263
+ return r.map((s) => C(e, t[0], s));
293
264
  if (t instanceof Object) {
294
265
  const s = {};
295
266
  for (const [n, a] of Object.entries(t)) {
@@ -306,7 +277,7 @@ function O(e, t, r) {
306
277
  s[n] = null;
307
278
  continue;
308
279
  }
309
- s[n] = O(
280
+ s[n] = C(
310
281
  e,
311
282
  a.schema,
312
283
  r[n]
@@ -315,7 +286,7 @@ function O(e, t, r) {
315
286
  return s;
316
287
  }
317
288
  }
318
- function N(e, t) {
289
+ function x(e, t) {
319
290
  return {
320
291
  required: !0,
321
292
  schema: e,
@@ -334,15 +305,15 @@ function c(e) {
334
305
  schema: e
335
306
  };
336
307
  }
337
- var P = {
308
+ var D = {
338
309
  type: o(i),
339
- id: o(p),
310
+ id: o(f),
340
311
  transports: c(i)
341
- }, T = {
312
+ }, V = {
342
313
  appid: c(i),
343
314
  appidExclude: c(i),
344
315
  credProps: c(i)
345
- }, V = {
316
+ }, K = {
346
317
  appid: c(i),
347
318
  appidExclude: c(i),
348
319
  credProps: c(i)
@@ -350,28 +321,28 @@ var P = {
350
321
  publicKey: o({
351
322
  rp: o(i),
352
323
  user: o({
353
- id: o(p),
324
+ id: o(f),
354
325
  name: o(i),
355
326
  displayName: o(i)
356
327
  }),
357
- challenge: o(p),
328
+ challenge: o(f),
358
329
  pubKeyCredParams: o(i),
359
330
  timeout: c(i),
360
- excludeCredentials: c([P]),
331
+ excludeCredentials: c([D]),
361
332
  authenticatorSelection: c(i),
362
333
  attestation: c(i),
363
- extensions: c(T)
334
+ extensions: c(V)
364
335
  }),
365
336
  signal: c(i)
366
337
  }, W = {
367
338
  type: o(i),
368
339
  id: o(i),
369
- rawId: o(p),
340
+ rawId: o(f),
370
341
  authenticatorAttachment: c(i),
371
342
  response: o({
372
- clientDataJSON: o(p),
373
- attestationObject: o(p),
374
- transports: N(
343
+ clientDataJSON: o(f),
344
+ attestationObject: o(f),
345
+ transports: x(
375
346
  i,
376
347
  (e) => {
377
348
  var t;
@@ -379,52 +350,52 @@ var P = {
379
350
  }
380
351
  )
381
352
  }),
382
- clientExtensionResults: N(
383
- V,
353
+ clientExtensionResults: x(
354
+ K,
384
355
  (e) => e.getClientExtensionResults()
385
356
  )
386
357
  }, $ = {
387
358
  mediation: c(i),
388
359
  publicKey: o({
389
- challenge: o(p),
360
+ challenge: o(f),
390
361
  timeout: c(i),
391
362
  rpId: c(i),
392
- allowCredentials: c([P]),
363
+ allowCredentials: c([D]),
393
364
  userVerification: c(i),
394
- extensions: c(T)
365
+ extensions: c(V)
395
366
  }),
396
367
  signal: c(i)
397
368
  }, z = {
398
369
  type: o(i),
399
370
  id: o(i),
400
- rawId: o(p),
371
+ rawId: o(f),
401
372
  authenticatorAttachment: c(i),
402
373
  response: o({
403
- clientDataJSON: o(p),
404
- authenticatorData: o(p),
405
- signature: o(p),
406
- userHandle: o(p)
374
+ clientDataJSON: o(f),
375
+ authenticatorData: o(f),
376
+ signature: o(f),
377
+ userHandle: o(f)
407
378
  }),
408
- clientExtensionResults: N(
409
- V,
379
+ clientExtensionResults: x(
380
+ K,
410
381
  (e) => e.getClientExtensionResults()
411
382
  )
412
383
  };
413
384
  function H(e) {
414
- return O(L, G, e);
385
+ return C(P, G, e);
415
386
  }
416
387
  function I(e) {
417
- return O(
388
+ return C(
418
389
  U,
419
390
  W,
420
391
  e
421
392
  );
422
393
  }
423
394
  function X(e) {
424
- return O(L, $, e);
395
+ return C(P, $, e);
425
396
  }
426
397
  function Y(e) {
427
- return O(
398
+ return C(
428
399
  U,
429
400
  z,
430
401
  e
@@ -443,7 +414,7 @@ async function k(e) {
443
414
  return t.toJSON = () => Y(t), t;
444
415
  }
445
416
  async function be(e) {
446
- const r = (await h({
417
+ const r = (await b({
447
418
  webAuthnRequestOptions: {
448
419
  __args: {
449
420
  username: e
@@ -452,20 +423,20 @@ async function be(e) {
452
423
  })).webAuthnRequestOptions, s = X({
453
424
  publicKey: r
454
425
  }), n = await k(s);
455
- await f("webAuthnAssertion", {
426
+ await u("webAuthnAssertion", {
456
427
  username: e,
457
428
  assertion: n.toJSON()
458
429
  });
459
430
  }
460
- async function _e() {
461
- const e = await h({ webAuthnCreationOptions: !0 }), t = H({
431
+ async function me() {
432
+ const e = await b({ webAuthnCreationOptions: !0 }), t = H({
462
433
  publicKey: e.webAuthnCreationOptions
463
434
  }), r = await Z(t);
464
- await f("webAuthnRegister", {
435
+ await u("webAuthnRegister", {
465
436
  registration: r.toJSON()
466
437
  });
467
438
  }
468
- const Fe = async (e) => (await h({
439
+ const _e = async (e) => (await b({
469
440
  fsListFiles: {
470
441
  __args: {
471
442
  path: e
@@ -477,7 +448,7 @@ const Fe = async (e) => (await h({
477
448
  canPreview: !0,
478
449
  imagePath: !0
479
450
  }
480
- })).fsListFiles, ye = async (e) => (await h({
451
+ })).fsListFiles, ye = async (e) => (await b({
481
452
  fsListFolders: {
482
453
  __args: {
483
454
  path: e
@@ -485,8 +456,8 @@ const Fe = async (e) => (await h({
485
456
  name: !0,
486
457
  path: !0
487
458
  }
488
- })).fsListFolders, Oe = async (e) => {
489
- let t = await h({
459
+ })).fsListFolders, Fe = async (e) => {
460
+ let t = await b({
490
461
  fsFile: {
491
462
  __args: {
492
463
  path: e
@@ -495,59 +466,58 @@ const Fe = async (e) => (await h({
495
466
  }
496
467
  });
497
468
  return window.atob(t.fsFile.base64Content);
498
- }, Ce = (e, t) => f("fsWriteFile", {
469
+ }, Ce = (e, t) => u("fsWriteFile", {
499
470
  path: e,
500
471
  content: t
501
- }), Ae = (e) => f("fsDeleteFile", {
472
+ }), Ae = (e) => u("fsDeleteFile", {
502
473
  path: e
503
- }), Se = (e) => f("fsCreateFolder", {
474
+ }), Oe = (e) => u("fsCreateFolder", {
504
475
  path: e
505
- }), ve = (e) => f("fsDeleteFolder", {
476
+ }), Se = (e) => u("fsDeleteFolder", {
506
477
  path: e
507
- }), Re = (e, t) => f("fsRenameFile", {
478
+ }), Re = (e, t) => u("fsRenameFile", {
508
479
  path: e,
509
480
  name: t
510
- }), Ee = (e, t) => f("fsRenameFolder", {
481
+ }), ve = (e, t) => u("fsRenameFolder", {
511
482
  path: e,
512
483
  name: t
513
- }), je = (e, t) => f("fsMoveFile", {
484
+ }), Ee = (e, t) => u("fsMoveFile", {
514
485
  source: e,
515
486
  target: t
516
487
  });
517
488
  export {
518
- pe as File,
519
- fe as convertData,
520
- ce as defineModel,
521
- j as file,
522
- ie as forgetPassword,
523
- Se as fsCreateFolder,
489
+ de as File,
490
+ le as defineModel,
491
+ v as file,
492
+ ae as forgetPassword,
493
+ Oe as fsCreateFolder,
524
494
  Ae as fsDeleteFile,
525
- ve as fsDeleteFolder,
526
- Fe as fsListFiles,
495
+ Se as fsDeleteFolder,
496
+ _e as fsListFiles,
527
497
  ye as fsListFolders,
528
- je as fsMoveFile,
529
- Oe as fsReadFile,
498
+ Ee as fsMoveFile,
499
+ Fe as fsReadFile,
530
500
  Re as fsRenameFile,
531
- Ee as fsRenameFolder,
501
+ ve as fsRenameFolder,
532
502
  Ce as fsWriteFile,
533
- E as getApiUrl,
534
- v as getAxios,
503
+ q as getApiUrl,
504
+ E as getAxios,
535
505
  he as getConfig,
536
506
  ue as getGQLFields,
537
- J as getModelField,
538
- le as granted,
507
+ L as getModelField,
508
+ ce as granted,
539
509
  re as login,
540
510
  ne as logout,
541
- de as model,
542
- f as mutation,
543
- h as query,
544
- ae as resetPassword,
545
- me as sendMail,
546
- ge as setApiUrl,
511
+ fe as model,
512
+ u as mutation,
513
+ b as query,
514
+ ie as resetPassword,
515
+ we as sendMail,
516
+ pe as setApiUrl,
547
517
  oe as setAxios,
548
- R as toQuery,
518
+ S as toQuery,
549
519
  se as updatePassword,
550
- we as uploadFile,
520
+ ge as uploadFile,
551
521
  be as webauthnLogin,
552
- _e as webauthnRegister
522
+ me as webauthnRegister
553
523
  };
@@ -1 +1 @@
1
- (function(i,S){typeof exports=="object"&&typeof module<"u"?S(exports,require("axios"),require("json-to-graphql-query")):typeof define=="function"&&define.amd?define(["exports","axios","json-to-graphql-query"],S):(i=typeof globalThis<"u"?globalThis:i||self,S(i.light={},i.axios,i.jsonToGraphqlQuery))})(this,function(i,S,F){"use strict";const B=(e,t,n="")=>f("login",{username:e,password:t,code:n}),Q=()=>f("logout"),W=(e,t)=>f("updatePassword",{old_password:e,new_password:t}),$=(e,t,n)=>f("resetPassword",{email:e,password:t,code:n}),z=e=>f("forgetPassword",{email:e});let j;const H=e=>{j=e},v=()=>(j||(j=S.create({withCredentials:!0})),j),I=async e=>(await w({granted:{__args:{rights:e}}})).granted,_={},G=(e,t)=>{_[e]={};for(const n of Object.entries(t)){const[a,r]=n;_[e][a]=()=>({name:r.name?r.name:a,raw:r,getName:()=>r.name?r.name:a,getGQLField:()=>r.gqlField!==void 0?r.gqlField:r.name||a,getRaw(){return r},getValue(s){return r.field&&typeof r.field=="function"?r.field(s):r.field&&typeof r.field=="string"?s[r.field]:s[this.getName()]},getFormattedValue(s){const c=this.getValue(s);return r.format?r.format(c):c}})}},D=(e,t)=>!_[e]||!_[e][t]?null:_[e][t](),X=(e,t)=>{const n=[];for(const a of t)if(typeof a=="string"){const r=D(e,a);r&&n.push(r.getGQLField())}else typeof a=="object"&&n.push(a);return n},Y=e=>{const t=new FormData,n={},a={},r={};let s=0,c=!1;return Object.entries(e).forEach(([d,p])=>{p instanceof File?(c=!0,a[d]="Upload!",r[d]=new F.VariableType(d),t.append(s.toString(),p),n[s]=["variables."+d],s++):r[d]=p}),c?(t.append("map",JSON.stringify(n)),{data:r,formData:t,mutation:{__variables:a}}):{data:r,formData:null,mutation:{}}},Z=e=>{const t=e;return{name:t,$fields:_[e],async update(n,a){return await f("update"+t,{id:n,data:a})},async delete(n){return await f("delete"+t,{id:n})},async add(n){return await f("add"+t,{data:n})},fields(n){let a=[];for(let r of n){const s=D(t,r);s&&a.push(s)}return a},async get(n,a){return(await w({["list"+t]:{__args:{filters:n},data:{__args:{limit:1},...R(a)}}}))["list"+t].data[0]},async list(n,a){return(await w({["list"+t]:{__args:{filters:n},data:{...R(a)}}}))["list"+t].data}}};function x(e){e="<~"+e+"~>";var t,n,a,r,s,c=String,d=255;for(e.slice(0,2)==="<~"&&e.slice(-2),e=e.slice(2,-2).replace(/\s/g,"").replace("z","!!!!!"),t="uuuuu".slice(e.length%5||5),e+=t,a=[],r=0,s=e.length;s>r;r+=5)n=52200625*(e.charCodeAt(r)-33)+614125*(e.charCodeAt(r+1)-33)+7225*(e.charCodeAt(r+2)-33)+85*(e.charCodeAt(r+3)-33)+(e.charCodeAt(r+4)-33),a.push(d&n>>24,d&n>>16,d&n>>8,d&n);return function(p,y){for(var A=y;A>0;A--)p.pop()}(a,t.length),c.fromCharCode.apply(c,a)}const q=(e="")=>{const t=e,n=(a="application/octet-stream")=>{const r=new Uint8Array(t.length);for(let d=0;d<t.length;d++)r[d]=t.charCodeAt(d);const s=new Blob([r],{type:a});return URL.createObjectURL(s)};return{getContent:()=>t,getURL:n,download:a=>{const r=document.createElement("a");r.download=a,r.href=n(),document.body.appendChild(r),r.click(),document.body.removeChild(r)},open:a=>{window.open(n(a),"_blank")}}},k={fromBase85:e=>q(x(e)),fromBase64:e=>q(atob(e)),fromString:e=>q(e)},N=e=>{let t={};return typeof e=="string"?(t[e]=!0,t):e instanceof Array?(e.forEach(n=>{Object.entries(N(n)).forEach(([a,r])=>{t[a]=r})}),t):(Object.entries(e).forEach(([n,a])=>{if(n=="__args"||n=="__aliasFor"||n=="__variables"||n=="__directives"||n=="__all_on"||n=="__name"){t[n]=a;return}if(typeof a=="boolean"){t[n]=a;return}t[n]=N(a)}),t)},R=e=>N(e),w=async e=>{let t=F.jsonToGraphQLQuery(R(e));const n=await v().post(E(),{query:`{ ${t} }`});if(n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data};function ee(e){for(let t=0;t<e.length;t++)if(e[t]instanceof File)return!0;return!1}function te(e){for(let t in e)if(e[t]instanceof File)return!0;return!1}const f=async(e,t=null,n=[])=>{let a={[e]:{}};const r=new FormData;let s=!1;if(t){const p={},y={},A={};let h=0;Object.entries(t).forEach(([b,m])=>{if(m instanceof Array&&ee(m)){s=!0;let C=0;m.forEach(L=>{L instanceof File&&(p[b]=new F.VariableType(b),y[h]=["variables."+b+"."+C],r.append(h.toString(),L),h++)}),A[b]="[Upload!]!"}else m instanceof File?(s=!0,p[b]=new F.VariableType(b),y[h]=["variables."+b],r.append(h.toString(),m),A[b]="Upload!",h++):m instanceof Object&&te(m)?(s=!0,Object.entries(m).forEach(([C,L])=>{L instanceof File?(p[C]=new F.VariableType(C),y[h]=["variables."+C],r.append(h.toString(),L),h++):p[C]=m})):p[b]=m}),a[e].__args=p,a.__variables=A,s&&r.append("map",JSON.stringify(y))}Object.entries(R(n)).forEach(([p,y])=>{a[e][p]=y}),Object.entries(a[e]).length===0&&(a[e]=!0);let c=null;const d=F.jsonToGraphQLQuery({mutation:a});if(s?(r.append("operations",JSON.stringify({query:d})),c=await v().post(E(),r)):c=await v().post(E(),{query:d}),c.data.errors)throw new Error(c.data.errors[0].message);return c.data.data[e]};let U="/api/";const ne=e=>{U=e},E=()=>U;async function re(e){const t={__variables:{file:"Upload!"},fsUploadTempFile:{__args:{file:new F.VariableType("file")},name:!0,path:!0,size:!0,mime:!0}},n=new FormData;n.append("operations",JSON.stringify({query:F.jsonToGraphQLQuery({mutation:t})})),n.append("map",JSON.stringify({0:["variables.file"]})),n.append("0",e);const a=await v().post(E(),n);if(a.data.errors)throw new Error(a.data.errors[0].message);return a.data.data.fsUploadTempFile}const ae=(e,t,n)=>f("sendMail",{email:e,subject:t,message:n}),ie=async e=>(await w({config:{__args:{name:e}}})).config;function P(e){const t="==".slice(0,(4-e.length%4)%4),n=e.replace(/-/g,"+").replace(/_/g,"/")+t,a=atob(n),r=new ArrayBuffer(a.length),s=new Uint8Array(r);for(let c=0;c<a.length;c++)s[c]=a.charCodeAt(c);return r}function V(e){const t=new Uint8Array(e);let n="";for(const s of t)n+=String.fromCharCode(s);return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var o="copy",g="convert";function O(e,t,n){if(t===o)return n;if(t===g)return e(n);if(t instanceof Array)return n.map(a=>O(e,t[0],a));if(t instanceof Object){const a={};for(const[r,s]of Object.entries(t)){if(s.derive){const c=s.derive(n);c!==void 0&&(n[r]=c)}if(!(r in n)){if(s.required)throw new Error(`Missing key: ${r}`);continue}if(n[r]==null){a[r]=null;continue}a[r]=O(e,s.schema,n[r])}return a}}function J(e,t){return{required:!0,schema:e,derive:t}}function l(e){return{required:!0,schema:e}}function u(e){return{required:!1,schema:e}}var M={type:l(o),id:l(g),transports:u(o)},T={appid:u(o),appidExclude:u(o),credProps:u(o)},K={appid:u(o),appidExclude:u(o),credProps:u(o)},se={publicKey:l({rp:l(o),user:l({id:l(g),name:l(o),displayName:l(o)}),challenge:l(g),pubKeyCredParams:l(o),timeout:u(o),excludeCredentials:u([M]),authenticatorSelection:u(o),attestation:u(o),extensions:u(T)}),signal:u(o)},oe={type:l(o),id:l(o),rawId:l(g),authenticatorAttachment:u(o),response:l({clientDataJSON:l(g),attestationObject:l(g),transports:J(o,e=>{var t;return((t=e.getTransports)==null?void 0:t.call(e))||[]})}),clientExtensionResults:J(K,e=>e.getClientExtensionResults())},le={mediation:u(o),publicKey:l({challenge:l(g),timeout:u(o),rpId:u(o),allowCredentials:u([M]),userVerification:u(o),extensions:u(T)}),signal:u(o)},ce={type:l(o),id:l(o),rawId:l(g),authenticatorAttachment:u(o),response:l({clientDataJSON:l(g),authenticatorData:l(g),signature:l(g),userHandle:l(g)}),clientExtensionResults:J(K,e=>e.getClientExtensionResults())};function ue(e){return O(P,se,e)}function fe(e){return O(V,oe,e)}function de(e){return O(P,le,e)}function pe(e){return O(V,ce,e)}async function ge(e){const t=await navigator.credentials.create(e);return t.toJSON=()=>fe(t),t}async function we(e){const t=await navigator.credentials.get(e);return t.toJSON=()=>pe(t),t}async function me(e){const n=(await w({webAuthnRequestOptions:{__args:{username:e}}})).webAuthnRequestOptions,a=de({publicKey:n}),r=await we(a);await f("webAuthnAssertion",{username:e,assertion:r.toJSON()})}async function he(){const e=await w({webAuthnCreationOptions:!0}),t=ue({publicKey:e.webAuthnCreationOptions}),n=await ge(t);await f("webAuthnRegister",{registration:n.toJSON()})}const be=async e=>(await w({fsListFiles:{__args:{path:e},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}})).fsListFiles,Fe=async e=>(await w({fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,ye=async e=>{let t=await w({fsFile:{__args:{path:e},base64Content:!0}});return window.atob(t.fsFile.base64Content)},_e=(e,t)=>f("fsWriteFile",{path:e,content:t}),Oe=e=>f("fsDeleteFile",{path:e}),Ae=e=>f("fsCreateFolder",{path:e}),Ce=e=>f("fsDeleteFolder",{path:e}),Se=(e,t)=>f("fsRenameFile",{path:e,name:t}),ve=(e,t)=>f("fsRenameFolder",{path:e,name:t}),Re=(e,t)=>f("fsMoveFile",{source:e,target:t});i.File=k,i.convertData=Y,i.defineModel=G,i.file=q,i.forgetPassword=z,i.fsCreateFolder=Ae,i.fsDeleteFile=Oe,i.fsDeleteFolder=Ce,i.fsListFiles=be,i.fsListFolders=Fe,i.fsMoveFile=Re,i.fsReadFile=ye,i.fsRenameFile=Se,i.fsRenameFolder=ve,i.fsWriteFile=_e,i.getApiUrl=E,i.getAxios=v,i.getConfig=ie,i.getGQLFields=X,i.getModelField=D,i.granted=I,i.login=B,i.logout=Q,i.model=Z,i.mutation=f,i.query=w,i.resetPassword=$,i.sendMail=ae,i.setApiUrl=ne,i.setAxios=H,i.toQuery=R,i.updatePassword=W,i.uploadFile=re,i.webauthnLogin=me,i.webauthnRegister=he,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,O){typeof exports=="object"&&typeof module<"u"?O(exports,require("axios"),require("json-to-graphql-query")):typeof define=="function"&&define.amd?define(["exports","axios","json-to-graphql-query"],O):(s=typeof globalThis<"u"?globalThis:s||self,O(s.light={},s.axios,s.jsonToGraphqlQuery))})(this,function(s,O,S){"use strict";const Q=(e,t,n="")=>u("login",{username:e,password:t,code:n}),B=()=>u("logout"),W=(e,t)=>u("updatePassword",{old_password:e,new_password:t}),$=(e,t,n)=>u("resetPassword",{email:e,password:t,code:n}),z=e=>u("forgetPassword",{email:e});let q;const G=e=>{q=e},j=()=>(q||(q=O.create({withCredentials:!0})),q),H=async e=>(await p({granted:{__args:{rights:e}}})).granted,y={},I=(e,t)=>{y[e]={};for(const n of Object.entries(t)){const[i,r]=n;y[e][i]=()=>({name:r.name?r.name:i,raw:r,getName:()=>r.name?r.name:i,getGQLField:()=>r.gqlField!==void 0?r.gqlField:r.name||i,getRaw(){return r},getValue(o){return r.field&&typeof r.field=="function"?r.field(o):r.field&&typeof r.field=="string"?o[r.field]:o[this.getName()]},getFormattedValue(o){const f=this.getValue(o);return r.format?r.format(f):f}})}},N=(e,t)=>!y[e]||!y[e][t]?null:y[e][t](),X=(e,t)=>{const n=[];for(const i of t)if(typeof i=="string"){const r=N(e,i);r&&n.push(r.getGQLField())}else typeof i=="object"&&n.push(i);return n},Y=e=>{const t=e;return{name:t,$fields:y[e],async update(n,i){return await u("update"+t,{id:n,data:i})},async delete(n){return await u("delete"+t,{id:n})},async add(n){return await u("add"+t,{data:n})},fields(n){let i=[];for(let r of n){const o=N(t,r);o&&i.push(o)}return i},async get(n,i){return(await p({["list"+t]:{__args:{filters:n},data:{__args:{limit:1},...R(i)}}}))["list"+t].data[0]},async list(n,i){return(await p({["list"+t]:{__args:{filters:n},data:{...R(i)}}}))["list"+t].data}}};function Z(e){e="<~"+e+"~>";var t,n,i,r,o,f=String,g=255;for(e.slice(0,2)==="<~"&&e.slice(-2),e=e.slice(2,-2).replace(/\s/g,"").replace("z","!!!!!"),t="uuuuu".slice(e.length%5||5),e+=t,i=[],r=0,o=e.length;o>r;r+=5)n=52200625*(e.charCodeAt(r)-33)+614125*(e.charCodeAt(r+1)-33)+7225*(e.charCodeAt(r+2)-33)+85*(e.charCodeAt(r+3)-33)+(e.charCodeAt(r+4)-33),i.push(g&n>>24,g&n>>16,g&n>>8,g&n);return function(w,F){for(var A=F;A>0;A--)w.pop()}(i,t.length),f.fromCharCode.apply(f,i)}const E=(e="")=>{const t=e,n=(i="application/octet-stream")=>{const r=new Uint8Array(t.length);for(let g=0;g<t.length;g++)r[g]=t.charCodeAt(g);const o=new Blob([r],{type:i});return URL.createObjectURL(o)};return{getContent:()=>t,getURL:n,download:i=>{const r=document.createElement("a");r.download=i,r.href=n(),document.body.appendChild(r),r.click(),document.body.removeChild(r)},open:i=>{window.open(n(i),"_blank")}}},k={fromBase85:e=>E(Z(e)),fromBase64:e=>E(atob(e)),fromString:e=>E(e)},P=e=>{let t={};return typeof e=="string"?(t[e]=!0,t):e instanceof Array?(e.forEach(n=>{Object.entries(P(n)).forEach(([i,r])=>{t[i]=r})}),t):(Object.entries(e).forEach(([n,i])=>{if(n=="__args"||n=="__aliasFor"||n=="__variables"||n=="__directives"||n=="__all_on"||n=="__name"){t[n]=i;return}if(typeof i=="boolean"){t[n]=i;return}t[n]=P(i)}),t)},R=e=>P(e),p=async e=>{let t=S.jsonToGraphQLQuery(R(e));const n=await j().post(L(),{query:`{ ${t} }`});if(n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data};function x(e){for(let t=0;t<e.length;t++)if(e[t]instanceof File)return!0;return!1}function ee(e){for(let t in e)if(e[t]instanceof File)return!0;return!1}const u=async(e,t=null,n=[])=>{let i={[e]:{}};const r=new FormData;let o=!1;if(t){const w={},F={},A={};let b=0;Object.entries(t).forEach(([m,h])=>{if(h instanceof Array&&x(h)){o=!0;let C=0;h.forEach(v=>{v instanceof File&&(w[m]=new S.VariableType(m),F[b]=["variables."+m+"."+C],r.append(b.toString(),v),b++)}),A[m]="[Upload!]!"}else h instanceof File?(o=!0,w[m]=new S.VariableType(m),F[b]=["variables."+m],r.append(b.toString(),h),A[m]="Upload!",b++):h instanceof Object&&ee(h)?(o=!0,Object.entries(h).forEach(([C,v])=>{v instanceof File?(w[C]=new S.VariableType(C),F[b]=["variables."+C],r.append(b.toString(),v),b++):w[C]=h})):w[m]=h}),i[e].__args=w,i.__variables=A,o&&r.append("map",JSON.stringify(F))}Object.entries(R(n)).forEach(([w,F])=>{i[e][w]=F}),Object.entries(i[e]).length===0&&(i[e]=!0);let f=null;const g=S.jsonToGraphQLQuery({mutation:i});if(o?(r.append("operations",JSON.stringify({query:g})),f=await j().post(L(),r)):f=await j().post(L(),{query:g}),f.data.errors)throw new Error(f.data.errors[0].message);return f.data.data[e]};let U="/api/";const te=e=>{U=e},L=()=>U;async function ne(e){return u("fsUploadTempFile",{file:e},{name:!0,path:!0,size:!0,mime:!0})}const re=(e,t,n)=>u("sendMail",{email:e,subject:t,message:n}),ie=async e=>(await p({config:{__args:{name:e}}})).config;function M(e){const t="==".slice(0,(4-e.length%4)%4),n=e.replace(/-/g,"+").replace(/_/g,"/")+t,i=atob(n),r=new ArrayBuffer(i.length),o=new Uint8Array(r);for(let f=0;f<i.length;f++)o[f]=i.charCodeAt(f);return r}function D(e){const t=new Uint8Array(e);let n="";for(const o of t)n+=String.fromCharCode(o);return btoa(n).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var a="copy",d="convert";function _(e,t,n){if(t===a)return n;if(t===d)return e(n);if(t instanceof Array)return n.map(i=>_(e,t[0],i));if(t instanceof Object){const i={};for(const[r,o]of Object.entries(t)){if(o.derive){const f=o.derive(n);f!==void 0&&(n[r]=f)}if(!(r in n)){if(o.required)throw new Error(`Missing key: ${r}`);continue}if(n[r]==null){i[r]=null;continue}i[r]=_(e,o.schema,n[r])}return i}}function J(e,t){return{required:!0,schema:e,derive:t}}function l(e){return{required:!0,schema:e}}function c(e){return{required:!1,schema:e}}var T={type:l(a),id:l(d),transports:c(a)},V={appid:c(a),appidExclude:c(a),credProps:c(a)},K={appid:c(a),appidExclude:c(a),credProps:c(a)},se={publicKey:l({rp:l(a),user:l({id:l(d),name:l(a),displayName:l(a)}),challenge:l(d),pubKeyCredParams:l(a),timeout:c(a),excludeCredentials:c([T]),authenticatorSelection:c(a),attestation:c(a),extensions:c(V)}),signal:c(a)},ae={type:l(a),id:l(a),rawId:l(d),authenticatorAttachment:c(a),response:l({clientDataJSON:l(d),attestationObject:l(d),transports:J(a,e=>{var t;return((t=e.getTransports)==null?void 0:t.call(e))||[]})}),clientExtensionResults:J(K,e=>e.getClientExtensionResults())},oe={mediation:c(a),publicKey:l({challenge:l(d),timeout:c(a),rpId:c(a),allowCredentials:c([T]),userVerification:c(a),extensions:c(V)}),signal:c(a)},le={type:l(a),id:l(a),rawId:l(d),authenticatorAttachment:c(a),response:l({clientDataJSON:l(d),authenticatorData:l(d),signature:l(d),userHandle:l(d)}),clientExtensionResults:J(K,e=>e.getClientExtensionResults())};function ce(e){return _(M,se,e)}function ue(e){return _(D,ae,e)}function fe(e){return _(M,oe,e)}function de(e){return _(D,le,e)}async function ge(e){const t=await navigator.credentials.create(e);return t.toJSON=()=>ue(t),t}async function pe(e){const t=await navigator.credentials.get(e);return t.toJSON=()=>de(t),t}async function we(e){const n=(await p({webAuthnRequestOptions:{__args:{username:e}}})).webAuthnRequestOptions,i=fe({publicKey:n}),r=await pe(i);await u("webAuthnAssertion",{username:e,assertion:r.toJSON()})}async function he(){const e=await p({webAuthnCreationOptions:!0}),t=ce({publicKey:e.webAuthnCreationOptions}),n=await ge(t);await u("webAuthnRegister",{registration:n.toJSON()})}const be=async e=>(await p({fsListFiles:{__args:{path:e},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}})).fsListFiles,me=async e=>(await p({fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,Fe=async e=>{let t=await p({fsFile:{__args:{path:e},base64Content:!0}});return window.atob(t.fsFile.base64Content)},ye=(e,t)=>u("fsWriteFile",{path:e,content:t}),_e=e=>u("fsDeleteFile",{path:e}),Ae=e=>u("fsCreateFolder",{path:e}),Ce=e=>u("fsDeleteFolder",{path:e}),Oe=(e,t)=>u("fsRenameFile",{path:e,name:t}),Se=(e,t)=>u("fsRenameFolder",{path:e,name:t}),Re=(e,t)=>u("fsMoveFile",{source:e,target:t});s.File=k,s.defineModel=I,s.file=E,s.forgetPassword=z,s.fsCreateFolder=Ae,s.fsDeleteFile=_e,s.fsDeleteFolder=Ce,s.fsListFiles=be,s.fsListFolders=me,s.fsMoveFile=Re,s.fsReadFile=Fe,s.fsRenameFile=Oe,s.fsRenameFolder=Se,s.fsWriteFile=ye,s.getApiUrl=L,s.getAxios=j,s.getConfig=ie,s.getGQLFields=X,s.getModelField=N,s.granted=H,s.login=Q,s.logout=B,s.model=Y,s.mutation=u,s.query=p,s.resetPassword=$,s.sendMail=re,s.setApiUrl=te,s.setAxios=G,s.toQuery=R,s.updatePassword=W,s.uploadFile=ne,s.webauthnLogin=we,s.webauthnRegister=he,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
package/dist/model.d.ts CHANGED
@@ -24,19 +24,6 @@ export declare const defineModel: (name: string, fields: {
24
24
  }) => void;
25
25
  export declare const getModelField: (name: string, field: string) => ModelField | null;
26
26
  export declare const getGQLFields: (model: string, fields: (string | object)[]) => any[];
27
- export declare const convertData: (data: Object) => {
28
- data: any;
29
- formData: FormData;
30
- mutation: {
31
- __variables: any;
32
- };
33
- } | {
34
- data: any;
35
- formData: null;
36
- mutation: {
37
- __variables?: undefined;
38
- };
39
- };
40
27
  export declare const model: (name: string) => {
41
28
  name: string;
42
29
  $fields: any;
package/package.json CHANGED
@@ -1,17 +1,12 @@
1
1
  {
2
2
  "name": "@hostlink/light",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
7
7
  ],
8
8
  "main": "./dist/light.umd.cjs",
9
9
  "module": "./dist/light.js",
10
- "exports": {
11
- ".": {
12
- "import": "./dist/light.js"
13
- }
14
- },
15
10
  "types": "./dist/index.d.ts",
16
11
  "scripts": {
17
12
  "dev": "vite --host",
@@ -21,10 +16,10 @@
21
16
  "test": "vitest"
22
17
  },
23
18
  "devDependencies": {
24
- "typescript": "^5.0.2",
25
- "vite": "^4.3.0",
26
- "vite-plugin-dts": "^3.6.0",
27
- "vitest": "^0.34.6"
19
+ "typescript": "^5.3.3",
20
+ "vite": "^5.1.4",
21
+ "vite-plugin-dts": "^3.7.3",
22
+ "vitest": "^1.3.1"
28
23
  },
29
24
  "dependencies": {
30
25
  "@github/webauthn-json": "^2.1.1",