jimpex 10.0.2 → 11.0.0
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/CHANGELOG.md +29 -0
- package/README.md +7 -9
- package/dist/app/index.d.ts +1 -1
- package/dist/app/index.js +1 -22
- package/dist/app/index.js.map +1 -1
- package/dist/app/jimpex.d.ts +1 -1
- package/dist/app/jimpex.js +100 -131
- package/dist/app/jimpex.js.map +1 -1
- package/dist/controllers/common/config.d.ts +2 -2
- package/dist/controllers/common/config.js +12 -39
- package/dist/controllers/common/config.js.map +1 -1
- package/dist/controllers/common/health.d.ts +4 -4
- package/dist/controllers/common/health.js +20 -47
- package/dist/controllers/common/health.js.map +1 -1
- package/dist/controllers/common/index.d.ts +1 -1
- package/dist/controllers/common/index.js +3 -26
- package/dist/controllers/common/index.js.map +1 -1
- package/dist/controllers/common/statics.d.ts +3 -3
- package/dist/controllers/common/statics.js +32 -65
- package/dist/controllers/common/statics.js.map +1 -1
- package/dist/controllers/index.d.ts +1 -1
- package/dist/controllers/index.js +2 -24
- package/dist/controllers/index.js.map +1 -1
- package/dist/controllers/utils/gateway.d.ts +5 -5
- package/dist/controllers/utils/gateway.js +70 -91
- package/dist/controllers/utils/gateway.js.map +1 -1
- package/dist/controllers/utils/index.d.ts +1 -1
- package/dist/controllers/utils/index.js +1 -22
- package/dist/controllers/utils/index.js.map +1 -1
- package/dist/{index-C6I3NCC-.d.ts → index-BlSpNHox.d.ts} +13 -13
- package/dist/index.d.ts +3 -3
- package/dist/index.js +6 -32
- package/dist/index.js.map +1 -1
- package/dist/middlewares/common/errorHandler.d.ts +5 -5
- package/dist/middlewares/common/errorHandler.js +31 -56
- package/dist/middlewares/common/errorHandler.js.map +1 -1
- package/dist/middlewares/common/forceHTTPS.d.ts +1 -1
- package/dist/middlewares/common/forceHTTPS.js +8 -35
- package/dist/middlewares/common/forceHTTPS.js.map +1 -1
- package/dist/middlewares/common/hsts.d.ts +1 -1
- package/dist/middlewares/common/hsts.js +12 -39
- package/dist/middlewares/common/hsts.js.map +1 -1
- package/dist/middlewares/common/index.d.ts +3 -3
- package/dist/middlewares/common/index.js +3 -26
- package/dist/middlewares/common/index.js.map +1 -1
- package/dist/middlewares/html/fastHTML.d.ts +4 -4
- package/dist/middlewares/html/fastHTML.js +43 -66
- package/dist/middlewares/html/fastHTML.js.map +1 -1
- package/dist/middlewares/html/index.d.ts +2 -2
- package/dist/middlewares/html/index.js +2 -24
- package/dist/middlewares/html/index.js.map +1 -1
- package/dist/middlewares/html/showHTML.d.ts +3 -3
- package/dist/middlewares/html/showHTML.js +25 -52
- package/dist/middlewares/html/showHTML.js.map +1 -1
- package/dist/middlewares/index.d.ts +4 -4
- package/dist/middlewares/index.js +3 -26
- package/dist/middlewares/index.js.map +1 -1
- package/dist/middlewares/utils/index.d.ts +3 -3
- package/dist/middlewares/utils/index.js +1 -22
- package/dist/middlewares/utils/index.js.map +1 -1
- package/dist/middlewares/utils/versionValidator.d.ts +5 -5
- package/dist/middlewares/utils/versionValidator.js +24 -51
- package/dist/middlewares/utils/versionValidator.js.map +1 -1
- package/dist/services/common/appError.d.ts +2 -2
- package/dist/services/common/appError.js +18 -46
- package/dist/services/common/appError.js.map +1 -1
- package/dist/services/common/httpError.d.ts +2 -2
- package/dist/services/common/httpError.js +7 -33
- package/dist/services/common/httpError.js.map +1 -1
- package/dist/services/common/index.d.ts +1 -1
- package/dist/services/common/index.js +14 -42
- package/dist/services/common/index.js.map +1 -1
- package/dist/services/common/sendFile.d.ts +1 -1
- package/dist/services/common/sendFile.js +4 -29
- package/dist/services/common/sendFile.js.map +1 -1
- package/dist/services/frontend/frontendFs.d.ts +2 -2
- package/dist/services/frontend/frontendFs.js +12 -49
- package/dist/services/frontend/frontendFs.js.map +1 -1
- package/dist/services/frontend/index.d.ts +2 -2
- package/dist/services/frontend/index.js +8 -34
- package/dist/services/frontend/index.js.map +1 -1
- package/dist/services/html/htmlGenerator.d.ts +5 -5
- package/dist/services/html/htmlGenerator.js +46 -75
- package/dist/services/html/htmlGenerator.js.map +1 -1
- package/dist/services/html/index.d.ts +2 -2
- package/dist/services/html/index.js +8 -34
- package/dist/services/html/index.js.map +1 -1
- package/dist/services/http/apiClient.d.ts +1 -1
- package/dist/services/http/apiClient.js +23 -48
- package/dist/services/http/apiClient.js.map +1 -1
- package/dist/services/http/http.d.ts +5 -5
- package/dist/services/http/http.js +23 -60
- package/dist/services/http/http.js.map +1 -1
- package/dist/services/http/index.d.ts +2 -2
- package/dist/services/http/index.js +14 -42
- package/dist/services/http/index.js.map +1 -1
- package/dist/services/http/responsesBuilder.d.ts +4 -4
- package/dist/services/http/responsesBuilder.js +13 -40
- package/dist/services/http/responsesBuilder.js.map +1 -1
- package/dist/services/index.d.ts +3 -3
- package/dist/services/index.js +5 -30
- package/dist/services/index.js.map +1 -1
- package/dist/services/utils/ensureBearerToken.d.ts +2 -2
- package/dist/services/utils/ensureBearerToken.js +15 -42
- package/dist/services/utils/ensureBearerToken.js.map +1 -1
- package/dist/services/utils/index.d.ts +1 -1
- package/dist/services/utils/index.js +8 -34
- package/dist/services/utils/index.js.map +1 -1
- package/dist/types/events.d.ts +1 -1
- package/dist/types/events.js +0 -16
- package/dist/types/events.js.map +1 -1
- package/dist/types/express.js +0 -16
- package/dist/types/express.js.map +1 -1
- package/dist/types/http.js +0 -16
- package/dist/types/http.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +6 -32
- package/dist/types/index.js.map +1 -1
- package/dist/types/options.d.ts +1 -1
- package/dist/types/options.js +0 -16
- package/dist/types/options.js.map +1 -1
- package/dist/types/utils.js +0 -16
- package/dist/types/utils.js.map +1 -1
- package/dist/types/wootils.js +0 -16
- package/dist/types/wootils.js.map +1 -1
- package/dist/utils/fns/index.js +4 -28
- package/dist/utils/fns/index.js.map +1 -1
- package/dist/utils/fns/others.js +2 -26
- package/dist/utils/fns/others.js.map +1 -1
- package/dist/utils/fns/routes.js +4 -31
- package/dist/utils/fns/routes.js.map +1 -1
- package/dist/utils/fns/statuses.js +3 -37
- package/dist/utils/fns/statuses.js.map +1 -1
- package/dist/utils/fns/text.js +2 -26
- package/dist/utils/fns/text.js.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +2 -24
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/wrappers.d.ts +1 -1
- package/dist/utils/wrappers.js +20 -48
- package/dist/utils/wrappers.js.map +1 -1
- package/eslint.config.js +19 -0
- package/examples/basic/app.ts +4 -4
- package/examples/basic/controller.ts +2 -2
- package/examples/basic/index.ts +4 -4
- package/examples/basic/middleware.ts +2 -2
- package/examples/basic/service.ts +1 -1
- package/package.json +61 -49
- package/pnpm-workspace.yaml +4 -0
- package/src/app/index.ts +1 -1
- package/src/app/jimpex.ts +23 -20
- package/src/controllers/common/config.ts +4 -4
- package/src/controllers/common/health.ts +9 -5
- package/src/controllers/common/index.ts +3 -3
- package/src/controllers/common/statics.ts +12 -7
- package/src/controllers/index.ts +2 -2
- package/src/controllers/utils/gateway.ts +8 -8
- package/src/controllers/utils/index.ts +1 -1
- package/src/index.ts +6 -6
- package/src/middlewares/common/errorHandler.ts +9 -5
- package/src/middlewares/common/forceHTTPS.ts +2 -2
- package/src/middlewares/common/hsts.ts +2 -2
- package/src/middlewares/common/index.ts +3 -3
- package/src/middlewares/html/fastHTML.ts +14 -5
- package/src/middlewares/html/index.ts +2 -2
- package/src/middlewares/html/showHTML.ts +8 -4
- package/src/middlewares/index.ts +3 -3
- package/src/middlewares/utils/index.ts +1 -1
- package/src/middlewares/utils/versionValidator.ts +6 -6
- package/src/services/common/appError.ts +1 -1
- package/src/services/common/httpError.ts +2 -2
- package/src/services/common/index.ts +7 -7
- package/src/services/common/sendFile.ts +2 -2
- package/src/services/frontend/frontendFs.ts +3 -3
- package/src/services/frontend/index.ts +3 -3
- package/src/services/html/htmlGenerator.ts +11 -13
- package/src/services/html/index.ts +3 -3
- package/src/services/http/apiClient.ts +3 -3
- package/src/services/http/http.ts +5 -5
- package/src/services/http/index.ts +7 -7
- package/src/services/http/responsesBuilder.ts +5 -5
- package/src/services/index.ts +5 -5
- package/src/services/utils/ensureBearerToken.ts +4 -4
- package/src/services/utils/index.ts +3 -3
- package/src/types/events.ts +8 -8
- package/src/types/http.ts +1 -1
- package/src/types/index.ts +6 -6
- package/src/types/options.ts +2 -2
- package/src/types/utils.ts +4 -4
- package/src/utils/fns/index.ts +4 -4
- package/src/utils/fns/routes.ts +1 -1
- package/src/utils/index.ts +2 -2
- package/src/utils/wrappers.ts +6 -6
- package/tsconfig.json +9 -4
- package/tsup.config.ts +1 -2
- package/vitest.config.ts +24 -0
- package/dist/app/index.d.mts +0 -14
- package/dist/app/jimpex.d.mts +0 -14
- package/dist/controllers/common/config.d.mts +0 -79
- package/dist/controllers/common/health.d.mts +0 -83
- package/dist/controllers/common/index.d.mts +0 -22
- package/dist/controllers/common/statics.d.mts +0 -223
- package/dist/controllers/index.d.mts +0 -25
- package/dist/controllers/utils/gateway.d.mts +0 -725
- package/dist/controllers/utils/index.d.mts +0 -17
- package/dist/esm/app/index.js +0 -2
- package/dist/esm/app/index.js.map +0 -1
- package/dist/esm/app/jimpex.js +0 -640
- package/dist/esm/app/jimpex.js.map +0 -1
- package/dist/esm/chunk-V6TY7KAL.js +0 -8
- package/dist/esm/chunk-V6TY7KAL.js.map +0 -1
- package/dist/esm/controllers/common/config.js +0 -80
- package/dist/esm/controllers/common/config.js.map +0 -1
- package/dist/esm/controllers/common/health.js +0 -88
- package/dist/esm/controllers/common/health.js.map +0 -1
- package/dist/esm/controllers/common/index.js +0 -4
- package/dist/esm/controllers/common/index.js.map +0 -1
- package/dist/esm/controllers/common/statics.js +0 -226
- package/dist/esm/controllers/common/statics.js.map +0 -1
- package/dist/esm/controllers/index.js +0 -3
- package/dist/esm/controllers/index.js.map +0 -1
- package/dist/esm/controllers/utils/gateway.js +0 -559
- package/dist/esm/controllers/utils/gateway.js.map +0 -1
- package/dist/esm/controllers/utils/index.js +0 -2
- package/dist/esm/controllers/utils/index.js.map +0 -1
- package/dist/esm/index.js +0 -7
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/middlewares/common/errorHandler.js +0 -116
- package/dist/esm/middlewares/common/errorHandler.js.map +0 -1
- package/dist/esm/middlewares/common/forceHTTPS.js +0 -52
- package/dist/esm/middlewares/common/forceHTTPS.js.map +0 -1
- package/dist/esm/middlewares/common/hsts.js +0 -74
- package/dist/esm/middlewares/common/hsts.js.map +0 -1
- package/dist/esm/middlewares/common/index.js +0 -4
- package/dist/esm/middlewares/common/index.js.map +0 -1
- package/dist/esm/middlewares/html/fastHTML.js +0 -157
- package/dist/esm/middlewares/html/fastHTML.js.map +0 -1
- package/dist/esm/middlewares/html/index.js +0 -3
- package/dist/esm/middlewares/html/index.js.map +0 -1
- package/dist/esm/middlewares/html/showHTML.js +0 -100
- package/dist/esm/middlewares/html/showHTML.js.map +0 -1
- package/dist/esm/middlewares/index.js +0 -4
- package/dist/esm/middlewares/index.js.map +0 -1
- package/dist/esm/middlewares/utils/index.js +0 -2
- package/dist/esm/middlewares/utils/index.js.map +0 -1
- package/dist/esm/middlewares/utils/versionValidator.js +0 -135
- package/dist/esm/middlewares/utils/versionValidator.js.map +0 -1
- package/dist/esm/services/common/appError.js +0 -98
- package/dist/esm/services/common/appError.js.map +0 -1
- package/dist/esm/services/common/httpError.js +0 -28
- package/dist/esm/services/common/httpError.js.map +0 -1
- package/dist/esm/services/common/index.js +0 -17
- package/dist/esm/services/common/index.js.map +0 -1
- package/dist/esm/services/common/sendFile.js +0 -27
- package/dist/esm/services/common/sendFile.js.map +0 -1
- package/dist/esm/services/frontend/frontendFs.js +0 -66
- package/dist/esm/services/frontend/frontendFs.js.map +0 -1
- package/dist/esm/services/frontend/index.js +0 -11
- package/dist/esm/services/frontend/index.js.map +0 -1
- package/dist/esm/services/html/htmlGenerator.js +0 -192
- package/dist/esm/services/html/htmlGenerator.js.map +0 -1
- package/dist/esm/services/html/index.js +0 -11
- package/dist/esm/services/html/index.js.map +0 -1
- package/dist/esm/services/http/apiClient.js +0 -94
- package/dist/esm/services/http/apiClient.js.map +0 -1
- package/dist/esm/services/http/http.js +0 -180
- package/dist/esm/services/http/http.js.map +0 -1
- package/dist/esm/services/http/index.js +0 -17
- package/dist/esm/services/http/index.js.map +0 -1
- package/dist/esm/services/http/responsesBuilder.js +0 -152
- package/dist/esm/services/http/responsesBuilder.js.map +0 -1
- package/dist/esm/services/index.js +0 -6
- package/dist/esm/services/index.js.map +0 -1
- package/dist/esm/services/utils/ensureBearerToken.js +0 -94
- package/dist/esm/services/utils/ensureBearerToken.js.map +0 -1
- package/dist/esm/services/utils/index.js +0 -11
- package/dist/esm/services/utils/index.js.map +0 -1
- package/dist/esm/types/events.js +0 -1
- package/dist/esm/types/events.js.map +0 -1
- package/dist/esm/types/express.js +0 -1
- package/dist/esm/types/express.js.map +0 -1
- package/dist/esm/types/http.js +0 -1
- package/dist/esm/types/http.js.map +0 -1
- package/dist/esm/types/index.js +0 -7
- package/dist/esm/types/index.js.map +0 -1
- package/dist/esm/types/options.js +0 -1
- package/dist/esm/types/options.js.map +0 -1
- package/dist/esm/types/utils.js +0 -1
- package/dist/esm/types/utils.js.map +0 -1
- package/dist/esm/types/wootils.js +0 -1
- package/dist/esm/types/wootils.js.map +0 -1
- package/dist/esm/utils/fns/index.js +0 -5
- package/dist/esm/utils/fns/index.js.map +0 -1
- package/dist/esm/utils/fns/others.js +0 -6
- package/dist/esm/utils/fns/others.js.map +0 -1
- package/dist/esm/utils/fns/routes.js +0 -25
- package/dist/esm/utils/fns/routes.js.map +0 -1
- package/dist/esm/utils/fns/statuses.js +0 -6
- package/dist/esm/utils/fns/statuses.js.map +0 -1
- package/dist/esm/utils/fns/text.js +0 -6
- package/dist/esm/utils/fns/text.js.map +0 -1
- package/dist/esm/utils/index.js +0 -3
- package/dist/esm/utils/index.js.map +0 -1
- package/dist/esm/utils/wrappers.js +0 -41
- package/dist/esm/utils/wrappers.js.map +0 -1
- package/dist/index-Bwf7JHu9.d.mts +0 -1287
- package/dist/index.d.mts +0 -47
- package/dist/middlewares/common/errorHandler.d.mts +0 -132
- package/dist/middlewares/common/forceHTTPS.d.mts +0 -69
- package/dist/middlewares/common/hsts.d.mts +0 -110
- package/dist/middlewares/common/index.d.mts +0 -22
- package/dist/middlewares/html/fastHTML.d.mts +0 -180
- package/dist/middlewares/html/index.d.mts +0 -21
- package/dist/middlewares/html/showHTML.d.mts +0 -127
- package/dist/middlewares/index.d.mts +0 -30
- package/dist/middlewares/utils/index.d.mts +0 -20
- package/dist/middlewares/utils/versionValidator.d.mts +0 -215
- package/dist/services/common/appError.d.mts +0 -139
- package/dist/services/common/httpError.d.mts +0 -80
- package/dist/services/common/index.d.mts +0 -47
- package/dist/services/common/sendFile.d.mts +0 -102
- package/dist/services/frontend/frontendFs.d.mts +0 -96
- package/dist/services/frontend/index.d.mts +0 -40
- package/dist/services/html/htmlGenerator.d.mts +0 -237
- package/dist/services/html/index.d.mts +0 -43
- package/dist/services/http/apiClient.d.mts +0 -170
- package/dist/services/http/http.d.mts +0 -182
- package/dist/services/http/index.d.mts +0 -51
- package/dist/services/http/responsesBuilder.d.mts +0 -179
- package/dist/services/index.d.mts +0 -33
- package/dist/services/utils/ensureBearerToken.d.mts +0 -158
- package/dist/services/utils/index.d.mts +0 -44
- package/dist/types/events.d.mts +0 -14
- package/dist/types/express.d.mts +0 -10
- package/dist/types/http.d.mts +0 -82
- package/dist/types/index.d.mts +0 -14
- package/dist/types/options.d.mts +0 -14
- package/dist/types/utils.d.mts +0 -48
- package/dist/types/wootils.d.mts +0 -4
- package/dist/utils/fns/index.d.mts +0 -5
- package/dist/utils/fns/others.d.mts +0 -17
- package/dist/utils/fns/routes.d.mts +0 -39
- package/dist/utils/fns/statuses.d.mts +0 -45
- package/dist/utils/fns/text.d.mts +0 -9
- package/dist/utils/index.d.mts +0 -19
- package/dist/utils/wrappers.d.mts +0 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/http/http.ts"],"sourcesContent":["import urijs from 'urijs';\nimport type { RequestInit, BodyInit } from 'node-fetch';\nimport { deepAssignWithOverwrite } from '@homer0/deep-assign';\nimport { provider } from '../../utils';\nimport { Logger, Request, HTTPResponse, NodeFetch } from '../../types';\n\n/**\n * The options to customize the service.\n *\n * @group Services/HTTP\n */\nexport type HTTPOptions = {\n /**\n * Whether or not the service should log the requests and their responses.\n */\n logRequests?: boolean;\n};\n/**\n * The options to construct a {@link HTTP}.\n *\n * @group Services/HTTP\n */\nexport type HTTPContructorOptions = Partial<HTTPOptions> & {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n logger: Logger;\n nodeFetch: NodeFetch;\n };\n};\n/**\n * The allowed formats for the body of a request.\n *\n * @group Services/HTTP\n */\nexport type HTTPFetchBody = string | Record<string | number, unknown> | BodyInit;\n/**\n * The options for a request.\n *\n * @group Services/HTTP\n */\nexport type HTTPFetchOptions = {\n /**\n * The HTTP method.\n *\n * @default 'GET'\n */\n method?: string;\n /**\n * The headers dictionary.\n */\n headers?: Record<string, string>;\n /**\n * The body of the request.\n */\n body?: HTTPFetchBody;\n /**\n * A dictionary of query string parameters.\n */\n qs?: Record<string, unknown>;\n /**\n * A request object generated by the application. This can be used to copy information\n * like custom headers or the IP (for the X-Forwarded-For header).\n */\n req?: Request;\n};\n/**\n * The options for the method that extracts custom headers from a request.\n *\n * @group Services/HTTP\n */\nexport type GetCustomHeadersFromRequestOptions = {\n /**\n * Since the method considers all headers that start with `x-` as custom headers,\n * setting this to `false` is the only way to exclude `x-forwarded-` headers from the\n * list.\n *\n * @default false\n */\n includeXForwardedHeaders?: boolean;\n};\n/**\n * A set of utilities to work with HTTP requests and responses.\n *\n * @group Services\n * @group Services/HTTP\n */\nexport class HTTP {\n /**\n * The service used to log information in the terminal.\n */\n protected readonly _logger: Logger;\n /**\n * The node-fetch library. Since it's an ESM only module, Jimpex loads it on boot and makes\n * it available on the container.\n */\n protected readonly _nodeFetch: NodeFetch;\n /**\n * The service customization options.\n */\n protected readonly _options: HTTPOptions;\n /**\n * @param options The options to construct the class.\n */\n constructor({ inject: { logger, nodeFetch }, ...options }: HTTPContructorOptions) {\n this._logger = logger;\n this._nodeFetch = nodeFetch;\n this._options = deepAssignWithOverwrite(\n {\n logRequests: false,\n },\n options,\n );\n\n this.fetch = this.fetch.bind(this);\n }\n /**\n * Makes a fetch request.\n *\n * @param url The URL to fetch.\n * @param options The custom options for the request.\n */\n async fetch(url: string, options: HTTPFetchOptions = {}): Promise<HTTPResponse> {\n let useURL = url;\n if (options.qs) {\n useURL = urijs(url).query(options.qs).toString();\n }\n\n const fetchOptions: RequestInit = {\n method: (options.method || 'get').toUpperCase(),\n body: options.body as BodyInit,\n };\n\n let defaultHeaders: Record<string, string> | undefined;\n if (options.req) {\n defaultHeaders = this.getCustomHeadersFromRequest(options.req);\n const ip = this.getIPFromRequest(options.req);\n if (ip) {\n defaultHeaders['x-forwarded-for'] = ip;\n }\n }\n const headers = {\n ...defaultHeaders,\n ...options.headers,\n };\n\n if (Object.keys(headers).length) {\n fetchOptions.headers = this.normalizeHeaders(headers);\n }\n\n const { logRequests } = this._options;\n if (logRequests) {\n this._logRequest(useURL, fetchOptions);\n }\n\n const response = await this._nodeFetch(useURL, fetchOptions);\n if (logRequests) {\n this._logResponse(response);\n }\n\n return response;\n }\n /**\n * Tries to get the IP address from a given request.\n *\n * @param req The request from which it will try to obtain the IP address.\n */\n getIPFromRequest(req: Request): string | undefined {\n const headerValue = req.headers['x-forwarded-for'];\n if (headerValue) {\n return String(headerValue);\n }\n\n return req?.connection?.remoteAddress || req?.socket?.remoteAddress;\n }\n /**\n * Creates a dictionary with all the custom headers a request has. By custom header it\n * means all the headers which name start with `x-`.\n *\n * @param req The request from which it will try to get the headers.\n * @param options The options to customize the behavior with certain headers.\n */\n getCustomHeadersFromRequest(\n req: Request,\n options: GetCustomHeadersFromRequestOptions = {},\n ): Record<string, string> {\n const { includeXForwardedHeaders = false } = options;\n return Object.keys(req.headers).reduce<Record<string, string>>((acc, headerName) => {\n if (\n headerName.startsWith('x-') &&\n (includeXForwardedHeaders || !headerName.startsWith('x-forwarded-'))\n ) {\n acc[headerName] = req.headers[headerName] as string;\n }\n return acc;\n }, {});\n }\n /**\n * It takes a dictionary of headers and normalize the names so each word will start with\n * an upper case character. This is helpful in case you added custom headers and didn't\n * care about the casing, or when copying headers from a server request, as they all\n * come tranformed into lower case.\n *\n * @param headers The dictionary of headers to normalize.\n */\n normalizeHeaders(headers: Record<string, string>): Record<string, string> {\n return Object.keys(headers).reduce<Record<string, string>>((acc, name) => {\n const newName = name\n .split('-')\n .map((part) => part.replace(/^(\\w)/, (_, letter) => letter.toUpperCase()))\n .join('-');\n\n acc[newName] = headers[name]!;\n return acc;\n }, {});\n }\n /**\n * The customization options.\n */\n get options(): Readonly<HTTPOptions> {\n return deepAssignWithOverwrite({}, this._options);\n }\n /**\n * Logs a request information into the terminal.\n *\n * @param url The request URL.\n * @param options The options for the request.\n */\n protected _logRequest(url: string, options: RequestInit): void {\n const { method, headers } = options;\n const prefix = 'REQUEST> ';\n const lines = ['--->>', `${prefix}${method} ${url}`];\n if (headers) {\n Object.keys(headers).forEach((header) => {\n const value = headers[header as keyof typeof headers];\n lines.push(`${prefix}${header}: ${value}`);\n });\n }\n\n if (options.body) {\n lines.push(`${prefix}body: \"${options.body}\"`);\n }\n\n this._logger.info(lines);\n }\n /**\n * Logs a response information into the terminal.\n *\n * @param response The response to log.\n */\n protected _logResponse(response: HTTPResponse) {\n const prefix = 'RESPONSE> ';\n const lines = [\n '<<---',\n `${prefix}${response.url}`,\n `${prefix}status: ${response.status}`,\n ];\n\n response.headers.forEach((value, header) => {\n lines.push(`${prefix}${header}: ${value}`);\n });\n\n this._logger.info(lines);\n }\n}\n/**\n * The service provider that once registered on the container will set an instance of\n * {@link HTTP} as the `http` service. The provider also checks the `debug.logRequests`\n * setting on the application configuration in order to enable or not the logging of\n * requests/responses.\n *\n * @example\n *\n * // Register it on the container\n * container.register(httpProvider);\n * // Getting access to the service instance\n * const http = container.get<HTTP>('http');\n *\n * @group Providers\n * @group Services/HTTP\n */\nexport const httpProvider = provider((app) => {\n app.set('http', () => {\n const config = app.getConfig();\n const logRequests = config.get<boolean | undefined>('debug.logRequests') === true;\n return new HTTP({\n inject: {\n logger: app.get('logger'),\n nodeFetch: app.get('node-fetch'),\n },\n logRequests,\n });\n });\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAElB,yBAAwC;AACxC,mBAAyB;AAqFlB,MAAM,KAAK;AAAA;AAAA;AAAA;AAAA,EAiBhB,YAAY,EAAE,QAAQ,EAAE,QAAQ,UAAU,GAAG,GAAG,QAAQ,GAA0B;AAblF;AAAA;AAAA;AAAA,wBAAmB;AAKnB;AAAA;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAmB;AAKjB,SAAK,UAAU;AACf,SAAK,aAAa;AAClB,SAAK,eAAW;AAAA,MACd;AAAA,QACE,aAAa;AAAA,MACf;AAAA,MACA;AAAA,IACF;AAEA,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,MAAM,KAAa,UAA4B,CAAC,GAA0B;AAC9E,QAAI,SAAS;AACb,QAAI,QAAQ,IAAI;AACd,mBAAS,aAAAA,SAAM,GAAG,EAAE,MAAM,QAAQ,EAAE,EAAE,SAAS;AAAA,IACjD;AAEA,UAAM,eAA4B;AAAA,MAChC,SAAS,QAAQ,UAAU,OAAO,YAAY;AAAA,MAC9C,MAAM,QAAQ;AAAA,IAChB;AAEA,QAAI;AACJ,QAAI,QAAQ,KAAK;AACf,uBAAiB,KAAK,4BAA4B,QAAQ,GAAG;AAC7D,YAAM,KAAK,KAAK,iBAAiB,QAAQ,GAAG;AAC5C,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AM;AACpB,UAAM,SAAS,IAAI,UAAU;AAC7B,UAAM,cAAc,OAAO,IAAyB,mBAAmB,MAAM;AAC7E,WAAO,IAAI,KAAK;AAAA,MACd,QAAQ;AAAA,QACN,QAAQ,IAAI,IAAI,QAAQ;AAAA,QACxB,WAAW,IAAI,IAAI,YAAY;AAAA,MACjC;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH,CAAC;","names":["urijs"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/services/http/http.ts"],"sourcesContent":["import urijs from 'urijs';\nimport type { RequestInit, BodyInit } from 'node-fetch';\nimport { deepAssignWithOverwrite } from '@homer0/deep-assign';\nimport { provider } from '../../utils/index.js';\nimport { Logger, Request, HTTPResponse, NodeFetch } from '../../types/index.js';\n\n/**\n * The options to customize the service.\n *\n * @group Services/HTTP\n */\nexport type HTTPOptions = {\n /**\n * Whether or not the service should log the requests and their responses.\n */\n logRequests?: boolean;\n};\n/**\n * The options to construct a {@link HTTP}.\n *\n * @group Services/HTTP\n */\nexport type HTTPConstructorOptions = Partial<HTTPOptions> & {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n logger: Logger;\n nodeFetch: NodeFetch;\n };\n};\n/**\n * The allowed formats for the body of a request.\n *\n * @group Services/HTTP\n */\nexport type HTTPFetchBody = string | Record<string | number, unknown> | BodyInit;\n/**\n * The options for a request.\n *\n * @group Services/HTTP\n */\nexport type HTTPFetchOptions = {\n /**\n * The HTTP method.\n *\n * @default 'GET'\n */\n method?: string;\n /**\n * The headers dictionary.\n */\n headers?: Record<string, string>;\n /**\n * The body of the request.\n */\n body?: HTTPFetchBody;\n /**\n * A dictionary of query string parameters.\n */\n qs?: Record<string, unknown>;\n /**\n * A request object generated by the application. This can be used to copy information\n * like custom headers or the IP (for the X-Forwarded-For header).\n */\n req?: Request;\n};\n/**\n * The options for the method that extracts custom headers from a request.\n *\n * @group Services/HTTP\n */\nexport type GetCustomHeadersFromRequestOptions = {\n /**\n * Since the method considers all headers that start with `x-` as custom headers,\n * setting this to `false` is the only way to exclude `x-forwarded-` headers from the\n * list.\n *\n * @default false\n */\n includeXForwardedHeaders?: boolean;\n};\n/**\n * A set of utilities to work with HTTP requests and responses.\n *\n * @group Services\n * @group Services/HTTP\n */\nexport class HTTP {\n /**\n * The service used to log information in the terminal.\n */\n protected readonly _logger: Logger;\n /**\n * The node-fetch library. Since it's an ESM only module, Jimpex loads it on boot and makes\n * it available on the container.\n */\n protected readonly _nodeFetch: NodeFetch;\n /**\n * The service customization options.\n */\n protected readonly _options: HTTPOptions;\n /**\n * @param options The options to construct the class.\n */\n constructor({ inject: { logger, nodeFetch }, ...options }: HTTPConstructorOptions) {\n this._logger = logger;\n this._nodeFetch = nodeFetch;\n this._options = deepAssignWithOverwrite(\n {\n logRequests: false,\n },\n options,\n );\n\n this.fetch = this.fetch.bind(this);\n }\n /**\n * Makes a fetch request.\n *\n * @param url The URL to fetch.\n * @param options The custom options for the request.\n */\n async fetch(url: string, options: HTTPFetchOptions = {}): Promise<HTTPResponse> {\n let useURL = url;\n if (options.qs) {\n useURL = urijs(url).query(options.qs).toString();\n }\n\n const fetchOptions: RequestInit = {\n method: (options.method || 'get').toUpperCase(),\n body: options.body as BodyInit,\n };\n\n let defaultHeaders: Record<string, string> | undefined;\n if (options.req) {\n defaultHeaders = this.getCustomHeadersFromRequest(options.req);\n const ip = this.getIPFromRequest(options.req);\n if (ip) {\n defaultHeaders['x-forwarded-for'] = ip;\n }\n }\n const headers = {\n ...defaultHeaders,\n ...options.headers,\n };\n\n if (Object.keys(headers).length) {\n fetchOptions.headers = this.normalizeHeaders(headers);\n }\n\n const { logRequests } = this._options;\n if (logRequests) {\n this._logRequest(useURL, fetchOptions);\n }\n\n const response = await this._nodeFetch(useURL, fetchOptions);\n if (logRequests) {\n this._logResponse(response);\n }\n\n return response;\n }\n /**\n * Tries to get the IP address from a given request.\n *\n * @param req The request from which it will try to obtain the IP address.\n */\n getIPFromRequest(req: Request): string | undefined {\n const headerValue = req.headers['x-forwarded-for'];\n if (headerValue) {\n return String(headerValue);\n }\n\n return req?.connection?.remoteAddress || req?.socket?.remoteAddress;\n }\n /**\n * Creates a dictionary with all the custom headers a request has. By custom header it\n * means all the headers which name start with `x-`.\n *\n * @param req The request from which it will try to get the headers.\n * @param options The options to customize the behavior with certain headers.\n */\n getCustomHeadersFromRequest(\n req: Request,\n options: GetCustomHeadersFromRequestOptions = {},\n ): Record<string, string> {\n const { includeXForwardedHeaders = false } = options;\n return Object.keys(req.headers).reduce<Record<string, string>>((acc, headerName) => {\n if (\n headerName.startsWith('x-') &&\n (includeXForwardedHeaders || !headerName.startsWith('x-forwarded-'))\n ) {\n acc[headerName] = req.headers[headerName] as string;\n }\n return acc;\n }, {});\n }\n /**\n * It takes a dictionary of headers and normalize the names so each word will start with\n * an upper case character. This is helpful in case you added custom headers and didn't\n * care about the casing, or when copying headers from a server request, as they all\n * come transformed into lower case.\n *\n * @param headers The dictionary of headers to normalize.\n */\n normalizeHeaders(headers: Record<string, string>): Record<string, string> {\n return Object.keys(headers).reduce<Record<string, string>>((acc, name) => {\n const newName = name\n .split('-')\n .map((part) => part.replace(/^(\\w)/, (_, letter) => letter.toUpperCase()))\n .join('-');\n\n acc[newName] = headers[name]!;\n return acc;\n }, {});\n }\n /**\n * The customization options.\n */\n get options(): Readonly<HTTPOptions> {\n return deepAssignWithOverwrite({}, this._options);\n }\n /**\n * Logs a request information into the terminal.\n *\n * @param url The request URL.\n * @param options The options for the request.\n */\n protected _logRequest(url: string, options: RequestInit): void {\n const { method, headers } = options;\n const prefix = 'REQUEST> ';\n const lines = ['--->>', `${prefix}${method} ${url}`];\n if (headers) {\n Object.keys(headers).forEach((header) => {\n const value = headers[header as keyof typeof headers];\n lines.push(`${prefix}${header}: ${value}`);\n });\n }\n\n if (options.body) {\n lines.push(`${prefix}body: \"${options.body}\"`);\n }\n\n this._logger.info(lines);\n }\n /**\n * Logs a response information into the terminal.\n *\n * @param response The response to log.\n */\n protected _logResponse(response: HTTPResponse) {\n const prefix = 'RESPONSE> ';\n const lines = [\n '<<---',\n `${prefix}${response.url}`,\n `${prefix}status: ${response.status}`,\n ];\n\n response.headers.forEach((value, header) => {\n lines.push(`${prefix}${header}: ${value}`);\n });\n\n this._logger.info(lines);\n }\n}\n/**\n * The service provider that once registered on the container will set an instance of\n * {@link HTTP} as the `http` service. The provider also checks the `debug.logRequests`\n * setting on the application configuration in order to enable or not the logging of\n * requests/responses.\n *\n * @example\n *\n * // Register it on the container\n * container.register(httpProvider);\n * // Getting access to the service instance\n * const http = container.get<HTTP>('http');\n *\n * @group Providers\n * @group Services/HTTP\n */\nexport const httpProvider = provider((app) => {\n app.set('http', () => {\n const config = app.getConfig();\n const logRequests = config.get<boolean | undefined>('debug.logRequests') === true;\n return new HTTP({\n inject: {\n logger: app.get('logger'),\n nodeFetch: app.get('node-fetch'),\n },\n logRequests,\n });\n });\n});\n"],"mappings":"AAAA,OAAO,WAAW;AAElB,SAAS,+BAA+B;AACxC,SAAS,gBAAgB;AAqFlB,MAAM,KAAK;AAAA;AAAA;AAAA;AAAA,EAIG;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA,EAIA;AAAA;AAAA;AAAA;AAAA,EAInB,YAAY,EAAE,QAAQ,EAAE,QAAQ,UAAU,GAAG,GAAG,QAAQ,GAA2B;AACjF,SAAK,UAAU;AACf,SAAK,aAAa;AAClB,SAAK,WAAW;AAAA,MACd;AAAA,QACE,aAAa;AAAA,MACf;AAAA,MACA;AAAA,IACF;AAEA,SAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,MAAM,KAAa,UAA4B,CAAC,GAA0B;AAC9E,QAAI,SAAS;AACb,QAAI,QAAQ,IAAI;AACd,eAAS,MAAM,GAAG,EAAE,MAAM,QAAQ,EAAE,EAAE,SAAS;AAAA,IACjD;AAEA,UAAM,e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AQ,CAAC,OAAO,WAAW;AAC1C,YAAM,KAAK,GAAG,MAAM,GAAG,MAAM,KAAK,KAAK,EAAE;AAAA,IAC3C,CAAC;AAED,SAAK,QAAQ,KAAK,KAAK;AAAA,EACzB;AACF;AAiBO,MAAM,eAAe,SAAS,CAAC,QAAQ;AAC5C,MAAI,IAAI,QAAQ,MAAM;AACpB,UAAM,SAAS,IAAI,UAAU;AAC7B,UAAM,cAAc,OAAO,IAAyB,mBAAmB,MAAM;AAC7E,WAAO,IAAI,KAAK;AAAA,MACd,QAAQ;AAAA,QACN,QAAQ,IAAI,IAAI,QAAQ;AAAA,QACxB,WAAW,IAAI,IAAI,YAAY;AAAA,MACjC;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH,CAAC;","names":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
-
import { J as Jimpex } from '../../index-
|
|
2
|
+
import { J as Jimpex } from '../../index-BlSpNHox.js';
|
|
3
3
|
export { ErrorResponse } from '@homer0/api-utils';
|
|
4
4
|
import { APIClientProviderOptions } from './apiClient.js';
|
|
5
5
|
export { APIClient, APIClientConfig, APIClientConstructorOptions, APIClientSettings, EndpointsType, apiClientProvider } from './apiClient.js';
|
|
6
|
-
export { GetCustomHeadersFromRequestOptions, HTTP,
|
|
6
|
+
export { GetCustomHeadersFromRequestOptions, HTTP, HTTPConstructorOptions, HTTPFetchBody, HTTPFetchOptions, HTTPOptions, httpProvider } from './http.js';
|
|
7
7
|
export { HTMLPostMessageResponseOptions, JSONResponseOptions, ResponsesBuilder, ResponsesBuilderConstructorOptions, responsesBuilderProvider } from './responsesBuilder.js';
|
|
8
8
|
import '../../types/express.js';
|
|
9
9
|
import 'express';
|
|
@@ -1,44 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var http_exports = {};
|
|
21
|
-
__export(http_exports, {
|
|
22
|
-
httpServicesProvider: () => httpServicesProvider
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(http_exports);
|
|
25
|
-
var import_utils = require("../../utils");
|
|
26
|
-
var import_apiClient = require("./apiClient");
|
|
27
|
-
var import_http = require("./http");
|
|
28
|
-
var import_responsesBuilder = require("./responsesBuilder");
|
|
29
|
-
__reExport(http_exports, require("./apiClient"), module.exports);
|
|
30
|
-
__reExport(http_exports, require("./http"), module.exports);
|
|
31
|
-
__reExport(http_exports, require("./responsesBuilder"), module.exports);
|
|
32
|
-
const httpServicesProvider = (0, import_utils.providers)({
|
|
33
|
-
apiClientProvider: import_apiClient.apiClientProvider,
|
|
34
|
-
httpProvider: import_http.httpProvider,
|
|
35
|
-
responsesBuilderProvider: import_responsesBuilder.responsesBuilderProvider
|
|
36
|
-
});
|
|
37
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
-
0 && (module.exports = {
|
|
39
|
-
httpServicesProvider,
|
|
40
|
-
...require("./apiClient"),
|
|
41
|
-
...require("./http"),
|
|
42
|
-
...require("./responsesBuilder")
|
|
1
|
+
import { providers } from "../../utils/index.js";
|
|
2
|
+
import { apiClientProvider } from "./apiClient.js";
|
|
3
|
+
import { httpProvider } from "./http.js";
|
|
4
|
+
import { responsesBuilderProvider } from "./responsesBuilder.js";
|
|
5
|
+
const httpServicesProvider = providers({
|
|
6
|
+
apiClientProvider,
|
|
7
|
+
httpProvider,
|
|
8
|
+
responsesBuilderProvider
|
|
43
9
|
});
|
|
10
|
+
export * from "./apiClient.js";
|
|
11
|
+
export * from "./http.js";
|
|
12
|
+
export * from "./responsesBuilder.js";
|
|
13
|
+
export {
|
|
14
|
+
httpServicesProvider
|
|
15
|
+
};
|
|
44
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/http/index.ts"],"sourcesContent":["import { providers } from '../../utils';\nimport { apiClientProvider } from './apiClient';\nimport { httpProvider } from './http';\nimport { responsesBuilderProvider } from './responsesBuilder';\n/**\n * Registers all the HTTP services on the container.\n *\n * - {@link APIClient | apiClient}\n * - {@link HTTP | http}\n * - {@link ResponsesBuilder | responsesBuilder}\n *\n * @example\n *\n * // Register the collection on the container\n * container.register(httpServicesProvider);\n * // Getting access to one the services instance\n * const apiClient = container.get<APIClient>('apiClient');\n *\n * @group Providers\n */\nexport const httpServicesProvider = providers({\n apiClientProvider,\n httpProvider,\n responsesBuilderProvider,\n});\n\nexport * from './apiClient';\nexport * from './http';\nexport * from './responsesBuilder';\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/services/http/index.ts"],"sourcesContent":["import { providers } from '../../utils/index.js';\nimport { apiClientProvider } from './apiClient.js';\nimport { httpProvider } from './http.js';\nimport { responsesBuilderProvider } from './responsesBuilder.js';\n/**\n * Registers all the HTTP services on the container.\n *\n * - {@link APIClient | apiClient}\n * - {@link HTTP | http}\n * - {@link ResponsesBuilder | responsesBuilder}\n *\n * @example\n *\n * // Register the collection on the container\n * container.register(httpServicesProvider);\n * // Getting access to one the services instance\n * const apiClient = container.get<APIClient>('apiClient');\n *\n * @group Providers\n */\nexport const httpServicesProvider = providers({\n apiClientProvider,\n httpProvider,\n responsesBuilderProvider,\n});\n\nexport * from './apiClient.js';\nexport * from './http.js';\nexport * from './responsesBuilder.js';\n"],"mappings":"AAAA,SAAS,iBAAiB;AAC1B,SAAS,yBAAyB;AAClC,SAAS,oBAAoB;AAC7B,SAAS,gCAAgC;AAiBlC,MAAM,uBAAuB,UAAU;AAAA,EAC5C;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
-
import { J as Jimpex } from '../../index-
|
|
2
|
+
import { J as Jimpex } from '../../index-BlSpNHox.js';
|
|
3
3
|
import { Response } from 'express';
|
|
4
4
|
import { Statuses } from '../../utils/fns/statuses.js';
|
|
5
5
|
import { SimpleConfig } from '@homer0/simple-config';
|
|
@@ -74,7 +74,7 @@ type HTMLPostMessageResponseOptions = {
|
|
|
74
74
|
closeDelay?: number;
|
|
75
75
|
};
|
|
76
76
|
/**
|
|
77
|
-
* The options to build a
|
|
77
|
+
* The options to build a response for JSON.
|
|
78
78
|
*
|
|
79
79
|
* @group Services/ResponsesBuilder
|
|
80
80
|
*/
|
|
@@ -110,7 +110,7 @@ declare class ResponsesBuilder {
|
|
|
110
110
|
*/
|
|
111
111
|
protected readonly _config: SimpleConfig;
|
|
112
112
|
/**
|
|
113
|
-
* The
|
|
113
|
+
* The utility service to get HTTP status codes.
|
|
114
114
|
*/
|
|
115
115
|
protected readonly _statuses: Statuses;
|
|
116
116
|
/**
|
|
@@ -152,7 +152,7 @@ declare class ResponsesBuilder {
|
|
|
152
152
|
*/
|
|
153
153
|
protected _htmlTemplate(title: string, code: string): string;
|
|
154
154
|
/**
|
|
155
|
-
* Utility method used to make sure a
|
|
155
|
+
* Utility method used to make sure a received status is a valid status code. If the
|
|
156
156
|
* status is a string, the method will try to find the code from the `statuses` package.
|
|
157
157
|
*
|
|
158
158
|
* @param status The status to normalize.
|
|
@@ -1,44 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
-
var responsesBuilder_exports = {};
|
|
22
|
-
__export(responsesBuilder_exports, {
|
|
23
|
-
ResponsesBuilder: () => ResponsesBuilder,
|
|
24
|
-
responsesBuilderProvider: () => responsesBuilderProvider
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(responsesBuilder_exports);
|
|
27
|
-
var import_utils = require("../../utils");
|
|
1
|
+
import { provider } from "../../utils/index.js";
|
|
28
2
|
const DEFAULT_CLOSE_DELAY_FOR_POST_MESSAGE = 700;
|
|
29
3
|
class ResponsesBuilder {
|
|
4
|
+
/**
|
|
5
|
+
* The application configuration, to get the `version` and the `postMessagesPrefix`.
|
|
6
|
+
*/
|
|
7
|
+
_config;
|
|
8
|
+
/**
|
|
9
|
+
* The utility service to get HTTP status codes.
|
|
10
|
+
*/
|
|
11
|
+
_statuses;
|
|
30
12
|
/**
|
|
31
13
|
* @param options The options to construct the service.
|
|
32
14
|
*/
|
|
33
15
|
constructor({ inject: { config, statuses } }) {
|
|
34
|
-
/**
|
|
35
|
-
* The application configuration, to get the `version` and the `postMessagesPrefix`.
|
|
36
|
-
*/
|
|
37
|
-
__publicField(this, "_config");
|
|
38
|
-
/**
|
|
39
|
-
* The uility service to get HTTP status codes.
|
|
40
|
-
*/
|
|
41
|
-
__publicField(this, "_statuses");
|
|
42
16
|
this._config = config;
|
|
43
17
|
this._statuses = statuses;
|
|
44
18
|
}
|
|
@@ -136,7 +110,7 @@ class ResponsesBuilder {
|
|
|
136
110
|
`;
|
|
137
111
|
}
|
|
138
112
|
/**
|
|
139
|
-
* Utility method used to make sure a
|
|
113
|
+
* Utility method used to make sure a received status is a valid status code. If the
|
|
140
114
|
* status is a string, the method will try to find the code from the `statuses` package.
|
|
141
115
|
*
|
|
142
116
|
* @param status The status to normalize.
|
|
@@ -157,7 +131,7 @@ class ResponsesBuilder {
|
|
|
157
131
|
return useStatus;
|
|
158
132
|
}
|
|
159
133
|
}
|
|
160
|
-
const responsesBuilderProvider =
|
|
134
|
+
const responsesBuilderProvider = provider((app) => {
|
|
161
135
|
app.set(
|
|
162
136
|
"responsesBuilder",
|
|
163
137
|
() => new ResponsesBuilder({
|
|
@@ -168,9 +142,8 @@ const responsesBuilderProvider = (0, import_utils.provider)((app) => {
|
|
|
168
142
|
})
|
|
169
143
|
);
|
|
170
144
|
});
|
|
171
|
-
|
|
172
|
-
0 && (module.exports = {
|
|
145
|
+
export {
|
|
173
146
|
ResponsesBuilder,
|
|
174
147
|
responsesBuilderProvider
|
|
175
|
-
}
|
|
148
|
+
};
|
|
176
149
|
//# sourceMappingURL=responsesBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/http/responsesBuilder.ts"],"sourcesContent":["import type { Config, Response } from '../../types';\nimport { provider, type Statuses } from '../../utils';\n/**\n * The options to construct a {@link ResponsesBuilder}.\n *\n * @group Services/ResponsesBuilder\n */\nexport type ResponsesBuilderConstructorOptions = {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n config: Config;\n statuses: Statuses;\n };\n};\n/**\n * The options to build a response for a post message.\n *\n * @group Services/ResponsesBuilder\n */\nexport type HTMLPostMessageResponseOptions = {\n /**\n * The response object generated by the application.\n */\n res: Response;\n /**\n * The title for the HTML.\n */\n title: string;\n /**\n * The contents of the post message.\n */\n message: string;\n /**\n * The status code for the response.\n *\n * @default 200\n */\n status?: number | string;\n /**\n * From which object will the `postMessage` method called from.\n *\n * @default 'window.opener'\n */\n target?: string;\n /**\n * Whether or not to call `window.close` after sending the message.\n *\n * @default true\n */\n close?: boolean;\n /**\n * In case `close` is set to `true`, this option is to specify how many milliseconds\n * should be waited before closing the window.\n *\n * @default 700\n */\n closeDelay?: number;\n};\n/**\n * The options to build a
|
|
1
|
+
{"version":3,"sources":["../../../src/services/http/responsesBuilder.ts"],"sourcesContent":["import type { Config, Response } from '../../types/index.js';\nimport { provider, type Statuses } from '../../utils/index.js';\n/**\n * The options to construct a {@link ResponsesBuilder}.\n *\n * @group Services/ResponsesBuilder\n */\nexport type ResponsesBuilderConstructorOptions = {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n config: Config;\n statuses: Statuses;\n };\n};\n/**\n * The options to build a response for a post message.\n *\n * @group Services/ResponsesBuilder\n */\nexport type HTMLPostMessageResponseOptions = {\n /**\n * The response object generated by the application.\n */\n res: Response;\n /**\n * The title for the HTML.\n */\n title: string;\n /**\n * The contents of the post message.\n */\n message: string;\n /**\n * The status code for the response.\n *\n * @default 200\n */\n status?: number | string;\n /**\n * From which object will the `postMessage` method called from.\n *\n * @default 'window.opener'\n */\n target?: string;\n /**\n * Whether or not to call `window.close` after sending the message.\n *\n * @default true\n */\n close?: boolean;\n /**\n * In case `close` is set to `true`, this option is to specify how many milliseconds\n * should be waited before closing the window.\n *\n * @default 700\n */\n closeDelay?: number;\n};\n/**\n * The options to build a response for JSON.\n *\n * @group Services/ResponsesBuilder\n */\nexport type JSONResponseOptions = {\n /**\n * The response object generated by the application.\n */\n res: Response;\n /**\n * The actual data for the response. It will be added in a `data` property.\n */\n data: unknown;\n /**\n * The status code for the response.\n *\n * @default 200\n */\n status?: number | string;\n /**\n * Extra information to include inside the `metadata` object.\n */\n metadata?: object;\n};\n/**\n * The default time to wait before closing a window, in case it's enabled.\n */\nconst DEFAULT_CLOSE_DELAY_FOR_POST_MESSAGE = 700;\n/**\n * A utility service to build responses.\n *\n * @group Services\n * @group Services/ResponsesBuilder\n */\nexport class ResponsesBuilder {\n /**\n * The application configuration, to get the `version` and the `postMessagesPrefix`.\n */\n protected readonly _config: Config;\n /**\n * The utility service to get HTTP status codes.\n */\n protected readonly _statuses: Statuses;\n /**\n * @param options The options to construct the service.\n */\n constructor({ inject: { config, statuses } }: ResponsesBuilderConstructorOptions) {\n this._config = config;\n this._statuses = statuses;\n }\n /**\n * Generates and send an HTML response that emits a post message.\n * The post message will be prefixed with the value of the configuration setting\n * `postMessagesPrefix`.\n *\n * @param options The options to customize how the HTML is generated.\n */\n htmlPostMessage(options: HTMLPostMessageResponseOptions): void {\n const {\n res,\n title,\n message,\n status,\n target = 'window.opener',\n close = true,\n closeDelay = DEFAULT_CLOSE_DELAY_FOR_POST_MESSAGE,\n } = options;\n const prefix = this._config.get<string | undefined>('postMessagesPrefix') ?? '';\n const closeCode = close\n ? `setTimeout(function() { window.close(); }, ${closeDelay});`\n : '';\n\n const html = this._htmlTemplate(\n title,\n `\n (function() {\n if (${target}) {\n ${target}.postMessage('${prefix}${message}', '*');\n ${closeCode}\n }\n })();\n `,\n );\n\n const useStatus =\n typeof status === 'undefined'\n ? (this._statuses('ok') as number)\n : this._normalizeStatus(status);\n\n res.setHeader('Content-Type', 'text/html');\n res.setHeader('Cache-Control', 'no-cache, max-age=0, must-revalidate, no-store');\n res.status(useStatus);\n res.write(html);\n res.end();\n }\n /**\n * Generates and sends a JSON response.\n *\n * @param options The options to customize how the JSON is generated.\n * @example\n *\n * <caption>The generated looks like this.</caption>\n *\n * {\n * metadata: {\n * version: 'dev',\n * status: 200,\n * },\n * data: { foo: 'bar' },\n * }\n *\n */\n json(options: JSONResponseOptions): void {\n const { res, data, status, metadata = {} } = options;\n const useStatus =\n typeof status === 'undefined'\n ? (this._statuses('ok') as number)\n : this._normalizeStatus(status);\n\n res.status(useStatus);\n res.json({\n metadata: {\n version: this._config.get<string>('version'),\n status: useStatus,\n ...metadata,\n },\n data,\n });\n res.end();\n }\n /**\n * Generates a basic HTML template for the service to use when generating a post message\n * response.\n *\n * @param title The HTML `<title />` attribute.\n * @param code Javascript code to be wrapped on a `<script />` tag.\n */\n protected _htmlTemplate(title: string, code: string): string {\n return `\n <!DOCTYPE html>\n <html>\n <head>\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"x-ua-compatible\" content=\"ie=edge\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <title>${title}</title>\n </head>\n <body>\n <script type=\"text/javascript\">\n ${code}\n </script>\n </body>\n </html>\n `;\n }\n /**\n * Utility method used to make sure a received status is a valid status code. If the\n * status is a string, the method will try to find the code from the `statuses` package.\n *\n * @param status The status to normalize.\n * @returns If `status` is a string, but there's no valid code, it will return 200.\n */\n protected _normalizeStatus(status: number | string): number {\n let useStatus: number;\n try {\n if (typeof status === 'string') {\n useStatus = this._statuses(status) as number;\n } else {\n this._statuses(status);\n useStatus = status;\n }\n } catch {\n useStatus = this._statuses('ok') as number;\n }\n\n return useStatus;\n }\n}\n/**\n * The service provider that once registered on the container will set an instance of\n * {@link ResponsesBuilder} as the `responsesBuilder` service.\n *\n * @example\n *\n * // Register it on the container\n * container.register(responsesBuilderProvider);\n * // Getting access to the service instance\n * const responsesBuilder = container.get<ResponsesBuilder>('responsesBuilder');\n *\n * @group Providers\n * @group Services/ResponsesBuilder\n */\nexport const responsesBuilderProvider = provider((app) => {\n app.set(\n 'responsesBuilder',\n () =>\n new ResponsesBuilder({\n inject: {\n config: app.getConfig(),\n statuses: app.get('statuses'),\n },\n }),\n );\n});\n"],"mappings":"AACA,SAAS,gBAA+B;AAuFxC,MAAM,uCAAuC;AAOtC,MAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAIT;AAAA;AAAA;AAAA;AAAA,EAIA;AAAA;AAAA;AAAA;AAAA,EAInB,YAAY,EAAE,QAAQ,EAAE,QAAQ,SAAS,EAAE,GAAuC;AAChF,SAAK,UAAU;AACf,SAAK,YAAY;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,gBAAgB,SAA+C;AAC7D,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,aAAa;AAAA,IACf,IAAI;AACJ,UAAM,SAAS,KAAK,QAAQ,IAAwB,oBAAoB,KAAK;AAC7E,UAAM,YAAY,QACd,8CAA8C,UAAU,OACxD;AAEJ,UAAM,OAAO,KAAK;AAAA,MAChB;AAAA,MACA;AAAA;AAAA,cAEQ,MAAM;AAAA,YACR,MAAM,iBAAiB,MAAM,GAAG,OAAO;AAAA,YACvC,SAAS;AAAA;AAAA;AAAA;AAAA,IAIjB;AAEA,UAAM,YACJ,OAAO,WAAW,cACb,KAAK,UAAU,IAAI,IACpB,KAAK,iBAAiB,MAAM;AAElC,QAAI,UAAU,gBAAgB,WAAW;AACzC,QAAI,UAAU,iBAAiB,gDAAgD;AAC/E,QAAI,OAAO,SAAS;AACpB,QAAI,MAAM,IAAI;AACd,QAAI,IAAI;AAAA,EACV;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBA,KAAK,SAAoC;AACvC,UAAM,EAAE,KAAK,MAAM,QAAQ,WAAW,CAAC,EAAE,IAAI;AAC7C,UAAM,YACJ,OAAO,WAAW,cACb,KAAK,UAAU,IAAI,IACpB,KAAK,iBAAiB,MAAM;AAElC,QAAI,OAAO,SAAS;AACpB,QAAI,KAAK;AAAA,MACP,UAAU;AAAA,QACR,SAAS,KAAK,QAAQ,IAAY,SAAS;AAAA,QAC3C,QAAQ;AAAA,QACR,GAAG;AAAA,MACL;AAAA,MACA;AAAA,IACF,CAAC;AACD,QAAI,IAAI;AAAA,EACV;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQU,cAAc,OAAe,MAAsB;AAC3D,WAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAOQ,KAAK;AAAA;AAAA;AAAA;AAAA,YAIZ,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA,EAKd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQU,iBAAiB,QAAiC;AAC1D,QAAI;AACJ,QAAI;AACF,UAAI,OAAO,WAAW,UAAU;AAC9B,oBAAY,KAAK,UAAU,MAAM;AAAA,MACnC,OAAO;AACL,aAAK,UAAU,MAAM;AACrB,oBAAY;AAAA,MACd;AAAA,IACF,QAAQ;AACN,kBAAY,KAAK,UAAU,IAAI;AAAA,IACjC;AAEA,WAAO;AAAA,EACT;AACF;AAeO,MAAM,2BAA2B,SAAS,CAAC,QAAQ;AACxD,MAAI;AAAA,IACF;AAAA,IACA,MACE,IAAI,iBAAiB;AAAA,MACnB,QAAQ;AAAA,QACN,QAAQ,IAAI,UAAU;AAAA,QACtB,UAAU,IAAI,IAAI,UAAU;AAAA,MAC9B;AAAA,IACF,CAAC;AAAA,EACL;AACF,CAAC;","names":[]}
|
package/dist/services/index.d.ts
CHANGED
|
@@ -10,11 +10,11 @@ export { FrontendFs, FrontendFsOptions, frontendFsProvider } from './frontend/fr
|
|
|
10
10
|
export { HTMLGenerator, HTMLGeneratorConstructorOptions, HTMLGeneratorOptions, HTMLGeneratorProviderOptions, HTMLGeneratorValuesService, htmlGeneratorProvider } from './html/htmlGenerator.js';
|
|
11
11
|
export { ErrorResponse } from '@homer0/api-utils';
|
|
12
12
|
export { APIClient, APIClientConfig, APIClientConstructorOptions, APIClientProviderOptions, APIClientSettings, EndpointsType, apiClientProvider } from './http/apiClient.js';
|
|
13
|
-
export { GetCustomHeadersFromRequestOptions, HTTP,
|
|
13
|
+
export { GetCustomHeadersFromRequestOptions, HTTP, HTTPConstructorOptions, HTTPFetchBody, HTTPFetchOptions, HTTPOptions, httpProvider } from './http/http.js';
|
|
14
14
|
export { HTMLPostMessageResponseOptions, JSONResponseOptions, ResponsesBuilder, ResponsesBuilderConstructorOptions, responsesBuilderProvider } from './http/responsesBuilder.js';
|
|
15
15
|
export { EnsureBearerConstructorOptions, EnsureBearerToken, EnsureBearerTokenErrorOptions, EnsureBearerTokenOptions, EnsureBearerTokenProviderOptions, ensureBearerTokenProvider } from './utils/ensureBearerToken.js';
|
|
16
16
|
import '@homer0/jimple';
|
|
17
|
-
import '../index-
|
|
17
|
+
import '../index-BlSpNHox.js';
|
|
18
18
|
import '../types/express.js';
|
|
19
19
|
import 'express';
|
|
20
20
|
import '../types/http.js';
|
|
@@ -29,5 +29,5 @@ import '@homer0/simple-config';
|
|
|
29
29
|
import '@homer0/events-hub';
|
|
30
30
|
import '../utils/fns/statuses.js';
|
|
31
31
|
import 'statuses';
|
|
32
|
-
import 'fs/promises';
|
|
32
|
+
import 'node:fs/promises';
|
|
33
33
|
import '@homer0/deferred';
|
package/dist/services/index.js
CHANGED
|
@@ -1,31 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
-
var services_exports = {};
|
|
17
|
-
module.exports = __toCommonJS(services_exports);
|
|
18
|
-
__reExport(services_exports, require("./common"), module.exports);
|
|
19
|
-
__reExport(services_exports, require("./frontend"), module.exports);
|
|
20
|
-
__reExport(services_exports, require("./html"), module.exports);
|
|
21
|
-
__reExport(services_exports, require("./http"), module.exports);
|
|
22
|
-
__reExport(services_exports, require("./utils"), module.exports);
|
|
23
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
24
|
-
0 && (module.exports = {
|
|
25
|
-
...require("./common"),
|
|
26
|
-
...require("./frontend"),
|
|
27
|
-
...require("./html"),
|
|
28
|
-
...require("./http"),
|
|
29
|
-
...require("./utils")
|
|
30
|
-
});
|
|
1
|
+
export * from "./common/index.js";
|
|
2
|
+
export * from "./frontend/index.js";
|
|
3
|
+
export * from "./html/index.js";
|
|
4
|
+
export * from "./http/index.js";
|
|
5
|
+
export * from "./utils/index.js";
|
|
31
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/services/index.ts"],"sourcesContent":["export * from './common';\nexport * from './frontend';\nexport * from './html';\nexport * from './http';\nexport * from './utils';\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/services/index.ts"],"sourcesContent":["export * from './common/index.js';\nexport * from './frontend/index.js';\nexport * from './html/index.js';\nexport * from './http/index.js';\nexport * from './utils/index.js';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
-
import { J as Jimpex } from '../../index-
|
|
2
|
+
import { J as Jimpex } from '../../index-BlSpNHox.js';
|
|
3
3
|
import { ExpressMiddleware } from '../../types/express.js';
|
|
4
4
|
import { Statuses } from '../../utils/fns/statuses.js';
|
|
5
5
|
import { DeepPartial } from '../../types/utils.js';
|
|
@@ -18,7 +18,7 @@ import 'statuses';
|
|
|
18
18
|
import '../common/appError.js';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* The options for the error the
|
|
21
|
+
* The options for the error the middleware can generate.
|
|
22
22
|
*
|
|
23
23
|
* @group Services/EnsureBearerToken
|
|
24
24
|
*/
|
|
@@ -1,32 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
-
var ensureBearerToken_exports = {};
|
|
22
|
-
__export(ensureBearerToken_exports, {
|
|
23
|
-
EnsureBearerToken: () => EnsureBearerToken,
|
|
24
|
-
ensureBearerTokenProvider: () => ensureBearerTokenProvider
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(ensureBearerToken_exports);
|
|
27
|
-
var import_deep_assign = require("@homer0/deep-assign");
|
|
28
|
-
var import_utils = require("../../utils");
|
|
1
|
+
import { deepAssignWithOverwrite } from "@homer0/deep-assign";
|
|
2
|
+
import { providerCreator } from "../../utils/index.js";
|
|
29
3
|
class EnsureBearerToken {
|
|
4
|
+
/**
|
|
5
|
+
* To generate the errors when the validation fails.
|
|
6
|
+
*/
|
|
7
|
+
_HTTPError;
|
|
8
|
+
/**
|
|
9
|
+
* The customization options for the service.
|
|
10
|
+
*/
|
|
11
|
+
_options;
|
|
30
12
|
/**
|
|
31
13
|
* @param options The options to construct the class.
|
|
32
14
|
*/
|
|
@@ -34,16 +16,8 @@ class EnsureBearerToken {
|
|
|
34
16
|
inject: { HTTPError, statuses },
|
|
35
17
|
...options
|
|
36
18
|
}) {
|
|
37
|
-
/**
|
|
38
|
-
* To generate the errors when the validation fails.
|
|
39
|
-
*/
|
|
40
|
-
__publicField(this, "_HTTPError");
|
|
41
|
-
/**
|
|
42
|
-
* The customization options for the service.
|
|
43
|
-
*/
|
|
44
|
-
__publicField(this, "_options");
|
|
45
19
|
this._HTTPError = HTTPError;
|
|
46
|
-
this._options =
|
|
20
|
+
this._options = deepAssignWithOverwrite(
|
|
47
21
|
{
|
|
48
22
|
error: {
|
|
49
23
|
message: "Unauthorized",
|
|
@@ -92,10 +66,10 @@ class EnsureBearerToken {
|
|
|
92
66
|
* The customization options.
|
|
93
67
|
*/
|
|
94
68
|
get options() {
|
|
95
|
-
return
|
|
69
|
+
return deepAssignWithOverwrite({}, this._options);
|
|
96
70
|
}
|
|
97
71
|
}
|
|
98
|
-
const ensureBearerTokenProvider =
|
|
72
|
+
const ensureBearerTokenProvider = providerCreator(
|
|
99
73
|
(options = {}) => (app) => {
|
|
100
74
|
const { serviceName = "ensureBearerToken", ...rest } = options;
|
|
101
75
|
app.set(
|
|
@@ -110,9 +84,8 @@ const ensureBearerTokenProvider = (0, import_utils.providerCreator)(
|
|
|
110
84
|
);
|
|
111
85
|
}
|
|
112
86
|
);
|
|
113
|
-
|
|
114
|
-
0 && (module.exports = {
|
|
87
|
+
export {
|
|
115
88
|
EnsureBearerToken,
|
|
116
89
|
ensureBearerTokenProvider
|
|
117
|
-
}
|
|
90
|
+
};
|
|
118
91
|
//# sourceMappingURL=ensureBearerToken.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/utils/ensureBearerToken.ts"],"sourcesContent":["import { deepAssignWithOverwrite } from '@homer0/deep-assign';\nimport { providerCreator, type Statuses } from '../../utils';\nimport type { HTTPErrorClass } from '../common';\nimport type { DeepPartial, ExpressMiddleware } from '../../types';\n/**\n * The options for the error the
|
|
1
|
+
{"version":3,"sources":["../../../src/services/utils/ensureBearerToken.ts"],"sourcesContent":["import { deepAssignWithOverwrite } from '@homer0/deep-assign';\nimport { providerCreator, type Statuses } from '../../utils/index.js';\nimport type { HTTPErrorClass } from '../common/index.js';\nimport type { DeepPartial, ExpressMiddleware } from '../../types/index.js';\n/**\n * The options for the error the middleware can generate.\n *\n * @group Services/EnsureBearerToken\n */\nexport type EnsureBearerTokenErrorOptions = {\n /**\n * The error message for the response.\n *\n * @default 'Unauthorized'\n */\n message: string;\n /**\n * The HTTP status that will be added to the error context.\n *\n * @default 401\n */\n status: number;\n /**\n * Context information for the error handler and that can be added to the actual\n * response.\n */\n response: unknown;\n};\n/**\n * The options to customize the service/middleware.\n *\n * @group Services/EnsureBearerToken\n */\nexport type EnsureBearerTokenOptions = {\n error: EnsureBearerTokenErrorOptions;\n expression: RegExp;\n local: string;\n};\n/**\n * The options to construct a {@link EnsureBearerToken}.\n *\n * @group Services/EnsureBearerToken\n */\nexport type EnsureBearerConstructorOptions = DeepPartial<EnsureBearerTokenOptions> & {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n HTTPError: HTTPErrorClass;\n statuses: Statuses;\n };\n};\n/**\n * Custom options for the provider that will register an instance of\n * {@link EnsureBearerToken}\n * as a service.\n *\n * @group Services/EnsureBearerToken\n */\nexport type EnsureBearerTokenProviderOptions = DeepPartial<EnsureBearerTokenOptions> & {\n /**\n * The name that will be used to register the service on the container. This is to allow\n * multiple \"instances\" of the service to be created.\n *\n * @default 'ensureBearerToken'\n */\n serviceName?: string;\n};\n/**\n * This service gives you a middleware that verifies if a request has an `Authorization`\n * header with a bearer token; if it does, the token will be saved on the `res.locals`,\n * otherwise, it will generate an error.\n *\n * This is a \"service middleware\" to allow certain flexibility: you can have controllers\n * where some routes are protected and others are not. For those cases, you get the\n * service from the container, and include it only in the routes that need it.\n *\n * @group Services\n * @group Services/EnsureBearerToken\n */\nexport class EnsureBearerToken {\n /**\n * To generate the errors when the validation fails.\n */\n protected readonly _HTTPError: HTTPErrorClass;\n /**\n * The customization options for the service.\n */\n protected readonly _options: EnsureBearerTokenOptions;\n /**\n * @param options The options to construct the class.\n */\n constructor({\n inject: { HTTPError, statuses },\n ...options\n }: EnsureBearerConstructorOptions) {\n this._HTTPError = HTTPError;\n this._options = deepAssignWithOverwrite(\n {\n error: {\n message: 'Unauthorized',\n status: statuses('unauthorized'),\n response: {},\n },\n expression: /bearer (.*?)(?:$|\\s)/i,\n local: 'token',\n },\n options,\n );\n }\n /**\n * Generates the middleware that verifies if a request has an `Authorization` header\n * with a bearer token.\n */\n getMiddleware(): ExpressMiddleware {\n return (req, res, next) => {\n let unauthorized = true;\n const {\n headers: { authorization },\n } = req;\n if (authorization) {\n const matches = this._options.expression.exec(authorization);\n if (matches) {\n const [, token] = matches;\n res.locals[this._options.local] = token;\n unauthorized = false;\n }\n }\n\n if (unauthorized) {\n const {\n error: { message, status, response },\n } = this._options;\n next(\n new this._HTTPError(message, status, {\n response,\n }),\n );\n } else {\n next();\n }\n };\n }\n /**\n * The customization options.\n */\n get options(): Readonly<EnsureBearerTokenOptions> {\n return deepAssignWithOverwrite({}, this._options);\n }\n}\n/**\n * Generates a \"service middleware\" that can be used on route controllers in order to\n * validate the presence of a bearer token on the requests authorization header.\n *\n * The registered service is an instance of {@link EnsureBearerToken}, and it uses the key\n * `ensureBearerToken`.\n *\n * Since it's a \"provider creator\", when registering it, you can pass custom options.\n *\n * @example\n *\n * <caption>Basic usage</caption>\n *\n * // Register it on the container\n * container.register(ensureBearerTokenProvider);\n *\n * // Let's assume we are in a controller now...\n * // Getting access to the middleware.\n * const ensureBearerToken = container.get<ExpressMiddleware>('ensureBearerToken');\n *\n * @example\n *\n * <caption>Customizing the service</caption>\n *\n * // Register it on the container\n * container.register(\n * ensureBearerTokenProvider({\n * serviceName: 'ensureBearerTokenCustom',\n * error: {\n * message: 'Missing token!',\n * },\n * }),\n * );\n *\n * @group Providers\n * @group Services/EnsureBearerToken\n */\nexport const ensureBearerTokenProvider = providerCreator(\n (options: EnsureBearerTokenProviderOptions = {}) =>\n (app) => {\n const { serviceName = 'ensureBearerToken', ...rest } = options;\n app.set(serviceName, () =>\n new EnsureBearerToken({\n inject: {\n HTTPError: app.get('HTTPError'),\n statuses: app.get('statuses'),\n },\n ...rest,\n }).getMiddleware(),\n );\n },\n);\n"],"mappings":"AAAA,SAAS,+BAA+B;AACxC,SAAS,uBAAsC;AA+ExC,MAAM,kBAAkB;AAAA;AAAA;AAAA;AAAA,EAIV;AAAA;AAAA;AAAA;AAAA,EAIA;AAAA;AAAA;AAAA;AAAA,EAInB,YAAY;AAAA,IACV,QAAQ,EAAE,WAAW,SAAS;AAAA,IAC9B,GAAG;AAAA,EACL,GAAmC;AACjC,SAAK,aAAa;AAClB,SAAK,WAAW;AAAA,MACd;AAAA,QACE,OAAO;AAAA,UACL,SAAS;AAAA,UACT,QAAQ,SAAS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1
|
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
-
import { J as Jimpex } from '../../index-
|
|
2
|
+
import { J as Jimpex } from '../../index-BlSpNHox.js';
|
|
3
3
|
import { EnsureBearerTokenProviderOptions } from './ensureBearerToken.js';
|
|
4
4
|
export { EnsureBearerConstructorOptions, EnsureBearerToken, EnsureBearerTokenErrorOptions, EnsureBearerTokenOptions, ensureBearerTokenProvider } from './ensureBearerToken.js';
|
|
5
5
|
import '../../types/express.js';
|
|
@@ -1,36 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var utils_exports = {};
|
|
21
|
-
__export(utils_exports, {
|
|
22
|
-
utilsServicesProvider: () => utilsServicesProvider
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(utils_exports);
|
|
25
|
-
var import_utils = require("../../utils");
|
|
26
|
-
var import_ensureBearerToken = require("./ensureBearerToken");
|
|
27
|
-
__reExport(utils_exports, require("./ensureBearerToken"), module.exports);
|
|
28
|
-
const utilsServicesProvider = (0, import_utils.providers)({
|
|
29
|
-
ensureBearerTokenProvider: import_ensureBearerToken.ensureBearerTokenProvider
|
|
30
|
-
});
|
|
31
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
-
0 && (module.exports = {
|
|
33
|
-
utilsServicesProvider,
|
|
34
|
-
...require("./ensureBearerToken")
|
|
1
|
+
import { providers } from "../../utils/index.js";
|
|
2
|
+
import { ensureBearerTokenProvider } from "./ensureBearerToken.js";
|
|
3
|
+
const utilsServicesProvider = providers({
|
|
4
|
+
ensureBearerTokenProvider
|
|
35
5
|
});
|
|
6
|
+
export * from "./ensureBearerToken.js";
|
|
7
|
+
export {
|
|
8
|
+
utilsServicesProvider
|
|
9
|
+
};
|
|
36
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/utils/index.ts"],"sourcesContent":["import { providers } from '../../utils';\nimport { ensureBearerTokenProvider } from './ensureBearerToken';\n/**\n * Registers all the utility services on the container.\n *\n * - {@link EnsureBearerToken | ensureBearerToken}\n *\n * @example\n *\n * // Register the collection on the container\n * container.register(utilsServicesProvider);\n * // Getting access to one the services instance\n * const ensureBearerToken = container.get<EnsureBearerToken>('ensureBearerToken');\n *\n * @group Providers\n */\nexport const utilsServicesProvider = providers({\n ensureBearerTokenProvider,\n});\n\nexport * from './ensureBearerToken';\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/services/utils/index.ts"],"sourcesContent":["import { providers } from '../../utils/index.js';\nimport { ensureBearerTokenProvider } from './ensureBearerToken.js';\n/**\n * Registers all the utility services on the container.\n *\n * - {@link EnsureBearerToken | ensureBearerToken}\n *\n * @example\n *\n * // Register the collection on the container\n * container.register(utilsServicesProvider);\n * // Getting access to one the services instance\n * const ensureBearerToken = container.get<EnsureBearerToken>('ensureBearerToken');\n *\n * @group Providers\n */\nexport const utilsServicesProvider = providers({\n ensureBearerTokenProvider,\n});\n\nexport * from './ensureBearerToken.js';\n"],"mappings":"AAAA,SAAS,iBAAiB;AAC1B,SAAS,iCAAiC;AAenC,MAAM,wBAAwB,UAAU;AAAA,EAC7C;AACF,CAAC;AAED,cAAc;","names":[]}
|
package/dist/types/events.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import './express.js';
|
|
2
|
-
export { E as EventPayload, l as Events, k as JimpexEventListener, b as JimpexEventName, i as JimpexEventNameLike, c as JimpexEventPayload, a as JimpexEvents, f as JimpexReducerEventName, h as JimpexReducerEventPayload, e as JimpexReducerEventPayloads, g as JimpexReducerEventTarget, d as JimpexReducerEventTargets } from '../index-
|
|
2
|
+
export { E as EventPayload, l as Events, k as JimpexEventListener, b as JimpexEventName, i as JimpexEventNameLike, c as JimpexEventPayload, a as JimpexEvents, f as JimpexReducerEventName, h as JimpexReducerEventPayload, e as JimpexReducerEventPayloads, g as JimpexReducerEventTarget, d as JimpexReducerEventTargets } from '../index-BlSpNHox.js';
|
|
3
3
|
import 'express';
|
|
4
4
|
import './http.js';
|
|
5
5
|
import 'https';
|
package/dist/types/events.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var events_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(events_exports);
|
|
17
1
|
//# sourceMappingURL=events.js.map
|