@hostlink/light 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/light.js +213 -204
- package/dist/light.umd.cjs +1 -1
- package/package.json +1 -1
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
11
|
resetPassword: (email: string, password: string, code: string) => Promise<boolean>;
|
|
11
12
|
forgetPassword: (email: string) => Promise<boolean>;
|
|
13
|
+
verifyCode(email: 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,179 @@ 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
|
-
email:
|
|
218
|
+
resetPassword: (e, r, n) => c(t, "resetPassword", {
|
|
219
|
+
email: e,
|
|
217
220
|
password: r,
|
|
218
221
|
code: n
|
|
219
222
|
}),
|
|
220
|
-
forgetPassword: (
|
|
221
|
-
email:
|
|
223
|
+
forgetPassword: (e) => c(t, "forgetPassword", {
|
|
224
|
+
email: e
|
|
222
225
|
}),
|
|
223
|
-
|
|
226
|
+
verifyCode(e, r) {
|
|
227
|
+
return c(t, "verifyCode", {
|
|
228
|
+
email: e,
|
|
229
|
+
code: r
|
|
230
|
+
});
|
|
231
|
+
},
|
|
232
|
+
granted: async (e) => (await h(t, {
|
|
224
233
|
granted: {
|
|
225
234
|
__args: {
|
|
226
|
-
rights:
|
|
235
|
+
rights: e
|
|
227
236
|
}
|
|
228
237
|
}
|
|
229
238
|
})).granted
|
|
230
|
-
}), M = (
|
|
231
|
-
const n =
|
|
239
|
+
}), M = (t, e, r) => {
|
|
240
|
+
const n = e, s = t, a = r, o = (i) => a[i] ? a[i]() : null;
|
|
232
241
|
return {
|
|
233
242
|
field: o,
|
|
234
243
|
$fields: a,
|
|
235
244
|
gqlFields(i) {
|
|
236
245
|
const p = [];
|
|
237
|
-
for (const
|
|
238
|
-
if (typeof
|
|
239
|
-
const g = o(
|
|
246
|
+
for (const f of i)
|
|
247
|
+
if (typeof f == "string") {
|
|
248
|
+
const g = o(f);
|
|
240
249
|
g && p.push(g.getGQLField());
|
|
241
|
-
} else typeof
|
|
250
|
+
} else typeof f == "object" && p.push(f);
|
|
242
251
|
return p;
|
|
243
252
|
},
|
|
244
253
|
async update(i, p) {
|
|
245
|
-
return await
|
|
254
|
+
return await c(s, "update" + n, { id: i, data: p });
|
|
246
255
|
},
|
|
247
256
|
async delete(i) {
|
|
248
|
-
return await
|
|
257
|
+
return await c(s, "delete" + n, { id: i });
|
|
249
258
|
},
|
|
250
259
|
async add(i) {
|
|
251
|
-
return await
|
|
260
|
+
return await c(s, "add" + n, { data: i });
|
|
252
261
|
},
|
|
253
262
|
fields(i) {
|
|
254
263
|
let p = [];
|
|
255
|
-
for (let
|
|
256
|
-
const g = o(
|
|
264
|
+
for (let f of i) {
|
|
265
|
+
const g = o(f);
|
|
257
266
|
g && p.push(g);
|
|
258
267
|
}
|
|
259
268
|
return p;
|
|
@@ -287,24 +296,24 @@ const H = (e) => ({
|
|
|
287
296
|
}
|
|
288
297
|
};
|
|
289
298
|
};
|
|
290
|
-
function X(
|
|
291
|
-
|
|
292
|
-
var
|
|
293
|
-
for (
|
|
294
|
-
return function(p,
|
|
295
|
-
for (var g =
|
|
296
|
-
}(n,
|
|
299
|
+
function X(t) {
|
|
300
|
+
t = "<~" + t + "~>";
|
|
301
|
+
var e, r, n, s, a, o = String, i = 255;
|
|
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(i & r >> 24, i & r >> 16, i & r >> 8, i & r);
|
|
303
|
+
return function(p, f) {
|
|
304
|
+
for (var g = f; g > 0; g--) p.pop();
|
|
305
|
+
}(n, e.length), o.fromCharCode.apply(o, n);
|
|
297
306
|
}
|
|
298
|
-
const
|
|
299
|
-
const
|
|
300
|
-
const s = new Uint8Array(
|
|
301
|
-
for (let i = 0; i <
|
|
302
|
-
s[i] =
|
|
307
|
+
const v = (t = "") => {
|
|
308
|
+
const e = t, r = (n = "application/octet-stream") => {
|
|
309
|
+
const s = new Uint8Array(e.length);
|
|
310
|
+
for (let i = 0; i < e.length; i++)
|
|
311
|
+
s[i] = e.charCodeAt(i);
|
|
303
312
|
const a = new Blob([s], { type: n });
|
|
304
313
|
return URL.createObjectURL(a);
|
|
305
314
|
};
|
|
306
315
|
return {
|
|
307
|
-
getContent: () =>
|
|
316
|
+
getContent: () => e,
|
|
308
317
|
getURL: r,
|
|
309
318
|
download: (n) => {
|
|
310
319
|
const s = document.createElement("a");
|
|
@@ -315,83 +324,83 @@ const q = (e = "") => {
|
|
|
315
324
|
}
|
|
316
325
|
};
|
|
317
326
|
}, ie = {
|
|
318
|
-
fromBase85: (
|
|
319
|
-
fromBase64: (
|
|
320
|
-
fromString: (
|
|
321
|
-
}, R = (
|
|
322
|
-
let
|
|
323
|
-
return typeof
|
|
327
|
+
fromBase85: (t) => v(X(t)),
|
|
328
|
+
fromBase64: (t) => v(atob(t)),
|
|
329
|
+
fromString: (t) => v(t)
|
|
330
|
+
}, R = (t) => {
|
|
331
|
+
let e = {};
|
|
332
|
+
return typeof t == "string" ? (e[t] = !0, e) : t instanceof Array ? (t.forEach((r) => {
|
|
324
333
|
Object.entries(R(r)).forEach(([n, s]) => {
|
|
325
|
-
|
|
334
|
+
e[n] = s;
|
|
326
335
|
});
|
|
327
|
-
}),
|
|
336
|
+
}), e) : (Object.entries(t).forEach(([r, n]) => {
|
|
328
337
|
if (r == "__args" || r == "__aliasFor" || r == "__variables" || r == "__directives" || r == "__all_on" || r == "__name") {
|
|
329
|
-
|
|
338
|
+
e[r] = n;
|
|
330
339
|
return;
|
|
331
340
|
}
|
|
332
341
|
if (typeof n == "boolean") {
|
|
333
|
-
|
|
342
|
+
e[r] = n;
|
|
334
343
|
return;
|
|
335
344
|
}
|
|
336
|
-
|
|
337
|
-
}),
|
|
338
|
-
}, A = (
|
|
339
|
-
let r = E(A(
|
|
340
|
-
const n = await
|
|
345
|
+
e[r] = R(n);
|
|
346
|
+
}), e);
|
|
347
|
+
}, A = (t) => R(t), h = async (t, e) => {
|
|
348
|
+
let r = E(A(e));
|
|
349
|
+
const n = await t.post("", {
|
|
341
350
|
query: `{ ${r} }`
|
|
342
351
|
});
|
|
343
352
|
if (n.data.errors)
|
|
344
353
|
throw new Error(n.data.errors[0].message);
|
|
345
354
|
return n.data.data;
|
|
346
355
|
};
|
|
347
|
-
function Y(
|
|
348
|
-
for (let
|
|
349
|
-
if (e
|
|
356
|
+
function Y(t) {
|
|
357
|
+
for (let e = 0; e < t.length; e++)
|
|
358
|
+
if (t[e] instanceof File)
|
|
350
359
|
return !0;
|
|
351
360
|
return !1;
|
|
352
361
|
}
|
|
353
|
-
function Z(
|
|
354
|
-
for (let
|
|
355
|
-
if (e
|
|
362
|
+
function Z(t) {
|
|
363
|
+
for (let e in t)
|
|
364
|
+
if (t[e] instanceof File)
|
|
356
365
|
return !0;
|
|
357
366
|
return !1;
|
|
358
367
|
}
|
|
359
|
-
const
|
|
368
|
+
const c = async (t, e, r = null, n = []) => {
|
|
360
369
|
let s = {
|
|
361
|
-
[
|
|
370
|
+
[e]: {}
|
|
362
371
|
};
|
|
363
372
|
const a = new FormData();
|
|
364
373
|
let o = !1;
|
|
365
374
|
if (r) {
|
|
366
|
-
const
|
|
375
|
+
const f = {}, g = {}, O = {};
|
|
367
376
|
let b = 0;
|
|
368
377
|
Object.entries(r).forEach(([w, _]) => {
|
|
369
378
|
if (_ instanceof Array && Y(_)) {
|
|
370
379
|
o = !0;
|
|
371
380
|
let y = 0;
|
|
372
|
-
_.forEach((
|
|
373
|
-
|
|
381
|
+
_.forEach((C) => {
|
|
382
|
+
C instanceof File && (f[w] = new S(w), g[b] = ["variables." + w + "." + y], a.append(b.toString(), C), b++);
|
|
374
383
|
}), O[w] = "[Upload!]!";
|
|
375
|
-
} else _ instanceof File ? (o = !0,
|
|
376
|
-
|
|
377
|
-
})) : _ !== void 0 && (
|
|
378
|
-
}), s[
|
|
384
|
+
} 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]) => {
|
|
385
|
+
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;
|
|
386
|
+
})) : _ !== void 0 && (f[w] = _);
|
|
387
|
+
}), s[e].__args = f, s.__variables = O, o && a.append("map", JSON.stringify(g));
|
|
379
388
|
}
|
|
380
|
-
Object.entries(A(n)).forEach(([
|
|
381
|
-
s[
|
|
382
|
-
}), Object.entries(s[
|
|
389
|
+
Object.entries(A(n)).forEach(([f, g]) => {
|
|
390
|
+
s[e][f] = g;
|
|
391
|
+
}), Object.entries(s[e]).length === 0 && (s[e] = !0);
|
|
383
392
|
let i = null;
|
|
384
393
|
const p = E({ mutation: s });
|
|
385
394
|
if (o ? (a.append("operations", JSON.stringify({
|
|
386
395
|
query: p
|
|
387
|
-
})), i = await
|
|
396
|
+
})), i = await t.post("", a)) : i = await t.post("", {
|
|
388
397
|
query: p
|
|
389
398
|
}), i.data.errors)
|
|
390
399
|
throw new Error(i.data.errors[0].message);
|
|
391
|
-
return i.data.data[
|
|
392
|
-
}, x = (
|
|
393
|
-
uploadTempFile: (
|
|
394
|
-
file:
|
|
400
|
+
return i.data.data[e];
|
|
401
|
+
}, x = (t) => ({
|
|
402
|
+
uploadTempFile: (e) => c(t, "fsUploadTempFile", {
|
|
403
|
+
file: e
|
|
395
404
|
}, {
|
|
396
405
|
name: !0,
|
|
397
406
|
path: !0,
|
|
@@ -399,24 +408,24 @@ const f = async (e, t, r = null, n = []) => {
|
|
|
399
408
|
mime: !0
|
|
400
409
|
}),
|
|
401
410
|
folders: {
|
|
402
|
-
list: async (
|
|
411
|
+
list: async (e) => (await h(t, {
|
|
403
412
|
fsListFolders: {
|
|
404
413
|
__args: {
|
|
405
|
-
path:
|
|
414
|
+
path: e
|
|
406
415
|
},
|
|
407
416
|
name: !0,
|
|
408
417
|
path: !0
|
|
409
418
|
}
|
|
410
419
|
})).fsListFolders,
|
|
411
|
-
create: (
|
|
412
|
-
delete: (
|
|
413
|
-
rename: (
|
|
420
|
+
create: (e) => c(t, "fsCreateFolder", { path: e }),
|
|
421
|
+
delete: (e) => c(t, "fsDeleteFolder", { path: e }),
|
|
422
|
+
rename: (e, r) => c(t, "fsRenameFolder", { path: e, name: r })
|
|
414
423
|
},
|
|
415
424
|
files: {
|
|
416
|
-
list: async (
|
|
425
|
+
list: async (e) => (await h(t, {
|
|
417
426
|
fsListFiles: {
|
|
418
427
|
__args: {
|
|
419
|
-
path:
|
|
428
|
+
path: e
|
|
420
429
|
},
|
|
421
430
|
name: !0,
|
|
422
431
|
path: !0,
|
|
@@ -426,41 +435,41 @@ const f = async (e, t, r = null, n = []) => {
|
|
|
426
435
|
imagePath: !0
|
|
427
436
|
}
|
|
428
437
|
})).fsListFiles,
|
|
429
|
-
read: async (
|
|
430
|
-
let r = await h(
|
|
438
|
+
read: async (e) => {
|
|
439
|
+
let r = await h(t, {
|
|
431
440
|
fsFile: {
|
|
432
441
|
__args: {
|
|
433
|
-
path:
|
|
442
|
+
path: e
|
|
434
443
|
},
|
|
435
444
|
base64Content: !0
|
|
436
445
|
}
|
|
437
446
|
});
|
|
438
447
|
return window.atob(r.fsFile.base64Content);
|
|
439
448
|
},
|
|
440
|
-
write: (
|
|
441
|
-
path:
|
|
449
|
+
write: (e, r) => c(t, "fsWriteFile", {
|
|
450
|
+
path: e,
|
|
442
451
|
content: r
|
|
443
452
|
}),
|
|
444
|
-
delete: (
|
|
445
|
-
rename: (
|
|
446
|
-
move: (
|
|
453
|
+
delete: (e) => c(t, "fsDeleteFile", { path: e }),
|
|
454
|
+
rename: (e, r) => c(t, "fsRenameFile", { path: e, name: r }),
|
|
455
|
+
move: (e, r) => c(t, "fsMoveFile", { source: e, target: r })
|
|
447
456
|
}
|
|
448
|
-
}), k = (
|
|
449
|
-
get: async (
|
|
457
|
+
}), k = (t) => ({
|
|
458
|
+
get: async (e) => (await t({
|
|
450
459
|
config: {
|
|
451
460
|
__args: {
|
|
452
|
-
name:
|
|
461
|
+
name: e
|
|
453
462
|
}
|
|
454
463
|
}
|
|
455
464
|
})).config
|
|
456
|
-
}), ee = (
|
|
457
|
-
send: (
|
|
458
|
-
email:
|
|
465
|
+
}), ee = (t) => ({
|
|
466
|
+
send: (e, r, n) => c(t, "sendMail", {
|
|
467
|
+
email: e,
|
|
459
468
|
subject: r,
|
|
460
469
|
message: n
|
|
461
470
|
})
|
|
462
|
-
}), te = (
|
|
463
|
-
list: async () => (await h(
|
|
471
|
+
}), te = (t) => ({
|
|
472
|
+
list: async () => (await h(t, {
|
|
464
473
|
listUser: {
|
|
465
474
|
data: {
|
|
466
475
|
user_id: !0,
|
|
@@ -472,13 +481,13 @@ const f = async (e, t, r = null, n = []) => {
|
|
|
472
481
|
}
|
|
473
482
|
})).listUser.data
|
|
474
483
|
}), re = () => {
|
|
475
|
-
const
|
|
484
|
+
const t = {};
|
|
476
485
|
return {
|
|
477
|
-
create(
|
|
478
|
-
e
|
|
486
|
+
create(e, r) {
|
|
487
|
+
t[e] = {};
|
|
479
488
|
for (const n of Object.entries(r)) {
|
|
480
489
|
const [s, a] = n;
|
|
481
|
-
e
|
|
490
|
+
t[e][s] = () => ({
|
|
482
491
|
name: a.name ? a.name : s,
|
|
483
492
|
raw: a,
|
|
484
493
|
getName: () => a.name ? a.name : s,
|
|
@@ -495,45 +504,45 @@ const f = async (e, t, r = null, n = []) => {
|
|
|
495
504
|
}
|
|
496
505
|
});
|
|
497
506
|
}
|
|
498
|
-
return e
|
|
507
|
+
return t[e];
|
|
499
508
|
},
|
|
500
|
-
get(
|
|
501
|
-
return e
|
|
509
|
+
get(e) {
|
|
510
|
+
return t[e];
|
|
502
511
|
}
|
|
503
512
|
};
|
|
504
|
-
}, ne = (
|
|
505
|
-
list: async () => (await h(
|
|
513
|
+
}, ne = (t) => ({
|
|
514
|
+
list: async () => (await h(t, {
|
|
506
515
|
listRole: {
|
|
507
516
|
name: !0
|
|
508
517
|
}
|
|
509
518
|
})).listRole
|
|
510
|
-
}), oe = (
|
|
511
|
-
const
|
|
512
|
-
baseURL:
|
|
519
|
+
}), oe = (t) => {
|
|
520
|
+
const e = U.create({
|
|
521
|
+
baseURL: t,
|
|
513
522
|
withCredentials: !0
|
|
514
|
-
}), r = (a, o = null, i = []) =>
|
|
523
|
+
}), r = (a, o = null, i = []) => c(e, a, o, i), n = (a) => h(e, a), s = re();
|
|
515
524
|
return {
|
|
516
|
-
baseURL:
|
|
517
|
-
axios:
|
|
518
|
-
auth: I(
|
|
525
|
+
baseURL: t,
|
|
526
|
+
axios: e,
|
|
527
|
+
auth: I(e),
|
|
519
528
|
mutation: r,
|
|
520
529
|
query: n,
|
|
521
530
|
config: k(n),
|
|
522
|
-
mail: ee(
|
|
523
|
-
users: te(
|
|
524
|
-
fs: x(
|
|
531
|
+
mail: ee(e),
|
|
532
|
+
users: te(e),
|
|
533
|
+
fs: x(e),
|
|
525
534
|
models: s,
|
|
526
535
|
model(a) {
|
|
527
|
-
return M(
|
|
536
|
+
return M(e, a, s.get(a));
|
|
528
537
|
},
|
|
529
|
-
roles: ne(
|
|
538
|
+
roles: ne(e)
|
|
530
539
|
};
|
|
531
540
|
};
|
|
532
541
|
export {
|
|
533
542
|
ie as File,
|
|
534
543
|
oe as createClient,
|
|
535
|
-
|
|
536
|
-
|
|
544
|
+
v as file,
|
|
545
|
+
c as mutation,
|
|
537
546
|
h as query,
|
|
538
547
|
A as toQuery
|
|
539
548
|
};
|
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",{email:e,password:r,code:n}),forgetPassword:e=>c(t,"forgetPassword",{email:e}),verifyCode(e,r){return c(t,"verifyCode",{email: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"})});
|