dymo-api 1.0.11 → 1.0.14
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/.github/workflows/publish.yml +31 -0
- package/LICENSE +201 -21
- package/README.md +3 -0
- package/index.d.ts +8 -7
- package/index.ts +35 -0
- package/package.json +15 -7
- package/{config.cjs → src/config.ts} +4 -2
- package/src/dymo-api.ts +101 -0
- package/src/private-api.ts +49 -0
- package/src/public-api.ts +94 -0
- package/test/preview.js +4 -10
- package/tsconfig.json +15 -0
- package/index.js +0 -20
- package/lib/dymo-api.cjs +0 -64
- package/lib/private-api.cjs +0 -21
- package/lib/public-api.cjs +0 -62
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Publish Package
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
name: publish
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
environment: publish
|
|
12
|
+
|
|
13
|
+
steps:
|
|
14
|
+
- name: Checkout code
|
|
15
|
+
uses: actions/checkout@v3
|
|
16
|
+
|
|
17
|
+
- name: Set up Node.js
|
|
18
|
+
uses: actions/setup-node@v3
|
|
19
|
+
with:
|
|
20
|
+
node-version: "18"
|
|
21
|
+
|
|
22
|
+
- name: Install dependencies
|
|
23
|
+
run: npm install
|
|
24
|
+
|
|
25
|
+
- name: Build
|
|
26
|
+
run: npm run build
|
|
27
|
+
|
|
28
|
+
- name: Publish to npm
|
|
29
|
+
run: npm publish
|
|
30
|
+
env:
|
|
31
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024 OpenAI
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
declare module
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
declare module "dymo-api" {
|
|
2
|
+
interface ConfigurationOptions {
|
|
3
|
+
rootApiKey?: string;
|
|
4
|
+
apiKey?: string;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
class DymoAPI {
|
|
8
|
-
|
|
8
|
+
private configuration: ConfigurationOptions;
|
|
9
|
+
constructor(configuration?: ConfigurationOptions);
|
|
9
10
|
initializeTokens(): Promise<void>;
|
|
10
11
|
isValidData(data: any): Promise<any>;
|
|
11
12
|
getPrayerTimes(data: any): Promise<any>;
|
|
@@ -14,5 +15,5 @@ declare module 'dymo-api' {
|
|
|
14
15
|
newURLEncrypt(data: any): Promise<any>;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
export {
|
|
18
|
-
}
|
|
18
|
+
export { DymoAPI };
|
|
19
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ConfigurationOptions } from "dymo-api";
|
|
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
|
+
}
|
|
34
|
+
|
|
35
|
+
export { DymoAPI };
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dymo-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
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": {
|
|
11
|
-
"url": "https://
|
|
13
|
+
"url": "https://github.com/TPEOficial/dymo-api-node"
|
|
12
14
|
},
|
|
13
15
|
"keywords": [
|
|
14
16
|
"Dymo",
|
|
@@ -17,9 +19,9 @@
|
|
|
17
19
|
"Ciphera"
|
|
18
20
|
],
|
|
19
21
|
"author": "TPEOficial LLC",
|
|
20
|
-
"license": "
|
|
22
|
+
"license": "Apache-2.0",
|
|
21
23
|
"bugs": {
|
|
22
|
-
"url": "https://
|
|
24
|
+
"url": "https://github.com/TPEOficial/dymo-api-node/issues"
|
|
23
25
|
},
|
|
24
26
|
"homepage": "https://dymo.tpeoficial.com",
|
|
25
27
|
"dependencies": {
|
|
@@ -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
|
+
}
|
package/src/dymo-api.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
organization: boolean;
|
|
13
|
+
root: boolean;
|
|
14
|
+
api: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
interface Tokens {
|
|
18
|
+
root?: string;
|
|
19
|
+
api?: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
class DymoAPI {
|
|
23
|
+
private organization: string | null;
|
|
24
|
+
private rootApiKey: string | null;
|
|
25
|
+
private apiKey: string | null;
|
|
26
|
+
private tokensResponse: TokensResponse | null;
|
|
27
|
+
private lastFetchTime: Date | null;
|
|
28
|
+
|
|
29
|
+
constructor({ organization = null, rootApiKey = null, apiKey = null }: { organization?: string | null; rootApiKey?: string | null; apiKey?: string | null }) {
|
|
30
|
+
if ((rootApiKey || apiKey) && !organization) throw customError(4000, "Organization is required when at least one token is specified.");
|
|
31
|
+
this.organization = organization;
|
|
32
|
+
this.rootApiKey = rootApiKey;
|
|
33
|
+
this.apiKey = apiKey;
|
|
34
|
+
this.tokensResponse = null;
|
|
35
|
+
this.lastFetchTime = null;
|
|
36
|
+
this.initializeTokens(); // Calls the function to obtain tokens when creating the object.
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private async getTokens(): Promise<TokensResponse | undefined> {
|
|
40
|
+
const currentTime = new Date();
|
|
41
|
+
if (this.tokensResponse && this.lastFetchTime && (currentTime.getTime() - this.lastFetchTime.getTime()) < 5 * 60 * 1000) {
|
|
42
|
+
console.log(`[${config.lib.name}] Using cached tokens response.`);
|
|
43
|
+
return this.tokensResponse;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const tokens: Tokens = {};
|
|
47
|
+
if (this.rootApiKey) tokens.root = `Bearer ${this.rootApiKey}`;
|
|
48
|
+
if (this.apiKey) tokens.api = `Bearer ${this.apiKey}`;
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
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
|
+
|
|
58
|
+
if (tokens.root && response.data.data.root === false) throw customError(3000, "Invalid root token.");
|
|
59
|
+
if (tokens.api && response.data.data.api === false) throw customError(3000, "Invalid API token.");
|
|
60
|
+
|
|
61
|
+
this.tokensResponse = response.data.data;
|
|
62
|
+
this.lastFetchTime = currentTime;
|
|
63
|
+
console.log(`[${config.lib.name}] Tokens initialized successfully.`);
|
|
64
|
+
return this.tokensResponse;
|
|
65
|
+
} catch (error: any) {
|
|
66
|
+
throw customError(5000, error.message);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private async initializeTokens() {
|
|
71
|
+
try {
|
|
72
|
+
await this.getTokens();
|
|
73
|
+
} catch (error: any) {
|
|
74
|
+
throw customError(5000, `Error initializing tokens: ${error.message}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// FUNCTIONS / Private.
|
|
79
|
+
async isValidData(data: any): Promise<any> {
|
|
80
|
+
return await PrivateAPI.isValidData(this.apiKey, data);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// FUNCTIONS / Public.
|
|
84
|
+
async getPrayerTimes(data: any): Promise<any> {
|
|
85
|
+
return await PublicAPI.getPrayerTimes(data);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async satinizer(data: any): Promise<any> {
|
|
89
|
+
return await PublicAPI.satinizer(data);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async isValidPwd(data: any): Promise<any> {
|
|
93
|
+
return await PublicAPI.isValidPwd(data);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async newURLEncrypt(data: any): Promise<any> {
|
|
97
|
+
return await PublicAPI.newURLEncrypt(data);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
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 === "phone" || 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 satinizer = 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
|
-
|
|
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/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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.
|
|
4
|
-
|
|
5
|
-
/*const {
|
|
6
|
-
dymo
|
|
7
|
-
} = dymoAPI;
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
dymoAPI as default
|
|
11
|
-
}*/
|
|
12
|
-
import pkg from './lib/dymo-api.cjs';
|
|
13
|
-
|
|
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
|
-
}
|
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 };
|
package/lib/private-api.cjs
DELETED
|
@@ -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
|
-
};
|
package/lib/public-api.cjs
DELETED
|
@@ -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
|
-
}
|