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