@hostlink/light 2.0.1 → 2.1.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/README.md +37 -0
- package/dist/auth.d.ts +5 -3
- package/dist/light.js +149 -142
- package/dist/light.umd.cjs +1 -1
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# HostLink Light Cient
|
|
2
|
+
|
|
3
|
+
A javascript library for Light Framework.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @hostlink/light
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```javascript
|
|
15
|
+
import { createClient } from '@hostlink/light';
|
|
16
|
+
|
|
17
|
+
const api=createClient('https://example.com/api');
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Login
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
await api.auth.login('username','password');
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Logout
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
await api.auth.logout();
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
package/dist/auth.d.ts
CHANGED
|
@@ -4,13 +4,15 @@ declare const _default: (axios: AxiosInstance) => {
|
|
|
4
4
|
login: (username: string) => Promise<void>;
|
|
5
5
|
register: () => Promise<void>;
|
|
6
6
|
};
|
|
7
|
+
facebookLogin: (accessToken: string) => Promise<boolean>;
|
|
8
|
+
microsoftLogin: (accessToken: string) => Promise<boolean>;
|
|
7
9
|
googleLogin: (credential: string) => Promise<boolean>;
|
|
8
10
|
login: (username: string, password: string, code?: string) => Promise<boolean>;
|
|
9
11
|
logout: () => Promise<boolean>;
|
|
10
12
|
updatePassword: (oldPassword: string, newPassword: string) => Promise<boolean>;
|
|
11
|
-
resetPassword: (
|
|
12
|
-
forgetPassword: (email: string) => Promise<boolean>;
|
|
13
|
-
verifyCode(
|
|
13
|
+
resetPassword: (username: string, password: string, code: string) => Promise<boolean>;
|
|
14
|
+
forgetPassword: (username: string, email: string) => Promise<boolean>;
|
|
15
|
+
verifyCode(username: string, code: string): Promise<boolean>;
|
|
14
16
|
granted: (rights: string[]) => Promise<string[]>;
|
|
15
17
|
};
|
|
16
18
|
export default _default;
|
package/dist/light.js
CHANGED
|
@@ -2,11 +2,11 @@ import { jsonToGraphQLQuery as E, VariableType as S } from "json-to-graphql-quer
|
|
|
2
2
|
import U from "axios";
|
|
3
3
|
function j(t) {
|
|
4
4
|
const e = "==".slice(0, (4 - t.length % 4) % 4), r = t.replace(/-/g, "+").replace(/_/g, "/") + e, n = atob(r), s = new ArrayBuffer(n.length), a = new Uint8Array(s);
|
|
5
|
-
for (let
|
|
6
|
-
a[
|
|
5
|
+
for (let i = 0; i < n.length; i++)
|
|
6
|
+
a[i] = n.charCodeAt(i);
|
|
7
7
|
return s;
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function L(t) {
|
|
10
10
|
const e = new Uint8Array(t);
|
|
11
11
|
let r = "";
|
|
12
12
|
for (const a of e)
|
|
@@ -16,9 +16,9 @@ function N(t) {
|
|
|
16
16
|
"_"
|
|
17
17
|
).replace(/=/g, "");
|
|
18
18
|
}
|
|
19
|
-
var
|
|
19
|
+
var u = "copy", m = "convert";
|
|
20
20
|
function F(t, e, r) {
|
|
21
|
-
if (e ===
|
|
21
|
+
if (e === u)
|
|
22
22
|
return r;
|
|
23
23
|
if (e === m)
|
|
24
24
|
return t(r);
|
|
@@ -28,8 +28,8 @@ function F(t, e, r) {
|
|
|
28
28
|
const n = {};
|
|
29
29
|
for (const [s, a] of Object.entries(e)) {
|
|
30
30
|
if (a.derive) {
|
|
31
|
-
const
|
|
32
|
-
|
|
31
|
+
const i = a.derive(r);
|
|
32
|
+
i !== void 0 && (r[s] = i);
|
|
33
33
|
}
|
|
34
34
|
if (!(s in r)) {
|
|
35
35
|
if (a.required)
|
|
@@ -56,57 +56,57 @@ function q(t, e) {
|
|
|
56
56
|
derive: e
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
|
-
function
|
|
59
|
+
function c(t) {
|
|
60
60
|
return {
|
|
61
61
|
required: !0,
|
|
62
62
|
schema: t
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function f(t) {
|
|
66
66
|
return {
|
|
67
67
|
required: !1,
|
|
68
68
|
schema: t
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
-
var
|
|
72
|
-
type: u
|
|
73
|
-
id:
|
|
74
|
-
transports:
|
|
75
|
-
},
|
|
76
|
-
appid:
|
|
77
|
-
appidExclude:
|
|
78
|
-
credProps:
|
|
71
|
+
var N = {
|
|
72
|
+
type: c(u),
|
|
73
|
+
id: c(m),
|
|
74
|
+
transports: f(u)
|
|
75
|
+
}, J = {
|
|
76
|
+
appid: f(u),
|
|
77
|
+
appidExclude: f(u),
|
|
78
|
+
credProps: f(u)
|
|
79
79
|
}, P = {
|
|
80
|
-
appid:
|
|
81
|
-
appidExclude:
|
|
82
|
-
credProps:
|
|
83
|
-
},
|
|
84
|
-
publicKey:
|
|
85
|
-
rp: u
|
|
86
|
-
user:
|
|
87
|
-
id:
|
|
88
|
-
name: u
|
|
89
|
-
displayName: u
|
|
80
|
+
appid: f(u),
|
|
81
|
+
appidExclude: f(u),
|
|
82
|
+
credProps: f(u)
|
|
83
|
+
}, V = {
|
|
84
|
+
publicKey: c({
|
|
85
|
+
rp: c(u),
|
|
86
|
+
user: c({
|
|
87
|
+
id: c(m),
|
|
88
|
+
name: c(u),
|
|
89
|
+
displayName: c(u)
|
|
90
90
|
}),
|
|
91
|
-
challenge:
|
|
92
|
-
pubKeyCredParams: u
|
|
93
|
-
timeout:
|
|
94
|
-
excludeCredentials:
|
|
95
|
-
authenticatorSelection:
|
|
96
|
-
attestation:
|
|
97
|
-
extensions:
|
|
91
|
+
challenge: c(m),
|
|
92
|
+
pubKeyCredParams: c(u),
|
|
93
|
+
timeout: f(u),
|
|
94
|
+
excludeCredentials: f([N]),
|
|
95
|
+
authenticatorSelection: f(u),
|
|
96
|
+
attestation: f(u),
|
|
97
|
+
extensions: f(J)
|
|
98
98
|
}),
|
|
99
|
-
signal:
|
|
100
|
-
},
|
|
101
|
-
type: u
|
|
102
|
-
id: u
|
|
103
|
-
rawId:
|
|
104
|
-
authenticatorAttachment:
|
|
105
|
-
response:
|
|
106
|
-
clientDataJSON:
|
|
107
|
-
attestationObject:
|
|
99
|
+
signal: f(u)
|
|
100
|
+
}, T = {
|
|
101
|
+
type: c(u),
|
|
102
|
+
id: c(u),
|
|
103
|
+
rawId: c(m),
|
|
104
|
+
authenticatorAttachment: f(u),
|
|
105
|
+
response: c({
|
|
106
|
+
clientDataJSON: c(m),
|
|
107
|
+
attestationObject: c(m),
|
|
108
108
|
transports: q(
|
|
109
|
-
|
|
109
|
+
u,
|
|
110
110
|
(t) => {
|
|
111
111
|
var e;
|
|
112
112
|
return ((e = t.getTransports) == null ? void 0 : e.call(t)) || [];
|
|
@@ -118,26 +118,26 @@ var J = {
|
|
|
118
118
|
(t) => t.getClientExtensionResults()
|
|
119
119
|
)
|
|
120
120
|
}, K = {
|
|
121
|
-
mediation:
|
|
122
|
-
publicKey:
|
|
123
|
-
challenge:
|
|
124
|
-
timeout:
|
|
125
|
-
rpId:
|
|
126
|
-
allowCredentials:
|
|
127
|
-
userVerification:
|
|
128
|
-
extensions:
|
|
121
|
+
mediation: f(u),
|
|
122
|
+
publicKey: c({
|
|
123
|
+
challenge: c(m),
|
|
124
|
+
timeout: f(u),
|
|
125
|
+
rpId: f(u),
|
|
126
|
+
allowCredentials: f([N]),
|
|
127
|
+
userVerification: f(u),
|
|
128
|
+
extensions: f(J)
|
|
129
129
|
}),
|
|
130
|
-
signal:
|
|
130
|
+
signal: f(u)
|
|
131
131
|
}, D = {
|
|
132
|
-
type: u
|
|
133
|
-
id: u
|
|
134
|
-
rawId:
|
|
135
|
-
authenticatorAttachment:
|
|
136
|
-
response:
|
|
137
|
-
clientDataJSON:
|
|
138
|
-
authenticatorData:
|
|
139
|
-
signature:
|
|
140
|
-
userHandle:
|
|
132
|
+
type: c(u),
|
|
133
|
+
id: c(u),
|
|
134
|
+
rawId: c(m),
|
|
135
|
+
authenticatorAttachment: f(u),
|
|
136
|
+
response: c({
|
|
137
|
+
clientDataJSON: c(m),
|
|
138
|
+
authenticatorData: c(m),
|
|
139
|
+
signature: c(m),
|
|
140
|
+
userHandle: c(m)
|
|
141
141
|
}),
|
|
142
142
|
clientExtensionResults: q(
|
|
143
143
|
P,
|
|
@@ -145,12 +145,12 @@ var J = {
|
|
|
145
145
|
)
|
|
146
146
|
};
|
|
147
147
|
function B(t) {
|
|
148
|
-
return F(j,
|
|
148
|
+
return F(j, V, t);
|
|
149
149
|
}
|
|
150
150
|
function Q(t) {
|
|
151
151
|
return F(
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
L,
|
|
153
|
+
T,
|
|
154
154
|
t
|
|
155
155
|
);
|
|
156
156
|
}
|
|
@@ -159,7 +159,7 @@ function W(t) {
|
|
|
159
159
|
}
|
|
160
160
|
function $(t) {
|
|
161
161
|
return F(
|
|
162
|
-
|
|
162
|
+
L,
|
|
163
163
|
D,
|
|
164
164
|
t
|
|
165
165
|
);
|
|
@@ -187,7 +187,7 @@ const H = (t) => ({
|
|
|
187
187
|
})).webAuthnRequestOptions, s = W({
|
|
188
188
|
publicKey: n
|
|
189
189
|
}), a = await G(s);
|
|
190
|
-
await
|
|
190
|
+
await l(t, "webAuthnAssertion", {
|
|
191
191
|
username: e,
|
|
192
192
|
assertion: a.toJSON()
|
|
193
193
|
});
|
|
@@ -196,36 +196,43 @@ const H = (t) => ({
|
|
|
196
196
|
const e = await h(t, { webAuthnCreationOptions: !0 }), r = B({
|
|
197
197
|
publicKey: e.webAuthnCreationOptions
|
|
198
198
|
}), n = await z(r);
|
|
199
|
-
await
|
|
199
|
+
await l(t, "webAuthnRegister", {
|
|
200
200
|
registration: n.toJSON()
|
|
201
201
|
});
|
|
202
202
|
}
|
|
203
203
|
}), I = (t) => ({
|
|
204
204
|
WebAuthn: H(t),
|
|
205
|
-
|
|
205
|
+
facebookLogin: (e) => l(t, "facebookLogin", {
|
|
206
|
+
access_token: e
|
|
207
|
+
}),
|
|
208
|
+
microsoftLogin: (e) => l(t, "microsoftLogin", {
|
|
209
|
+
access_token: e
|
|
210
|
+
}),
|
|
211
|
+
googleLogin: (e) => l(t, "googleLogin", {
|
|
206
212
|
credential: e
|
|
207
213
|
}),
|
|
208
|
-
login: (e, r, n = "") =>
|
|
214
|
+
login: (e, r, n = "") => l(t, "login", {
|
|
209
215
|
username: e,
|
|
210
216
|
password: r,
|
|
211
217
|
code: n
|
|
212
218
|
}),
|
|
213
|
-
logout: () =>
|
|
214
|
-
updatePassword: (e, r) =>
|
|
219
|
+
logout: () => l(t, "logout"),
|
|
220
|
+
updatePassword: (e, r) => l(t, "updatePassword", {
|
|
215
221
|
old_password: e,
|
|
216
222
|
new_password: r
|
|
217
223
|
}),
|
|
218
|
-
resetPassword: (e, r, n) =>
|
|
219
|
-
|
|
224
|
+
resetPassword: (e, r, n) => l(t, "resetPassword", {
|
|
225
|
+
username: e,
|
|
220
226
|
password: r,
|
|
221
227
|
code: n
|
|
222
228
|
}),
|
|
223
|
-
forgetPassword: (e) =>
|
|
224
|
-
|
|
229
|
+
forgetPassword: (e, r) => l(t, "forgetPassword", {
|
|
230
|
+
username: e,
|
|
231
|
+
email: r
|
|
225
232
|
}),
|
|
226
233
|
verifyCode(e, r) {
|
|
227
|
-
return
|
|
228
|
-
|
|
234
|
+
return l(t, "forgetPasswordVerifyCode", {
|
|
235
|
+
username: e,
|
|
229
236
|
code: r
|
|
230
237
|
});
|
|
231
238
|
},
|
|
@@ -237,41 +244,41 @@ const H = (t) => ({
|
|
|
237
244
|
}
|
|
238
245
|
})).granted
|
|
239
246
|
}), M = (t, e, r) => {
|
|
240
|
-
const n = e, s = t, a = r,
|
|
247
|
+
const n = e, s = t, a = r, i = (o) => a[o] ? a[o]() : null;
|
|
241
248
|
return {
|
|
242
|
-
field:
|
|
249
|
+
field: i,
|
|
243
250
|
$fields: a,
|
|
244
|
-
gqlFields(
|
|
251
|
+
gqlFields(o) {
|
|
245
252
|
const p = [];
|
|
246
|
-
for (const
|
|
247
|
-
if (typeof
|
|
248
|
-
const g =
|
|
253
|
+
for (const d of o)
|
|
254
|
+
if (typeof d == "string") {
|
|
255
|
+
const g = i(d);
|
|
249
256
|
g && p.push(g.getGQLField());
|
|
250
|
-
} else typeof
|
|
257
|
+
} else typeof d == "object" && p.push(d);
|
|
251
258
|
return p;
|
|
252
259
|
},
|
|
253
|
-
async update(
|
|
254
|
-
return await
|
|
260
|
+
async update(o, p) {
|
|
261
|
+
return await l(s, "update" + n, { id: o, data: p });
|
|
255
262
|
},
|
|
256
|
-
async delete(
|
|
257
|
-
return await
|
|
263
|
+
async delete(o) {
|
|
264
|
+
return await l(s, "delete" + n, { id: o });
|
|
258
265
|
},
|
|
259
|
-
async add(
|
|
260
|
-
return await
|
|
266
|
+
async add(o) {
|
|
267
|
+
return await l(s, "add" + n, { data: o });
|
|
261
268
|
},
|
|
262
|
-
fields(
|
|
269
|
+
fields(o) {
|
|
263
270
|
let p = [];
|
|
264
|
-
for (let
|
|
265
|
-
const g =
|
|
271
|
+
for (let d of o) {
|
|
272
|
+
const g = i(d);
|
|
266
273
|
g && p.push(g);
|
|
267
274
|
}
|
|
268
275
|
return p;
|
|
269
276
|
},
|
|
270
|
-
async get(
|
|
277
|
+
async get(o, p) {
|
|
271
278
|
return (await h(s, {
|
|
272
279
|
["list" + n]: {
|
|
273
280
|
__args: {
|
|
274
|
-
filters:
|
|
281
|
+
filters: o
|
|
275
282
|
},
|
|
276
283
|
data: {
|
|
277
284
|
__args: {
|
|
@@ -282,11 +289,11 @@ const H = (t) => ({
|
|
|
282
289
|
}
|
|
283
290
|
}))["list" + n].data[0];
|
|
284
291
|
},
|
|
285
|
-
async list(
|
|
292
|
+
async list(o, p) {
|
|
286
293
|
return (await h(s, {
|
|
287
294
|
["list" + n]: {
|
|
288
295
|
__args: {
|
|
289
|
-
filters:
|
|
296
|
+
filters: o
|
|
290
297
|
},
|
|
291
298
|
data: {
|
|
292
299
|
...A(p)
|
|
@@ -298,17 +305,17 @@ const H = (t) => ({
|
|
|
298
305
|
};
|
|
299
306
|
function X(t) {
|
|
300
307
|
t = "<~" + t + "~>";
|
|
301
|
-
var e, r, n, s, a,
|
|
302
|
-
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, n = [], s = 0, a = t.length; a > s; s += 5) r = 52200625 * (t.charCodeAt(s) - 33) + 614125 * (t.charCodeAt(s + 1) - 33) + 7225 * (t.charCodeAt(s + 2) - 33) + 85 * (t.charCodeAt(s + 3) - 33) + (t.charCodeAt(s + 4) - 33), n.push(
|
|
303
|
-
return function(p,
|
|
304
|
-
for (var g =
|
|
305
|
-
}(n, e.length),
|
|
308
|
+
var e, r, n, s, a, i = String, o = 255;
|
|
309
|
+
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, n = [], s = 0, a = t.length; a > s; s += 5) r = 52200625 * (t.charCodeAt(s) - 33) + 614125 * (t.charCodeAt(s + 1) - 33) + 7225 * (t.charCodeAt(s + 2) - 33) + 85 * (t.charCodeAt(s + 3) - 33) + (t.charCodeAt(s + 4) - 33), n.push(o & r >> 24, o & r >> 16, o & r >> 8, o & r);
|
|
310
|
+
return function(p, d) {
|
|
311
|
+
for (var g = d; g > 0; g--) p.pop();
|
|
312
|
+
}(n, e.length), i.fromCharCode.apply(i, n);
|
|
306
313
|
}
|
|
307
314
|
const v = (t = "") => {
|
|
308
315
|
const e = t, r = (n = "application/octet-stream") => {
|
|
309
316
|
const s = new Uint8Array(e.length);
|
|
310
|
-
for (let
|
|
311
|
-
s[
|
|
317
|
+
for (let o = 0; o < e.length; o++)
|
|
318
|
+
s[o] = e.charCodeAt(o);
|
|
312
319
|
const a = new Blob([s], { type: n });
|
|
313
320
|
return URL.createObjectURL(a);
|
|
314
321
|
};
|
|
@@ -323,7 +330,7 @@ const v = (t = "") => {
|
|
|
323
330
|
window.open(r(n), "_blank");
|
|
324
331
|
}
|
|
325
332
|
};
|
|
326
|
-
},
|
|
333
|
+
}, oe = {
|
|
327
334
|
fromBase85: (t) => v(X(t)),
|
|
328
335
|
fromBase64: (t) => v(atob(t)),
|
|
329
336
|
fromString: (t) => v(t)
|
|
@@ -365,41 +372,41 @@ function Z(t) {
|
|
|
365
372
|
return !0;
|
|
366
373
|
return !1;
|
|
367
374
|
}
|
|
368
|
-
const
|
|
375
|
+
const l = async (t, e, r = null, n = []) => {
|
|
369
376
|
let s = {
|
|
370
377
|
[e]: {}
|
|
371
378
|
};
|
|
372
379
|
const a = new FormData();
|
|
373
|
-
let
|
|
380
|
+
let i = !1;
|
|
374
381
|
if (r) {
|
|
375
|
-
const
|
|
382
|
+
const d = {}, g = {}, O = {};
|
|
376
383
|
let b = 0;
|
|
377
384
|
Object.entries(r).forEach(([w, _]) => {
|
|
378
385
|
if (_ instanceof Array && Y(_)) {
|
|
379
|
-
|
|
386
|
+
i = !0;
|
|
380
387
|
let y = 0;
|
|
381
388
|
_.forEach((C) => {
|
|
382
|
-
C instanceof File && (
|
|
389
|
+
C instanceof File && (d[w] = new S(w), g[b] = ["variables." + w + "." + y], a.append(b.toString(), C), b++);
|
|
383
390
|
}), O[w] = "[Upload!]!";
|
|
384
|
-
} else _ instanceof File ? (
|
|
385
|
-
C instanceof File ? (
|
|
386
|
-
})) : _ !== void 0 && (
|
|
387
|
-
}), s[e].__args =
|
|
391
|
+
} else _ instanceof File ? (i = !0, d[w] = new S(w), g[b] = ["variables." + w], a.append(b.toString(), _), O[w] = "Upload!", b++) : _ instanceof Object && Z(_) ? (i = !0, d[w] = {}, Object.entries(_).forEach(([y, C]) => {
|
|
392
|
+
C instanceof File ? (d[w][y] = new S(y), g[b] = ["variables." + y], a.append(b.toString(), C), O[y] = "Upload!", b++) : d[w][y] = C;
|
|
393
|
+
})) : _ !== void 0 && (d[w] = _);
|
|
394
|
+
}), s[e].__args = d, s.__variables = O, i && a.append("map", JSON.stringify(g));
|
|
388
395
|
}
|
|
389
|
-
Object.entries(A(n)).forEach(([
|
|
390
|
-
s[e][
|
|
396
|
+
Object.entries(A(n)).forEach(([d, g]) => {
|
|
397
|
+
s[e][d] = g;
|
|
391
398
|
}), Object.entries(s[e]).length === 0 && (s[e] = !0);
|
|
392
|
-
let
|
|
399
|
+
let o = null;
|
|
393
400
|
const p = E({ mutation: s });
|
|
394
|
-
if (
|
|
401
|
+
if (i ? (a.append("operations", JSON.stringify({
|
|
395
402
|
query: p
|
|
396
|
-
})),
|
|
403
|
+
})), o = await t.post("", a)) : o = await t.post("", {
|
|
397
404
|
query: p
|
|
398
|
-
}),
|
|
399
|
-
throw new Error(
|
|
400
|
-
return
|
|
405
|
+
}), o.data.errors)
|
|
406
|
+
throw new Error(o.data.errors[0].message);
|
|
407
|
+
return o.data.data[e];
|
|
401
408
|
}, x = (t) => ({
|
|
402
|
-
uploadTempFile: (e) =>
|
|
409
|
+
uploadTempFile: (e) => l(t, "fsUploadTempFile", {
|
|
403
410
|
file: e
|
|
404
411
|
}, {
|
|
405
412
|
name: !0,
|
|
@@ -417,9 +424,9 @@ const c = async (t, e, r = null, n = []) => {
|
|
|
417
424
|
path: !0
|
|
418
425
|
}
|
|
419
426
|
})).fsListFolders,
|
|
420
|
-
create: (e) =>
|
|
421
|
-
delete: (e) =>
|
|
422
|
-
rename: (e, r) =>
|
|
427
|
+
create: (e) => l(t, "fsCreateFolder", { path: e }),
|
|
428
|
+
delete: (e) => l(t, "fsDeleteFolder", { path: e }),
|
|
429
|
+
rename: (e, r) => l(t, "fsRenameFolder", { path: e, name: r })
|
|
423
430
|
},
|
|
424
431
|
files: {
|
|
425
432
|
list: async (e) => (await h(t, {
|
|
@@ -446,13 +453,13 @@ const c = async (t, e, r = null, n = []) => {
|
|
|
446
453
|
});
|
|
447
454
|
return window.atob(r.fsFile.base64Content);
|
|
448
455
|
},
|
|
449
|
-
write: (e, r) =>
|
|
456
|
+
write: (e, r) => l(t, "fsWriteFile", {
|
|
450
457
|
path: e,
|
|
451
458
|
content: r
|
|
452
459
|
}),
|
|
453
|
-
delete: (e) =>
|
|
454
|
-
rename: (e, r) =>
|
|
455
|
-
move: (e, r) =>
|
|
460
|
+
delete: (e) => l(t, "fsDeleteFile", { path: e }),
|
|
461
|
+
rename: (e, r) => l(t, "fsRenameFile", { path: e, name: r }),
|
|
462
|
+
move: (e, r) => l(t, "fsMoveFile", { source: e, target: r })
|
|
456
463
|
}
|
|
457
464
|
}), k = (t) => ({
|
|
458
465
|
get: async (e) => (await t({
|
|
@@ -463,7 +470,7 @@ const c = async (t, e, r = null, n = []) => {
|
|
|
463
470
|
}
|
|
464
471
|
})).config
|
|
465
472
|
}), ee = (t) => ({
|
|
466
|
-
send: (e, r, n) =>
|
|
473
|
+
send: (e, r, n) => l(t, "sendMail", {
|
|
467
474
|
email: e,
|
|
468
475
|
subject: r,
|
|
469
476
|
message: n
|
|
@@ -495,12 +502,12 @@ const c = async (t, e, r = null, n = []) => {
|
|
|
495
502
|
getRaw() {
|
|
496
503
|
return a;
|
|
497
504
|
},
|
|
498
|
-
getValue(
|
|
499
|
-
return a.field && typeof a.field == "function" ? a.field(
|
|
505
|
+
getValue(i) {
|
|
506
|
+
return a.field && typeof a.field == "function" ? a.field(i) : a.field && typeof a.field == "string" ? i[a.field] : i[this.getName()];
|
|
500
507
|
},
|
|
501
|
-
getFormattedValue(
|
|
502
|
-
const
|
|
503
|
-
return a.format ? a.format(
|
|
508
|
+
getFormattedValue(i) {
|
|
509
|
+
const o = this.getValue(i);
|
|
510
|
+
return a.format ? a.format(o) : o;
|
|
504
511
|
}
|
|
505
512
|
});
|
|
506
513
|
}
|
|
@@ -516,11 +523,11 @@ const c = async (t, e, r = null, n = []) => {
|
|
|
516
523
|
name: !0
|
|
517
524
|
}
|
|
518
525
|
})).listRole
|
|
519
|
-
}),
|
|
526
|
+
}), ie = (t) => {
|
|
520
527
|
const e = U.create({
|
|
521
528
|
baseURL: t,
|
|
522
529
|
withCredentials: !0
|
|
523
|
-
}), r = (a,
|
|
530
|
+
}), r = (a, i = null, o = []) => l(e, a, i, o), n = (a) => h(e, a), s = re();
|
|
524
531
|
return {
|
|
525
532
|
baseURL: t,
|
|
526
533
|
axios: e,
|
|
@@ -539,10 +546,10 @@ const c = async (t, e, r = null, n = []) => {
|
|
|
539
546
|
};
|
|
540
547
|
};
|
|
541
548
|
export {
|
|
542
|
-
|
|
543
|
-
|
|
549
|
+
oe as File,
|
|
550
|
+
ie as createClient,
|
|
544
551
|
v as file,
|
|
545
|
-
|
|
552
|
+
l as mutation,
|
|
546
553
|
h as query,
|
|
547
554
|
A as toQuery
|
|
548
555
|
};
|
package/dist/light.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(m,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("json-to-graphql-query"),require("axios")):typeof define=="function"&&define.amd?define(["exports","json-to-graphql-query","axios"],y):(m=typeof globalThis<"u"?globalThis:m||self,y(m.light={},m.jsonToGraphqlQuery,m.axios))})(this,function(m,y,T){"use strict";function E(t){const e="==".slice(0,(4-t.length%4)%4),r=t.replace(/-/g,"+").replace(/_/g,"/")+e,n=atob(r),s=new ArrayBuffer(n.length),a=new Uint8Array(s);for(let u=0;u<n.length;u++)a[u]=n.charCodeAt(u);return s}function L(t){const e=new Uint8Array(t);let r="";for(const a of e)r+=String.fromCharCode(a);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var o="copy",h="convert";function O(t,e,r){if(e===o)return r;if(e===h)return t(r);if(e instanceof Array)return r.map(n=>O(t,e[0],n));if(e instanceof Object){const n={};for(const[s,a]of Object.entries(e)){if(a.derive){const u=a.derive(r);u!==void 0&&(r[s]=u)}if(!(s in r)){if(a.required)throw new Error(`Missing key: ${s}`);continue}if(r[s]==null){n[s]=null;continue}n[s]=O(t,a.schema,r[s])}return n}}function j(t,e){return{required:!0,schema:t,derive:e}}function c(t){return{required:!0,schema:t}}function f(t){return{required:!1,schema:t}}var N={type:c(o),id:c(h),transports:f(o)},J={appid:f(o),appidExclude:f(o),credProps:f(o)},P={appid:f(o),appidExclude:f(o),credProps:f(o)},V={publicKey:c({rp:c(o),user:c({id:c(h),name:c(o),displayName:c(o)}),challenge:c(h),pubKeyCredParams:c(o),timeout:f(o),excludeCredentials:f([N]),authenticatorSelection:f(o),attestation:f(o),extensions:f(J)}),signal:f(o)},U={type:c(o),id:c(o),rawId:c(h),authenticatorAttachment:f(o),response:c({clientDataJSON:c(h),attestationObject:c(h),transports:j(o,t=>{var e;return((e=t.getTransports)==null?void 0:e.call(t))||[]})}),clientExtensionResults:j(P,t=>t.getClientExtensionResults())},K={mediation:f(o),publicKey:c({challenge:c(h),timeout:f(o),rpId:f(o),allowCredentials:f([N]),userVerification:f(o),extensions:f(J)}),signal:f(o)},D={type:c(o),id:c(o),rawId:c(h),authenticatorAttachment:f(o),response:c({clientDataJSON:c(h),authenticatorData:c(h),signature:c(h),userHandle:c(h)}),clientExtensionResults:j(P,t=>t.getClientExtensionResults())};function B(t){return O(E,V,t)}function Q(t){return O(L,U,t)}function W(t){return O(E,K,t)}function M(t){return O(L,D,t)}async function $(t){const e=await navigator.credentials.create(t);return e.toJSON=()=>Q(e),e}async function z(t){const e=await navigator.credentials.get(t);return e.toJSON=()=>M(e),e}const H=t=>({login:async e=>{const n=(await w(t,{webAuthnRequestOptions:{__args:{username:e}}})).webAuthnRequestOptions,s=W({publicKey:n}),a=await z(s);await l(t,"webAuthnAssertion",{username:e,assertion:a.toJSON()})},register:async()=>{const e=await w(t,{webAuthnCreationOptions:!0}),r=B({publicKey:e.webAuthnCreationOptions}),n=await $(r);await l(t,"webAuthnRegister",{registration:n.toJSON()})}}),I=t=>({WebAuthn:H(t),facebookLogin:e=>l(t,"facebookLogin",{access_token:e}),microsoftLogin:e=>l(t,"microsoftLogin",{access_token:e}),googleLogin:e=>l(t,"googleLogin",{credential:e}),login:(e,r,n="")=>l(t,"login",{username:e,password:r,code:n}),logout:()=>l(t,"logout"),updatePassword:(e,r)=>l(t,"updatePassword",{old_password:e,new_password:r}),resetPassword:(e,r,n)=>l(t,"resetPassword",{username:e,password:r,code:n}),forgetPassword:(e,r)=>l(t,"forgetPassword",{username:e,email:r}),verifyCode(e,r){return l(t,"forgetPasswordVerifyCode",{username:e,code:r})},granted:async e=>(await w(t,{granted:{__args:{rights:e}}})).granted}),G=(t,e,r)=>{const n=e,s=t,a=r,u=i=>a[i]?a[i]():null;return{field:u,$fields:a,gqlFields(i){const p=[];for(const d of i)if(typeof d=="string"){const g=u(d);g&&p.push(g.getGQLField())}else typeof d=="object"&&p.push(d);return p},async update(i,p){return await l(s,"update"+n,{id:i,data:p})},async delete(i){return await l(s,"delete"+n,{id:i})},async add(i){return await l(s,"add"+n,{data:i})},fields(i){let p=[];for(let d of i){const g=u(d);g&&p.push(g)}return p},async get(i,p){return(await w(s,{["list"+n]:{__args:{filters:i},data:{__args:{limit:1},...S(p)}}}))["list"+n].data[0]},async list(i,p){return(await w(s,{["list"+n]:{__args:{filters:i},data:{...S(p)}}}))["list"+n].data}}};function X(t){t="<~"+t+"~>";var e,r,n,s,a,u=String,i=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,n=[],s=0,a=t.length;a>s;s+=5)r=52200625*(t.charCodeAt(s)-33)+614125*(t.charCodeAt(s+1)-33)+7225*(t.charCodeAt(s+2)-33)+85*(t.charCodeAt(s+3)-33)+(t.charCodeAt(s+4)-33),n.push(i&r>>24,i&r>>16,i&r>>8,i&r);return function(p,d){for(var g=d;g>0;g--)p.pop()}(n,e.length),u.fromCharCode.apply(u,n)}const q=(t="")=>{const e=t,r=(n="application/octet-stream")=>{const s=new Uint8Array(e.length);for(let i=0;i<e.length;i++)s[i]=e.charCodeAt(i);const a=new Blob([s],{type:n});return URL.createObjectURL(a)};return{getContent:()=>e,getURL:r,download:n=>{const s=document.createElement("a");s.download=n,s.href=r(),document.body.appendChild(s),s.click(),document.body.removeChild(s)},open:n=>{window.open(r(n),"_blank")}}},Y={fromBase85:t=>q(X(t)),fromBase64:t=>q(atob(t)),fromString:t=>q(t)},R=t=>{let e={};return typeof t=="string"?(e[t]=!0,e):t instanceof Array?(t.forEach(r=>{Object.entries(R(r)).forEach(([n,s])=>{e[n]=s})}),e):(Object.entries(t).forEach(([r,n])=>{if(r=="__args"||r=="__aliasFor"||r=="__variables"||r=="__directives"||r=="__all_on"||r=="__name"){e[r]=n;return}if(typeof n=="boolean"){e[r]=n;return}e[r]=R(n)}),e)},S=t=>R(t),w=async(t,e)=>{let r=y.jsonToGraphQLQuery(S(e));const n=await t.post("",{query:`{ ${r} }`});if(n.data.errors)throw new Error(n.data.errors[0].message);return n.data.data};function Z(t){for(let e=0;e<t.length;e++)if(t[e]instanceof File)return!0;return!1}function x(t){for(let e in t)if(t[e]instanceof File)return!0;return!1}const l=async(t,e,r=null,n=[])=>{let s={[e]:{}};const a=new FormData;let u=!1;if(r){const d={},g={},v={};let C=0;Object.entries(r).forEach(([b,_])=>{if(_ instanceof Array&&Z(_)){u=!0;let F=0;_.forEach(A=>{A instanceof File&&(d[b]=new y.VariableType(b),g[C]=["variables."+b+"."+F],a.append(C.toString(),A),C++)}),v[b]="[Upload!]!"}else _ instanceof File?(u=!0,d[b]=new y.VariableType(b),g[C]=["variables."+b],a.append(C.toString(),_),v[b]="Upload!",C++):_ instanceof Object&&x(_)?(u=!0,d[b]={},Object.entries(_).forEach(([F,A])=>{A instanceof File?(d[b][F]=new y.VariableType(F),g[C]=["variables."+F],a.append(C.toString(),A),v[F]="Upload!",C++):d[b][F]=A})):_!==void 0&&(d[b]=_)}),s[e].__args=d,s.__variables=v,u&&a.append("map",JSON.stringify(g))}Object.entries(S(n)).forEach(([d,g])=>{s[e][d]=g}),Object.entries(s[e]).length===0&&(s[e]=!0);let i=null;const p=y.jsonToGraphQLQuery({mutation:s});if(u?(a.append("operations",JSON.stringify({query:p})),i=await t.post("",a)):i=await t.post("",{query:p}),i.data.errors)throw new Error(i.data.errors[0].message);return i.data.data[e]},k=t=>({uploadTempFile:e=>l(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=>l(t,"fsCreateFolder",{path:e}),delete:e=>l(t,"fsDeleteFolder",{path:e}),rename:(e,r)=>l(t,"fsRenameFolder",{path:e,name:r})},files:{list:async e=>(await w(t,{fsListFiles:{__args:{path:e},name:!0,path:!0,size:!0,mime:!0,canPreview:!0,imagePath:!0}})).fsListFiles,read:async e=>{let r=await w(t,{fsFile:{__args:{path:e},base64Content:!0}});return window.atob(r.fsFile.base64Content)},write:(e,r)=>l(t,"fsWriteFile",{path:e,content:r}),delete:e=>l(t,"fsDeleteFile",{path:e}),rename:(e,r)=>l(t,"fsRenameFile",{path:e,name:r}),move:(e,r)=>l(t,"fsMoveFile",{source:e,target:r})}}),ee=t=>({get:async e=>(await t({config:{__args:{name:e}}})).config}),te=t=>({send:(e,r,n)=>l(t,"sendMail",{email:e,subject:r,message:n})}),re=t=>({list:async()=>(await w(t,{listUser:{data:{user_id:!0,username:!0,first_name:!0,last_name:!0,status:!0}}})).listUser.data}),ne=()=>{const t={};return{create(e,r){t[e]={};for(const n of Object.entries(r)){const[s,a]=n;t[e][s]=()=>({name:a.name?a.name:s,raw:a,getName:()=>a.name?a.name:s,getGQLField:()=>a.gqlField!==void 0?a.gqlField:a.name||s,getRaw(){return a},getValue(u){return a.field&&typeof a.field=="function"?a.field(u):a.field&&typeof a.field=="string"?u[a.field]:u[this.getName()]},getFormattedValue(u){const i=this.getValue(u);return a.format?a.format(i):i}})}return t[e]},get(e){return t[e]}}},se=t=>({list:async()=>(await w(t,{listRole:{name:!0}})).listRole}),ae=t=>{const e=T.create({baseURL:t,withCredentials:!0}),r=(a,u=null,i=[])=>l(e,a,u,i),n=a=>w(e,a),s=ne();return{baseURL:t,axios:e,auth:I(e),mutation:r,query:n,config:ee(n),mail:te(e),users:re(e),fs:k(e),models:s,model(a){return G(e,a,s.get(a))},roles:se(e)}};m.File=Y,m.createClient=ae,m.file=q,m.mutation=l,m.query=w,m.toQuery=S,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hostlink/light",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"dev": "vite --host",
|
|
19
19
|
"build": "tsc && vite build",
|
|
20
20
|
"preview": "vite preview",
|
|
21
|
-
"release": "npm run build && npm
|
|
21
|
+
"release": "npm run build && npm publish --access public && git push --follow-tags",
|
|
22
22
|
"test": "vitest"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|