@hostlink/light 2.8.0 → 2.9.0

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/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { default as useWebAuthn } from './useWebAuthn';
1
2
  export * from './auth';
2
3
  export * from './model';
3
4
  export * from './file';
package/dist/light.js CHANGED
@@ -5,32 +5,44 @@ import { jsonToGraphQLQuery as P, VariableType as F } from "json-to-graphql-quer
5
5
  import R from "axios";
6
6
  import D from "collect.js";
7
7
  const E = (t) => ({
8
- login: async () => {
9
- const { app: e } = await w(t, {
8
+ assertion: async () => {
9
+ const { app: s } = await w(t, {
10
10
  app: {
11
11
  auth: {
12
12
  webAuthnRequestOptions: !0
13
13
  }
14
14
  }
15
- }), r = e.auth.webAuthnRequestOptions, s = PublicKeyCredential.parseRequestOptionsFromJSON(r), i = await navigator.credentials.get({ publicKey: s });
16
- await l(t, "webAuthnAssertion", {
17
- assertion: i.toJSON()
18
- });
15
+ }), a = s.auth.webAuthnRequestOptions, h = PublicKeyCredential.parseRequestOptionsFromJSON(a);
16
+ return await navigator.credentials.get({ publicKey: h });
19
17
  },
20
- register: async () => {
21
- const { app: e } = await w(t, {
18
+ attestation: async () => {
19
+ const { app: s } = await w(t, {
22
20
  app: {
23
21
  auth: {
24
22
  webAuthnCreationOptions: !0
25
23
  }
26
24
  }
27
- }), r = PublicKeyCredential.parseCreationOptionsFromJSON(e.auth.webAuthnCreationOptions), s = await navigator.credentials.create({ publicKey: r });
28
- await l(t, "webAuthnRegister", {
29
- registration: s.toJSON()
30
- });
25
+ }), a = PublicKeyCredential.parseCreationOptionsFromJSON(s.auth.webAuthnCreationOptions);
26
+ return await navigator.credentials.create({ publicKey: a });
31
27
  }
32
- }), j = (t) => ({
33
- WebAuthn: E(t),
28
+ }), j = (t) => {
29
+ const { assertion: e, attestation: r } = E(t);
30
+ return {
31
+ login: async () => {
32
+ const s = await e();
33
+ await l(t, "webAuthnAssertion", {
34
+ assertion: s.toJSON()
35
+ });
36
+ },
37
+ register: async () => {
38
+ const s = await r();
39
+ await l(t, "webAuthnRegister", {
40
+ registration: s.toJSON()
41
+ });
42
+ }
43
+ };
44
+ }, S = (t) => ({
45
+ WebAuthn: j(t),
34
46
  google: {
35
47
  unlink: () => l(t, "lightAuthUnlinkGoogle"),
36
48
  login: (e) => l(t, "lightAuthLoginGoogle", {
@@ -100,95 +112,95 @@ const E = (t) => ({
100
112
  });
101
113
  return r.grantedRights;
102
114
  }
103
- }), S = (t, e, r) => {
104
- const s = e, i = t, g = r;
105
- let h = "list" + e;
106
- const n = (a) => g[a] ? g[a]() : null;
115
+ }), q = (t, e, r) => {
116
+ const s = e, a = t, h = r;
117
+ let p = "list" + e;
118
+ const n = (i) => h[i] ? h[i]() : null;
107
119
  return {
108
120
  field: n,
109
- $fields: g,
110
- setDataPath(a) {
111
- return h = a, h;
121
+ $fields: h,
122
+ setDataPath(i) {
123
+ return p = i, p;
112
124
  },
113
125
  getDataPath() {
114
- return h;
126
+ return p;
115
127
  },
116
- gqlFields(a) {
128
+ gqlFields(i) {
117
129
  const o = [];
118
- for (const c of a)
130
+ for (const c of i)
119
131
  if (typeof c == "string") {
120
132
  const u = n(c);
121
133
  u && o.push(u.getGQLField());
122
134
  } else typeof c == "object" && o.push(c);
123
135
  return o;
124
136
  },
125
- async update(a, o) {
126
- return await l(i, "update" + s, { id: a, data: o });
137
+ async update(i, o) {
138
+ return await l(a, "update" + s, { id: i, data: o });
127
139
  },
128
- async delete(a) {
129
- return await l(i, "delete" + s, { id: a });
140
+ async delete(i) {
141
+ return await l(a, "delete" + s, { id: i });
130
142
  },
131
- async add(a) {
132
- return await l(i, "add" + s, { data: a });
143
+ async add(i) {
144
+ return await l(a, "add" + s, { data: i });
133
145
  },
134
- fields(a) {
146
+ fields(i) {
135
147
  let o = [];
136
- for (let c of a) {
148
+ for (let c of i) {
137
149
  const u = n(c);
138
150
  u && o.push(u);
139
151
  }
140
152
  return o;
141
153
  },
142
- async get(a, o) {
143
- const c = (await Promise.resolve().then(() => A)).default, u = c(s, i, C(o));
144
- for (const [p, d] of Object.entries(a))
145
- u.where(p, "==", d);
154
+ async get(i, o) {
155
+ const c = (await Promise.resolve().then(() => O)).default, u = c(s, a, C(o));
156
+ for (const [d, g] of Object.entries(i))
157
+ u.where(d, "==", g);
146
158
  return await u.first();
147
159
  },
148
- async list(a, o) {
149
- const c = (await Promise.resolve().then(() => A)).default, u = c(s, i, C(o));
150
- for (const [p, d] of Object.entries(a))
151
- u.where(p, "==", d);
160
+ async list(i, o) {
161
+ const c = (await Promise.resolve().then(() => O)).default, u = c(s, a, C(o));
162
+ for (const [d, g] of Object.entries(i))
163
+ u.where(d, "==", g);
152
164
  return await u.all();
153
165
  }
154
166
  };
155
167
  };
156
- function q(t) {
168
+ function U(t) {
157
169
  t = "<~" + t + "~>";
158
- var e, r, s, i, g, h = String, n = 255;
159
- for (t.slice(0, 2) === "<~" && t.slice(-2), t = t.slice(2, -2).replace(/\s/g, "").replace("z", "!!!!!"), e = "uuuuu".slice(t.length % 5 || 5), t += e, s = [], i = 0, g = t.length; g > i; i += 5) r = 52200625 * (t.charCodeAt(i) - 33) + 614125 * (t.charCodeAt(i + 1) - 33) + 7225 * (t.charCodeAt(i + 2) - 33) + 85 * (t.charCodeAt(i + 3) - 33) + (t.charCodeAt(i + 4) - 33), s.push(n & r >> 24, n & r >> 16, n & r >> 8, n & r);
160
- return function(a, o) {
161
- for (var c = o; c > 0; c--) a.pop();
162
- }(s, e.length), h.fromCharCode.apply(h, s);
170
+ var e, r, s, a, h, p = String, n = 255;
171
+ for (t.slice(0, 2) === "<~" && t.slice(-2), t = t.slice(2, -2).replace(/\s/g, "").replace("z", "!!!!!"), e = "uuuuu".slice(t.length % 5 || 5), t += e, s = [], a = 0, h = t.length; h > a; a += 5) r = 52200625 * (t.charCodeAt(a) - 33) + 614125 * (t.charCodeAt(a + 1) - 33) + 7225 * (t.charCodeAt(a + 2) - 33) + 85 * (t.charCodeAt(a + 3) - 33) + (t.charCodeAt(a + 4) - 33), s.push(n & r >> 24, n & r >> 16, n & r >> 8, n & r);
172
+ return function(i, o) {
173
+ for (var c = o; c > 0; c--) i.pop();
174
+ }(s, e.length), p.fromCharCode.apply(p, s);
163
175
  }
164
176
  const k = (t = "") => {
165
177
  const e = t, r = (s = "application/octet-stream") => {
166
- const i = new Uint8Array(e.length);
178
+ const a = new Uint8Array(e.length);
167
179
  for (let n = 0; n < e.length; n++)
168
- i[n] = e.charCodeAt(n);
169
- const g = new Blob([i], { type: s });
170
- return URL.createObjectURL(g);
180
+ a[n] = e.charCodeAt(n);
181
+ const h = new Blob([a], { type: s });
182
+ return URL.createObjectURL(h);
171
183
  };
172
184
  return {
173
185
  getContent: () => e,
174
186
  getURL: r,
175
187
  download: (s) => {
176
- const i = document.createElement("a");
177
- i.download = s, i.href = r(), document.body.appendChild(i), i.click(), document.body.removeChild(i);
188
+ const a = document.createElement("a");
189
+ a.download = s, a.href = r(), document.body.appendChild(a), a.click(), document.body.removeChild(a);
178
190
  },
179
191
  open: (s) => {
180
192
  window.open(r(s), "_blank");
181
193
  }
182
194
  };
183
- }, Z = {
184
- fromBase85: (t) => k(q(t)),
195
+ }, x = {
196
+ fromBase85: (t) => k(U(t)),
185
197
  fromBase64: (t) => k(atob(t)),
186
198
  fromString: (t) => k(t)
187
199
  }, v = (t) => {
188
200
  let e = {};
189
201
  return typeof t == "string" ? (e[t] = !0, e) : t instanceof Array ? (t.forEach((r) => {
190
- Object.entries(v(r)).forEach(([s, i]) => {
191
- e[s] = i;
202
+ Object.entries(v(r)).forEach(([s, a]) => {
203
+ e[s] = a;
192
204
  });
193
205
  }), e) : (Object.entries(t).forEach(([r, s]) => {
194
206
  if (r == "__args" || r == "__aliasFor" || r == "__variables" || r == "__directives" || r == "__all_on" || r == "__name") {
@@ -210,52 +222,52 @@ const k = (t = "") => {
210
222
  throw new Error(s.data.errors[0].message);
211
223
  return s.data.data;
212
224
  };
213
- function U(t) {
225
+ function L(t) {
214
226
  for (let e = 0; e < t.length; e++)
215
227
  if (t[e] instanceof File)
216
228
  return !0;
217
229
  return !1;
218
230
  }
219
- function L(t) {
231
+ function J(t) {
220
232
  for (let e in t)
221
233
  if (t[e] instanceof File)
222
234
  return !0;
223
235
  return !1;
224
236
  }
225
237
  const l = async (t, e, r = null, s = []) => {
226
- let i = {
238
+ let a = {
227
239
  [e]: {}
228
240
  };
229
- const g = new FormData();
230
- let h = !1;
241
+ const h = new FormData();
242
+ let p = !1;
231
243
  if (r) {
232
244
  const o = {}, c = {}, u = {};
233
- let p = 0;
234
- Object.entries(r).forEach(([d, y]) => {
235
- if (y instanceof Array && U(y)) {
236
- h = !0;
245
+ let d = 0;
246
+ Object.entries(r).forEach(([g, y]) => {
247
+ if (y instanceof Array && L(y)) {
248
+ p = !0;
237
249
  let _ = 0;
238
250
  y.forEach((b) => {
239
- b instanceof File && (o[d] = new F(d), c[p] = ["variables." + d + "." + _], g.append(p.toString(), b), p++);
240
- }), u[d] = "[Upload!]!";
241
- } else y instanceof File ? (h = !0, o[d] = new F(d), c[p] = ["variables." + d], g.append(p.toString(), y), u[d] = "Upload!", p++) : y instanceof Object && L(y) ? (h = !0, o[d] = {}, Object.entries(y).forEach(([_, b]) => {
242
- b instanceof File ? (o[d][_] = new F(_), c[p] = ["variables." + _], g.append(p.toString(), b), u[_] = "Upload!", p++) : o[d][_] = b;
243
- })) : y !== void 0 && (o[d] = y);
244
- }), i[e].__args = o, i.__variables = u, h && g.append("map", JSON.stringify(c));
251
+ b instanceof File && (o[g] = new F(g), c[d] = ["variables." + g + "." + _], h.append(d.toString(), b), d++);
252
+ }), u[g] = "[Upload!]!";
253
+ } else y instanceof File ? (p = !0, o[g] = new F(g), c[d] = ["variables." + g], h.append(d.toString(), y), u[g] = "Upload!", d++) : y instanceof Object && J(y) ? (p = !0, o[g] = {}, Object.entries(y).forEach(([_, b]) => {
254
+ b instanceof File ? (o[g][_] = new F(_), c[d] = ["variables." + _], h.append(d.toString(), b), u[_] = "Upload!", d++) : o[g][_] = b;
255
+ })) : y !== void 0 && (o[g] = y);
256
+ }), a[e].__args = o, a.__variables = u, p && h.append("map", JSON.stringify(c));
245
257
  }
246
258
  Object.entries(C(s)).forEach(([o, c]) => {
247
- i[e][o] = c;
248
- }), Object.entries(i[e]).length === 0 && (i[e] = !0);
259
+ a[e][o] = c;
260
+ }), Object.entries(a[e]).length === 0 && (a[e] = !0);
249
261
  let n = null;
250
- const a = P({ mutation: i });
251
- if (h ? (g.append("operations", JSON.stringify({
252
- query: a
253
- })), n = await t.post("", g)) : n = await t.post("", {
254
- query: a
262
+ const i = P({ mutation: a });
263
+ if (p ? (h.append("operations", JSON.stringify({
264
+ query: i
265
+ })), n = await t.post("", h)) : n = await t.post("", {
266
+ query: i
255
267
  }), n.data.errors)
256
268
  throw new Error(n.data.errors[0].message);
257
269
  return n.data.data[e];
258
- }, J = (t) => ({
270
+ }, T = (t) => ({
259
271
  uploadTempFile: (e) => l(t, "fsUploadTempFile", {
260
272
  file: e
261
273
  }, {
@@ -322,7 +334,7 @@ const l = async (t, e, r = null, s = []) => {
322
334
  rename: (e, r) => l(t, "fsRenameFile", { path: e, name: r }),
323
335
  move: (e, r) => l(t, "fsMoveFile", { source: e, target: r })
324
336
  }
325
- }), T = (t) => ({
337
+ }), M = (t) => ({
326
338
  get: async (e) => (await t({
327
339
  config: {
328
340
  __args: {
@@ -330,13 +342,13 @@ const l = async (t, e, r = null, s = []) => {
330
342
  }
331
343
  }
332
344
  })).config
333
- }), M = (t) => ({
345
+ }), W = (t) => ({
334
346
  send: (e, r, s) => l(t, "sendMail", {
335
347
  email: e,
336
348
  subject: r,
337
349
  message: s
338
350
  })
339
- }), W = (t) => ({
351
+ }), z = (t) => ({
340
352
  list: async (e = {
341
353
  user_id: !0,
342
354
  username: !0,
@@ -344,41 +356,41 @@ const l = async (t, e, r = null, s = []) => {
344
356
  last_name: !0,
345
357
  status: !0
346
358
  }) => {
347
- const r = O("Users", t, e);
359
+ const r = A("Users", t, e);
348
360
  return r.data_path = "app.users", r.all();
349
361
  }
350
- }), z = (t) => {
362
+ }), G = (t) => {
351
363
  const e = t, r = {};
352
364
  return {
353
- create(s, i) {
365
+ create(s, a) {
354
366
  r[s] = null;
355
- let g = {};
356
- for (const h of Object.entries(i)) {
357
- const [n, a] = h;
358
- g[n] = () => ({
359
- name: a.name ? a.name : n,
360
- raw: a,
361
- getName: () => a.name ? a.name : n,
362
- getGQLField: () => a.gqlField !== void 0 ? a.gqlField : a.name || n,
367
+ let h = {};
368
+ for (const p of Object.entries(a)) {
369
+ const [n, i] = p;
370
+ h[n] = () => ({
371
+ name: i.name ? i.name : n,
372
+ raw: i,
373
+ getName: () => i.name ? i.name : n,
374
+ getGQLField: () => i.gqlField !== void 0 ? i.gqlField : i.name || n,
363
375
  getRaw() {
364
- return a;
376
+ return i;
365
377
  },
366
378
  getValue(o) {
367
- return a.field && typeof a.field == "function" ? a.field(o) : a.field && typeof a.field == "string" ? o[a.field] : o[this.getName()];
379
+ return i.field && typeof i.field == "function" ? i.field(o) : i.field && typeof i.field == "string" ? o[i.field] : o[this.getName()];
368
380
  },
369
381
  getFormattedValue(o) {
370
382
  const c = this.getValue(o);
371
- return a.format ? a.format(c) : c;
383
+ return i.format ? i.format(c) : c;
372
384
  }
373
385
  });
374
386
  }
375
- r[s] = S(e, s, g);
387
+ r[s] = q(e, s, h);
376
388
  },
377
389
  get(s) {
378
390
  return r[s] || this.create(s, {}), r[s];
379
391
  }
380
392
  };
381
- }, G = (t) => ({
393
+ }, Q = (t) => ({
382
394
  list: async (e = {
383
395
  name: !0
384
396
  }) => {
@@ -389,7 +401,7 @@ const l = async (t, e, r = null, s = []) => {
389
401
  });
390
402
  return r;
391
403
  }
392
- }), Q = "list", I = [
404
+ }), I = "list", $ = [
393
405
  "flatMap",
394
406
  "chunk",
395
407
  "shuffle",
@@ -415,7 +427,7 @@ const l = async (t, e, r = null, s = []) => {
415
427
  "slice",
416
428
  "tap",
417
429
  "sort"
418
- ], $ = [
430
+ ], K = [
419
431
  "avg",
420
432
  "count",
421
433
  "countBy",
@@ -505,18 +517,18 @@ f.prototype.fetchData = async function() {
505
517
  };
506
518
  t.__args = this.buildArgs(), t.data = this.fields, this.already_limit && (t.data.__args = t.data.__args || {}, t.data.__args.limit = this.limit), this.already_offset && (t.data.__args = t.data.__args || {}, t.data.__args.offset = this.offset);
507
519
  const e = this.data_path.split(".");
508
- let r = {}, s = r, i = e[e.length - 1];
520
+ let r = {}, s = r, a = e[e.length - 1];
509
521
  for (const n of e) {
510
- if (n === i) {
522
+ if (n === a) {
511
523
  s[n] = t;
512
524
  break;
513
525
  }
514
526
  s[n] = {}, s = s[n];
515
527
  }
516
- let h = await w(this.axios, r);
528
+ let p = await w(this.axios, r);
517
529
  for (const n of e)
518
- h = h[n];
519
- return this.meta = h.meta, D(h.data);
530
+ p = p[n];
531
+ return this.meta = p.meta, D(p.data);
520
532
  } catch (t) {
521
533
  throw console.error("Error fetching collection data:", t), t;
522
534
  }
@@ -530,12 +542,12 @@ f.prototype.processData = async function() {
530
542
  f.prototype.all = async function() {
531
543
  return (await this.processData()).all();
532
544
  };
533
- for (const t of I)
545
+ for (const t of $)
534
546
  f.prototype[t] = function(...e) {
535
547
  const r = this.clone();
536
548
  return r.steps.push({ type: t, args: e }), r;
537
549
  };
538
- for (const t of $)
550
+ for (const t of K)
539
551
  f.prototype[t] = async function(...e) {
540
552
  return (await this.clone().processData())[t](...e);
541
553
  };
@@ -552,25 +564,25 @@ f.prototype.where = function(...t) {
552
564
  if (t.length === 2)
553
565
  this.filters[t[0]] = t[1];
554
566
  else if (t.length === 3) {
555
- const r = t[0], s = t[1], i = t[2];
567
+ const r = t[0], s = t[1], a = t[2];
556
568
  switch (s) {
557
569
  case "==":
558
- this.filters[r] = i;
570
+ this.filters[r] = a;
559
571
  break;
560
572
  case "<":
561
- this.filters[r] = { lt: i };
573
+ this.filters[r] = { lt: a };
562
574
  break;
563
575
  case "<=":
564
- this.filters[r] = { lte: i };
576
+ this.filters[r] = { lte: a };
565
577
  break;
566
578
  case ">":
567
- this.filters[r] = { gt: i };
579
+ this.filters[r] = { gt: a };
568
580
  break;
569
581
  case ">=":
570
- this.filters[r] = { gte: i };
582
+ this.filters[r] = { gte: a };
571
583
  break;
572
584
  case "!==":
573
- this.filters[r] = { ne: i };
585
+ this.filters[r] = { ne: a };
574
586
  break;
575
587
  default:
576
588
  throw new Error(`Unsupported operator: ${s}`);
@@ -620,13 +632,13 @@ f.prototype.take = function(t) {
620
632
  f.prototype.splice = function(t, e) {
621
633
  return this.steps.push({ type: "splice", args: [t, e] }), this.offset = t, this.limit = e, this.already_limit = !0, this.already_offset = !0, this;
622
634
  };
623
- const O = (t, e, r) => {
635
+ const A = (t, e, r) => {
624
636
  const s = new f(r, e);
625
- return s.data_path = Q + t, s;
626
- }, A = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
637
+ return s.data_path = I + t, s;
638
+ }, O = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
627
639
  __proto__: null,
628
- default: O
629
- }, Symbol.toStringTag, { value: "Module" })), K = (t, e) => ({
640
+ default: A
641
+ }, Symbol.toStringTag, { value: "Module" })), V = (t, e) => ({
630
642
  uploadTempFile: (r) => l(e, "lightDriveUploadTempFile", {
631
643
  index: t,
632
644
  file: r
@@ -727,7 +739,7 @@ const O = (t, e, r) => {
727
739
  rename: (r, s) => l(e, "lightDriveRenameFile", { index: t, path: r, name: s }),
728
740
  move: (r, s) => l(e, "lightDriveMoveFile", { index: t, source: r, destination: s })
729
741
  }
730
- }), x = (t) => {
742
+ }), tt = (t) => {
731
743
  const e = typeof window > "u";
732
744
  let r = [];
733
745
  const s = R.create({
@@ -736,59 +748,59 @@ const O = (t, e, r) => {
736
748
  });
737
749
  e && (s.interceptors.request.use((n) => (n.withCredentials = !0, r.length > 0 && (n.headers.Cookie = r.join("; ")), n)), s.interceptors.response.use((n) => {
738
750
  if (n.headers["set-cookie"]) {
739
- const a = n.headers["set-cookie"].map((u) => u.split(";")[0]), o = r.map((u) => u.split("=")[0]), c = a.filter((u) => {
740
- const p = u.split("=")[0];
741
- return !o.includes(p);
751
+ const i = n.headers["set-cookie"].map((u) => u.split(";")[0]), o = r.map((u) => u.split("=")[0]), c = i.filter((u) => {
752
+ const d = u.split("=")[0];
753
+ return !o.includes(d);
742
754
  });
743
755
  r = [...r, ...c];
744
756
  }
745
757
  return n;
746
758
  }));
747
- const i = (n, a = null, o = []) => l(s, n, a, o), g = (n) => w(s, n), h = z(s);
759
+ const a = (n, i = null, o = []) => l(s, n, i, o), h = (n) => w(s, n), p = G(s);
748
760
  return {
749
761
  baseURL: t,
750
762
  axios: s,
751
- auth: j(s),
752
- mutation: i,
753
- query: g,
754
- config: T(g),
755
- mail: M(s),
756
- users: W(s),
757
- fs: J(s),
758
- models: h,
763
+ auth: S(s),
764
+ mutation: a,
765
+ query: h,
766
+ config: M(h),
767
+ mail: W(s),
768
+ users: z(s),
769
+ fs: T(s),
770
+ models: p,
759
771
  model(n) {
760
- return h.get(n);
772
+ return p.get(n);
761
773
  },
762
- roles: G(s),
763
- collect: (n, a) => {
764
- const o = O(n, s, a);
765
- return o.data_path = h.get(n).getDataPath(), o;
774
+ roles: Q(s),
775
+ collect: (n, i) => {
776
+ const o = A(n, s, i);
777
+ return o.data_path = p.get(n).getDataPath(), o;
766
778
  },
767
779
  drive(n) {
768
- return K(n, s);
780
+ return V(n, s);
769
781
  },
770
782
  async collects(n) {
771
- const a = {}, o = {};
783
+ const i = {}, o = {};
772
784
  for (const u in n) {
773
- const p = n[u].getQueryPayload();
774
- o[u] = p.data_path, a[u] = {};
775
- const d = p.data_path.split(".");
776
- let y = d[d.length - 1], _ = a[u];
777
- for (const b of d) {
785
+ const d = n[u].getQueryPayload();
786
+ o[u] = d.data_path, i[u] = {};
787
+ const g = d.data_path.split(".");
788
+ let y = g[g.length - 1], _ = i[u];
789
+ for (const b of g) {
778
790
  if (b === y) {
779
- _[b] = p.query;
791
+ _[b] = d.query;
780
792
  break;
781
793
  }
782
794
  _[b] = _[b] || {};
783
795
  }
784
- a[u].__aliasFor = d[0];
796
+ i[u].__aliasFor = g[0];
785
797
  }
786
- const c = await w(s, a);
798
+ const c = await w(s, i);
787
799
  for (const u in n) {
788
- const p = o[u].split(".");
789
- let d = p[p.length - 1], y = c[u];
790
- for (const _ of p) {
791
- if (_ === d) {
800
+ const d = o[u].split(".");
801
+ let g = d[d.length - 1], y = c[u];
802
+ for (const _ of d) {
803
+ if (_ === g) {
792
804
  n[u]._batchData = c[u][_];
793
805
  break;
794
806
  }
@@ -800,11 +812,12 @@ const O = (t, e, r) => {
800
812
  };
801
813
  };
802
814
  export {
803
- Z as File,
804
- x as createClient,
805
- O as createCollection,
815
+ x as File,
816
+ tt as createClient,
817
+ A as createCollection,
806
818
  k as file,
807
819
  l as mutation,
808
820
  w as query,
809
- C as toQuery
821
+ C as toQuery,
822
+ E as useWebAuthn
810
823
  };
@@ -1 +1 @@
1
- (function(_,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("json-to-graphql-query"),require("axios"),require("collect.js")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","axios","collect.js"],y):(_=typeof globalThis<"u"?globalThis:_||self,y(_.light={},_.jsonToGraphqlQuery,_.axios,_.collect))})(this,function(_,y,k,A){"use strict";var K=Object.defineProperty;var H=(_,y,k)=>y in _?K(_,y,{enumerable:!0,configurable:!0,writable:!0,value:k}):_[y]=k;var C=(_,y,k)=>H(_,typeof y!="symbol"?y+"":y,k);const N=t=>({login:async()=>{const{app:e}=await w(t,{app:{auth:{webAuthnRequestOptions:!0}}}),r=e.auth.webAuthnRequestOptions,s=PublicKeyCredential.parseRequestOptionsFromJSON(r),a=await navigator.credentials.get({publicKey:s});await o(t,"webAuthnAssertion",{assertion:a.toJSON()})},register:async()=>{const{app:e}=await w(t,{app:{auth:{webAuthnCreationOptions:!0}}}),r=PublicKeyCredential.parseCreationOptionsFromJSON(e.auth.webAuthnCreationOptions),s=await navigator.credentials.create({publicKey:r});await o(t,"webAuthnRegister",{registration:s.toJSON()})}}),q=t=>({WebAuthn:N(t),google:{unlink:()=>o(t,"lightAuthUnlinkGoogle"),login:e=>o(t,"lightAuthLoginGoogle",{credential:e}),register:e=>o(t,"lightAuthRegisterGoogle",{credential:e})},facebook:{unlink:()=>o(t,"lightAuthUnlinkFacebook"),login:e=>o(t,"lightAuthLoginFacebook",{access_token:e}),register:e=>o(t,"lightAuthRegisterFacebook",{access_token:e})},microsoft:{unlink:()=>o(t,"lightAuthUnlinkMicrosoft"),login:e=>o(t,"lightAuthLoginMicrosoft",{access_token:e}),register:e=>o(t,"lightAuthRegisterMicrosoft",{account_id:e})},login:(e,r,s="")=>o(t,"login",{username:e,password:r,code:s}),logout:()=>o(t,"logout"),changeExpiredPassword:(e,r,s)=>o(t,"changeExpiredPassword",{username:e,old_password:r,new_password:s}),updatePassword:(e,r)=>o(t,"changeUserPassword",{old_password:e,new_password:r}),resetPassword:(e,r,s)=>o(t,"resetPassword",{jwt:e,password:r,code:s}),forgetPassword:(e,r)=>o(t,"forgetPassword",{username:e,email:r}),verifyCode(e,r){return o(t,"forgetPasswordVerifyCode",{jwt:e,code:r})},granted:async e=>{const{my:r}=await w(t,{my:{grantedRights:{__args:{rights:e}}}});return r.grantedRights}}),B=(t,e,r)=>{const s=e,a=t,g=r;let h="list"+e;const n=i=>g[i]?g[i]():null;return{field:n,$fields:g,setDataPath(i){return h=i,h},getDataPath(){return h},gqlFields(i){const l=[];for(const c of i)if(typeof c=="string"){const u=n(c);u&&l.push(u.getGQLField())}else typeof c=="object"&&l.push(c);return l},async update(i,l){return await o(a,"update"+s,{id:i,data:l})},async delete(i){return await o(a,"delete"+s,{id:i})},async add(i){return await o(a,"add"+s,{data:i})},fields(i){let l=[];for(let c of i){const u=n(c);u&&l.push(u)}return l},async get(i,l){const c=(await Promise.resolve().then(()=>j)).default,u=c(s,a,D(l));for(const[p,d]of Object.entries(i))u.where(p,"==",d);return await u.first()},async list(i,l){const c=(await Promise.resolve().then(()=>j)).default,u=c(s,a,D(l));for(const[p,d]of Object.entries(i))u.where(p,"==",d);return await u.all()}}};function R(t){t="<~"+t+"~>";var e,r,s,a,g,h=String,n=255;for(t.slice(0,2)==="<~"&&t.slice(-2),t=t.slice(2,-2).replace(/\s/g,"").replace("z","!!!!!"),e="uuuuu".slice(t.length%5||5),t+=e,s=[],a=0,g=t.length;g>a;a+=5)r=52200625*(t.charCodeAt(a)-33)+614125*(t.charCodeAt(a+1)-33)+7225*(t.charCodeAt(a+2)-33)+85*(t.charCodeAt(a+3)-33)+(t.charCodeAt(a+4)-33),s.push(n&r>>24,n&r>>16,n&r>>8,n&r);return function(i,l){for(var c=l;c>0;c--)i.pop()}(s,e.length),h.fromCharCode.apply(h,s)}const v=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const a=new Uint8Array(e.length);for(let n=0;n<e.length;n++)a[n]=e.charCodeAt(n);const g=new Blob([a],{type:s});return URL.createObjectURL(g)};return{getContent:()=>e,getURL:r,download:s=>{const a=document.createElement("a");a.download=s,a.href=r(),document.body.appendChild(a),a.click(),document.body.removeChild(a)},open:s=>{window.open(r(s),"_blank")}}},E={fromBase85:t=>v(R(t)),fromBase64:t=>v(atob(t)),fromString:t=>v(t)},P=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(P(r)).forEach(([s,a])=>{e[s]=a})}),e):(Object.entries(t).forEach(([r,s])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=s;return}if(typeof s=="boolean"){e[r]=s;return}e[r]=P(s)}),e)},D=t=>P(t),w=async(t,e)=>{let r=y.jsonToGraphQLQuery(D(e));const s=await t.post("",{query:`{ ${r} }`});if(s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function S(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function L(t){for(let e in t)if(t[e]instanceof File)return!0;return!1}const o=async(t,e,r=null,s=[])=>{let a={[e]:{}};const g=new FormData;let h=!1;if(r){const l={},c={},u={};let p=0;Object.entries(r).forEach(([d,b])=>{if(b instanceof Array&&S(b)){h=!0;let m=0;b.forEach(F=>{F instanceof File&&(l[d]=new y.VariableType(d),c[p]=["variables."+d+"."+m],g.append(p.toString(),F),p++)}),u[d]="[Upload!]!"}else b instanceof File?(h=!0,l[d]=new y.VariableType(d),c[p]=["variables."+d],g.append(p.toString(),b),u[d]="Upload!",p++):b instanceof Object&&L(b)?(h=!0,l[d]={},Object.entries(b).forEach(([m,F])=>{F instanceof File?(l[d][m]=new y.VariableType(m),c[p]=["variables."+m],g.append(p.toString(),F),u[m]="Upload!",p++):l[d][m]=F})):b!==void 0&&(l[d]=b)}),a[e].__args=l,a.__variables=u,h&&g.append("map",JSON.stringify(c))}Object.entries(D(s)).forEach(([l,c])=>{a[e][l]=c}),Object.entries(a[e]).length===0&&(a[e]=!0);let n=null;const i=y.jsonToGraphQLQuery({mutation:a});if(h?(g.append("operations",JSON.stringify({query:i})),n=await t.post("",g)):n=await t.post("",{query:i}),n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data[e]},U=t=>({uploadTempFile:e=>o(t,"fsUploadTempFile",{file:e},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async e=>(await w(t,{fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,create:e=>o(t,"fsCreateFolder",{path:e}),delete:e=>o(t,"fsDeleteFolder",{path:e}),rename:(e,r)=>o(t,"fsRenameFolder",{path:e,name:r})},files:{list:async e=>{let{app:r}=await w(t,{app:{drive:{files:{__args:{path:e},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}}}});return r.drive.files},read:async e=>{let{app:r}=await w(t,{app:{drive:{files:{__args:{path:e},base64Content:!0}}}});return window.atob(r.drive.files[0].base64Content)},write:(e,r)=>o(t,"fsWriteFile",{path:e,content:r}),delete:e=>o(t,"fsDeleteFile",{path:e}),rename:(e,r)=>o(t,"fsRenameFile",{path:e,name:r}),move:(e,r)=>o(t,"fsMoveFile",{source:e,target:r})}}),J=t=>({get:async e=>(await t({config:{__args:{name:e}}})).config}),T=t=>({send:(e,r,s)=>o(t,"sendMail",{email:e,subject:r,message:s})}),M=t=>({list:async(e={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0})=>{const r=O("Users",t,e);return r.data_path="app.users",r.all()}}),W=t=>{const e=t,r={};return{create(s,a){r[s]=null;let g={};for(const h of Object.entries(a)){const[n,i]=h;g[n]=()=>({name:i.name?i.name:n,raw:i,getName:()=>i.name?i.name:n,getGQLField:()=>i.gqlField!==void 0?i.gqlField:i.name||n,getRaw(){return i},getValue(l){return i.field&&typeof i.field=="function"?i.field(l):i.field&&typeof i.field=="string"?l[i.field]:l[this.getName()]},getFormattedValue(l){const c=this.getValue(l);return i.format?i.format(c):c}})}r[s]=B(e,s,g)},get(s){return r[s]||this.create(s,{}),r[s]}}},z=t=>({list:async(e={name:!0})=>{const{app:{roles:r}}=await w(t,{app:{roles:e}});return r}}),Q="list",V=["flatMap","chunk","shuffle","splice","sortBy","map","reverse","groupBy","keyBy","keys","mapToDictionary","mapWithKeys","nth","skipUntil","skipWhile","takeUntil","takeWhile","unique","pluck","push","only","pad","slice","tap","sort"],I=["avg","count","countBy","dd","each","every","filter","firstWhere","isEmpty","isNotEmpty","last","mapToGroups","max","median","min","mode","contains","sole","sort","split","sum","toJson","get","has","implode","partition"];class f{constructor(e,r){C(this,"_batchData",null);C(this,"data_path","");C(this,"axios");C(this,"filters");C(this,"steps");C(this,"fields");C(this,"already_limit",!1);C(this,"already_offset",!1);C(this,"limit",null);C(this,"offset",null);C(this,"_sort",null);C(this,"_sortDesc",!1);C(this,"meta",{});this.axios=r,this.filters={},this.steps=[],this.fields=e}}f.prototype.getQueryPayload=function(){let t={meta:{total:!0,key:!0,name:!0}};return t.__args=this.buildArgs(),t.data=this.fields,t.data.__args=t.data.__args||{},this.limit&&(t.data.__args.limit=this.limit),this.offset&&(t.data.__args.offset=this.offset),{data_path:this.data_path,query:t,steps:this.steps}},f.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},f.prototype.buildArgs=function(){let t={};return Object.keys(this.filters).length>0&&(t.filters=this.filters),this._sort&&(t.sort=this._sort,this._sortDesc&&(t.sort+=":desc")),t},f.prototype.clone=function(){const t=Object.create(this);return t.steps=JSON.parse(JSON.stringify(this.steps)),t.filters=JSON.parse(JSON.stringify(this.filters)),t.fields=JSON.parse(JSON.stringify(this.fields)),t},A().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),f.prototype.fetchData=async function(){try{if(this._batchData){const n=this._batchData;return this.meta=n.meta,A(n.data)}let t={meta:{total:!0,key:!0,name:!0}};t.__args=this.buildArgs(),t.data=this.fields,this.already_limit&&(t.data.__args=t.data.__args||{},t.data.__args.limit=this.limit),this.already_offset&&(t.data.__args=t.data.__args||{},t.data.__args.offset=this.offset);const e=this.data_path.split(".");let r={},s=r,a=e[e.length-1];for(const n of e){if(n===a){s[n]=t;break}s[n]={},s=s[n]}let h=await w(this.axios,r);for(const n of e)h=h[n];return this.meta=h.meta,A(h.data)}catch(t){throw console.error("Error fetching collection data:",t),t}},f.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},f.prototype.all=async function(){return(await this.processData()).all()};for(const t of V)f.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of I)f.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};f.prototype.average=f.prototype.avg,f.prototype.first=async function(){return this.take(1),(await this.processData()).first()},f.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},f.prototype.where=function(...t){const e=this._handleBatchData("where",t);if(e)return e;if(t.length===2)this.filters[t[0]]=t[1];else if(t.length===3){const r=t[0],s=t[1],a=t[2];switch(s){case"==":this.filters[r]=a;break;case"<":this.filters[r]={lt:a};break;case"<=":this.filters[r]={lte:a};break;case">":this.filters[r]={gt:a};break;case">=":this.filters[r]={gte:a};break;case"!==":this.filters[r]={ne:a};break;default:throw new Error(`Unsupported operator: ${s}`)}}return this},f.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},f.prototype.forPage=function(t,e){return t=Math.max(1,t),this.already_limit?(this.steps.push({type:"forPage",args:[t,e]}),this):(this.limit=e,this.offset=(t-1)*e,this.already_limit=!0,this.already_offset=!0,this)},f.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},f.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},f.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},f.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},f.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},f.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},f.prototype.skip=function(t){if(t<0)throw new Error("Offset must be non-negative");return this.already_offset&&this.steps.push({type:"skip",args:[t]}),this.offset=t,this.already_offset=!0,this},f.prototype.take=function(t){if(t<0)throw new Error("Length must be non-negative");return this.already_limit?(this.steps.push({type:"take",args:[t]}),this):(this.limit=t,this.already_limit=!0,this)},f.prototype.splice=function(t,e){return this.steps.push({type:"splice",args:[t,e]}),this.offset=t,this.limit=e,this.already_limit=!0,this.already_offset=!0,this};const O=(t,e,r)=>{const s=new f(r,e);return s.data_path=Q+t,s},j=Object.freeze(Object.defineProperty({__proto__:null,default:O},Symbol.toStringTag,{value:"Module"})),$=(t,e)=>({uploadTempFile:r=>o(e,"lightDriveUploadTempFile",{index:t,file:r},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async(r,s={name:!0,path:!0})=>(await w(e,{app:{drive:{__args:{index:t},folders:{__args:{path:r},...s}}}})).app.drive.folders,create:r=>o(e,"lightDriveCreateFolder",{index:t,path:r}),delete:r=>o(e,"lightDriveDeleteFolder",{index:t,path:r}),rename:(r,s)=>o(e,"lightDriveRenameFolder",{index:t,path:r,name:s})},files:{list:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await w(e,{app:{drive:{__args:{index:t},files:{__args:{path:r},...s}}}})).app.drive.files,get:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await w(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},...s}}}})).app.drive.file,read:async r=>{let s=await w(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},base64Content:!0}}}});if(!s.app.drive.file||!s.app.drive.file.base64Content)throw new Error(`File not found or cannot read content: ${r}`);return typeof window<"u"&&window.atob?window.atob(s.app.drive.file.base64Content):s.app.drive.file.base64Content},write:(r,s)=>o(e,"lightDriveWriteFile",{index:t,path:r,content:s}),delete:r=>o(e,"lightDriveDeleteFile",{index:t,path:r}),rename:(r,s)=>o(e,"lightDriveRenameFile",{index:t,path:r,name:s}),move:(r,s)=>o(e,"lightDriveMoveFile",{index:t,source:r,destination:s})}}),G=t=>{const e=typeof window>"u";let r=[];const s=k.create({baseURL:t,withCredentials:!0});e&&(s.interceptors.request.use(n=>(n.withCredentials=!0,r.length>0&&(n.headers.Cookie=r.join("; ")),n)),s.interceptors.response.use(n=>{if(n.headers["set-cookie"]){const i=n.headers["set-cookie"].map(u=>u.split(";")[0]),l=r.map(u=>u.split("=")[0]),c=i.filter(u=>{const p=u.split("=")[0];return!l.includes(p)});r=[...r,...c]}return n}));const a=(n,i=null,l=[])=>o(s,n,i,l),g=n=>w(s,n),h=W(s);return{baseURL:t,axios:s,auth:q(s),mutation:a,query:g,config:J(g),mail:T(s),users:M(s),fs:U(s),models:h,model(n){return h.get(n)},roles:z(s),collect:(n,i)=>{const l=O(n,s,i);return l.data_path=h.get(n).getDataPath(),l},drive(n){return $(n,s)},async collects(n){const i={},l={};for(const u in n){const p=n[u].getQueryPayload();l[u]=p.data_path,i[u]={};const d=p.data_path.split(".");let b=d[d.length-1],m=i[u];for(const F of d){if(F===b){m[F]=p.query;break}m[F]=m[F]||{}}i[u].__aliasFor=d[0]}const c=await w(s,i);for(const u in n){const p=l[u].split(".");let d=p[p.length-1],b=c[u];for(const m of p){if(m===d){n[u]._batchData=c[u][m];break}b[m]=b[m]||{}}}return n}}};_.File=E,_.createClient=G,_.createCollection=O,_.file=v,_.mutation=o,_.query=w,_.toQuery=D,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
1
+ (function(_,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("json-to-graphql-query"),require("axios"),require("collect.js")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","axios","collect.js"],y):(_=typeof globalThis<"u"?globalThis:_||self,y(_.light={},_.jsonToGraphqlQuery,_.axios,_.collect))})(this,function(_,y,k,O){"use strict";var H=Object.defineProperty;var X=(_,y,k)=>y in _?H(_,y,{enumerable:!0,configurable:!0,writable:!0,value:k}):_[y]=k;var C=(_,y,k)=>X(_,typeof y!="symbol"?y+"":y,k);const j=t=>({assertion:async()=>{const{app:s}=await w(t,{app:{auth:{webAuthnRequestOptions:!0}}}),i=s.auth.webAuthnRequestOptions,h=PublicKeyCredential.parseRequestOptionsFromJSON(i);return await navigator.credentials.get({publicKey:h})},attestation:async()=>{const{app:s}=await w(t,{app:{auth:{webAuthnCreationOptions:!0}}}),i=PublicKeyCredential.parseCreationOptionsFromJSON(s.auth.webAuthnCreationOptions);return await navigator.credentials.create({publicKey:i})}}),q=t=>{const{assertion:e,attestation:r}=j(t);return{login:async()=>{const s=await e();await o(t,"webAuthnAssertion",{assertion:s.toJSON()})},register:async()=>{const s=await r();await o(t,"webAuthnRegister",{registration:s.toJSON()})}}},B=t=>({WebAuthn:q(t),google:{unlink:()=>o(t,"lightAuthUnlinkGoogle"),login:e=>o(t,"lightAuthLoginGoogle",{credential:e}),register:e=>o(t,"lightAuthRegisterGoogle",{credential:e})},facebook:{unlink:()=>o(t,"lightAuthUnlinkFacebook"),login:e=>o(t,"lightAuthLoginFacebook",{access_token:e}),register:e=>o(t,"lightAuthRegisterFacebook",{access_token:e})},microsoft:{unlink:()=>o(t,"lightAuthUnlinkMicrosoft"),login:e=>o(t,"lightAuthLoginMicrosoft",{access_token:e}),register:e=>o(t,"lightAuthRegisterMicrosoft",{account_id:e})},login:(e,r,s="")=>o(t,"login",{username:e,password:r,code:s}),logout:()=>o(t,"logout"),changeExpiredPassword:(e,r,s)=>o(t,"changeExpiredPassword",{username:e,old_password:r,new_password:s}),updatePassword:(e,r)=>o(t,"changeUserPassword",{old_password:e,new_password:r}),resetPassword:(e,r,s)=>o(t,"resetPassword",{jwt:e,password:r,code:s}),forgetPassword:(e,r)=>o(t,"forgetPassword",{username:e,email:r}),verifyCode(e,r){return o(t,"forgetPasswordVerifyCode",{jwt:e,code:r})},granted:async e=>{const{my:r}=await w(t,{my:{grantedRights:{__args:{rights:e}}}});return r.grantedRights}}),R=(t,e,r)=>{const s=e,i=t,h=r;let p="list"+e;const n=a=>h[a]?h[a]():null;return{field:n,$fields:h,setDataPath(a){return p=a,p},getDataPath(){return p},gqlFields(a){const l=[];for(const c of a)if(typeof c=="string"){const u=n(c);u&&l.push(u.getGQLField())}else typeof c=="object"&&l.push(c);return l},async update(a,l){return await o(i,"update"+s,{id:a,data:l})},async delete(a){return await o(i,"delete"+s,{id:a})},async add(a){return await o(i,"add"+s,{data:a})},fields(a){let l=[];for(let c of a){const u=n(c);u&&l.push(u)}return l},async get(a,l){const c=(await Promise.resolve().then(()=>N)).default,u=c(s,i,D(l));for(const[d,g]of Object.entries(a))u.where(d,"==",g);return await u.first()},async list(a,l){const c=(await Promise.resolve().then(()=>N)).default,u=c(s,i,D(l));for(const[d,g]of Object.entries(a))u.where(d,"==",g);return await u.all()}}};function E(t){t="<~"+t+"~>";var e,r,s,i,h,p=String,n=255;for(t.slice(0,2)==="<~"&&t.slice(-2),t=t.slice(2,-2).replace(/\s/g,"").replace("z","!!!!!"),e="uuuuu".slice(t.length%5||5),t+=e,s=[],i=0,h=t.length;h>i;i+=5)r=52200625*(t.charCodeAt(i)-33)+614125*(t.charCodeAt(i+1)-33)+7225*(t.charCodeAt(i+2)-33)+85*(t.charCodeAt(i+3)-33)+(t.charCodeAt(i+4)-33),s.push(n&r>>24,n&r>>16,n&r>>8,n&r);return function(a,l){for(var c=l;c>0;c--)a.pop()}(s,e.length),p.fromCharCode.apply(p,s)}const v=(t="")=>{const e=t,r=(s="application/octet-stream")=>{const i=new Uint8Array(e.length);for(let n=0;n<e.length;n++)i[n]=e.charCodeAt(n);const h=new Blob([i],{type:s});return URL.createObjectURL(h)};return{getContent:()=>e,getURL:r,download:s=>{const i=document.createElement("a");i.download=s,i.href=r(),document.body.appendChild(i),i.click(),document.body.removeChild(i)},open:s=>{window.open(r(s),"_blank")}}},S={fromBase85:t=>v(E(t)),fromBase64:t=>v(atob(t)),fromString:t=>v(t)},P=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(P(r)).forEach(([s,i])=>{e[s]=i})}),e):(Object.entries(t).forEach(([r,s])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=s;return}if(typeof s=="boolean"){e[r]=s;return}e[r]=P(s)}),e)},D=t=>P(t),w=async(t,e)=>{let r=y.jsonToGraphQLQuery(D(e));const s=await t.post("",{query:`{ ${r} }`});if(s.data.errors)throw new Error(s.data.errors[0].message);return s.data.data};function L(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function U(t){for(let e in t)if(t[e]instanceof File)return!0;return!1}const o=async(t,e,r=null,s=[])=>{let i={[e]:{}};const h=new FormData;let p=!1;if(r){const l={},c={},u={};let d=0;Object.entries(r).forEach(([g,b])=>{if(b instanceof Array&&L(b)){p=!0;let m=0;b.forEach(F=>{F instanceof File&&(l[g]=new y.VariableType(g),c[d]=["variables."+g+"."+m],h.append(d.toString(),F),d++)}),u[g]="[Upload!]!"}else b instanceof File?(p=!0,l[g]=new y.VariableType(g),c[d]=["variables."+g],h.append(d.toString(),b),u[g]="Upload!",d++):b instanceof Object&&U(b)?(p=!0,l[g]={},Object.entries(b).forEach(([m,F])=>{F instanceof File?(l[g][m]=new y.VariableType(m),c[d]=["variables."+m],h.append(d.toString(),F),u[m]="Upload!",d++):l[g][m]=F})):b!==void 0&&(l[g]=b)}),i[e].__args=l,i.__variables=u,p&&h.append("map",JSON.stringify(c))}Object.entries(D(s)).forEach(([l,c])=>{i[e][l]=c}),Object.entries(i[e]).length===0&&(i[e]=!0);let n=null;const a=y.jsonToGraphQLQuery({mutation:i});if(p?(h.append("operations",JSON.stringify({query:a})),n=await t.post("",h)):n=await t.post("",{query:a}),n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data[e]},J=t=>({uploadTempFile:e=>o(t,"fsUploadTempFile",{file:e},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async e=>(await w(t,{fsListFolders:{__args:{path:e},name:!0,path:!0}})).fsListFolders,create:e=>o(t,"fsCreateFolder",{path:e}),delete:e=>o(t,"fsDeleteFolder",{path:e}),rename:(e,r)=>o(t,"fsRenameFolder",{path:e,name:r})},files:{list:async e=>{let{app:r}=await w(t,{app:{drive:{files:{__args:{path:e},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}}}});return r.drive.files},read:async e=>{let{app:r}=await w(t,{app:{drive:{files:{__args:{path:e},base64Content:!0}}}});return window.atob(r.drive.files[0].base64Content)},write:(e,r)=>o(t,"fsWriteFile",{path:e,content:r}),delete:e=>o(t,"fsDeleteFile",{path:e}),rename:(e,r)=>o(t,"fsRenameFile",{path:e,name:r}),move:(e,r)=>o(t,"fsMoveFile",{source:e,target:r})}}),T=t=>({get:async e=>(await t({config:{__args:{name:e}}})).config}),M=t=>({send:(e,r,s)=>o(t,"sendMail",{email:e,subject:r,message:s})}),W=t=>({list:async(e={user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0})=>{const r=A("Users",t,e);return r.data_path="app.users",r.all()}}),z=t=>{const e=t,r={};return{create(s,i){r[s]=null;let h={};for(const p of Object.entries(i)){const[n,a]=p;h[n]=()=>({name:a.name?a.name:n,raw:a,getName:()=>a.name?a.name:n,getGQLField:()=>a.gqlField!==void 0?a.gqlField:a.name||n,getRaw(){return a},getValue(l){return a.field&&typeof a.field=="function"?a.field(l):a.field&&typeof a.field=="string"?l[a.field]:l[this.getName()]},getFormattedValue(l){const c=this.getValue(l);return a.format?a.format(c):c}})}r[s]=R(e,s,h)},get(s){return r[s]||this.create(s,{}),r[s]}}},Q=t=>({list:async(e={name:!0})=>{const{app:{roles:r}}=await w(t,{app:{roles:e}});return r}}),V="list",I=["flatMap","chunk","shuffle","splice","sortBy","map","reverse","groupBy","keyBy","keys","mapToDictionary","mapWithKeys","nth","skipUntil","skipWhile","takeUntil","takeWhile","unique","pluck","push","only","pad","slice","tap","sort"],$=["avg","count","countBy","dd","each","every","filter","firstWhere","isEmpty","isNotEmpty","last","mapToGroups","max","median","min","mode","contains","sole","sort","split","sum","toJson","get","has","implode","partition"];class f{constructor(e,r){C(this,"_batchData",null);C(this,"data_path","");C(this,"axios");C(this,"filters");C(this,"steps");C(this,"fields");C(this,"already_limit",!1);C(this,"already_offset",!1);C(this,"limit",null);C(this,"offset",null);C(this,"_sort",null);C(this,"_sortDesc",!1);C(this,"meta",{});this.axios=r,this.filters={},this.steps=[],this.fields=e}}f.prototype.getQueryPayload=function(){let t={meta:{total:!0,key:!0,name:!0}};return t.__args=this.buildArgs(),t.data=this.fields,t.data.__args=t.data.__args||{},this.limit&&(t.data.__args.limit=this.limit),this.offset&&(t.data.__args.offset=this.offset),{data_path:this.data_path,query:t,steps:this.steps}},f.prototype.dataPath=function(t){const e=this.clone();return e.data_path=t,e},f.prototype.buildArgs=function(){let t={};return Object.keys(this.filters).length>0&&(t.filters=this.filters),this._sort&&(t.sort=this._sort,this._sortDesc&&(t.sort+=":desc")),t},f.prototype.clone=function(){const t=Object.create(this);return t.steps=JSON.parse(JSON.stringify(this.steps)),t.filters=JSON.parse(JSON.stringify(this.filters)),t.fields=JSON.parse(JSON.stringify(this.fields)),t},O().macro("whereContains",function(t,e){return this.filter(r=>r[t].toLowerCase().includes(e.toLowerCase()))}),f.prototype.fetchData=async function(){try{if(this._batchData){const n=this._batchData;return this.meta=n.meta,O(n.data)}let t={meta:{total:!0,key:!0,name:!0}};t.__args=this.buildArgs(),t.data=this.fields,this.already_limit&&(t.data.__args=t.data.__args||{},t.data.__args.limit=this.limit),this.already_offset&&(t.data.__args=t.data.__args||{},t.data.__args.offset=this.offset);const e=this.data_path.split(".");let r={},s=r,i=e[e.length-1];for(const n of e){if(n===i){s[n]=t;break}s[n]={},s=s[n]}let p=await w(this.axios,r);for(const n of e)p=p[n];return this.meta=p.meta,O(p.data)}catch(t){throw console.error("Error fetching collection data:",t),t}},f.prototype.processData=async function(){let t=await this.fetchData();for(const e of this.steps)t=t[e.type](...e.args);return t},f.prototype.all=async function(){return(await this.processData()).all()};for(const t of I)f.prototype[t]=function(...e){const r=this.clone();return r.steps.push({type:t,args:e}),r};for(const t of $)f.prototype[t]=async function(...e){return(await this.clone().processData())[t](...e)};f.prototype.average=f.prototype.avg,f.prototype.first=async function(){return this.take(1),(await this.processData()).first()},f.prototype._handleBatchData=function(t,e){return this._batchData?(this.steps.push({type:t,args:e}),this):null},f.prototype.where=function(...t){const e=this._handleBatchData("where",t);if(e)return e;if(t.length===2)this.filters[t[0]]=t[1];else if(t.length===3){const r=t[0],s=t[1],i=t[2];switch(s){case"==":this.filters[r]=i;break;case"<":this.filters[r]={lt:i};break;case"<=":this.filters[r]={lte:i};break;case">":this.filters[r]={gt:i};break;case">=":this.filters[r]={gte:i};break;case"!==":this.filters[r]={ne:i};break;default:throw new Error(`Unsupported operator: ${s}`)}}return this},f.prototype.whereContains=function(t,e){const r=this._handleBatchData("whereContains",[t,e]);return r||(this.filters[t]={contains:e},this)},f.prototype.forPage=function(t,e){return t=Math.max(1,t),this.already_limit?(this.steps.push({type:"forPage",args:[t,e]}),this):(this.limit=e,this.offset=(t-1)*e,this.already_limit=!0,this.already_offset=!0,this)},f.prototype.whereIn=function(t,e){const r=this._handleBatchData("whereIn",[t,e]);return r||(this.filters[t]={in:e},this)},f.prototype.whereNotIn=function(t,e){const r=this._handleBatchData("whereNotIn",[t,e]);return r||(this.filters[t]={nin:e},this)},f.prototype.whereNotBetween=function(t,e){const r=this._handleBatchData("whereNotBetween",[t,e]);return r||(this.filters[t]={notBetween:e},this)},f.prototype.whereBetween=function(t,e){const r=this._handleBatchData("whereBetween",[t,e]);return r||(this.filters[t]={between:e},this)},f.prototype.sortBy=function(t){return this.steps.push({type:"sortBy",args:[t]}),typeof t=="string"&&(this._sort=t),this},f.prototype.sortByDesc=function(t){return this.steps.push({type:"sortByDesc",args:[t]}),typeof t=="string"&&(this._sort=t,this._sortDesc=!0),this},f.prototype.skip=function(t){if(t<0)throw new Error("Offset must be non-negative");return this.already_offset&&this.steps.push({type:"skip",args:[t]}),this.offset=t,this.already_offset=!0,this},f.prototype.take=function(t){if(t<0)throw new Error("Length must be non-negative");return this.already_limit?(this.steps.push({type:"take",args:[t]}),this):(this.limit=t,this.already_limit=!0,this)},f.prototype.splice=function(t,e){return this.steps.push({type:"splice",args:[t,e]}),this.offset=t,this.limit=e,this.already_limit=!0,this.already_offset=!0,this};const A=(t,e,r)=>{const s=new f(r,e);return s.data_path=V+t,s},N=Object.freeze(Object.defineProperty({__proto__:null,default:A},Symbol.toStringTag,{value:"Module"})),G=(t,e)=>({uploadTempFile:r=>o(e,"lightDriveUploadTempFile",{index:t,file:r},{name:!0,path:!0,size:!0,mime:!0}),folders:{list:async(r,s={name:!0,path:!0})=>(await w(e,{app:{drive:{__args:{index:t},folders:{__args:{path:r},...s}}}})).app.drive.folders,create:r=>o(e,"lightDriveCreateFolder",{index:t,path:r}),delete:r=>o(e,"lightDriveDeleteFolder",{index:t,path:r}),rename:(r,s)=>o(e,"lightDriveRenameFolder",{index:t,path:r,name:s})},files:{list:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await w(e,{app:{drive:{__args:{index:t},files:{__args:{path:r},...s}}}})).app.drive.files,get:async(r,s={name:!0,path:!0,size:!0,mime:!0,url:!0})=>(await w(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},...s}}}})).app.drive.file,read:async r=>{let s=await w(e,{app:{drive:{__args:{index:t},file:{__args:{path:r},base64Content:!0}}}});if(!s.app.drive.file||!s.app.drive.file.base64Content)throw new Error(`File not found or cannot read content: ${r}`);return typeof window<"u"&&window.atob?window.atob(s.app.drive.file.base64Content):s.app.drive.file.base64Content},write:(r,s)=>o(e,"lightDriveWriteFile",{index:t,path:r,content:s}),delete:r=>o(e,"lightDriveDeleteFile",{index:t,path:r}),rename:(r,s)=>o(e,"lightDriveRenameFile",{index:t,path:r,name:s}),move:(r,s)=>o(e,"lightDriveMoveFile",{index:t,source:r,destination:s})}}),K=t=>{const e=typeof window>"u";let r=[];const s=k.create({baseURL:t,withCredentials:!0});e&&(s.interceptors.request.use(n=>(n.withCredentials=!0,r.length>0&&(n.headers.Cookie=r.join("; ")),n)),s.interceptors.response.use(n=>{if(n.headers["set-cookie"]){const a=n.headers["set-cookie"].map(u=>u.split(";")[0]),l=r.map(u=>u.split("=")[0]),c=a.filter(u=>{const d=u.split("=")[0];return!l.includes(d)});r=[...r,...c]}return n}));const i=(n,a=null,l=[])=>o(s,n,a,l),h=n=>w(s,n),p=z(s);return{baseURL:t,axios:s,auth:B(s),mutation:i,query:h,config:T(h),mail:M(s),users:W(s),fs:J(s),models:p,model(n){return p.get(n)},roles:Q(s),collect:(n,a)=>{const l=A(n,s,a);return l.data_path=p.get(n).getDataPath(),l},drive(n){return G(n,s)},async collects(n){const a={},l={};for(const u in n){const d=n[u].getQueryPayload();l[u]=d.data_path,a[u]={};const g=d.data_path.split(".");let b=g[g.length-1],m=a[u];for(const F of g){if(F===b){m[F]=d.query;break}m[F]=m[F]||{}}a[u].__aliasFor=g[0]}const c=await w(s,a);for(const u in n){const d=l[u].split(".");let g=d[d.length-1],b=c[u];for(const m of d){if(m===g){n[u]._batchData=c[u][m];break}b[m]=b[m]||{}}}return n}}};_.File=S,_.createClient=K,_.createCollection=A,_.file=v,_.mutation=o,_.query=w,_.toQuery=D,_.useWebAuthn=j,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1,6 @@
1
+ import { AxiosInstance } from 'axios';
2
+ declare const _default: (axios: AxiosInstance) => {
3
+ assertion: () => Promise<PublicKeyCredential>;
4
+ attestation: () => Promise<PublicKeyCredential>;
5
+ };
6
+ export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hostlink/light",
3
- "version": "2.8.0",
3
+ "version": "2.9.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"