dymo-api 1.0.17 → 1.0.19
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/index.d.ts +30 -6
- package/index.ts +1 -33
- package/package.json +1 -1
- package/src/config/index.ts +19 -0
- package/src/dymo-api.ts +11 -4
- package/src/private-api.ts +3 -3
- package/src/public-api.ts +6 -7
- package/src/config.ts +0 -8
package/index.d.ts
CHANGED
|
@@ -1,11 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export interface ConfigurationOptions {
|
|
2
|
+
rootApiKey?: string;
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
local?: boolean;
|
|
5
|
+
serverEmailConfig?: {
|
|
6
|
+
host: string;
|
|
7
|
+
port: number;
|
|
8
|
+
secure: boolean;
|
|
9
|
+
auth: {
|
|
10
|
+
user: string;
|
|
11
|
+
pass: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
}
|
|
6
15
|
|
|
16
|
+
declare module "dymo-api" {
|
|
7
17
|
class DymoAPI {
|
|
8
|
-
private
|
|
18
|
+
private rootApiKey: string | null;
|
|
19
|
+
private apiKey: string | null;
|
|
20
|
+
private tokensResponse: { root: boolean; api: boolean; } | null;
|
|
21
|
+
private lastFetchTime: Date | null;
|
|
22
|
+
private serverEmailConfig?: {
|
|
23
|
+
host: string;
|
|
24
|
+
port: number;
|
|
25
|
+
secure: boolean;
|
|
26
|
+
auth: {
|
|
27
|
+
user: string;
|
|
28
|
+
pass: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
private local: boolean;
|
|
9
32
|
constructor(configuration?: ConfigurationOptions);
|
|
10
33
|
initializeTokens(): Promise<void>;
|
|
11
34
|
isValidData(data: any): Promise<any>;
|
|
@@ -13,6 +36,7 @@ declare module "dymo-api" {
|
|
|
13
36
|
inputSatinizer(data: any): Promise<any>;
|
|
14
37
|
isValidPwd(data: any): Promise<any>;
|
|
15
38
|
newURLEncrypt(data: any): Promise<any>;
|
|
39
|
+
sendEmail(data: any): Promise<any>;
|
|
16
40
|
}
|
|
17
41
|
|
|
18
42
|
export { DymoAPI };
|
package/index.ts
CHANGED
|
@@ -1,35 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
class DymoAPI {
|
|
4
|
-
private configuration: ConfigurationOptions;
|
|
5
|
-
|
|
6
|
-
constructor(configuration: ConfigurationOptions = {}) {
|
|
7
|
-
this.configuration = configuration;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
async initializeTokens(): Promise<void> {
|
|
11
|
-
// Implementación aquí
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async isValidData(data: any): Promise<any> {
|
|
15
|
-
// Implementación aquí
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async getPrayerTimes(data: any): Promise<any> {
|
|
19
|
-
// Implementación aquí
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async inputSatinizer(data: any): Promise<any> {
|
|
23
|
-
// Implementación aquí
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async isValidPwd(data: any): Promise<any> {
|
|
27
|
-
// Implementación aquí
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async newURLEncrypt(data: any): Promise<any> {
|
|
31
|
-
// Implementación aquí
|
|
32
|
-
}
|
|
33
|
-
}
|
|
1
|
+
import { DymoAPI } from "./src/dymo-api";
|
|
34
2
|
|
|
35
3
|
export { DymoAPI };
|
package/package.json
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const config = {
|
|
2
|
+
lib: {
|
|
3
|
+
name: "Dymo API",
|
|
4
|
+
dir: "dymo-api"
|
|
5
|
+
},
|
|
6
|
+
env: {
|
|
7
|
+
baseUrl: "https://api.tpeoficial.com"
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default config;
|
|
12
|
+
|
|
13
|
+
let BASE_URL: string = config.env.baseUrl;
|
|
14
|
+
|
|
15
|
+
export const setBaseUrl = (isLocal: boolean): void => {
|
|
16
|
+
BASE_URL = isLocal ? "http://localhost:3050" : config.env.baseUrl;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { BASE_URL };
|
package/src/dymo-api.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
-
import * as PrivateAPI from "./private-api";
|
|
3
2
|
import * as PublicAPI from "./public-api";
|
|
4
|
-
import
|
|
3
|
+
import * as PrivateAPI from "./private-api";
|
|
4
|
+
import config, { BASE_URL, setBaseUrl } from "./config";
|
|
5
5
|
|
|
6
6
|
const customError = (code: number, message: string): Error => {
|
|
7
7
|
return Object.assign(new Error(), { code, message: `[${config.lib.name}] ${message}` });
|
|
@@ -33,16 +33,23 @@ class DymoAPI {
|
|
|
33
33
|
private tokensResponse: TokensResponse | null;
|
|
34
34
|
private lastFetchTime: Date | null;
|
|
35
35
|
private serverEmailConfig?: ServerEmailConfig;
|
|
36
|
+
private local: boolean;
|
|
36
37
|
|
|
37
|
-
constructor({ rootApiKey = null, apiKey = null, serverEmailConfig = undefined }: { rootApiKey?: string | null; apiKey?: string | null; serverEmailConfig?: ServerEmailConfig; }) {
|
|
38
|
+
constructor({ rootApiKey = null, apiKey = null, local = false, serverEmailConfig = undefined }: { rootApiKey?: string | null; apiKey?: string | null; local?: boolean; serverEmailConfig?: ServerEmailConfig; }) {
|
|
38
39
|
this.rootApiKey = rootApiKey;
|
|
39
40
|
this.apiKey = apiKey;
|
|
40
41
|
this.tokensResponse = null;
|
|
41
42
|
this.lastFetchTime = null;
|
|
42
43
|
this.serverEmailConfig = serverEmailConfig;
|
|
44
|
+
this.local = rootApiKey ? local : false; // Only allow setting local if rootApiKey is defined.
|
|
45
|
+
setBaseUrl(this.local);
|
|
43
46
|
this.initializeTokens(); // Calls the function to obtain tokens when creating the object.
|
|
44
47
|
}
|
|
45
48
|
|
|
49
|
+
private getBaseUrl(): string {
|
|
50
|
+
return this.local ? "http://localhost:3050" : "https://api.tpeoficial.com";
|
|
51
|
+
}
|
|
52
|
+
|
|
46
53
|
private async getTokens(): Promise<TokensResponse | undefined> {
|
|
47
54
|
const currentTime = new Date();
|
|
48
55
|
if (this.tokensResponse && this.lastFetchTime && (currentTime.getTime() - this.lastFetchTime.getTime()) < 5 * 60 * 1000) {
|
|
@@ -56,7 +63,7 @@ class DymoAPI {
|
|
|
56
63
|
|
|
57
64
|
try {
|
|
58
65
|
if (Object.keys(tokens).length === 0) return;
|
|
59
|
-
const response = await axios.post<{ data: TokensResponse }>(
|
|
66
|
+
const response = await axios.post<{ data: TokensResponse }>(`${BASE_URL}/v1/dvr/tokens`, { tokens });
|
|
60
67
|
if (tokens.root && response.data.data.root === false) throw customError(3000, "Invalid root token.");
|
|
61
68
|
if (tokens.api && response.data.data.api === false) throw customError(3000, "Invalid API token.");
|
|
62
69
|
this.tokensResponse = response.data.data;
|
package/src/private-api.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
-
import config from "./config";
|
|
2
|
+
import config, { BASE_URL } from "./config";
|
|
3
3
|
import * as Interfaces from "./lib/interfaces";
|
|
4
4
|
import { renderAsync } from "@react-email/render";
|
|
5
5
|
|
|
@@ -18,7 +18,7 @@ export const isValidData = async (token: string | null, data: Interfaces.Validat
|
|
|
18
18
|
}
|
|
19
19
|
if (!i) throw customError(1500, "You must provide at least one parameter.");
|
|
20
20
|
try {
|
|
21
|
-
const response = await axios.post(
|
|
21
|
+
const response = await axios.post(`${BASE_URL}/v1/private/secure/verify`, data, { headers: { "Authorization": token } });
|
|
22
22
|
return response.data;
|
|
23
23
|
} catch (error: any) {
|
|
24
24
|
throw customError(5000, error.message);
|
|
@@ -40,7 +40,7 @@ export const sendEmail = async (token: string | null, data: Interfaces.SendEmail
|
|
|
40
40
|
throw customError(1500, "An error occurred while rendering your React component.");
|
|
41
41
|
}
|
|
42
42
|
try {
|
|
43
|
-
const response = await axios.post(
|
|
43
|
+
const response = await axios.post(`${BASE_URL}/v1/private/sender/sendEmail`, data, { headers: { "Authorization": token } });
|
|
44
44
|
return response.data;
|
|
45
45
|
} catch (error: any) {
|
|
46
46
|
throw customError(5000, error.message);
|
package/src/public-api.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
-
import config from "./config";
|
|
2
|
+
import config, { BASE_URL } from "./config";
|
|
3
3
|
|
|
4
4
|
const customError = (code: number, message: string): Error => {
|
|
5
|
-
|
|
6
|
-
return Object.assign(error, { code, message: `[${config.lib.name}] ${message}` });
|
|
5
|
+
return Object.assign(new Error(), { code, message: `[${config.lib.name}] ${message}` });
|
|
7
6
|
};
|
|
8
7
|
|
|
9
8
|
interface PrayerTimesData {
|
|
@@ -31,7 +30,7 @@ export const getPrayerTimes = async (data: PrayerTimesData): Promise<any> => {
|
|
|
31
30
|
const { lat, lon } = data;
|
|
32
31
|
if (lat === undefined || lon === undefined) throw customError(1000, "You must provide a latitude and longitude.");
|
|
33
32
|
try {
|
|
34
|
-
const response = await axios.get(
|
|
33
|
+
const response = await axios.get(`${BASE_URL}/v1/public/islam/prayertimes`, { params: data });
|
|
35
34
|
return response.data;
|
|
36
35
|
} catch (error: any) {
|
|
37
36
|
throw customError(5000, error.message);
|
|
@@ -42,7 +41,7 @@ export const satinizer = async (data: InputSatinizerData): Promise<any> => {
|
|
|
42
41
|
const { input } = data;
|
|
43
42
|
if (input === undefined) throw customError(1000, "You must specify at least the input.");
|
|
44
43
|
try {
|
|
45
|
-
const response = await axios.get(
|
|
44
|
+
const response = await axios.get(`${BASE_URL}/v1/public/inputSatinizer`, { params: { input: encodeURIComponent(input) } });
|
|
46
45
|
return response.data;
|
|
47
46
|
} catch (error: any) {
|
|
48
47
|
throw customError(5000, error.message);
|
|
@@ -75,7 +74,7 @@ export const isValidPwd = async (data: IsValidPwdData): Promise<any> => {
|
|
|
75
74
|
if (max !== undefined) params.max = max;
|
|
76
75
|
|
|
77
76
|
try {
|
|
78
|
-
const response = await axios.get(
|
|
77
|
+
const response = await axios.get(`${BASE_URL}/v1/public/validPwd`, { params });
|
|
79
78
|
return response.data;
|
|
80
79
|
} catch (error: any) {
|
|
81
80
|
throw customError(5000, error.message);
|
|
@@ -86,7 +85,7 @@ export const newURLEncrypt = async (data: NewURLEncryptData): Promise<any> => {
|
|
|
86
85
|
const { url } = data;
|
|
87
86
|
if (url === undefined || (!url.startsWith("https://") && !url.startsWith("http://"))) throw customError(1500, "You must provide a valid url.");
|
|
88
87
|
try {
|
|
89
|
-
const response = await axios.get(
|
|
88
|
+
const response = await axios.get(`${BASE_URL}/v1/public/url-encrypt`, { params: data });
|
|
90
89
|
return response.data;
|
|
91
90
|
} catch (error: any) {
|
|
92
91
|
throw customError(5000, error.message);
|