@xylabs/express 5.0.80 → 5.0.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +229 -55
  2. package/package.json +10 -14
  3. package/src/Handler/RouteDefinition/RouteDefinition.ts +0 -18
  4. package/src/Handler/RouteDefinition/addRouteDefinitions.ts +0 -9
  5. package/src/Handler/RouteDefinition/index.ts +0 -2
  6. package/src/Handler/StatusCodeHandlers/index.ts +0 -1
  7. package/src/Handler/StatusCodeHandlers/notImplemented.ts +0 -6
  8. package/src/Handler/asyncHandler.ts +0 -21
  9. package/src/Handler/errorToJsonHandler.ts +0 -16
  10. package/src/Handler/index.ts +0 -4
  11. package/src/HttpUtil/getHttpHeader.ts +0 -27
  12. package/src/HttpUtil/index.ts +0 -1
  13. package/src/Logger/LogFormats/LocalDev/index.ts +0 -1
  14. package/src/Logger/LogFormats/LocalDev/logFormatLocalDev.ts +0 -11
  15. package/src/Logger/LogFormats/Rollbar/index.ts +0 -1
  16. package/src/Logger/LogFormats/Rollbar/logFormatRollbar.ts +0 -5
  17. package/src/Logger/LogFormats/Structured/index.ts +0 -1
  18. package/src/Logger/LogFormats/Structured/logFormatStructured.ts +0 -7
  19. package/src/Logger/LogFormats/index.ts +0 -3
  20. package/src/Logger/LoggerMeta.ts +0 -1
  21. package/src/Logger/LoggerOptions.ts +0 -7
  22. package/src/Logger/LoggerVerbosity.ts +0 -1
  23. package/src/Logger/Transports/Rollbar/RollbarTransport.ts +0 -24
  24. package/src/Logger/Transports/Rollbar/canGetDefaultRollbarTransport.ts +0 -3
  25. package/src/Logger/Transports/Rollbar/getDefaultRollbarTransport.ts +0 -10
  26. package/src/Logger/Transports/Rollbar/index.ts +0 -3
  27. package/src/Logger/Transports/index.ts +0 -1
  28. package/src/Logger/WinstonVerbosity.ts +0 -5
  29. package/src/Logger/WrappedWinstonLogger.ts +0 -20
  30. package/src/Logger/getDefaultLogger.ts +0 -21
  31. package/src/Logger/getLogger.ts +0 -55
  32. package/src/Logger/index.ts +0 -13
  33. package/src/Logger/toWinstonVerbosity.ts +0 -6
  34. package/src/Model/ExpressError.ts +0 -3
  35. package/src/Model/index.ts +0 -1
  36. package/src/Performance/Counters.ts +0 -36
  37. package/src/Performance/Profiler.ts +0 -10
  38. package/src/Performance/index.ts +0 -2
  39. package/src/Util/compactObject.ts +0 -9
  40. package/src/Util/index.ts +0 -2
  41. package/src/Util/tryParse.ts +0 -17
  42. package/src/Validation/index.ts +0 -1
  43. package/src/Validation/requestHandlerValidator.ts +0 -120
  44. package/src/index.ts +0 -8
  45. package/src/middleware/caseInsensitiveRouting/caseInsensitiveRouting.ts +0 -21
  46. package/src/middleware/caseInsensitiveRouting/index.ts +0 -1
  47. package/src/middleware/customPoweredByHeader/customPoweredByHeader.ts +0 -29
  48. package/src/middleware/customPoweredByHeader/index.ts +0 -1
  49. package/src/middleware/index.ts +0 -5
  50. package/src/middleware/jsonBodyParser/index.ts +0 -1
  51. package/src/middleware/jsonBodyParser/jsonBodyParser.ts +0 -59
  52. package/src/middleware/metrics/counters.ts +0 -25
  53. package/src/middleware/metrics/index.ts +0 -2
  54. package/src/middleware/metrics/responseProfiler.ts +0 -23
  55. package/src/middleware/standardResponses/getResponseMetadata.ts +0 -18
  56. package/src/middleware/standardResponses/index.ts +0 -4
  57. package/src/middleware/standardResponses/jsonApi/README.md +0 -4
  58. package/src/middleware/standardResponses/jsonApi/error.ts +0 -52
  59. package/src/middleware/standardResponses/jsonApi/index.ts +0 -5
  60. package/src/middleware/standardResponses/jsonApi/links.ts +0 -6
  61. package/src/middleware/standardResponses/jsonApi/relationship.ts +0 -43
  62. package/src/middleware/standardResponses/jsonApi/resourceIdentifier.ts +0 -15
  63. package/src/middleware/standardResponses/jsonApi/response.ts +0 -49
  64. package/src/middleware/standardResponses/standardErrors.ts +0 -27
  65. package/src/middleware/standardResponses/standardResponses.ts +0 -61
@@ -1,52 +0,0 @@
1
- import type { ApiLinks } from './links.ts'
2
-
3
- /**
4
- * An object containing references to the source of the error
5
- */
6
- export interface Source {
7
- /**
8
- * A string indicating which URI query parameter caused the error.
9
- */
10
- parameter?: string
11
- /**
12
- * A JSON Pointer [RFC6901] to the associated entity in the request document [e.g. "/data" for a primary data object,
13
- * or "/data/attributes/title" for a specific attribute].
14
- */
15
- pointer?: string
16
- }
17
-
18
- export interface ApiError {
19
- /**
20
- * An application-specific error code, expressed as a string value.
21
- */
22
- code?: string
23
- /**
24
- * A human-readable explanation specific to this occurrence of the problem. Like title, this field's value can be localized.
25
- */
26
- detail?: string
27
- /**
28
- * A unique identifier for this particular occurrence of the problem.
29
- */
30
- id?: string
31
- /**
32
- * A links object containing the following members:
33
- * about: a link that leads to further details about this particular occurrence of the problem
34
- */
35
- links?: ApiLinks
36
- /**
37
- * A meta object containing non-standard meta-information about the error.
38
- */
39
- meta?: Record<string, unknown>
40
- /**
41
- * An object containing references to the source of the error, optionally including any of the following members:
42
- */
43
- source?: Source
44
- /**
45
- * The HTTP status code applicable to this problem, expressed as a string value.
46
- */
47
- status?: string
48
- /**
49
- * A short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization.
50
- */
51
- title?: string
52
- }
@@ -1,5 +0,0 @@
1
- export * from './error.ts'
2
- export * from './links.ts'
3
- export * from './relationship.ts'
4
- export * from './resourceIdentifier.ts'
5
- export * from './response.ts'
@@ -1,6 +0,0 @@
1
- export interface HrefWithMeta {
2
- href: string
3
- meta: Record<string, unknown>
4
- }
5
- export type ApiLink = string | HrefWithMeta
6
- export type ApiLinks = Record<string, ApiLink>
@@ -1,43 +0,0 @@
1
- import type { ApiResourceIdentifierObject } from './resourceIdentifier.ts'
2
-
3
- export interface IRelationshipSelfLink {
4
- /**
5
- * A link for the relationship itself (a "relationship link"). This link allows the client to directly manipulate the relationship.
6
- * For example, removing an author through an article’s relationship URL would disconnect the person from the article without
7
- * deleting the people resource itself. When fetched successfully, this link returns the linkage for the related resources as its primary data.
8
- */
9
- self: string
10
- }
11
-
12
- export interface IRelationshipRelatedLink {
13
- /**
14
- * A related resource link
15
- */
16
- related: string
17
- }
18
-
19
- export interface IRelationshipLinks {
20
- links: IRelationshipRelatedLink | IRelationshipSelfLink
21
- }
22
-
23
- /**
24
- * Resource linkage in a compound document allows a client to link together all of the included resource objects without having to GET any URLs via links.
25
- * Resource linkage MUST be represented as one of the following:
26
- * • null for empty to-one relationships.
27
- * • an empty array ([]) for empty to-many relationships.
28
- * • a single resource identifier object for non-empty to-one relationships.
29
- * • an array of resource identifier objects for non-empty to-many relationships.
30
- */
31
- export type ResourceLinkage = null | [] | ApiResourceIdentifierObject | ApiResourceIdentifierObject[]
32
- export interface IRelationshipData {
33
- data: ResourceLinkage
34
- }
35
-
36
- export type RelationshipMeta = Record<string, unknown>
37
-
38
- /**
39
- * The value of the relationships key MUST be an object (a "relationships object"). Members of the relationships object ("relationships")
40
- * represent references from the resource object in which it’s defined to other resource objects.
41
- * Relationships may be to-one or to-many.
42
- */
43
- export type Relationship = IRelationshipLinks | IRelationshipData | RelationshipMeta
@@ -1,15 +0,0 @@
1
- /**
2
- * Within a given API, each resource object's type and id pair MUST identify a single, unique resource.
3
- * (The set of URIs controlled by a server, or multiple servers acting as one, constitute an API.)
4
- */
5
- export interface ApiResourceIdentifierObject {
6
- /**
7
- * The id member is not required when the resource object originates at the client and represents a new resource to be created on the server.
8
- */
9
- id: string
10
- /**
11
- * The type member is used to describe resource objects that share common attributes and relationships.
12
- * The values of type members MUST adhere to the same constraints as member names.
13
- */
14
- type: string
15
- }
@@ -1,49 +0,0 @@
1
- /**
2
- * Loosely following the JSON API 1.0 formats and conventions
3
- * https://jsonapi.org/format/
4
- */
5
-
6
- import type { ApiError } from './error.ts'
7
- import type { ApiLinks } from './links.ts'
8
- import type { Relationship } from './relationship.ts'
9
- import type { ApiResourceIdentifierObject } from './resourceIdentifier.ts'
10
-
11
- export interface ApiResourceObject extends ApiResourceIdentifierObject {
12
- /**
13
- * An attributes object representing some of the resource's data.
14
- */
15
- attributes?: Record<string, unknown>
16
- /**
17
- * A links object containing links related to the resource.
18
- */
19
- links?: ApiLinks
20
- /**
21
- * A meta object containing non-standard meta-information about a resource that can not be represented as an attribute or relationship.
22
- */
23
- meta?: Record<string, unknown>
24
- /**
25
- * A relationships object describing relationships between the resource and other JSON:API resources.
26
- */
27
- relationships?: Record<string, Relationship>
28
- }
29
-
30
- export interface JsonApi {
31
- meta?: Record<string, unknown>
32
- version?: '1.0' | '1.1'
33
- }
34
-
35
- export interface ApiResponseBase {
36
- jsonapi?: JsonApi
37
- links?: ApiLinks
38
- meta?: Record<string, unknown>
39
- }
40
-
41
- export interface ApiDataResponse<T extends ApiResourceIdentifierObject> extends ApiResponseBase {
42
- data: T
43
- included?: ApiResourceObject[]
44
- }
45
- export interface ApiErrorResponse extends ApiResponseBase {
46
- errors: ApiError[]
47
- }
48
-
49
- export type ApiResponse<T extends ApiResourceIdentifierObject> = ApiDataResponse<T> | ApiErrorResponse
@@ -1,27 +0,0 @@
1
- import { isError } from '@xylabs/typeof'
2
- import type {
3
- NextFunction, Request, Response,
4
- } from 'express'
5
-
6
- import { getDefaultLogger } from '../../Logger/index.ts'
7
- import type { ExpressError } from '../../Model/index.ts'
8
- import type { ApiError } from './jsonApi/index.ts'
9
-
10
- export const standardErrors = (err: ExpressError | undefined, req: Request, res: Response, next: NextFunction) => {
11
- if (!isError(err)) {
12
- next(err)
13
- return
14
- }
15
- getDefaultLogger().error(err.message)
16
- err.statusCode = err.statusCode ?? 500
17
-
18
- const error: ApiError = {
19
- detail: err.message,
20
- status: `${err.statusCode}`,
21
- title: err.name,
22
- }
23
-
24
- res.status(err.statusCode).json(error)
25
-
26
- next(err)
27
- }
@@ -1,61 +0,0 @@
1
- import type {
2
- Request, RequestHandler, Response,
3
- } from 'express'
4
- import mung from 'express-mung'
5
-
6
- import { getResponseMetadata } from './getResponseMetadata.js'
7
-
8
- interface TransformResponseLocals {
9
- rawResponse?: boolean
10
- }
11
-
12
- /**
13
- * Flags the response to forgo the standard response envelope
14
- * and return the raw response body to the client
15
- * @param res The response to disable the standard response format on
16
- */
17
- export const setRawResponseFormat = (res: Response): void => {
18
- res.locals.rawResponse = true
19
- }
20
-
21
- /**
22
- * Clears any flags on the response, allowing the response to
23
- * use the default standard response envelope
24
- * @param res The response to set to the standard response format
25
- */
26
- export const clearRawResponseFormat = (res: Response): void => {
27
- res.locals.rawResponse = false
28
- }
29
-
30
- /**
31
- * Checks if there are any flags on the response that would cause it
32
- * to forgo the standard response envelope and return the raw response
33
- * body to the client
34
- * @param res
35
- * @returns True if there are any flags on the response, false otherwise
36
- */
37
- export const isRawResponseFormatSet = (res: Response): boolean => {
38
- return res.locals.rawResponse ? true : false
39
- }
40
-
41
- /**
42
- * Transforms each response to conform to the standard response format (compatible with JSON API)
43
- * @param body The original request body
44
- * @param _req The request
45
- * @param res The response
46
- * @returns The transformed response body
47
- */
48
- const transformResponse = (body: unknown, _req: Request, res: Response<unknown, TransformResponseLocals>) => {
49
- return isRawResponseFormatSet(res)
50
- ? body
51
- : (res.statusCode >= 200 && res.statusCode < 300)
52
- ? { data: body, meta: getResponseMetadata(res) }
53
- : { error: body, meta: getResponseMetadata(res) }
54
- }
55
-
56
- /**
57
- * Connect middleware to enable the transform of all responses to match
58
- * the standard response format (compatible with JSON API)
59
- */
60
-
61
- export const standardResponses: RequestHandler = mung.json(transformResponse, { mungError: true })