@pikku/core 0.6.9

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 (167) hide show
  1. package/CHANGELOG.md +339 -0
  2. package/README.md +5 -0
  3. package/dist/channel/channel-handler.d.ts +3 -0
  4. package/dist/channel/channel-handler.js +97 -0
  5. package/dist/channel/channel-runner.d.ts +26 -0
  6. package/dist/channel/channel-runner.js +86 -0
  7. package/dist/channel/channel-store.d.ts +14 -0
  8. package/dist/channel/channel-store.js +2 -0
  9. package/dist/channel/channel.types.d.ts +106 -0
  10. package/dist/channel/channel.types.js +1 -0
  11. package/dist/channel/eventhub-forwarder.d.ts +17 -0
  12. package/dist/channel/eventhub-forwarder.js +1 -0
  13. package/dist/channel/eventhub-service.d.ts +23 -0
  14. package/dist/channel/eventhub-service.js +1 -0
  15. package/dist/channel/eventhub-store.d.ts +5 -0
  16. package/dist/channel/eventhub-store.js +2 -0
  17. package/dist/channel/index.d.ts +9 -0
  18. package/dist/channel/index.js +9 -0
  19. package/dist/channel/local/index.d.ts +3 -0
  20. package/dist/channel/local/index.js +3 -0
  21. package/dist/channel/local/local-channel-handler.d.ts +17 -0
  22. package/dist/channel/local/local-channel-handler.js +41 -0
  23. package/dist/channel/local/local-channel-runner.d.ts +3 -0
  24. package/dist/channel/local/local-channel-runner.js +46 -0
  25. package/dist/channel/local/local-eventhub-service.d.ts +44 -0
  26. package/dist/channel/local/local-eventhub-service.js +81 -0
  27. package/dist/channel/log-channels.d.ts +6 -0
  28. package/dist/channel/log-channels.js +17 -0
  29. package/dist/channel/pikku-abstract-channel-handler.d.ts +15 -0
  30. package/dist/channel/pikku-abstract-channel-handler.js +33 -0
  31. package/dist/channel/serverless/index.d.ts +1 -0
  32. package/dist/channel/serverless/index.js +1 -0
  33. package/dist/channel/serverless/serverless-channel-runner.d.ts +10 -0
  34. package/dist/channel/serverless/serverless-channel-runner.js +98 -0
  35. package/dist/errors/error-handler.d.ts +39 -0
  36. package/dist/errors/error-handler.js +54 -0
  37. package/dist/errors/errors.d.ts +190 -0
  38. package/dist/errors/errors.js +315 -0
  39. package/dist/errors/index.d.ts +2 -0
  40. package/dist/errors/index.js +2 -0
  41. package/dist/http/http-route-runner.d.ts +30 -0
  42. package/dist/http/http-route-runner.js +208 -0
  43. package/dist/http/http-routes.types.d.ts +127 -0
  44. package/dist/http/http-routes.types.js +1 -0
  45. package/dist/http/http-session-service.d.ts +15 -0
  46. package/dist/http/http-session-service.js +1 -0
  47. package/dist/http/index.d.ts +6 -0
  48. package/dist/http/index.js +5 -0
  49. package/dist/http/log-http-routes.d.ts +6 -0
  50. package/dist/http/log-http-routes.js +17 -0
  51. package/dist/http/pikku-http-abstract-request.d.ts +57 -0
  52. package/dist/http/pikku-http-abstract-request.js +69 -0
  53. package/dist/http/pikku-http-abstract-response.d.ts +58 -0
  54. package/dist/http/pikku-http-abstract-response.js +54 -0
  55. package/dist/http/pikku-http-session-service.d.ts +45 -0
  56. package/dist/http/pikku-http-session-service.js +92 -0
  57. package/dist/index.d.ts +14 -0
  58. package/dist/index.js +14 -0
  59. package/dist/permissions.d.ts +10 -0
  60. package/dist/permissions.js +32 -0
  61. package/dist/pikku-request.d.ts +14 -0
  62. package/dist/pikku-request.js +21 -0
  63. package/dist/pikku-response.d.ts +6 -0
  64. package/dist/pikku-response.js +6 -0
  65. package/dist/scheduler/index.d.ts +3 -0
  66. package/dist/scheduler/index.js +3 -0
  67. package/dist/scheduler/log-schedulers.d.ts +6 -0
  68. package/dist/scheduler/log-schedulers.js +17 -0
  69. package/dist/scheduler/scheduler-runner.d.ts +21 -0
  70. package/dist/scheduler/scheduler-runner.js +73 -0
  71. package/dist/scheduler/scheduler.types.d.ts +21 -0
  72. package/dist/scheduler/scheduler.types.js +1 -0
  73. package/dist/schema.d.ts +26 -0
  74. package/dist/schema.js +100 -0
  75. package/dist/services/content-service.d.ts +55 -0
  76. package/dist/services/content-service.js +1 -0
  77. package/dist/services/index.d.ts +12 -0
  78. package/dist/services/index.js +14 -0
  79. package/dist/services/jwt-service.d.ts +29 -0
  80. package/dist/services/jwt-service.js +1 -0
  81. package/dist/services/local-content.d.ts +33 -0
  82. package/dist/services/local-content.js +6 -0
  83. package/dist/services/local-secrets.d.ts +26 -0
  84. package/dist/services/local-secrets.js +39 -0
  85. package/dist/services/local-variables.d.ts +7 -0
  86. package/dist/services/local-variables.js +12 -0
  87. package/dist/services/logger-console.d.ts +52 -0
  88. package/dist/services/logger-console.js +82 -0
  89. package/dist/services/logger.d.ts +48 -0
  90. package/dist/services/logger.js +9 -0
  91. package/dist/services/schema-service.d.ts +24 -0
  92. package/dist/services/schema-service.js +1 -0
  93. package/dist/services/secret-service.d.ts +17 -0
  94. package/dist/services/secret-service.js +1 -0
  95. package/dist/services/user-session-service.d.ts +6 -0
  96. package/dist/services/user-session-service.js +1 -0
  97. package/dist/services/variables-service.d.ts +4 -0
  98. package/dist/services/variables-service.js +1 -0
  99. package/dist/types/core.types.d.ts +109 -0
  100. package/dist/types/core.types.js +1 -0
  101. package/dist/types/functions.types.d.ts +27 -0
  102. package/dist/types/functions.types.js +1 -0
  103. package/dist/utils.d.ts +2 -0
  104. package/dist/utils.js +15 -0
  105. package/package.json +48 -0
  106. package/run-tests.sh +53 -0
  107. package/src/channel/channel-handler.ts +179 -0
  108. package/src/channel/channel-runner.ts +156 -0
  109. package/src/channel/channel-store.ts +32 -0
  110. package/src/channel/channel.types.ts +202 -0
  111. package/src/channel/eventhub-forwarder.ts +25 -0
  112. package/src/channel/eventhub-service.ts +30 -0
  113. package/src/channel/eventhub-store.ts +8 -0
  114. package/src/channel/index.ts +9 -0
  115. package/src/channel/local/index.ts +3 -0
  116. package/src/channel/local/local-channel-handler.ts +56 -0
  117. package/src/channel/local/local-channel-runner.test.ts +128 -0
  118. package/src/channel/local/local-channel-runner.ts +94 -0
  119. package/src/channel/local/local-eventhub-service.test.ts +95 -0
  120. package/src/channel/local/local-eventhub-service.ts +95 -0
  121. package/src/channel/log-channels.ts +20 -0
  122. package/src/channel/pikku-abstract-channel-handler.test.ts +77 -0
  123. package/src/channel/pikku-abstract-channel-handler.ts +44 -0
  124. package/src/channel/serverless/index.ts +1 -0
  125. package/src/channel/serverless/serverless-channel-runner.ts +190 -0
  126. package/src/errors/error-handler.ts +74 -0
  127. package/src/errors/error.test.ts +54 -0
  128. package/src/errors/errors.ts +340 -0
  129. package/src/errors/index.ts +2 -0
  130. package/src/http/http-route-runner.test.ts +193 -0
  131. package/src/http/http-route-runner.ts +365 -0
  132. package/src/http/http-routes.types.ts +189 -0
  133. package/src/http/http-session-service.ts +19 -0
  134. package/src/http/index.ts +16 -0
  135. package/src/http/log-http-routes.ts +20 -0
  136. package/src/http/pikku-http-abstract-request.ts +95 -0
  137. package/src/http/pikku-http-abstract-response.ts +79 -0
  138. package/src/http/pikku-http-session-service.test.ts +106 -0
  139. package/src/http/pikku-http-session-service.ts +135 -0
  140. package/src/index.ts +15 -0
  141. package/src/permissions.test.ts +58 -0
  142. package/src/permissions.ts +45 -0
  143. package/src/pikku-request.ts +19 -0
  144. package/src/pikku-response.ts +5 -0
  145. package/src/scheduler/index.ts +11 -0
  146. package/src/scheduler/log-schedulers.ts +20 -0
  147. package/src/scheduler/scheduler-runner.ts +132 -0
  148. package/src/scheduler/scheduler.types.ts +27 -0
  149. package/src/schema.test.ts +57 -0
  150. package/src/schema.ts +124 -0
  151. package/src/services/content-service.ts +69 -0
  152. package/src/services/index.ts +16 -0
  153. package/src/services/jwt-service.ts +36 -0
  154. package/src/services/local-content.ts +39 -0
  155. package/src/services/local-secrets.ts +43 -0
  156. package/src/services/local-variables.ts +17 -0
  157. package/src/services/logger-console.ts +97 -0
  158. package/src/services/logger.ts +57 -0
  159. package/src/services/schema-service.ts +26 -0
  160. package/src/services/secret-service.ts +17 -0
  161. package/src/services/user-session-service.ts +7 -0
  162. package/src/services/variables-service.ts +6 -0
  163. package/src/types/core.types.ts +162 -0
  164. package/src/types/functions.types.ts +44 -0
  165. package/src/utils.ts +21 -0
  166. package/tsconfig.json +13 -0
  167. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,190 @@
1
+ import { CoreUserSession, SessionServices } from '../../types/core.types.js'
2
+ import { closeSessionServices } from '../../utils.js'
3
+ import { processMessageHandlers } from '../channel-handler.js'
4
+ import { getChannels, openChannel } from '../channel-runner.js'
5
+ import type {
6
+ CoreAPIChannel,
7
+ RunChannelOptions,
8
+ RunChannelParams,
9
+ PikkuChannelHandlerFactory,
10
+ } from '../channel.types.js'
11
+ import {
12
+ createHTTPInteraction,
13
+ handleError,
14
+ } from '../../http/http-route-runner.js'
15
+ import { ChannelStore } from '../channel-store.js'
16
+
17
+ export interface RunServerlessChannelParams<ChannelData>
18
+ extends RunChannelParams<ChannelData> {
19
+ channelStore: ChannelStore
20
+ channelHandlerFactory: PikkuChannelHandlerFactory
21
+ channelObject?: unknown
22
+ }
23
+
24
+ const getVariablesForChannel = ({
25
+ channelId,
26
+ userSession,
27
+ channelName,
28
+ channelHandlerFactory,
29
+ openingData,
30
+ }: {
31
+ channelId: string
32
+ channelName: string
33
+ userSession?: CoreUserSession
34
+ channelHandlerFactory: PikkuChannelHandlerFactory
35
+ openingData?: unknown
36
+ }) => {
37
+ const { channels } = getChannels()
38
+ const channelConfig = channels.find(
39
+ (channelConfig) => channelConfig.name === channelName
40
+ )
41
+ if (!channelConfig) {
42
+ throw new Error(`Channel not found: ${channelName}`)
43
+ }
44
+ const channelHandler = channelHandlerFactory(
45
+ channelId,
46
+ channelConfig.name,
47
+ openingData,
48
+ userSession
49
+ )
50
+ return {
51
+ channelConfig,
52
+ channelHandler,
53
+ channel: channelHandler.getChannel(),
54
+ }
55
+ }
56
+
57
+ export const runChannelConnect = async ({
58
+ singletonServices,
59
+ channelId,
60
+ channelObject,
61
+ request,
62
+ response,
63
+ route,
64
+ createSessionServices,
65
+ channelStore,
66
+ channelHandlerFactory,
67
+ coerceToArray = false,
68
+ logWarningsForStatusCodes = [],
69
+ respondWith404 = true,
70
+ bubbleErrors = false,
71
+ }: Pick<CoreAPIChannel<unknown, any>, 'route'> &
72
+ RunChannelOptions &
73
+ RunServerlessChannelParams<unknown>) => {
74
+ let sessionServices: SessionServices | undefined
75
+ const http = createHTTPInteraction(request, response)
76
+ try {
77
+ const { userSession, channelConfig, openingData } = await openChannel({
78
+ channelId,
79
+ createSessionServices,
80
+ http,
81
+ route,
82
+ singletonServices,
83
+ coerceToArray,
84
+ })
85
+ await channelStore.addChannel({
86
+ channelId,
87
+ channelName: channelConfig.name,
88
+ openingData,
89
+ channelObject,
90
+ })
91
+ const { channel } = getVariablesForChannel({
92
+ channelId,
93
+ userSession,
94
+ channelHandlerFactory,
95
+ channelName: channelConfig.name,
96
+ })
97
+ if (createSessionServices) {
98
+ sessionServices = await createSessionServices(
99
+ singletonServices,
100
+ { http },
101
+ userSession
102
+ )
103
+ }
104
+ await channelConfig.onConnect?.(
105
+ { ...singletonServices, ...sessionServices },
106
+ channel
107
+ )
108
+ http?.response?.setStatus(101)
109
+ } catch (e: any) {
110
+ handleError(
111
+ e,
112
+ http,
113
+ channelId,
114
+ singletonServices.logger,
115
+ logWarningsForStatusCodes,
116
+ respondWith404,
117
+ bubbleErrors
118
+ )
119
+ } finally {
120
+ if (sessionServices) {
121
+ await closeSessionServices(singletonServices.logger, sessionServices)
122
+ }
123
+ }
124
+ }
125
+
126
+ export const runChannelDisconnect = async ({
127
+ singletonServices,
128
+ ...params
129
+ }: RunServerlessChannelParams<unknown>): Promise<void> => {
130
+ let sessionServices: SessionServices | undefined
131
+ const { userSession, openingData, channelName } =
132
+ await params.channelStore.getChannel(params.channelId)
133
+ const { channel, channelConfig } = getVariablesForChannel({
134
+ ...params,
135
+ userSession,
136
+ openingData,
137
+ channelName,
138
+ })
139
+ if (!sessionServices && params.createSessionServices) {
140
+ sessionServices = await params.createSessionServices(
141
+ singletonServices,
142
+ {},
143
+ userSession
144
+ )
145
+ }
146
+ await channelConfig.onDisconnect?.(
147
+ { ...singletonServices, ...sessionServices },
148
+ channel
149
+ )
150
+ await params.channelStore.removeChannels([channel.channelId])
151
+ if (sessionServices) {
152
+ await closeSessionServices(singletonServices.logger, sessionServices)
153
+ }
154
+ }
155
+
156
+ export const runChannelMessage = async (
157
+ { singletonServices, ...params }: RunServerlessChannelParams<unknown>,
158
+ data: unknown
159
+ ): Promise<unknown> => {
160
+ let sessionServices: SessionServices | undefined
161
+ const { userSession, openingData, channelName } =
162
+ await params.channelStore.getChannel(params.channelId)
163
+ const { channelHandler, channelConfig } = getVariablesForChannel({
164
+ ...params,
165
+ userSession,
166
+ openingData,
167
+ channelName,
168
+ })
169
+ if (params.createSessionServices) {
170
+ sessionServices = await params.createSessionServices(
171
+ singletonServices,
172
+ {},
173
+ userSession
174
+ )
175
+ }
176
+ let response: unknown
177
+ try {
178
+ const onMessage = processMessageHandlers(
179
+ { ...singletonServices, ...sessionServices },
180
+ channelConfig,
181
+ channelHandler
182
+ )
183
+ response = await onMessage(data)
184
+ } finally {
185
+ if (sessionServices) {
186
+ await closeSessionServices(singletonServices.logger, sessionServices)
187
+ }
188
+ }
189
+ return response
190
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Base class for custom errors.
3
+ * @extends {Error}
4
+ */
5
+ export class EError extends Error {
6
+ /**
7
+ * Creates an instance of EError.
8
+ * @param message - The error message.
9
+ */
10
+ constructor(message: string = 'An error occurred') {
11
+ super(message)
12
+ Object.setPrototypeOf(this, new.target.prototype)
13
+ }
14
+ }
15
+
16
+ /**
17
+ * Interface for error details.
18
+ */
19
+ export interface ErrorDetails {
20
+ status: number
21
+ message: string
22
+ }
23
+
24
+ /**
25
+ * Map of API errors to their details.
26
+ */
27
+ if (!globalThis.pikku?.apiErrors) {
28
+ globalThis.pikku = globalThis.pikku || {}
29
+ globalThis.pikku.apiErrors = new Map<any, ErrorDetails>([])
30
+ }
31
+
32
+ const apiErrors = (): Map<any, ErrorDetails> => {
33
+ return globalThis.pikku.apiErrors
34
+ }
35
+
36
+ export const getErrors = () => apiErrors()
37
+
38
+ /**
39
+ * Adds an error to the API errors map.
40
+ * @param error - The error to add.
41
+ * @param details - The details of the error.
42
+ */
43
+ export const addError = (error: any, { status, message }: ErrorDetails) => {
44
+ apiErrors().set(error, { status, message })
45
+ }
46
+
47
+ /**
48
+ * Adds multiple errors to the API errors map.
49
+ * @param errors - An array of errors and their details.
50
+ */
51
+ export const addErrors = (
52
+ errors: Array<[error: any, details: ErrorDetails]>
53
+ ) => {
54
+ errors.forEach((error) => {
55
+ addError(error[0], error[1])
56
+ })
57
+ }
58
+
59
+ /**
60
+ * Retrieves the error response for a given error.
61
+ * @param error - The error to get the response for.
62
+ * @returns An object containing the status and message, or undefined if the error is not found.
63
+ */
64
+ export const getErrorResponse = (
65
+ error: Error
66
+ ): { status: number; message: string } | undefined => {
67
+ const foundError = Array.from(apiErrors().entries()).find(
68
+ ([e]) => e.name === error.constructor.name
69
+ )
70
+ if (foundError) {
71
+ return foundError[1]
72
+ }
73
+ return apiErrors().get(error)
74
+ }
@@ -0,0 +1,54 @@
1
+ import { test, describe } from 'node:test'
2
+ import assert from 'assert'
3
+ import { getErrorResponse, addError } from './error-handler.js'
4
+ import { ForbiddenError, BadRequestError, NotFoundError } from './errors.js'
5
+
6
+ describe('getErrorResponse', () => {
7
+ test('should return the correct error response for BadRequestError', () => {
8
+ const error = new BadRequestError()
9
+ const response = getErrorResponse(error)
10
+ assert.deepStrictEqual(response, {
11
+ status: 400,
12
+ message:
13
+ 'The server cannot or will not process the request due to client error (e.g., malformed request syntax).',
14
+ })
15
+ })
16
+
17
+ test('should return the correct error response for NotFoundError', () => {
18
+ const error = new NotFoundError()
19
+ const response = getErrorResponse(error)
20
+ assert.deepStrictEqual(response, {
21
+ status: 404,
22
+ message: 'The server cannot find the requested resource.',
23
+ })
24
+ })
25
+
26
+ test('should return the correct error response for ForbiddenError', () => {
27
+ const error = new ForbiddenError()
28
+ const response = getErrorResponse(error)
29
+ assert.deepStrictEqual(response, {
30
+ status: 403,
31
+ message:
32
+ 'The client does not have permission to access the requested resource.',
33
+ })
34
+ })
35
+
36
+ test('should return undefined for an unknown error', () => {
37
+ class UnknownError extends Error {}
38
+ const error = new UnknownError()
39
+ const response = getErrorResponse(error)
40
+ assert.strictEqual(response, undefined)
41
+ })
42
+
43
+ test('should return the correct error response for a custom error added to apiErrors', () => {
44
+ class CustomError extends Error {}
45
+ const customError = new CustomError()
46
+ const customErrorDetails = { status: 400, message: 'Custom Error' }
47
+
48
+ // Add the custom error to the apiErrors map
49
+ addError(CustomError, customErrorDetails)
50
+
51
+ const response = getErrorResponse(customError)
52
+ assert.deepStrictEqual(response, customErrorDetails)
53
+ })
54
+ })
@@ -0,0 +1,340 @@
1
+ /**
2
+ * The server cannot or will not process the request due to client error (e.g., malformed request syntax).
3
+ */
4
+ import { addError, EError } from './error-handler.js'
5
+
6
+ /**
7
+ * The server cannot or will not process the request due to client error (e.g., malformed request syntax).
8
+ * @group Error
9
+ */
10
+ export class BadRequestError extends EError {}
11
+ addError(BadRequestError, {
12
+ status: 400,
13
+ message:
14
+ 'The server cannot or will not process the request due to client error (e.g., malformed request syntax).',
15
+ })
16
+
17
+ /**
18
+ * Authentication is required and has failed or has not yet been provided.
19
+ * @group Error
20
+ */
21
+ export class UnauthorizedError extends EError {}
22
+ /**
23
+ * More specific error to why it's unauthorized.
24
+ * @group Error
25
+ */
26
+ export class MissingSessionError extends EError {}
27
+ /**
28
+ * More specific error to why it's unauthorized.
29
+ * @group Error
30
+ */
31
+ export class InvalidSessionError extends EError {}
32
+
33
+ addError(UnauthorizedError, {
34
+ status: 401,
35
+ message:
36
+ 'Authentication is required and has failed or has not yet been provided.',
37
+ })
38
+ addError(MissingSessionError, { status: 401, message: 'Session missing.' })
39
+ addError(InvalidSessionError, {
40
+ status: 401,
41
+ message: 'The session provided is not valid.',
42
+ })
43
+
44
+ /**
45
+ * Reserved for future use, often related to digital payment or subscription services.
46
+ * @group Error
47
+ */
48
+ export class PaymentRequiredError extends EError {}
49
+ addError(PaymentRequiredError, {
50
+ status: 402,
51
+ message:
52
+ 'Reserved for future use, often related to digital payment or subscription services.',
53
+ })
54
+
55
+ /**
56
+ * The client does not have permission to access the requested resource.
57
+ * @group Error
58
+ */
59
+ export class ForbiddenError extends EError {}
60
+ addError(ForbiddenError, {
61
+ status: 403,
62
+ message:
63
+ 'The client does not have permission to access the requested resource.',
64
+ })
65
+
66
+ /**
67
+ * The request was made from an origin that is not permitted to access this resource.
68
+ * @group Error
69
+ */
70
+ export class InvalidOriginError extends EError {}
71
+ addError(InvalidOriginError, {
72
+ status: 403,
73
+ message:
74
+ 'The request was made from an origin that is not permitted to access this resource.',
75
+ })
76
+
77
+ /**
78
+ * The server cannot find the requested resource.
79
+ * @group Error
80
+ */
81
+ export class NotFoundError extends EError {}
82
+ /**
83
+ * The server cannot find the requested route.
84
+ * @group Error
85
+ */
86
+ addError(NotFoundError, {
87
+ status: 404,
88
+ message: 'The server cannot find the requested resource.',
89
+ })
90
+
91
+ /**
92
+ * The request method is known by the server but is not supported by the resource.
93
+ * @group Error
94
+ */
95
+ export class MethodNotAllowedError extends EError {}
96
+ addError(MethodNotAllowedError, {
97
+ status: 405,
98
+ message:
99
+ 'The request method is known by the server but is not supported by the resource.',
100
+ })
101
+
102
+ /**
103
+ * The requested resource cannot produce a response matching the list of acceptable values in the request's headers.
104
+ * @group Error
105
+ */
106
+ export class NotAcceptableError extends EError {}
107
+ addError(NotAcceptableError, {
108
+ status: 406,
109
+ message:
110
+ "The requested resource cannot produce a response matching the list of acceptable values in the request's headers.",
111
+ })
112
+
113
+ /**
114
+ * The client must authenticate itself to get the requested response.
115
+ * @group Error
116
+ */
117
+ export class ProxyAuthenticationRequiredError extends EError {}
118
+ addError(ProxyAuthenticationRequiredError, {
119
+ status: 407,
120
+ message: 'The client must authenticate itself to get the requested response.',
121
+ })
122
+
123
+ /**
124
+ * The server did not receive a timely response from an upstream server.
125
+ * @group Error
126
+ */
127
+ export class RequestTimeoutError extends EError {}
128
+ addError(RequestTimeoutError, {
129
+ status: 408,
130
+ message:
131
+ 'The server did not receive a timely response from an upstream server.',
132
+ })
133
+
134
+ /**
135
+ * The request could not be completed due to a conflict with the current state of the target resource.
136
+ * @group Error
137
+ */
138
+ export class ConflictError extends EError {}
139
+ addError(ConflictError, {
140
+ status: 409,
141
+ message:
142
+ 'The request could not be completed due to a conflict with the current state of the target resource.',
143
+ })
144
+
145
+ /**
146
+ * The resource that is being accessed is no longer available and will not be available again.
147
+ * @group Error
148
+ */
149
+ export class GoneError extends EError {}
150
+ addError(GoneError, {
151
+ status: 410,
152
+ message:
153
+ 'The resource that is being accessed is no longer available and will not be available again.',
154
+ })
155
+
156
+ /**
157
+ * The request did not specify the length of its content, which is required by the requested resource.
158
+ * @group Error
159
+ */
160
+ export class LengthRequiredError extends EError {}
161
+ addError(LengthRequiredError, {
162
+ status: 411,
163
+ message:
164
+ 'The request did not specify the length of its content, which is required by the requested resource.',
165
+ })
166
+
167
+ /**
168
+ * The server does not meet one of the preconditions that the requester put on the request.
169
+ * @group Error
170
+ */
171
+ export class PreconditionFailedError extends EError {}
172
+ addError(PreconditionFailedError, {
173
+ status: 412,
174
+ message:
175
+ 'The server does not meet one of the preconditions that the requester put on the request.',
176
+ })
177
+
178
+ /**
179
+ * The request is larger than the server is willing or able to process.
180
+ * @group Error
181
+ */
182
+ export class PayloadTooLargeError extends EError {}
183
+ addError(PayloadTooLargeError, {
184
+ status: 413,
185
+ message:
186
+ 'The request is larger than the server is willing or able to process.',
187
+ })
188
+
189
+ /**
190
+ * The URI requested by the client is longer than the server is willing to interpret.
191
+ * @group Error
192
+ */
193
+ export class URITooLongError extends EError {}
194
+ addError(URITooLongError, {
195
+ status: 414,
196
+ message:
197
+ 'The URI requested by the client is longer than the server is willing to interpret.',
198
+ })
199
+
200
+ /**
201
+ * The server does not support the media format of the requested data.
202
+ * @group Error
203
+ */
204
+ export class UnsupportedMediaTypeError extends EError {}
205
+ addError(UnsupportedMediaTypeError, {
206
+ status: 415,
207
+ message:
208
+ 'The server does not support the media format of the requested data.',
209
+ })
210
+
211
+ /**
212
+ * The client has asked for a portion of the file, but the server cannot supply that portion.
213
+ * @group Error
214
+ */
215
+ export class RangeNotSatisfiableError extends EError {}
216
+ addError(RangeNotSatisfiableError, {
217
+ status: 416,
218
+ message:
219
+ 'The client has asked for a portion of the file, but the server cannot supply that portion.',
220
+ })
221
+
222
+ /**
223
+ * The server cannot meet the requirements of the Expect request-header field.
224
+ * @group Error
225
+ */
226
+ export class ExpectationFailedError extends EError {}
227
+ addError(ExpectationFailedError, {
228
+ status: 417,
229
+ message:
230
+ 'The server cannot meet the requirements of the Expect request-header field.',
231
+ })
232
+
233
+ /**
234
+ * Indicates that the server understood the content type of the request content, and the syntax of the request content was correct, but it was unable to process the contained instructions.
235
+ * @group Error
236
+ */
237
+ export class UnprocessableContentError extends EError {}
238
+ addError(UnprocessableContentError, {
239
+ status: 422,
240
+ message:
241
+ 'The server understood the content type of the request content, and the syntax of the request content was correct, but it was unable to process the contained instructions..',
242
+ })
243
+
244
+ /**
245
+ * Indicates that the server understood the content type of the request content, and the syntax of the request content was correct, but it was unable to process the contained instructions.
246
+ * @group Error
247
+ */
248
+ export class LockedError extends EError {}
249
+ addError(LockedError, {
250
+ status: 423,
251
+ message:
252
+ "The resource is locked, meaning it can't be accessed. Its response body should contain information in WebDAV's XML format.",
253
+ })
254
+
255
+ /**
256
+ * The user has sent too many requests in a given amount of time ("rate limiting").
257
+ * @group Error
258
+ */
259
+ export class TooManyRequestsError extends EError {}
260
+ addError(TooManyRequestsError, {
261
+ status: 429,
262
+ message:
263
+ 'The user has sent too many requests in a given amount of time ("rate limiting").',
264
+ })
265
+
266
+ /**
267
+ * A generic error message, given when no more specific message is suitable.
268
+ * @group Error
269
+ */
270
+ export class InternalServerError extends EError {}
271
+ addError(InternalServerError, {
272
+ status: 500,
273
+ message:
274
+ 'A generic error message, given when no more specific message is suitable.',
275
+ })
276
+
277
+ /**
278
+ * The server does not recognize the request method and cannot support it.
279
+ * @group Error
280
+ */
281
+ export class NotImplementedError extends EError {}
282
+ addError(NotImplementedError, {
283
+ status: 501,
284
+ message:
285
+ 'The server does not recognize the request method and cannot support it.',
286
+ })
287
+
288
+ /**
289
+ * The server was acting as a gateway or proxy and received an invalid response from the upstream server.
290
+ * @group Error
291
+ */
292
+ export class BadGatewayError extends EError {}
293
+ addError(BadGatewayError, {
294
+ status: 502,
295
+ message:
296
+ 'The server was acting as a gateway or proxy and received an invalid response from the upstream server.',
297
+ })
298
+
299
+ /**
300
+ * The server is currently unavailable (overloaded or down).
301
+ * @group Error
302
+ */
303
+ export class ServiceUnavailableError extends EError {}
304
+ addError(ServiceUnavailableError, {
305
+ status: 503,
306
+ message: 'The server is currently unavailable (overloaded or down).',
307
+ })
308
+
309
+ /**
310
+ * The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.
311
+ * @group Error
312
+ */
313
+ export class GatewayTimeoutError extends EError {}
314
+ addError(GatewayTimeoutError, {
315
+ status: 504,
316
+ message:
317
+ 'The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.',
318
+ })
319
+
320
+ /**
321
+ * The server does not support the HTTP protocol version used in the request.
322
+ * @group Error
323
+ */
324
+ export class HTTPVersionNotSupportedError extends EError {}
325
+ addError(HTTPVersionNotSupportedError, {
326
+ status: 505,
327
+ message:
328
+ 'The server does not support the HTTP protocol version used in the request.',
329
+ })
330
+
331
+ /**
332
+ * The server took too long to complete the request, reaching the maximum compute time allowed.
333
+ * @group Error
334
+ */
335
+ export class MaxComputeTimeReachedError extends EError {}
336
+ addError(MaxComputeTimeReachedError, {
337
+ status: 524,
338
+ message:
339
+ 'The server took too long to complete the request, reaching the maximum compute time allowed.',
340
+ })
@@ -0,0 +1,2 @@
1
+ export * from './error-handler.js'
2
+ export * from './errors.js'