pwi-plata-type 0.3.7 → 0.3.10
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/bin/plata.ts +3 -1
- package/index.ts +4 -1
- package/libs/axios.ts +43 -0
- package/libs/tools.ts +5 -1
- package/package.json +2 -1
- package/templates/create-cli/lib.ts +5 -1
- package/templates/postinstall/api/envs/debug.env +1 -0
- package/templates/postinstall/api/envs/homolog.env +1 -0
- package/templates/postinstall/api/envs/prod.env +1 -0
package/bin/plata.ts
CHANGED
|
@@ -59,6 +59,8 @@ const main = async () => {
|
|
|
59
59
|
const port = process.env.PORT ?? 3050
|
|
60
60
|
const app: Express = express()
|
|
61
61
|
|
|
62
|
+
app.disable('x-powered-by')
|
|
63
|
+
|
|
62
64
|
app.use(process.env._PLATA_API_ROOT ?? '/api',await buildExpressRouter())
|
|
63
65
|
|
|
64
66
|
app.use((err, _req, res, _next) => {
|
|
@@ -100,7 +102,7 @@ const main = async () => {
|
|
|
100
102
|
PlataDirs.getProjectDir(),
|
|
101
103
|
process.env._PLATA_API_SSL_KEY
|
|
102
104
|
))),
|
|
103
|
-
|
|
105
|
+
passphrase: process.env._PLATA_API_SSL_PASS
|
|
104
106
|
}, app)
|
|
105
107
|
|
|
106
108
|
https.listen(port, () => {
|
package/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import * as PlataTools from './libs/tools'
|
|
|
5
5
|
import * as PlataModels from './libs/model'
|
|
6
6
|
import * as PlataTasks from './libs/tasks'
|
|
7
7
|
import { PlataSwagger } from './libs/swagger'
|
|
8
|
+
import { PlataAxios, PlataAxiosUnsafe } from './libs/axios'
|
|
8
9
|
|
|
9
10
|
export {
|
|
10
11
|
PlataCluster,
|
|
@@ -13,5 +14,7 @@ export {
|
|
|
13
14
|
PlataTools,
|
|
14
15
|
PlataModels,
|
|
15
16
|
PlataSwagger,
|
|
16
|
-
PlataTasks
|
|
17
|
+
PlataTasks,
|
|
18
|
+
PlataAxios,
|
|
19
|
+
PlataAxiosUnsafe,
|
|
17
20
|
}
|
package/libs/axios.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import axios, { AxiosResponse, AxiosRequestConfig } from 'axios'
|
|
2
|
+
import { PlataExtra, PlataResultado } from './tools';
|
|
3
|
+
|
|
4
|
+
export async function PlataAxios<T = any>(config: AxiosRequestConfig): Promise<PlataResultado<AxiosResponse<T>>> {
|
|
5
|
+
config.timeout = config.timeout ?? 1000
|
|
6
|
+
|
|
7
|
+
if (config.timeout === 0) {
|
|
8
|
+
return PlataAxiosUnsafe(config)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const axiosPromise = PlataAxiosUnsafe(config)
|
|
12
|
+
const timeoutPromise = PlataExtra.timeout(config.timeout, {
|
|
13
|
+
errorID: 'PLAX0003',
|
|
14
|
+
msg: 'API externa não respondeu'
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
return Promise.race([axiosPromise, timeoutPromise])
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function PlataAxiosUnsafe<T = any>(config: AxiosRequestConfig): Promise<PlataResultado<AxiosResponse<T>>> {
|
|
21
|
+
return axios(config).then(
|
|
22
|
+
resp => resp,
|
|
23
|
+
err => {
|
|
24
|
+
if (err.response) {
|
|
25
|
+
return err.response
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (err.request) {
|
|
29
|
+
return {
|
|
30
|
+
errorID: 'PLAX0001',
|
|
31
|
+
msg: 'Erro ao se comunicar com API externa',
|
|
32
|
+
error: err
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
errorID: 'PLAX0002',
|
|
38
|
+
msg: 'Erro inesperado ao se comunicar com API externa',
|
|
39
|
+
error: err
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
)
|
|
43
|
+
}
|
package/libs/tools.ts
CHANGED
|
@@ -246,7 +246,11 @@ export namespace PlataRequire {
|
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
export namespace PlataExtra {
|
|
249
|
-
export function
|
|
249
|
+
export function sleep(ms: number) {
|
|
250
250
|
return new Promise(resolve => setTimeout(resolve, ms))
|
|
251
251
|
}
|
|
252
|
+
|
|
253
|
+
export function timeout(ms: number, error: PlataError): Promise<PlataError> {
|
|
254
|
+
return new Promise((_, reject) => setTimeout(() => reject(error), ms))
|
|
255
|
+
}
|
|
252
256
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pwi-plata-type",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.10",
|
|
4
4
|
"main": "index.ts",
|
|
5
5
|
"bin": {
|
|
6
6
|
"plata": "bin/plata.ts",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"@types/jest": "^28.1.1",
|
|
22
22
|
"@types/node-schedule": "^2.1.0",
|
|
23
23
|
"@types/swagger-ui-express": "^4.1.3",
|
|
24
|
+
"axios": "^0.27.2",
|
|
24
25
|
"commander": "^9.4.0",
|
|
25
26
|
"express": "^4.18.1",
|
|
26
27
|
"glob": "^8.0.3",
|
|
@@ -9,11 +9,15 @@ export class ç__Name__ç {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
export function newç__Name__ç(config: typeof ç__Name__çConfig.default): ç__Name__ç {
|
|
13
|
+
return new ç__Name__ç(ç__Name__çConfig.default)
|
|
14
|
+
}
|
|
15
|
+
|
|
12
16
|
export function getç__Name__ç(): ç__Name__ç {
|
|
13
17
|
const p = process as any
|
|
14
18
|
|
|
15
19
|
if (p._plata._libç__Name__ç === undefined) {
|
|
16
|
-
p._plata._libç__Name__ç =
|
|
20
|
+
p._plata._libç__Name__ç = newç__Name__ç(ç__Name__çConfig.default)
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
return p._plata._libç__Name__ç
|