neekuro 2.2.0 → 2.3.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/CHANGELOG.md +39 -14
- package/README.md +117 -117
- package/package.json +64 -64
- package/sources/classes/SFW.js +26 -5
- package/sources/classes/errors/APIError.js +49 -49
- package/sources/classes/errors/Error.js +21 -21
- package/sources/classes/package/NekoGif.js +46 -46
- package/sources/classes/package/welcome.js +446 -446
- package/sources/classes/user/BaseUser.js +20 -20
- package/sources/classes/user/User.js +34 -34
- package/sources/main/index.js +20 -20
- package/sources/rest/APIClient.js +34 -34
- package/sources/typings/index.d.ts +374 -355
- package/sources/utils/imageLoader.js +38 -26
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
3
|
let tokenGlobal = null;
|
|
4
4
|
let tokenVersion = 0;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Clase BaseUser
|
|
8
|
-
* Solamente gestiona el token por todo el paquete.
|
|
9
|
-
*/
|
|
10
|
-
class BaseUser {
|
|
11
|
-
/**
|
|
12
|
-
* Establece el token "global" en todo el paquete.
|
|
13
|
-
* @param {string} token token a establecer.
|
|
14
|
-
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Clase BaseUser
|
|
8
|
+
* Solamente gestiona el token por todo el paquete.
|
|
9
|
+
*/
|
|
10
|
+
class BaseUser {
|
|
11
|
+
/**
|
|
12
|
+
* Establece el token "global" en todo el paquete.
|
|
13
|
+
* @param {string} token token a establecer.
|
|
14
|
+
*/
|
|
15
15
|
static setToken(token) {
|
|
16
16
|
if (typeof token !== 'string' || !token.trim()) {
|
|
17
17
|
throw new TypeError('El token debe ser una cadena no vacía');
|
|
@@ -19,12 +19,12 @@ class BaseUser {
|
|
|
19
19
|
const normalizedToken = token.trim();
|
|
20
20
|
if (tokenGlobal !== normalizedToken) tokenVersion += 1;
|
|
21
21
|
tokenGlobal = normalizedToken;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Obten el token del usuario si este ya se estableció
|
|
26
|
-
* @returns {string} Token de usuario
|
|
27
|
-
*/
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Obten el token del usuario si este ya se estableció
|
|
26
|
+
* @returns {string} Token de usuario
|
|
27
|
+
*/
|
|
28
28
|
static getToken() {
|
|
29
29
|
return tokenGlobal;
|
|
30
30
|
}
|
|
@@ -37,5 +37,5 @@ class BaseUser {
|
|
|
37
37
|
return tokenVersion;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
module.exports = BaseUser;
|
|
40
|
+
|
|
41
|
+
module.exports = BaseUser;
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { setToken } = require("./BaseUser.js");
|
|
4
|
-
const NekoError = require('../errors/Error.js')
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Clase Usuario
|
|
8
|
-
* Instancia al usuario que hara uso de la api
|
|
9
|
-
*/
|
|
10
|
-
class User {
|
|
11
|
-
/**
|
|
12
|
-
* Puedes establecer el token aqui, sin embargo, recomiendo hacerlo en el metodo dedicado
|
|
13
|
-
* @param {string} token Token de la api
|
|
14
|
-
*/
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { setToken } = require("./BaseUser.js");
|
|
4
|
+
const NekoError = require('../errors/Error.js')
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Clase Usuario
|
|
8
|
+
* Instancia al usuario que hara uso de la api
|
|
9
|
+
*/
|
|
10
|
+
class User {
|
|
11
|
+
/**
|
|
12
|
+
* Puedes establecer el token aqui, sin embargo, recomiendo hacerlo en el metodo dedicado
|
|
13
|
+
* @param {string} token Token de la api
|
|
14
|
+
*/
|
|
15
15
|
constructor(token) {
|
|
16
16
|
this.token_ = undefined;
|
|
17
17
|
if (token !== undefined) this.token(token);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Establece el token para usar la api
|
|
22
|
-
* @param {string} token token de la api
|
|
23
|
-
* @throws {NekoError} si el token no fue dado o no es una cadena
|
|
24
|
-
*/
|
|
25
|
-
token(token) {
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Establece el token para usar la api
|
|
22
|
+
* @param {string} token token de la api
|
|
23
|
+
* @throws {NekoError} si el token no fue dado o no es una cadena
|
|
24
|
+
*/
|
|
25
|
+
token(token) {
|
|
26
26
|
if(typeof(token) !== 'string') throw new NekoError('InvalidType', `El token debe ser string, no ${typeof(token)}`);
|
|
27
27
|
if(!token.trim()) throw new NekoError('NoToken', 'el parametro <token> es requerido');
|
|
28
28
|
this.token_ = token.trim();
|
|
29
|
-
setToken(this.#getToken());
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Obtiene el token
|
|
34
|
-
* @returns {string|undefined} token de la api
|
|
35
|
-
*/
|
|
36
|
-
#getToken() {
|
|
37
|
-
return this.token_;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
29
|
+
setToken(this.#getToken());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Obtiene el token
|
|
34
|
+
* @returns {string|undefined} token de la api
|
|
35
|
+
*/
|
|
36
|
+
#getToken() {
|
|
37
|
+
return this.token_;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
41
|
module.exports = User
|
package/sources/main/index.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
//#region Clases
|
|
4
|
-
|
|
5
|
-
exports.User = require('../classes/user/User.js')
|
|
6
|
-
|
|
7
|
-
// paquete
|
|
8
|
-
|
|
9
|
-
exports.NekoGif = require('../classes/package/NekoGif.js')
|
|
10
|
-
exports.BaseUser = require('../classes/user/BaseUser.js')
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
//#region Clases
|
|
4
|
+
|
|
5
|
+
exports.User = require('../classes/user/User.js')
|
|
6
|
+
|
|
7
|
+
// paquete
|
|
8
|
+
|
|
9
|
+
exports.NekoGif = require('../classes/package/NekoGif.js')
|
|
10
|
+
exports.BaseUser = require('../classes/user/BaseUser.js')
|
|
11
11
|
exports.Welcome = require('../classes/package/welcome.js')
|
|
12
|
-
|
|
13
|
-
// rest
|
|
14
|
-
|
|
15
|
-
exports.APIClient = require('../rest/APIClient.js')
|
|
16
|
-
|
|
17
|
-
// errores
|
|
18
|
-
|
|
12
|
+
|
|
13
|
+
// rest
|
|
14
|
+
|
|
15
|
+
exports.APIClient = require('../rest/APIClient.js')
|
|
16
|
+
|
|
17
|
+
// errores
|
|
18
|
+
|
|
19
19
|
exports.APIError = require('../classes/errors/APIError.js')
|
|
20
20
|
exports.NekoError = require('../classes/errors/Error.js')
|
|
21
21
|
// Alias conservado por compatibilidad con versiones 2.0.x.
|
|
22
22
|
exports.Error = exports.NekoError
|
|
23
|
-
|
|
24
|
-
//#region "constantes"
|
|
25
|
-
|
|
23
|
+
|
|
24
|
+
//#region "constantes"
|
|
25
|
+
|
|
26
26
|
exports.SFW = require('../classes/SFW.js')
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {import('../typings').APIClientData} APIClientData
|
|
5
|
-
* @typedef {import('../typings').GifResponse} GifResponse
|
|
6
|
-
*/
|
|
7
|
-
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {import('../typings').APIClientData} APIClientData
|
|
5
|
+
* @typedef {import('../typings').GifResponse} GifResponse
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
8
|
const APIError = require('../classes/errors/APIError.js');
|
|
9
9
|
const NekoError = require('../classes/errors/Error.js');
|
|
10
10
|
|
|
11
11
|
const DEFAULT_TIMEOUT_MS = 10_000;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Clase APIClient
|
|
15
|
-
* Se encarga de la comunicacion y control de solicitudes a la api
|
|
16
|
-
*/
|
|
17
|
-
class APIClient {
|
|
18
|
-
/**
|
|
19
|
-
* Instanciamiento de la clase
|
|
20
|
-
* @param {string} baseURL link principal de la api
|
|
21
|
-
* @param {APIClientData} data objeto para las solicitudes
|
|
22
|
-
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Clase APIClient
|
|
15
|
+
* Se encarga de la comunicacion y control de solicitudes a la api
|
|
16
|
+
*/
|
|
17
|
+
class APIClient {
|
|
18
|
+
/**
|
|
19
|
+
* Instanciamiento de la clase
|
|
20
|
+
* @param {string} baseURL link principal de la api
|
|
21
|
+
* @param {APIClientData} data objeto para las solicitudes
|
|
22
|
+
*/
|
|
23
23
|
constructor(baseURL, data) {
|
|
24
24
|
if (typeof baseURL !== 'string' || !baseURL) {
|
|
25
25
|
throw new NekoError('InvalidBaseURL', 'El parámetro <baseURL> debe ser una URL válida');
|
|
@@ -37,24 +37,24 @@ class APIClient {
|
|
|
37
37
|
if (!data || typeof data.token !== 'string' || !data.token.trim()) {
|
|
38
38
|
throw new NekoError('NoToken', 'Se requiere un token para utilizar la API');
|
|
39
39
|
}
|
|
40
|
-
/**
|
|
41
|
-
* url principal
|
|
42
|
-
* @type {string}
|
|
43
|
-
*/
|
|
40
|
+
/**
|
|
41
|
+
* url principal
|
|
42
|
+
* @type {string}
|
|
43
|
+
*/
|
|
44
44
|
this.baseURL = baseURL.replace(/\/$/, '')
|
|
45
|
-
/**
|
|
46
|
-
* data
|
|
47
|
-
* @type {APIClientData}
|
|
48
|
-
*/
|
|
49
|
-
this.data = data
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Obtiene el objeto compartido por la api a traves de la ruta y con autorizacion por token
|
|
53
|
-
* @param {string} endpoint establece la ruta a la que se quiere comunicar
|
|
45
|
+
/**
|
|
46
|
+
* data
|
|
47
|
+
* @type {APIClientData}
|
|
48
|
+
*/
|
|
49
|
+
this.data = data
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Obtiene el objeto compartido por la api a traves de la ruta y con autorizacion por token
|
|
53
|
+
* @param {string} endpoint establece la ruta a la que se quiere comunicar
|
|
54
54
|
* @template {import('../typings').ApiResponse} [T=GifResponse]
|
|
55
55
|
* @returns {Promise<T>}
|
|
56
|
-
* @throws {APIError} solo si sucede un error entre solicitudes
|
|
57
|
-
*/
|
|
56
|
+
* @throws {APIError} solo si sucede un error entre solicitudes
|
|
57
|
+
*/
|
|
58
58
|
async get(endpoint, options = {}) {
|
|
59
59
|
if (typeof endpoint !== 'string' || !endpoint.startsWith('/')) {
|
|
60
60
|
throw new NekoError('InvalidEndpoint', 'El endpoint debe comenzar con "/"');
|
|
@@ -103,5 +103,5 @@ async function readJson(response) {
|
|
|
103
103
|
return { code: response.status, message: 'La API devolvió una respuesta que no es JSON' };
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
|
|
106
|
+
|
|
107
107
|
module.exports = APIClient;
|