dymo-api 1.0.11 → 1.0.13

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.
@@ -0,0 +1,30 @@
1
+ name: Publish Package
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ publish:
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - name: Checkout code
14
+ uses: actions/checkout@v3
15
+
16
+ - name: Set up Node.js
17
+ uses: actions/setup-node@v3
18
+ with:
19
+ node-version: "18"
20
+
21
+ - name: Install dependencies
22
+ run: npm install
23
+
24
+ - name: Build
25
+ run: npm run build
26
+
27
+ - name: Publish to npm
28
+ run: npm publish
29
+ env:
30
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/dist/config.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const config = {
4
+ lib: {
5
+ name: "Dymo API",
6
+ dir: "dymo-api"
7
+ }
8
+ };
9
+ exports.default = config;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.DymoAPI = void 0;
30
+ const axios_1 = __importDefault(require("axios"));
31
+ const PrivateAPI = __importStar(require("./private-api"));
32
+ const PublicAPI = __importStar(require("./public-api"));
33
+ const config_1 = __importDefault(require("./config"));
34
+ const customError = (code, message) => {
35
+ const error = new Error();
36
+ return Object.assign(error, { code, message: `[${config_1.default.lib.name}] ${message}` });
37
+ };
38
+ class DymoAPI {
39
+ constructor({ rootApiKey = null, apiKey = null }) {
40
+ this.rootApiKey = rootApiKey;
41
+ this.apiKey = apiKey;
42
+ this.tokensResponse = null;
43
+ this.lastFetchTime = null;
44
+ this.initializeTokens(); // Calls the function to obtain tokens when creating the object.
45
+ }
46
+ async getTokens() {
47
+ const currentTime = new Date();
48
+ if (this.tokensResponse && this.lastFetchTime && (currentTime.getTime() - this.lastFetchTime.getTime()) < 5 * 60 * 1000) {
49
+ console.log(`[${config_1.default.lib.name}] Using cached tokens response.`);
50
+ return this.tokensResponse;
51
+ }
52
+ const tokens = {};
53
+ if (this.rootApiKey)
54
+ tokens.root = `Bearer ${this.rootApiKey}`;
55
+ if (this.apiKey)
56
+ tokens.api = `Bearer ${this.apiKey}`;
57
+ try {
58
+ if (Object.keys(tokens).length === 0)
59
+ return;
60
+ const response = await axios_1.default.post("https://api.tpeoficial.com/v1/dvr/tokens", { tokens });
61
+ if (tokens.root && response.data.data.root === false)
62
+ throw customError(3000, "Invalid root token.");
63
+ if (tokens.api && response.data.data.api === false)
64
+ throw customError(3000, "Invalid API token.");
65
+ this.tokensResponse = response.data.data;
66
+ this.lastFetchTime = currentTime;
67
+ console.log(`[${config_1.default.lib.name}] Tokens initialized successfully.`);
68
+ return this.tokensResponse;
69
+ }
70
+ catch (error) {
71
+ throw customError(5000, error.message);
72
+ }
73
+ }
74
+ async initializeTokens() {
75
+ try {
76
+ await this.getTokens();
77
+ }
78
+ catch (error) {
79
+ throw customError(5000, `Error initializing tokens: ${error.message}`);
80
+ }
81
+ }
82
+ // FUNCTIONS / Private.
83
+ async isValidData(data) {
84
+ return await PrivateAPI.isValidData(this.apiKey, data);
85
+ }
86
+ // FUNCTIONS / Public.
87
+ async getPrayerTimes(data) {
88
+ return await PublicAPI.getPrayerTimes(data);
89
+ }
90
+ async inputSatinizer(data) {
91
+ return await PublicAPI.inputSatinizer(data);
92
+ }
93
+ async isValidPwd(data) {
94
+ return await PublicAPI.isValidPwd(data);
95
+ }
96
+ async newURLEncrypt(data) {
97
+ return await PublicAPI.newURLEncrypt(data);
98
+ }
99
+ }
100
+ exports.DymoAPI = DymoAPI;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isValidData = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const config_1 = __importDefault(require("./config"));
9
+ const customError = (code, message) => {
10
+ const error = new Error();
11
+ return Object.assign(error, { code, message: `[${config_1.default.lib.name}] ${message}` });
12
+ };
13
+ ;
14
+ ;
15
+ ;
16
+ const isValidData = async (token, data) => {
17
+ if (token === null)
18
+ throw customError(3000, "Invalid private token.");
19
+ let i = false;
20
+ for (const key in data) {
21
+ if (data.hasOwnProperty(key) && (key === "email" || key === "tel" || key === "domain" || key === "creditCard" || key === "ip")) {
22
+ i = true;
23
+ break;
24
+ }
25
+ }
26
+ if (!i)
27
+ throw customError(1500, "You must provide at least one parameter.");
28
+ try {
29
+ const response = await axios_1.default.post("https://api.tpeoficial.com/v1/private/secure/verify", data, {
30
+ headers: { "Authorization": token },
31
+ });
32
+ return response.data;
33
+ }
34
+ catch (error) {
35
+ throw customError(5000, error.message);
36
+ }
37
+ };
38
+ exports.isValidData = isValidData;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.newURLEncrypt = exports.isValidPwd = exports.inputSatinizer = exports.getPrayerTimes = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const config_1 = __importDefault(require("./config"));
9
+ const customError = (code, message) => {
10
+ const error = new Error();
11
+ return Object.assign(error, { code, message: `[${config_1.default.lib.name}] ${message}` });
12
+ };
13
+ const getPrayerTimes = async (data) => {
14
+ const { lat, lon } = data;
15
+ if (lat === undefined || lon === undefined)
16
+ throw customError(1000, "You must provide a latitude and longitude.");
17
+ try {
18
+ const response = await axios_1.default.get("https://api.tpeoficial.com/v1/public/islam/prayertimes", { params: data });
19
+ return response.data;
20
+ }
21
+ catch (error) {
22
+ throw customError(5000, error.message);
23
+ }
24
+ };
25
+ exports.getPrayerTimes = getPrayerTimes;
26
+ const inputSatinizer = async (data) => {
27
+ const { input } = data;
28
+ if (input === undefined)
29
+ throw customError(1000, "You must specify at least the input.");
30
+ try {
31
+ const response = await axios_1.default.get("https://api.tpeoficial.com/v1/public/inputSatinizer", { params: { input: encodeURIComponent(input) } });
32
+ return response.data;
33
+ }
34
+ catch (error) {
35
+ throw customError(5000, error.message);
36
+ }
37
+ };
38
+ exports.inputSatinizer = inputSatinizer;
39
+ const isValidPwd = async (data) => {
40
+ let { email, password, bannedWords, min, max } = data;
41
+ if (password === undefined)
42
+ throw customError(1000, "You must specify at least the password.");
43
+ const params = { password: encodeURIComponent(password) };
44
+ if (email) {
45
+ if (!/^[a-zA-Z0-9._\-+]+@?[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(email))
46
+ throw customError(1500, "If you provide an email address it must be valid.");
47
+ params.email = encodeURIComponent(email);
48
+ }
49
+ if (bannedWords) {
50
+ if (typeof bannedWords === "string")
51
+ bannedWords = bannedWords.slice(1, -1).trim().split(",").map(item => item.trim());
52
+ if (!Array.isArray(bannedWords) || bannedWords.length > 10)
53
+ throw customError(1500, "If you provide a list of banned words; the list may not exceed 10 words and must be of array type.");
54
+ if (!bannedWords.every(word => typeof word === "string") || new Set(bannedWords).size !== bannedWords.length)
55
+ throw customError(1500, "If you provide a list of banned words; all elements must be non-repeated strings.");
56
+ params.bannedWords = bannedWords;
57
+ }
58
+ if (min !== undefined && (!Number.isInteger(min) || min < 8 || min > 32))
59
+ throw customError(1500, "If you provide a minimum it must be valid.");
60
+ if (max !== undefined && (!Number.isInteger(max) || max < 32 || max > 100))
61
+ throw customError(1500, "If you provide a maximum it must be valid.");
62
+ if (min !== undefined)
63
+ params.min = min;
64
+ if (max !== undefined)
65
+ params.max = max;
66
+ try {
67
+ const response = await axios_1.default.get("https://api.tpeoficial.com/v1/public/validPwd", { params });
68
+ return response.data;
69
+ }
70
+ catch (error) {
71
+ throw customError(5000, error.message);
72
+ }
73
+ };
74
+ exports.isValidPwd = isValidPwd;
75
+ const newURLEncrypt = async (data) => {
76
+ const { url } = data;
77
+ if (url === undefined || (!url.startsWith("https://") && !url.startsWith("http://")))
78
+ throw customError(1500, "You must provide a valid url.");
79
+ try {
80
+ const response = await axios_1.default.get("https://api.tpeoficial.com/v1/public/url-encrypt", { params: data });
81
+ return response.data;
82
+ }
83
+ catch (error) {
84
+ throw customError(5000, error.message);
85
+ }
86
+ };
87
+ exports.newURLEncrypt = newURLEncrypt;
package/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- declare module 'dymo-api' {
2
- class Configuration {
3
- constructor({ rootApiKey, apiKey }?: { rootApiKey?: string; apiKey?: string });
4
- getTokens(): Promise<any>;
1
+ declare module "dymo-api" {
2
+ interface ConfigurationOptions {
3
+ rootApiKey?: string;
4
+ apiKey?: string;
5
5
  }
6
6
 
7
7
  class DymoAPI {
8
- constructor(configuration: Configuration);
8
+ constructor(configuration: ConfigurationOptions);
9
9
  initializeTokens(): Promise<void>;
10
10
  isValidData(data: any): Promise<any>;
11
11
  getPrayerTimes(data: any): Promise<any>;
@@ -14,5 +14,5 @@ declare module 'dymo-api' {
14
14
  newURLEncrypt(data: any): Promise<any>;
15
15
  }
16
16
 
17
- export { Configuration, DymoAPI };
18
- }
17
+ export { DymoAPI };
18
+ };
package/index.js CHANGED
@@ -1,20 +1,7 @@
1
- // This module is intended to unwrap Dymo API default export as named.
2
- // Keep top-level export same with static properties.
3
- // so that it can keep same with es module or cjs.
1
+ import pkg from "./lib/dymo-api.cjs";
4
2
 
5
- /*const {
6
- dymo
7
- } = dymoAPI;
3
+ const { DymoAPI: _DymoAPI } = pkg;
8
4
 
9
- export {
10
- dymoAPI as default
11
- }*/
12
- import pkg from './lib/dymo-api.cjs';
5
+ export { _DymoAPI as DymoAPI };
13
6
 
14
- const { Configuration: _Configuration, DymoAPI: _DymoAPI } = pkg;
15
-
16
- export { _Configuration as Configuration, _DymoAPI as DymoAPI };
17
-
18
- if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
19
- module.exports = { Configuration: _Configuration, DymoAPI: _DymoAPI };
20
- }
7
+ if (typeof module !== "undefined" && typeof module.exports !== "undefined") module.exports = { DymoAPI: _DymoAPI };
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "dymo-api",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "Flow system for Dymo API.",
5
- "main": "index.js",
5
+ "main": "dist/index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
+ "build": "tsc",
9
+ "start": "ts-node src/dymo-api.ts",
8
10
  "test": "echo \"Error: no test specified\" && exit 1"
9
11
  },
10
12
  "repository": {
@@ -28,5 +30,11 @@
28
30
  "contributors": [
29
31
  "TPEOficial (https://github.com/TPEOficial)",
30
32
  "FJRG2007 (https://github.com/FJRG2007)"
31
- ]
32
- }
33
+ ],
34
+ "devDependencies": {
35
+ "@types/axios": "^0.9.36",
36
+ "@types/node": "^22.0.2",
37
+ "ts-node": "^10.9.2",
38
+ "typescript": "^5.5.4"
39
+ }
40
+ }
@@ -1,6 +1,8 @@
1
- module.exports = {
1
+ const config = {
2
2
  lib: {
3
3
  name: "Dymo API",
4
4
  dir: "dymo-api"
5
5
  }
6
- }
6
+ };
7
+
8
+ export default config;
@@ -0,0 +1,97 @@
1
+ import axios from "axios";
2
+ import * as PrivateAPI from "./private-api";
3
+ import * as PublicAPI from "./public-api";
4
+ import config from "./config";
5
+
6
+ const customError = (code: number, message: string): Error => {
7
+ const error = new Error();
8
+ return Object.assign(error, { code, message: `[${config.lib.name}] ${message}` });
9
+ };
10
+
11
+ interface TokensResponse {
12
+ root: boolean;
13
+ api: boolean;
14
+ }
15
+
16
+ interface Tokens {
17
+ root?: string;
18
+ api?: string;
19
+ }
20
+
21
+ class DymoAPI {
22
+ private rootApiKey: string | null;
23
+ private apiKey: string | null;
24
+ private tokensResponse: TokensResponse | null;
25
+ private lastFetchTime: Date | null;
26
+
27
+ constructor({ rootApiKey = null, apiKey = null }: { rootApiKey?: string | null; apiKey?: string | null }) {
28
+ this.rootApiKey = rootApiKey;
29
+ this.apiKey = apiKey;
30
+ this.tokensResponse = null;
31
+ this.lastFetchTime = null;
32
+ this.initializeTokens(); // Calls the function to obtain tokens when creating the object.
33
+ }
34
+
35
+ private async getTokens(): Promise<TokensResponse | undefined> {
36
+ const currentTime = new Date();
37
+ if (this.tokensResponse && this.lastFetchTime && (currentTime.getTime() - this.lastFetchTime.getTime()) < 5 * 60 * 1000) {
38
+ console.log(`[${config.lib.name}] Using cached tokens response.`);
39
+ return this.tokensResponse;
40
+ }
41
+
42
+ const tokens: Tokens = {};
43
+ if (this.rootApiKey) tokens.root = `Bearer ${this.rootApiKey}`;
44
+ if (this.apiKey) tokens.api = `Bearer ${this.apiKey}`;
45
+
46
+ try {
47
+ if (Object.keys(tokens).length === 0) return;
48
+
49
+ const response = await axios.post<{ data: TokensResponse }>(
50
+ "https://api.tpeoficial.com/v1/dvr/tokens",
51
+ { tokens }
52
+ );
53
+
54
+ if (tokens.root && response.data.data.root === false) throw customError(3000, "Invalid root token.");
55
+ if (tokens.api && response.data.data.api === false) throw customError(3000, "Invalid API token.");
56
+
57
+ this.tokensResponse = response.data.data;
58
+ this.lastFetchTime = currentTime;
59
+ console.log(`[${config.lib.name}] Tokens initialized successfully.`);
60
+ return this.tokensResponse;
61
+ } catch (error: any) {
62
+ throw customError(5000, error.message);
63
+ }
64
+ }
65
+
66
+ private async initializeTokens() {
67
+ try {
68
+ await this.getTokens();
69
+ } catch (error: any) {
70
+ throw customError(5000, `Error initializing tokens: ${error.message}`);
71
+ }
72
+ }
73
+
74
+ // FUNCTIONS / Private.
75
+ async isValidData(data: any): Promise<any> {
76
+ return await PrivateAPI.isValidData(this.apiKey, data);
77
+ }
78
+
79
+ // FUNCTIONS / Public.
80
+ async getPrayerTimes(data: any): Promise<any> {
81
+ return await PublicAPI.getPrayerTimes(data);
82
+ }
83
+
84
+ async inputSatinizer(data: any): Promise<any> {
85
+ return await PublicAPI.inputSatinizer(data);
86
+ }
87
+
88
+ async isValidPwd(data: any): Promise<any> {
89
+ return await PublicAPI.isValidPwd(data);
90
+ }
91
+
92
+ async newURLEncrypt(data: any): Promise<any> {
93
+ return await PublicAPI.newURLEncrypt(data);
94
+ }
95
+ }
96
+
97
+ export { DymoAPI };
@@ -0,0 +1,49 @@
1
+ import axios from "axios";
2
+ import config from "./config";
3
+
4
+ const customError = (code: number, message: string): Error => {
5
+ const error = new Error();
6
+ return Object.assign(error, { code, message: `[${config.lib.name}] ${message}` });
7
+ };
8
+
9
+ interface PhoneData {
10
+ iso: any;
11
+ phone: string;
12
+ };
13
+
14
+ interface CreditCardData {
15
+ pan: string | number;
16
+ expirationDate?: string;
17
+ cvc?: string | number;
18
+ cvv?: string | number;
19
+ };
20
+
21
+ interface Data {
22
+ email?: string;
23
+ phone?: PhoneData;
24
+ domain?: string;
25
+ creditCard?: string | CreditCardData;
26
+ ip?: string;
27
+ };
28
+
29
+ export const isValidData = async (token: string | null, data: Data): Promise<any> => {
30
+ if (token === null) throw customError(3000, "Invalid private token.");
31
+
32
+ let i = false;
33
+ for (const key in data) {
34
+ if (data.hasOwnProperty(key) && (key === "email" || key === "tel" || key === "domain" || key === "creditCard" || key === "ip")) {
35
+ i = true;
36
+ break;
37
+ }
38
+ }
39
+ if (!i) throw customError(1500, "You must provide at least one parameter.");
40
+
41
+ try {
42
+ const response = await axios.post("https://api.tpeoficial.com/v1/private/secure/verify", data, {
43
+ headers: { "Authorization": token },
44
+ });
45
+ return response.data;
46
+ } catch (error: any) {
47
+ throw customError(5000, error.message);
48
+ }
49
+ };
@@ -0,0 +1,94 @@
1
+ import axios from "axios";
2
+ import config from "./config";
3
+
4
+ const customError = (code: number, message: string): Error => {
5
+ const error = new Error();
6
+ return Object.assign(error, { code, message: `[${config.lib.name}] ${message}` });
7
+ };
8
+
9
+ interface PrayerTimesData {
10
+ lat?: number;
11
+ lon?: number;
12
+ }
13
+
14
+ interface InputSatinizerData {
15
+ input?: string;
16
+ }
17
+
18
+ interface IsValidPwdData {
19
+ email?: string;
20
+ password?: string;
21
+ bannedWords?: string | string[];
22
+ min?: number;
23
+ max?: number;
24
+ }
25
+
26
+ interface NewURLEncryptData {
27
+ url?: string;
28
+ }
29
+
30
+ export const getPrayerTimes = async (data: PrayerTimesData): Promise<any> => {
31
+ const { lat, lon } = data;
32
+ if (lat === undefined || lon === undefined) throw customError(1000, "You must provide a latitude and longitude.");
33
+ try {
34
+ const response = await axios.get("https://api.tpeoficial.com/v1/public/islam/prayertimes", { params: data });
35
+ return response.data;
36
+ } catch (error: any) {
37
+ throw customError(5000, error.message);
38
+ }
39
+ };
40
+
41
+ export const inputSatinizer = async (data: InputSatinizerData): Promise<any> => {
42
+ const { input } = data;
43
+ if (input === undefined) throw customError(1000, "You must specify at least the input.");
44
+ try {
45
+ const response = await axios.get("https://api.tpeoficial.com/v1/public/inputSatinizer", { params: { input: encodeURIComponent(input) } });
46
+ return response.data;
47
+ } catch (error: any) {
48
+ throw customError(5000, error.message);
49
+ }
50
+ };
51
+
52
+ export const isValidPwd = async (data: IsValidPwdData): Promise<any> => {
53
+ let { email, password, bannedWords, min, max } = data;
54
+ if (password === undefined) throw customError(1000, "You must specify at least the password.");
55
+ const params: { [key: string]: any } = { password: encodeURIComponent(password) };
56
+
57
+ if (email) {
58
+ if (!/^[a-zA-Z0-9._\-+]+@?[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(email)) throw customError(1500, "If you provide an email address it must be valid.");
59
+ params.email = encodeURIComponent(email);
60
+ }
61
+
62
+ if (bannedWords) {
63
+ if (typeof bannedWords === "string") bannedWords = bannedWords.slice(1, -1).trim().split(",").map(item => item.trim());
64
+
65
+ if (!Array.isArray(bannedWords) || bannedWords.length > 10)
66
+ throw customError(1500, "If you provide a list of banned words; the list may not exceed 10 words and must be of array type.");
67
+ if (!bannedWords.every(word => typeof word === "string") || new Set(bannedWords).size !== bannedWords.length)
68
+ throw customError(1500, "If you provide a list of banned words; all elements must be non-repeated strings.");
69
+ params.bannedWords = bannedWords;
70
+ }
71
+
72
+ if (min !== undefined && (!Number.isInteger(min) || min < 8 || min > 32)) throw customError(1500, "If you provide a minimum it must be valid.");
73
+ if (max !== undefined && (!Number.isInteger(max) || max < 32 || max > 100)) throw customError(1500, "If you provide a maximum it must be valid.");
74
+ if (min !== undefined) params.min = min;
75
+ if (max !== undefined) params.max = max;
76
+
77
+ try {
78
+ const response = await axios.get("https://api.tpeoficial.com/v1/public/validPwd", { params });
79
+ return response.data;
80
+ } catch (error: any) {
81
+ throw customError(5000, error.message);
82
+ }
83
+ };
84
+
85
+ export const newURLEncrypt = async (data: NewURLEncryptData): Promise<any> => {
86
+ const { url } = data;
87
+ if (url === undefined || (!url.startsWith("https://") && !url.startsWith("http://"))) throw customError(1500, "You must provide a valid url.");
88
+ try {
89
+ const response = await axios.get("https://api.tpeoficial.com/v1/public/url-encrypt", { params: data });
90
+ return response.data;
91
+ } catch (error: any) {
92
+ throw customError(5000, error.message);
93
+ }
94
+ };
package/test/preview.js CHANGED
@@ -1,18 +1,12 @@
1
- // npm install dymo-api
2
- // /* 1. */ const { Configuration, DymoAPI } = require("dymo-api");
3
- // /* 2. */ import { Configuration, DymoAPI } from "dymo-api"; // Coming Soon.
4
- // /* 3. */ import('dymo-api').then(({ Configuration, DymoAPI }) => { CODE HERE });
5
- // /* 4. */ const { Configuration, DymoAPI } = await import('dymo-api');
6
- import { Configuration, DymoAPI } from "../index.js";
7
1
 
8
- const configuration = new Configuration({
2
+ import { DymoAPI } from "../index.js";
3
+
4
+ // Creating the client for use.
5
+ const dymo = new DymoAPI({
9
6
  /*rootApiKey: "ROOT_TOKEN_HERE",
10
7
  apiKey: "PRIVATE_TOKEN_HERE",*/
11
8
  });
12
9
 
13
- // Creating the client for use.
14
- const dymo = new DymoAPI(configuration);
15
-
16
10
  /*
17
11
  console.log(await dymo.isValidData({ email: "test@test.com", tel: "+34617509462", domain: "test.com", creditCard: "5110929780543845", ip: "52.94.236.248" })); // Private authorization required.
18
12
  console.log(await dymo.getPrayerTimes({ lat: "37.3755847689721", lon: "-4.457957889422379" })); // No authorization required.
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "CommonJS",
5
+ "strict": true,
6
+ "esModuleInterop": true,
7
+ "skipLibCheck": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "outDir": "./dist",
10
+ "rootDir": "./src"
11
+ },
12
+ "include": [
13
+ "src/**/*"
14
+ ]
15
+ }
package/lib/dymo-api.cjs DELETED
@@ -1,64 +0,0 @@
1
- const axios = require("axios");
2
- const config = require("../config.cjs");
3
- const customError = (code, message) => Object.assign(new Error(), { code, message: `[${config.lib.name}] ${message}` });
4
-
5
- /* INTERNALS */
6
- const privateAPI = require("./private-api.cjs");
7
- const publicAPI = require("./public-api.cjs");
8
-
9
- class Configuration {
10
- constructor({ rootApiKey, apiKey } = {}) {
11
- // If neither is provided, set them as empty strings.
12
- this.rootApiKey = rootApiKey || null;
13
- this.apiKey = apiKey || null;
14
- this.tokensResponse = null; // Variable to store the response.
15
- this.lastFetchTime = null; // Variable to store the time of last request.
16
- }
17
- async getTokens() {
18
- // Checks if the response is available and if 5 minutes have passed since the last request.
19
- const currentTime = new Date();
20
- if (this.tokensResponse && this.lastFetchTime && currentTime - this.lastFetchTime < 5 * 60 * 1000) {
21
- console.log(`[${config.lib.name}] Using cached tokens response.`);
22
- return this.tokensResponse;
23
- }
24
- const tokens = {};
25
- if (this.rootApiKey !== null) tokens.root = `Bearer ${this.rootApiKey}`;
26
- if (this.apiKey !== null) tokens.api = `Bearer ${this.apiKey}`;
27
- try {
28
- if (Object.keys(tokens).length < 1) return;
29
- const response = await axios.post('https://api.tpeoficial.com/v1/dvr/tokens', { tokens });
30
- if (tokens.root && response.data.root === false) throw customError(3000, "Invalid root token.");
31
- if (tokens.private && response.data.private === false) throw customError(3000, "Invalid private token.");
32
- // Saves the response and the current request time.
33
- this.tokensResponse = response.data;
34
- this.lastFetchTime = currentTime;
35
- console.log(`[${config.lib.name}] Tokens initialized successfully.`);
36
- return response.data;
37
- } catch (error) {
38
- throw customError(5000, error.message);
39
- }
40
- }
41
- }
42
-
43
- class DymoAPI {
44
- constructor(configuration) {
45
- this.configuration = configuration;
46
- this.initializeTokens(); // Calls the function to obtain tokens when creating the object.
47
- }
48
- async initializeTokens() {
49
- try {
50
- await this.configuration.getTokens();
51
- } catch (error) {
52
- throw customError(5000, `Error initializing tokens: ${error.message}`);
53
- }
54
- }
55
- // FUNCTIONS / Private.
56
- async isValidData(data) { return await privateAPI.isValidData(this.configuration.apiKey, data); }
57
- // FUNCTIONS / Public.
58
- async getPrayerTimes(data) { return await publicAPI.getPrayerTimes(data); }
59
- async inputSatinizer(data) { return await publicAPI.inputSatinizer(data); }
60
- async isValidPwd(data) { return await publicAPI.isValidPwd(data); }
61
- async newURLEncrypt(data) { return await publicAPI.newURLEncrypt(data); }
62
- }
63
-
64
- module.exports = { Configuration, DymoAPI };
@@ -1,21 +0,0 @@
1
- const axios = require("axios");
2
- const config = require("../config.cjs");
3
- const customError = (code, message) => Object.assign(new Error(), { code, message: `[${config.lib.name}] ${message}` });
4
-
5
- exports.isValidData = async (token, data) => {
6
- if (token === null) throw customError(3000, "Invalid private token.");
7
- let i = false;
8
- for (const key in data) {
9
- if (data.hasOwnProperty(key) && (key === 'email' || key === 'tel' || key === 'domain' || key === 'creditCard' || key === 'ip')) {
10
- i = true;
11
- break;
12
- }
13
- }
14
- if (!i) throw customError(1500, "You must provide at least one parameter.");
15
- try {
16
- const response = await axios.get(`https://api.tpeoficial.com/v1/private/secure/verify`, { params: data, headers: { 'Authorization': token } });
17
- return response.data;
18
- } catch (error) {
19
- throw customError(5000, error.message);
20
- }
21
- };
@@ -1,62 +0,0 @@
1
- const axios = require("axios");
2
- const config = require("../config.cjs");
3
- const customError = (code, message) => Object.assign(new Error(), { code, message: `[${config.lib.name}] ${message}` });
4
-
5
- exports.getPrayerTimes = async (data) => {
6
- const { lat, lon } = data;
7
- if (!lat || !lon) throw customError(1000, "You must provide a latitude and longitude.");
8
- try {
9
- const response = await axios.get(`https://api.tpeoficial.com/v1/public/islam/prayertimes`, { params: data });
10
- return response.data;
11
- } catch (error) {
12
- throw customError(5000, error.message);
13
- }
14
- };
15
-
16
- exports.inputSatinizer = async (data) => {
17
- const { input } = data;
18
- if (!input) throw customError(1000, "You must specify at least the input.");
19
- try {
20
- const response = await axios.get('https://api.tpeoficial.com/v1/public/inputSatinizer', { params: { input: encodeURIComponent(input) } });
21
- return response.data;
22
- } catch (error) {
23
- throw customError(5000, error.message);
24
- }
25
- };
26
-
27
- exports.isValidPwd = async (data) => {
28
- var { email, password, bannedWords, min, max } = data;
29
- if (!password) throw customError(1000, "You must specify at least the password.");
30
- const params = {
31
- password: encodeURIComponent(password),
32
- };
33
- if (email) {
34
- if (!/^[a-zA-Z0-9._\-+]+@?[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(email)) throw customError(1500, "If you provide an email address it must be valid.");
35
- params.email = encodeURIComponent(email);
36
- }
37
- if (bannedWords && typeof bannedWords === 'string') bannedWords = bannedWords.slice(1, -1).trim().split(',').map(item => item.trim());
38
- if (bannedWords && (!Array.isArray(bannedWords) || bannedWords.length > 10)) throw customError(1500, "If you provide a list of banned words; the list may not exceed 10 words and must be of array type.");
39
- if (bannedWords && (!bannedWords.every(word => typeof word === 'string') || new Set(bannedWords).size !== bannedWords.length)) throw customError(1500, "If you provide a list of banned words; all elements must be non-repeated strings.");
40
- if (bannedWords) params.bannedWords = bannedWords;
41
- if (min && (!Number.isInteger(min) && min < 8 && min > 32)) throw customError(1500, "If you provide a minimum it must be valid.");
42
- if (max && (!Number.isInteger(max) && max < 32 && max > 100)) throw customError(1500, "If you provide a maximum it must be valid.");
43
- if (min) params.min = min;
44
- if (max) params.max = max;
45
- try {
46
- const response = await axios.get(`https://api.tpeoficial.com/v1/public/validPwd`, { params });
47
- return response.data;
48
- } catch (error) {
49
- throw customError(5000, error.message);
50
- }
51
- };
52
-
53
- exports.newURLEncrypt = async (data) => {
54
- const { url } = data;
55
- if (!url || (!url.startsWith("https://") && !url.startsWith("http://"))) throw customError(1500, "You must provide a valid url.");
56
- try {
57
- const response = await axios.get(`https://api.tpeoficial.com/v1/public/url-encrypt`, { params: data });
58
- return response.data;
59
- } catch (error) {
60
- throw customError(5000, error.message);
61
- }
62
- }