beavuck-time 2.3.5 → 2.3.7
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/build/api.js +20 -0
- package/build/config/corsOptions.js +60 -0
- package/build/config/logger.js +36 -0
- package/build/controllers/nowController.js +30 -0
- package/build/errors/BeavuckTimeClientError.js +13 -0
- package/build/errors/BeavuckTimeServerError.js +16 -0
- package/build/errors/CorsError.js +13 -0
- package/build/errors/base/BeavuckTimeError.js +14 -0
- package/build/middlewares/corsMiddleware.js +34 -0
- package/build/middlewares/errorHandler.js +47 -0
- package/build/middlewares/notFoundHandler.js +9 -0
- package/build/middlewares/rateLimiter.js +16 -0
- package/build/models/now.js +14 -0
- package/build/routes/routes.js +54 -0
- package/build/server.js +63 -0
- package/build/services/nowService.js +11 -0
- package/build/types/isoTimestamp.js +4 -0
- package/build/utils/urlUtil.js +31 -0
- package/openapi/swagger.json +1 -1
- package/package.json +14 -4
- package/.env +0 -21
- package/.env.test +0 -30
- package/.gitlab/issue_templates/bug.md +0 -53
- package/.gitlab/issue_templates/enhancement.md +0 -53
- package/.gitlab/merge_request_templates/bug_fix.md +0 -9
- package/.gitlab/merge_request_templates/enhancement.md +0 -9
- package/.gitlab-ci.yml +0 -158
- package/.nvmrc +0 -1
- package/.sonarlint/connectedMode.json +0 -4
- package/DOCKERHUB_OVERVIEW.md +0 -185
- package/Dockerfile +0 -25
- package/HELP.md +0 -53
- package/api-tests/bruno/bruno.json +0 -9
- package/api-tests/bruno/collection.bru +0 -7
- package/api-tests/bruno/environments/local.bru +0 -8
- package/api-tests/bruno/now/nok/nok_no_origin.bru +0 -19
- package/api-tests/bruno/now/nok/nok_non_recognized_referrer.bru +0 -23
- package/api-tests/bruno/now/nok/nok_non_trusted_origin.bru +0 -23
- package/api-tests/bruno/now/nok/nok_non_truted_origin_nor_referrer.bru +0 -24
- package/api-tests/bruno/now/ok/ok_same_origin.bru +0 -23
- package/api-tests/bruno/now/ok/ok_same_referrer.bru +0 -23
- package/api-tests/bruno/now/ok/ok_trusted_origin.bru +0 -23
- package/eslint.config.mjs +0 -28
- package/sonar-project.properties +0 -9
- package/src/__tests__/api.test.ts +0 -98
- package/src/__tests__/middlewares/errorHandler.test.ts +0 -93
- package/src/__tests__/utils/urlUtil.test.ts +0 -53
- package/src/api.ts +0 -19
- package/src/config/corsOptions.ts +0 -63
- package/src/config/logger.ts +0 -38
- package/src/controllers/nowController.ts +0 -19
- package/src/errors/BeavuckTimeClientError.ts +0 -12
- package/src/errors/BeavuckTimeServerError.ts +0 -18
- package/src/errors/CorsError.ts +0 -12
- package/src/errors/base/BeavuckTimeError.ts +0 -12
- package/src/middlewares/corsMiddleware.ts +0 -32
- package/src/middlewares/errorHandler.ts +0 -57
- package/src/middlewares/notFoundHandler.ts +0 -8
- package/src/middlewares/rateLimiter.ts +0 -15
- package/src/models/now.ts +0 -14
- package/src/routes/routes.ts +0 -84
- package/src/server.ts +0 -83
- package/src/services/nowService.ts +0 -9
- package/src/types/isoTimestamp.ts +0 -8
- package/src/utils/urlUtil.ts +0 -29
- package/tsconfig.json +0 -38
- package/tsoa.json +0 -12
package/src/models/now.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// src/models/now.ts
|
|
2
|
-
|
|
3
|
-
import {IsoTimestamp} from '../types/isoTimestamp'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @example {"now": "2019-08-24T14:15:22Z"}
|
|
7
|
-
*/
|
|
8
|
-
export class Now {
|
|
9
|
-
readonly now: IsoTimestamp
|
|
10
|
-
|
|
11
|
-
constructor() {
|
|
12
|
-
this.now = new Date().toISOString()
|
|
13
|
-
}
|
|
14
|
-
}
|
package/src/routes/routes.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/* tslint:disable */
|
|
2
|
-
|
|
3
|
-
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
|
4
|
-
import type {TsoaRoute} from '@tsoa/runtime'
|
|
5
|
-
import {fetchMiddlewares, ExpressTemplateService} from '@tsoa/runtime'
|
|
6
|
-
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
|
7
|
-
import {NowController} from './../controllers/nowController'
|
|
8
|
-
import type {
|
|
9
|
-
Request as ExRequest,
|
|
10
|
-
Response as ExResponse,
|
|
11
|
-
RequestHandler,
|
|
12
|
-
Router,
|
|
13
|
-
} from 'express'
|
|
14
|
-
|
|
15
|
-
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
|
16
|
-
|
|
17
|
-
const models: TsoaRoute.Models = {
|
|
18
|
-
IsoTimestamp: {
|
|
19
|
-
dataType: 'refAlias',
|
|
20
|
-
type: {dataType: 'string', validators: {}},
|
|
21
|
-
},
|
|
22
|
-
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
|
23
|
-
Now: {
|
|
24
|
-
dataType: 'refObject',
|
|
25
|
-
properties: {
|
|
26
|
-
now: {ref: 'IsoTimestamp', required: true},
|
|
27
|
-
},
|
|
28
|
-
additionalProperties: false,
|
|
29
|
-
},
|
|
30
|
-
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
|
31
|
-
}
|
|
32
|
-
const templateService = new ExpressTemplateService(models, {
|
|
33
|
-
noImplicitAdditionalProperties: 'throw-on-extras',
|
|
34
|
-
bodyCoercion: true,
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
|
38
|
-
|
|
39
|
-
export function RegisterRoutes(app: Router) {
|
|
40
|
-
// ###########################################################################################################
|
|
41
|
-
// NOTE: If you do not see routes for all of your controllers in this file, then you might not have informed tsoa of where to look
|
|
42
|
-
// Please look into the "controllerPathGlobs" config option described in the readme: https://github.com/lukeautry/tsoa
|
|
43
|
-
// ###########################################################################################################
|
|
44
|
-
|
|
45
|
-
const argsNowController_getNow: Record<string, TsoaRoute.ParameterSchema> = {}
|
|
46
|
-
app.get(
|
|
47
|
-
'/now',
|
|
48
|
-
...fetchMiddlewares<RequestHandler>(NowController),
|
|
49
|
-
...fetchMiddlewares<RequestHandler>(NowController.prototype.getNow),
|
|
50
|
-
|
|
51
|
-
async function NowController_getNow(request: ExRequest, response: ExResponse, next: any) {
|
|
52
|
-
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
|
53
|
-
|
|
54
|
-
let validatedArgs: any[] = []
|
|
55
|
-
try {
|
|
56
|
-
validatedArgs = templateService.getValidatedArgs({
|
|
57
|
-
args: argsNowController_getNow,
|
|
58
|
-
request,
|
|
59
|
-
response,
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
const controller = new NowController()
|
|
63
|
-
|
|
64
|
-
await templateService.apiHandler({
|
|
65
|
-
methodName: 'getNow',
|
|
66
|
-
controller,
|
|
67
|
-
response,
|
|
68
|
-
next,
|
|
69
|
-
validatedArgs,
|
|
70
|
-
successStatus: undefined,
|
|
71
|
-
})
|
|
72
|
-
} catch (err) {
|
|
73
|
-
return next(err)
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
)
|
|
77
|
-
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
|
78
|
-
|
|
79
|
-
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
|
80
|
-
|
|
81
|
-
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
package/src/server.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// src/server.ts
|
|
4
|
-
|
|
5
|
-
import {api} from './api'
|
|
6
|
-
import {logger} from './config/logger'
|
|
7
|
-
import {tryParseUrl} from './utils/urlUtil'
|
|
8
|
-
import dotenvx from '@dotenvx/dotenvx'
|
|
9
|
-
import http from 'http'
|
|
10
|
-
|
|
11
|
-
dotenvx.config()
|
|
12
|
-
|
|
13
|
-
type ServerOptions = {
|
|
14
|
-
port?: number
|
|
15
|
-
hostUrl?: string
|
|
16
|
-
trustedOrigins?: string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function validateEnv({
|
|
20
|
-
hostUrl,
|
|
21
|
-
trustedOrigins,
|
|
22
|
-
}: Required<Pick<ServerOptions, 'hostUrl' | 'trustedOrigins'>>) {
|
|
23
|
-
if (!hostUrl || !tryParseUrl(hostUrl)) {
|
|
24
|
-
logger.error('HOST_URL not set or is not a valid URL')
|
|
25
|
-
process.exit(1)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (!trustedOrigins) {
|
|
29
|
-
logger.error('TRUSTED_ORIGINS not set')
|
|
30
|
-
process.exit(1)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function startServer(options: ServerOptions = {}): http.Server {
|
|
35
|
-
const API_PORT = options.port ?? process.env.BEAVUCK_TIME_API_PORT ?? 3000
|
|
36
|
-
const HOST_URL = options.hostUrl ?? process.env.BEAVUCK_TIME_HOST_URL ?? ''
|
|
37
|
-
const TRUSTED_ORIGINS =
|
|
38
|
-
options.trustedOrigins ?? process.env.BEAVUCK_TIME_TRUSTED_ORIGINS ?? ''
|
|
39
|
-
|
|
40
|
-
validateEnv({hostUrl: HOST_URL, trustedOrigins: TRUSTED_ORIGINS})
|
|
41
|
-
|
|
42
|
-
const server = api.listen(API_PORT, () => {
|
|
43
|
-
logger.info(
|
|
44
|
-
`
|
|
45
|
-
| | | | ,=.
|
|
46
|
-
| |__ ___ __ ___ ___ _ ___| | __ ,=""""==.__.=" o".___
|
|
47
|
-
| '_ \\ / _ \\/ _\` \\ \\ / / | | |/ __| |/ / ,=.==" ___/
|
|
48
|
-
| |_) | __/ (_| |\\ V /| |_| | (__| < ,==.," , , \\,===""
|
|
49
|
-
|_.__/ \\___|\\__,_| \\_/ \\__,_|\\___|_|\\_\\ < ,==) \\"'"=._.==) \\
|
|
50
|
-
\`=='' \`" \`"
|
|
51
|
-
|
|
52
|
-
Beavuck Time microservice started successfully
|
|
53
|
-
|
|
54
|
-
Ready on API port ${API_PORT} (if this is running in a container, this port number is internal to the container)
|
|
55
|
-
`,
|
|
56
|
-
)
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
server.on('error', (err: NodeJS.ErrnoException) => {
|
|
60
|
-
logger.error(`Beavuck Time Server error [${err.code}]: ${err.message}`)
|
|
61
|
-
process.exit(1)
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
const gracefulShutdown = (signal: string) => {
|
|
65
|
-
logger.info(`${signal} signal received: closing HTTP server`)
|
|
66
|
-
server.close(() => {
|
|
67
|
-
logger.info('HTTP server closed')
|
|
68
|
-
process.exit(0)
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const SIGTERM = 'SIGTERM'
|
|
73
|
-
const SIGINT = 'SIGINT'
|
|
74
|
-
process.on(SIGTERM, () => gracefulShutdown(SIGTERM))
|
|
75
|
-
process.on(SIGINT, () => gracefulShutdown(SIGINT))
|
|
76
|
-
|
|
77
|
-
return server
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Support running as standalone binary
|
|
81
|
-
if (require.main === module) {
|
|
82
|
-
startServer()
|
|
83
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stringified date-time in RFC 3339 format (often referred to as ISO 8601 format)
|
|
3
|
-
* See [RFC 3339 section 5.6](https://datatracker.ietf.org/doc/html/rfc3339#section-5.6)
|
|
4
|
-
* @example 2019-08-24T14:15:22Z
|
|
5
|
-
* @format date-time
|
|
6
|
-
*/
|
|
7
|
-
export type IsoTimestamp = string
|
|
8
|
-
export const RFC_3339_FORMAT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/
|
package/src/utils/urlUtil.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// src/utils/urlUtil.ts
|
|
2
|
-
|
|
3
|
-
import {URL} from 'url'
|
|
4
|
-
import {logger} from '../config/logger'
|
|
5
|
-
|
|
6
|
-
export function isSameOrigin(thisUrl?: URL, thatUrl?: URL): boolean {
|
|
7
|
-
logger.debug(`Comparing origins: ${thisUrl?.origin} and ${thatUrl?.origin}`)
|
|
8
|
-
if (!thisUrl || !thatUrl) return false
|
|
9
|
-
if (thisUrl.origin === thatUrl.origin) return true
|
|
10
|
-
|
|
11
|
-
const isSameProtocol = thisUrl.protocol === thatUrl.protocol
|
|
12
|
-
const isSameHost = thisUrl.hostname === thatUrl.hostname
|
|
13
|
-
const isSamePort = thisUrl.port === thatUrl.port
|
|
14
|
-
|
|
15
|
-
return isSameProtocol && isSameHost && isSamePort
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function tryParseUrl(urlString?: string): URL | undefined {
|
|
19
|
-
if (!urlString) {
|
|
20
|
-
logger.debug('Empty URL string')
|
|
21
|
-
return undefined
|
|
22
|
-
}
|
|
23
|
-
try {
|
|
24
|
-
return new URL(urlString)
|
|
25
|
-
} catch (error: unknown) {
|
|
26
|
-
logger.warn(`Invalid URL string: ${urlString} (${error})`)
|
|
27
|
-
}
|
|
28
|
-
return undefined
|
|
29
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
/* Basic Options */
|
|
4
|
-
"incremental": true,
|
|
5
|
-
"target": "ESNext",
|
|
6
|
-
"module": "commonjs",
|
|
7
|
-
"outDir": "build",
|
|
8
|
-
"rootDir": "src",
|
|
9
|
-
/* Strict Type-Checking Options */
|
|
10
|
-
"strict": true,
|
|
11
|
-
"noImplicitAny": true,
|
|
12
|
-
"strictNullChecks": true,
|
|
13
|
-
"strictFunctionTypes": true,
|
|
14
|
-
"strictBindCallApply": true,
|
|
15
|
-
"strictPropertyInitialization": true,
|
|
16
|
-
"noImplicitThis": true,
|
|
17
|
-
"alwaysStrict": true,
|
|
18
|
-
/* Additional Checks */
|
|
19
|
-
"allowUnreachableCode": false,
|
|
20
|
-
"allowUnusedLabels": false,
|
|
21
|
-
"noEmitOnError": true,
|
|
22
|
-
"noUnusedLocals": true,
|
|
23
|
-
"noUnusedParameters": true,
|
|
24
|
-
"noImplicitReturns": true,
|
|
25
|
-
"noFallthroughCasesInSwitch": true,
|
|
26
|
-
/* Module Resolution Options */
|
|
27
|
-
"moduleResolution": "node",
|
|
28
|
-
"baseUrl": ".",
|
|
29
|
-
"esModuleInterop": true,
|
|
30
|
-
"resolveJsonModule": true,
|
|
31
|
-
/* Experimental Options */
|
|
32
|
-
"experimentalDecorators": true,
|
|
33
|
-
/* Advanced Options */
|
|
34
|
-
"forceConsistentCasingInFileNames": true
|
|
35
|
-
},
|
|
36
|
-
"include": ["src/**/*.ts"],
|
|
37
|
-
"exclude": ["node_modules"]
|
|
38
|
-
}
|
package/tsoa.json
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"entryFile": "src/server.ts",
|
|
3
|
-
"noImplicitAdditionalProperties": "throw-on-extras",
|
|
4
|
-
"controllerPathGlobs": ["src/controllers/*Controller.ts"],
|
|
5
|
-
"spec": {
|
|
6
|
-
"outputDirectory": "openapi",
|
|
7
|
-
"specVersion": 3
|
|
8
|
-
},
|
|
9
|
-
"routes": {
|
|
10
|
-
"routesDir": "src/routes"
|
|
11
|
-
}
|
|
12
|
-
}
|