dymo-api 1.0.14 → 1.0.15
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/package.json +1 -1
- package/src/dymo-api.ts +2 -12
- package/src/private-api.ts +1 -3
package/package.json
CHANGED
package/src/dymo-api.ts
CHANGED
|
@@ -9,7 +9,6 @@ const customError = (code: number, message: string): Error => {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
interface TokensResponse {
|
|
12
|
-
organization: boolean;
|
|
13
12
|
root: boolean;
|
|
14
13
|
api: boolean;
|
|
15
14
|
};
|
|
@@ -20,15 +19,12 @@ interface Tokens {
|
|
|
20
19
|
};
|
|
21
20
|
|
|
22
21
|
class DymoAPI {
|
|
23
|
-
private organization: string | null;
|
|
24
22
|
private rootApiKey: string | null;
|
|
25
23
|
private apiKey: string | null;
|
|
26
24
|
private tokensResponse: TokensResponse | null;
|
|
27
25
|
private lastFetchTime: Date | null;
|
|
28
26
|
|
|
29
|
-
constructor({
|
|
30
|
-
if ((rootApiKey || apiKey) && !organization) throw customError(4000, "Organization is required when at least one token is specified.");
|
|
31
|
-
this.organization = organization;
|
|
27
|
+
constructor({ rootApiKey = null, apiKey = null }: { rootApiKey?: string | null; apiKey?: string | null }) {
|
|
32
28
|
this.rootApiKey = rootApiKey;
|
|
33
29
|
this.apiKey = apiKey;
|
|
34
30
|
this.tokensResponse = null;
|
|
@@ -49,15 +45,9 @@ class DymoAPI {
|
|
|
49
45
|
|
|
50
46
|
try {
|
|
51
47
|
if (Object.keys(tokens).length === 0) return;
|
|
52
|
-
|
|
53
|
-
const response = await axios.post<{ data: TokensResponse }>(
|
|
54
|
-
"https://api.tpeoficial.com/v1/dvr/tokens",
|
|
55
|
-
{ organization: this.organization, tokens }
|
|
56
|
-
);
|
|
57
|
-
|
|
48
|
+
const response = await axios.post<{ data: TokensResponse }>("https://api.tpeoficial.com/v1/dvr/tokens", { tokens });
|
|
58
49
|
if (tokens.root && response.data.data.root === false) throw customError(3000, "Invalid root token.");
|
|
59
50
|
if (tokens.api && response.data.data.api === false) throw customError(3000, "Invalid API token.");
|
|
60
|
-
|
|
61
51
|
this.tokensResponse = response.data.data;
|
|
62
52
|
this.lastFetchTime = currentTime;
|
|
63
53
|
console.log(`[${config.lib.name}] Tokens initialized successfully.`);
|
package/src/private-api.ts
CHANGED
|
@@ -39,9 +39,7 @@ export const isValidData = async (token: string | null, data: Data): Promise<any
|
|
|
39
39
|
if (!i) throw customError(1500, "You must provide at least one parameter.");
|
|
40
40
|
|
|
41
41
|
try {
|
|
42
|
-
const response = await axios.post("https://api.tpeoficial.com/v1/private/secure/verify", data, {
|
|
43
|
-
headers: { "Authorization": token },
|
|
44
|
-
});
|
|
42
|
+
const response = await axios.post("https://api.tpeoficial.com/v1/private/secure/verify", data, { headers: { "Authorization": token } });
|
|
45
43
|
return response.data;
|
|
46
44
|
} catch (error: any) {
|
|
47
45
|
throw customError(5000, error.message);
|