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