dymo-api 1.0.26 → 1.0.27

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.
Files changed (2) hide show
  1. package/dist/dymo-api.mjs +116 -0
  2. package/package.json +3 -3
@@ -0,0 +1,116 @@
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
+ const axios_1 = __importDefault(require("axios"));
30
+ const PublicAPI = __importStar(require("./branches/public"));
31
+ const PrivateAPI = __importStar(require("./branches/private"));
32
+ const config_1 = __importStar(require("./config"));
33
+ const customError = (code, message) => {
34
+ return Object.assign(new Error(), { code, message: `[${config_1.default.lib.name}] ${message}` });
35
+ };
36
+ ;
37
+ ;
38
+ ;
39
+ class DymoAPI {
40
+ constructor({ rootApiKey = null, apiKey = null, local = false, serverEmailConfig = undefined }) {
41
+ this.rootApiKey = rootApiKey;
42
+ this.apiKey = apiKey;
43
+ this.tokensResponse = null;
44
+ this.lastFetchTime = null;
45
+ this.serverEmailConfig = serverEmailConfig;
46
+ this.local = rootApiKey ? local : false; // Only allow setting local if rootApiKey is defined.
47
+ (0, config_1.setBaseUrl)(this.local);
48
+ this.initializeTokens(); // Calls the function to obtain tokens when creating the object.
49
+ }
50
+ getBaseUrl() {
51
+ return this.local ? "http://localhost:3050" : "https://api.tpeoficial.com";
52
+ }
53
+ async getTokens() {
54
+ const currentTime = new Date();
55
+ if (this.tokensResponse && this.lastFetchTime && (currentTime.getTime() - this.lastFetchTime.getTime()) < 5 * 60 * 1000) {
56
+ console.log(`[${config_1.default.lib.name}] Using cached tokens response.`);
57
+ return this.tokensResponse;
58
+ }
59
+ ;
60
+ const tokens = {};
61
+ if (this.rootApiKey)
62
+ tokens.root = `Bearer ${this.rootApiKey}`;
63
+ if (this.apiKey)
64
+ tokens.api = `Bearer ${this.apiKey}`;
65
+ try {
66
+ if (Object.keys(tokens).length === 0)
67
+ return;
68
+ const response = await axios_1.default.post(`${config_1.BASE_URL}/v1/dvr/tokens`, { tokens });
69
+ if (tokens.root && response.data.data.root === false)
70
+ throw customError(3000, "Invalid root token.");
71
+ if (tokens.api && response.data.data.api === false)
72
+ throw customError(3000, "Invalid API token.");
73
+ this.tokensResponse = response.data.data;
74
+ this.lastFetchTime = currentTime;
75
+ console.log(`[${config_1.default.lib.name}] Tokens initialized successfully.`);
76
+ return this.tokensResponse;
77
+ }
78
+ catch (error) {
79
+ throw customError(5000, error.message);
80
+ }
81
+ }
82
+ async initializeTokens() {
83
+ try {
84
+ await this.getTokens();
85
+ }
86
+ catch (error) {
87
+ throw customError(5000, `Error initializing tokens: ${error.message}`);
88
+ }
89
+ }
90
+ // FUNCTIONS / Private.
91
+ async isValidData(data) {
92
+ return await PrivateAPI.isValidData(this.apiKey, data);
93
+ }
94
+ async sendEmail(data) {
95
+ if (this.serverEmailConfig)
96
+ throw customError(5000, `You must configure the email client settings.`);
97
+ return await PrivateAPI.sendEmail(this.apiKey, { serverEmailConfig: this.serverEmailConfig, ...data });
98
+ }
99
+ async getRandom(data) {
100
+ return await PrivateAPI.getRandom(this.apiKey, data);
101
+ }
102
+ // FUNCTIONS / Public.
103
+ async getPrayerTimes(data) {
104
+ return await PublicAPI.getPrayerTimes(data);
105
+ }
106
+ async satinizer(data) {
107
+ return await PublicAPI.satinizer(data);
108
+ }
109
+ async isValidPwd(data) {
110
+ return await PublicAPI.isValidPwd(data);
111
+ }
112
+ async newURLEncrypt(data) {
113
+ return await PublicAPI.newURLEncrypt(data);
114
+ }
115
+ }
116
+ exports.default = DymoAPI;
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "dymo-api",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "Flow system for Dymo API.",
5
5
  "main": "dist/dymo-api.js",
6
+ "module": "dist/dymo-api.mjs",
6
7
  "files": [
7
8
  "dist/**/*",
8
9
  "README.md",
9
10
  "LICENSE"
10
11
  ],
11
12
  "types": "dist/types/dymo-api.d.ts",
12
- "type": "module",
13
13
  "scripts": {
14
- "build": "tsc",
14
+ "build": "tsc && shx cp dist/dymo-api.js dist/dymo-api.mjs",
15
15
  "start": "ts-node src/dymo-api.ts",
16
16
  "prepublishOnly": "npm run build",
17
17
  "test": "echo \"Error: no test specified\" && exit 1"