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