better-call 0.2.13-beta.8 → 0.2.13

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/dist/index.mjs DELETED
@@ -1,768 +0,0 @@
1
- import crypto from 'uncrypto';
2
- import { extendZodWithOpenApi, OpenAPIRegistry } from '@asteasolutions/zod-to-openapi';
3
- import { z } from 'zod';
4
- import { createRouter as createRouter$1, addRoute, findRoute, findAllRoutes } from 'rou3';
5
-
6
- function runValidation(options, context) {
7
- let request = {
8
- body: void 0,
9
- query: void 0
10
- };
11
- if (options.body) {
12
- const result = options.body.safeParse(context.body);
13
- if (result.error) {
14
- return {
15
- data: null,
16
- error: fromError(result.error)
17
- };
18
- }
19
- request.body = result.data;
20
- }
21
- if (options.query) {
22
- const result = options.query.safeParse(context.query);
23
- if (result.error) {
24
- return {
25
- data: null,
26
- error: fromError(result.error)
27
- };
28
- }
29
- request.query = result.data;
30
- }
31
- if (options.requireHeaders && !(context.headers instanceof Headers)) {
32
- return {
33
- data: null,
34
- error: { message: "Validation Error: Headers are required" }
35
- };
36
- }
37
- if (options.requireRequest && !context.request) {
38
- return {
39
- data: null,
40
- error: { message: "Validation Error: Request is required" }
41
- };
42
- }
43
- return {
44
- data: request,
45
- error: null
46
- };
47
- }
48
- function fromError(error) {
49
- const errorMessages = [];
50
- for (const issue of error.issues) {
51
- const path = issue.path.join(".");
52
- const message = issue.message;
53
- if (path) {
54
- errorMessages.push(`${message} at "${path}"`);
55
- } else {
56
- errorMessages.push(message);
57
- }
58
- }
59
- return {
60
- message: `Validation error: ${errorMessages.join(", ")}`
61
- };
62
- }
63
-
64
- function createSetHeader(headers) {
65
- return (key, value) => {
66
- headers.set(key, value);
67
- };
68
- }
69
- function createGetHeader(headers) {
70
- return (key) => {
71
- return headers.get(key);
72
- };
73
- }
74
-
75
- const _statusCode = {
76
- OK: 200,
77
- CREATED: 201,
78
- ACCEPTED: 202,
79
- NO_CONTENT: 204,
80
- MULTIPLE_CHOICES: 300,
81
- MOVED_PERMANENTLY: 301,
82
- FOUND: 302,
83
- SEE_OTHER: 303,
84
- NOT_MODIFIED: 304,
85
- TEMPORARY_REDIRECT: 307,
86
- BAD_REQUEST: 400,
87
- UNAUTHORIZED: 401,
88
- PAYMENT_REQUIRED: 402,
89
- FORBIDDEN: 403,
90
- NOT_FOUND: 404,
91
- METHOD_NOT_ALLOWED: 405,
92
- NOT_ACCEPTABLE: 406,
93
- PROXY_AUTHENTICATION_REQUIRED: 407,
94
- REQUEST_TIMEOUT: 408,
95
- CONFLICT: 409,
96
- GONE: 410,
97
- LENGTH_REQUIRED: 411,
98
- PRECONDITION_FAILED: 412,
99
- PAYLOAD_TOO_LARGE: 413,
100
- URI_TOO_LONG: 414,
101
- UNSUPPORTED_MEDIA_TYPE: 415,
102
- RANGE_NOT_SATISFIABLE: 416,
103
- EXPECTATION_FAILED: 417,
104
- "I'M_A_TEAPOT": 418,
105
- MISDIRECTED_REQUEST: 421,
106
- UNPROCESSABLE_ENTITY: 422,
107
- LOCKED: 423,
108
- FAILED_DEPENDENCY: 424,
109
- TOO_EARLY: 425,
110
- UPGRADE_REQUIRED: 426,
111
- PRECONDITION_REQUIRED: 428,
112
- TOO_MANY_REQUESTS: 429,
113
- REQUEST_HEADER_FIELDS_TOO_LARGE: 431,
114
- UNAVAILABLE_FOR_LEGAL_REASONS: 451,
115
- INTERNAL_SERVER_ERROR: 500,
116
- NOT_IMPLEMENTED: 501,
117
- BAD_GATEWAY: 502,
118
- SERVICE_UNAVAILABLE: 503,
119
- GATEWAY_TIMEOUT: 504,
120
- HTTP_VERSION_NOT_SUPPORTED: 505,
121
- VARIANT_ALSO_NEGOTIATES: 506,
122
- INSUFFICIENT_STORAGE: 507,
123
- LOOP_DETECTED: 508,
124
- NOT_EXTENDED: 510,
125
- NETWORK_AUTHENTICATION_REQUIRED: 511
126
- };
127
- class APIError extends Error {
128
- constructor(status = "INTERNAL_SERVER_ERROR", body = void 0, headers = {}, statusCode = _statusCode[status]) {
129
- super(body?.message || status);
130
- this.status = status;
131
- this.body = body;
132
- this.headers = headers;
133
- this.statusCode = statusCode;
134
- this.name = "APIError";
135
- this.status = status;
136
- this.headers = headers;
137
- this.statusCode = statusCode;
138
- this.stack = "";
139
- }
140
- }
141
-
142
- const algorithm = { name: "HMAC", hash: "SHA-256" };
143
- const getCryptoKey = async (secret) => {
144
- const secretBuf = typeof secret === "string" ? new TextEncoder().encode(secret) : secret;
145
- return await crypto.subtle.importKey("raw", secretBuf, algorithm, false, [
146
- "sign",
147
- "verify"
148
- ]);
149
- };
150
- const makeSignature = async (value, secret) => {
151
- const key = await getCryptoKey(secret);
152
- const signature = await crypto.subtle.sign(
153
- algorithm.name,
154
- key,
155
- new TextEncoder().encode(value)
156
- );
157
- return btoa(String.fromCharCode(...new Uint8Array(signature)));
158
- };
159
- const verifySignature = async (base64Signature, value, secret) => {
160
- try {
161
- const signatureBinStr = atob(base64Signature);
162
- const signature = new Uint8Array(signatureBinStr.length);
163
- for (let i = 0, len = signatureBinStr.length; i < len; i++) {
164
- signature[i] = signatureBinStr.charCodeAt(i);
165
- }
166
- return await crypto.subtle.verify(
167
- algorithm,
168
- secret,
169
- signature,
170
- new TextEncoder().encode(value)
171
- );
172
- } catch (e) {
173
- return false;
174
- }
175
- };
176
- const validCookieNameRegEx = /^[\w!#$%&'*.^`|~+-]+$/;
177
- const validCookieValueRegEx = /^[ !#-:<-[\]-~]*$/;
178
- const parse = (cookie, name) => {
179
- const pairs = cookie.trim().split(";");
180
- return pairs.reduce((parsedCookie, pairStr) => {
181
- pairStr = pairStr.trim();
182
- const valueStartPos = pairStr.indexOf("=");
183
- if (valueStartPos === -1) {
184
- return parsedCookie;
185
- }
186
- const cookieName = pairStr.substring(0, valueStartPos).trim();
187
- if (name && name !== cookieName || !validCookieNameRegEx.test(cookieName)) {
188
- return parsedCookie;
189
- }
190
- let cookieValue = pairStr.substring(valueStartPos + 1).trim();
191
- if (cookieValue.startsWith('"') && cookieValue.endsWith('"')) {
192
- cookieValue = cookieValue.slice(1, -1);
193
- }
194
- if (validCookieValueRegEx.test(cookieValue)) {
195
- parsedCookie[cookieName] = decodeURIComponent(cookieValue);
196
- }
197
- return parsedCookie;
198
- }, {});
199
- };
200
- const parseSigned = async (cookie, secret, name) => {
201
- const parsedCookie = {};
202
- const secretKey = await getCryptoKey(secret);
203
- for (const [key, value] of Object.entries(parse(cookie, name))) {
204
- const signatureStartPos = value.lastIndexOf(".");
205
- if (signatureStartPos < 1) {
206
- continue;
207
- }
208
- const signedValue = value.substring(0, signatureStartPos);
209
- const signature = value.substring(signatureStartPos + 1);
210
- if (signature.length !== 44 || !signature.endsWith("=")) {
211
- continue;
212
- }
213
- const isVerified = await verifySignature(signature, signedValue, secretKey);
214
- parsedCookie[key] = isVerified ? signedValue : false;
215
- }
216
- return parsedCookie;
217
- };
218
- const _serialize = (name, value, opt = {}) => {
219
- let cookie = `${name}=${value}`;
220
- if (name.startsWith("__Secure-") && !opt.secure) {
221
- opt.secure = true;
222
- }
223
- if (name.startsWith("__Host-")) {
224
- if (!opt.secure) {
225
- opt.secure = true;
226
- }
227
- if (opt.path !== "/") {
228
- opt.path = "/";
229
- }
230
- if (opt.domain) {
231
- opt.domain = void 0;
232
- }
233
- }
234
- if (opt && typeof opt.maxAge === "number" && opt.maxAge >= 0) {
235
- if (opt.maxAge > 3456e4) {
236
- throw new Error(
237
- "Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration."
238
- );
239
- }
240
- cookie += `; Max-Age=${Math.floor(opt.maxAge)}`;
241
- }
242
- if (opt.domain && opt.prefix !== "host") {
243
- cookie += `; Domain=${opt.domain}`;
244
- }
245
- if (opt.path) {
246
- cookie += `; Path=${opt.path}`;
247
- }
248
- if (opt.expires) {
249
- if (opt.expires.getTime() - Date.now() > 3456e7) {
250
- throw new Error(
251
- "Cookies Expires SHOULD NOT be greater than 400 days (34560000 seconds) in the future."
252
- );
253
- }
254
- cookie += `; Expires=${opt.expires.toUTCString()}`;
255
- }
256
- if (opt.httpOnly) {
257
- cookie += "; HttpOnly";
258
- }
259
- if (opt.secure) {
260
- cookie += "; Secure";
261
- }
262
- if (opt.sameSite) {
263
- cookie += `; SameSite=${opt.sameSite.charAt(0).toUpperCase() + opt.sameSite.slice(1)}`;
264
- }
265
- if (opt.partitioned) {
266
- if (!opt.secure) {
267
- throw new Error("Partitioned Cookie must have Secure attributes");
268
- }
269
- cookie += "; Partitioned";
270
- }
271
- return cookie;
272
- };
273
- const serialize = (name, value, opt) => {
274
- value = encodeURIComponent(value);
275
- return _serialize(name, value, opt);
276
- };
277
- const serializeSigned = async (name, value, secret, opt = {}) => {
278
- const signature = await makeSignature(value, secret);
279
- value = `${value}.${signature}`;
280
- value = encodeURIComponent(value);
281
- return _serialize(name, value, opt);
282
- };
283
-
284
- const getCookie = (cookie, key, prefix) => {
285
- if (!cookie) {
286
- return void 0;
287
- }
288
- let finalKey = key;
289
- if (prefix) {
290
- if (prefix === "secure") {
291
- finalKey = "__Secure-" + key;
292
- } else if (prefix === "host") {
293
- finalKey = "__Host-" + key;
294
- } else {
295
- return void 0;
296
- }
297
- }
298
- const obj = parse(cookie, finalKey);
299
- return obj[finalKey];
300
- };
301
- const setCookie = (header, name, value, opt) => {
302
- const existingCookies = header.get("Set-Cookie");
303
- if (existingCookies) {
304
- const cookies = existingCookies.split(", ");
305
- const updatedCookies = cookies.filter(
306
- (cookie2) => !cookie2.startsWith(`${name}=`)
307
- );
308
- header.delete("Set-Cookie");
309
- updatedCookies.forEach((cookie2) => header.append("Set-Cookie", cookie2));
310
- }
311
- let cookie;
312
- if (opt?.prefix === "secure") {
313
- cookie = serialize("__Secure-" + name, value, {
314
- path: "/",
315
- ...opt,
316
- secure: true
317
- });
318
- } else if (opt?.prefix === "host") {
319
- cookie = serialize("__Host-" + name, value, {
320
- ...opt,
321
- path: "/",
322
- secure: true,
323
- domain: void 0
324
- });
325
- } else {
326
- cookie = serialize(name, value, { path: "/", ...opt });
327
- }
328
- header.append("Set-Cookie", cookie);
329
- };
330
- const setSignedCookie = async (header, name, value, secret, opt) => {
331
- let cookie;
332
- if (opt?.prefix === "secure") {
333
- cookie = await serializeSigned("__Secure-" + name, value, secret, {
334
- path: "/",
335
- ...opt,
336
- secure: true
337
- });
338
- } else if (opt?.prefix === "host") {
339
- cookie = await serializeSigned("__Host-" + name, value, secret, {
340
- ...opt,
341
- path: "/",
342
- secure: true,
343
- domain: void 0
344
- });
345
- } else {
346
- cookie = await serializeSigned(name, value, secret, { path: "/", ...opt });
347
- }
348
- header.append("Set-Cookie", cookie);
349
- };
350
- const getSignedCookie = async (header, secret, key, prefix) => {
351
- const cookie = header.get("cookie");
352
- if (!cookie) {
353
- return void 0;
354
- }
355
- let finalKey = key;
356
- if (prefix) {
357
- if (prefix === "secure") {
358
- finalKey = "__Secure-" + key;
359
- } else if (prefix === "host") {
360
- finalKey = "__Host-" + key;
361
- }
362
- }
363
- const obj = await parseSigned(cookie, secret, finalKey);
364
- return obj[finalKey];
365
- };
366
-
367
- function paramToZod(path) {
368
- const parts = path.split("/");
369
- const params = parts.filter((part) => part.startsWith(":"));
370
- const zod = z.object({});
371
- for (const param of params) {
372
- zod.merge(z.object({ [param.slice(1)]: z.string() }));
373
- }
374
- return zod;
375
- }
376
-
377
- extendZodWithOpenApi(z);
378
- const createResponse = (handlerResponse, response) => {
379
- if (handlerResponse instanceof Response) {
380
- response.headers.forEach((value, key) => {
381
- handlerResponse.headers.set(key, value);
382
- });
383
- return handlerResponse;
384
- } else if (handlerResponse?._flag === "json") {
385
- const responseObj = new Response(
386
- JSON.stringify(
387
- handlerResponse.routerResponse?.body || handlerResponse.body
388
- ),
389
- {
390
- status: handlerResponse.routerResponse?.status || 200,
391
- headers: handlerResponse.routerResponse?.headers
392
- }
393
- );
394
- response.headers.forEach((value, key) => {
395
- responseObj.headers.set(key, value);
396
- });
397
- return responseObj;
398
- } else {
399
- const responseObj = new Response(
400
- handlerResponse ? JSON.stringify(handlerResponse) : void 0
401
- );
402
- response.headers.forEach((value, key) => {
403
- responseObj.headers.set(key, value);
404
- });
405
- return responseObj;
406
- }
407
- };
408
- const runMiddleware = async (options, context) => {
409
- let finalContext = {};
410
- for (const middleware of options.use || []) {
411
- const result = await middleware(context);
412
- if (result?.context && result._flag === "context") {
413
- context = { ...context, ...result.context };
414
- } else {
415
- finalContext = { ...result, ...finalContext };
416
- context.context = finalContext;
417
- }
418
- }
419
- return finalContext;
420
- };
421
- const createEndpoint = (path, options, handler) => {
422
- const internalHandler = async (...inputCtx) => {
423
- let response = new Response();
424
- const { asResponse, ...ctx } = inputCtx[0] || {};
425
- const { data, error } = runValidation(options, ctx);
426
- if (error) {
427
- throw new APIError("BAD_REQUEST", {
428
- message: error.message
429
- });
430
- }
431
- const context = {
432
- json: (json, routerResponse) => {
433
- if (!asResponse) {
434
- return json;
435
- }
436
- return {
437
- body: json,
438
- routerResponse,
439
- _flag: "json"
440
- };
441
- },
442
- body: "body" in data ? data.body : void 0,
443
- path,
444
- method: "method" in ctx ? ctx.method : void 0,
445
- query: "query" in data ? data.query : void 0,
446
- params: "params" in ctx ? ctx.params : void 0,
447
- headers: "headers" in ctx ? ctx.headers : void 0,
448
- request: "request" in ctx ? ctx.request : void 0,
449
- setHeader: createSetHeader(response.headers),
450
- getHeader: (key) => {
451
- const requestHeaders = "headers" in ctx && ctx.headers instanceof Headers ? ctx.headers : "request" in ctx && ctx.request instanceof Request ? ctx.request.headers : null;
452
- if (!requestHeaders)
453
- return null;
454
- return requestHeaders.get(key);
455
- },
456
- setCookie: (name, value, options2) => {
457
- setCookie(response.headers, name, value, options2);
458
- },
459
- getCookie(key, prefix) {
460
- const headers = context.headers?.get("cookie");
461
- if (!headers)
462
- return void 0;
463
- return getCookie(headers, key, prefix);
464
- },
465
- setSignedCookie(key, value, secret, options2) {
466
- return setSignedCookie(response.headers, key, value, secret, options2);
467
- },
468
- async getSignedCookie(key, secret, prefix) {
469
- const headers = context.headers;
470
- if (!headers)
471
- return void 0;
472
- return getSignedCookie(headers, secret, key, prefix);
473
- },
474
- redirect: (url) => {
475
- const apiError = new APIError("FOUND", void 0, {
476
- Location: url,
477
- ...response.headers
478
- });
479
- return apiError;
480
- },
481
- context: {}
482
- };
483
- const finalContext = await runMiddleware(options, context);
484
- context.context = finalContext;
485
- const handlerResponse = await handler(context).catch((e) => {
486
- if (e instanceof APIError && asResponse) {
487
- const headers = response.headers;
488
- for (const [key, value] of Object.entries(e.headers)) {
489
- headers.set(key, value);
490
- }
491
- return new Response(null, {
492
- status: e.statusCode,
493
- headers
494
- });
495
- }
496
- throw e;
497
- });
498
- response = createResponse(handlerResponse, response);
499
- const res = asResponse ? response : handlerResponse;
500
- return res;
501
- };
502
- internalHandler.path = path;
503
- internalHandler.options = options;
504
- const registry = new OpenAPIRegistry();
505
- registry.registerPath({
506
- path,
507
- method: Array.isArray(options.method) ? options.method[0].toLowerCase() : options.method.toLowerCase(),
508
- request: {
509
- ...options.body ? {
510
- body: {
511
- content: {
512
- "application/json": {
513
- schema: options.body
514
- }
515
- }
516
- }
517
- } : {},
518
- ...options.query ? {
519
- query: options.query
520
- } : {},
521
- params: paramToZod(path)
522
- },
523
- responses: {
524
- 200: {
525
- description: "Successful response",
526
- content: {
527
- "application/json": {
528
- schema: z.record(z.unknown())
529
- }
530
- }
531
- },
532
- 400: {
533
- description: "Bad request",
534
- content: {
535
- "application/json": {
536
- schema: z.object({
537
- message: z.string()
538
- })
539
- }
540
- }
541
- },
542
- ...options.openAPI?.responses
543
- }
544
- });
545
- internalHandler.openAPI = {
546
- definitions: registry.definitions
547
- };
548
- return internalHandler;
549
- };
550
- function createEndpointCreator(opts) {
551
- return (path, options, handler) => {
552
- const res = createEndpoint(
553
- path,
554
- {
555
- ...options,
556
- use: [...options?.use || [], ...opts?.use || []]
557
- },
558
- handler
559
- );
560
- return res;
561
- };
562
- }
563
- createEndpoint.creator = createEndpointCreator;
564
-
565
- async function getBody(request) {
566
- const contentType = request.headers.get("content-type") || "";
567
- if (!request.body) {
568
- return void 0;
569
- }
570
- if (contentType.includes("application/json")) {
571
- return await request.json();
572
- }
573
- if (contentType.includes("application/x-www-form-urlencoded")) {
574
- const formData = await request.formData();
575
- const result = {};
576
- formData.forEach((value, key) => {
577
- result[key] = value.toString();
578
- });
579
- return result;
580
- }
581
- if (contentType.includes("multipart/form-data")) {
582
- const formData = await request.formData();
583
- const result = {};
584
- formData.forEach((value, key) => {
585
- result[key] = value;
586
- });
587
- return result;
588
- }
589
- if (contentType.includes("text/plain")) {
590
- return await request.text();
591
- }
592
- if (contentType.includes("application/octet-stream")) {
593
- return await request.arrayBuffer();
594
- }
595
- if (contentType.includes("application/pdf") || contentType.includes("image/") || contentType.includes("video/")) {
596
- const blob = await request.blob();
597
- return blob;
598
- }
599
- if (contentType.includes("application/stream") || request.body instanceof ReadableStream) {
600
- return request.body;
601
- }
602
- return await request.text();
603
- }
604
-
605
- const createRouter = (endpoints, config) => {
606
- const _endpoints = Object.values(endpoints);
607
- const router = createRouter$1();
608
- for (const endpoint of _endpoints) {
609
- if (Array.isArray(endpoint.options?.method)) {
610
- for (const method of endpoint.options.method) {
611
- addRoute(router, method, endpoint.path, endpoint);
612
- }
613
- } else {
614
- addRoute(router, endpoint.options.method, endpoint.path, endpoint);
615
- }
616
- }
617
- const middlewareRouter = createRouter$1();
618
- for (const route of config?.routerMiddleware || []) {
619
- addRoute(middlewareRouter, "*", route.path, route.middleware);
620
- }
621
- const handler = async (request) => {
622
- const url = new URL(request.url);
623
- let path = url.pathname;
624
- if (config?.basePath) {
625
- path = path.split(config.basePath)[1];
626
- }
627
- if (!path?.length) {
628
- config?.onError?.(new APIError("NOT_FOUND"));
629
- console.warn(
630
- `[better-call]: Make sure the URL has the basePath (${config?.basePath}).`
631
- );
632
- return new Response(null, {
633
- status: 404,
634
- statusText: "Not Found"
635
- });
636
- }
637
- const method = request.method;
638
- const route = findRoute(router, method, path);
639
- const handler2 = route?.data;
640
- const body = await getBody(request);
641
- const headers = request.headers;
642
- const query = Object.fromEntries(url.searchParams);
643
- const routerMiddleware = findAllRoutes(middlewareRouter, "*", path);
644
- if (!handler2) {
645
- return new Response(null, {
646
- status: 404,
647
- statusText: "Not Found"
648
- });
649
- }
650
- try {
651
- let middlewareContext = {};
652
- if (routerMiddleware?.length) {
653
- for (const route2 of routerMiddleware) {
654
- const middleware = route2.data;
655
- const res = await middleware({
656
- path,
657
- method,
658
- headers,
659
- params: route2?.params,
660
- request,
661
- body,
662
- query,
663
- context: {
664
- ...config?.extraContext
665
- }
666
- });
667
- if (res instanceof Response) {
668
- return res;
669
- }
670
- if (res?._flag === "json") {
671
- return new Response(JSON.stringify(res), {
672
- headers: res.headers
673
- });
674
- }
675
- if (res) {
676
- middlewareContext = {
677
- ...res,
678
- ...middlewareContext
679
- };
680
- }
681
- }
682
- }
683
- const handlerRes = await handler2({
684
- path,
685
- method,
686
- headers,
687
- params: route?.params,
688
- request,
689
- body,
690
- query,
691
- context: {
692
- ...middlewareContext,
693
- ...config?.extraContext
694
- },
695
- asResponse: true
696
- });
697
- if (handlerRes instanceof Response) {
698
- return handlerRes;
699
- }
700
- return new Response(handlerRes ? JSON.stringify(handlerRes) : void 0, {
701
- status: 200
702
- });
703
- } catch (e) {
704
- if (config?.onError) {
705
- const onErrorRes = await config.onError(e);
706
- if (onErrorRes instanceof Response) {
707
- return onErrorRes;
708
- }
709
- }
710
- if (e instanceof APIError) {
711
- return new Response(e.body ? JSON.stringify(e.body) : null, {
712
- status: e.statusCode,
713
- headers: e.headers
714
- });
715
- }
716
- if (config?.throwError) {
717
- throw e;
718
- }
719
- return new Response(null, {
720
- status: 500,
721
- statusText: "Internal Server Error"
722
- });
723
- }
724
- };
725
- return {
726
- handler,
727
- endpoints
728
- };
729
- };
730
-
731
- function createMiddleware(optionsOrHandler, handler) {
732
- if (typeof optionsOrHandler === "function") {
733
- return createEndpoint(
734
- "*",
735
- {
736
- method: "*"
737
- },
738
- optionsOrHandler
739
- );
740
- }
741
- if (!handler) {
742
- throw new Error("Middleware handler is required");
743
- }
744
- const endpoint = createEndpoint(
745
- "*",
746
- {
747
- ...optionsOrHandler,
748
- method: "*"
749
- },
750
- handler
751
- );
752
- return endpoint;
753
- }
754
- function createMiddlewareCreator(opts) {
755
- return (handler) => {
756
- const res = createMiddleware(
757
- {
758
- method: "*",
759
- use: opts.use
760
- },
761
- handler
762
- );
763
- return res;
764
- };
765
- }
766
- createMiddleware.creator = createMiddlewareCreator;
767
-
768
- export { APIError, _statusCode, createEndpoint, createGetHeader, createMiddleware, createRouter, createSetHeader, fromError, getCookie, getSignedCookie, parse, parseSigned, runValidation, serialize, serializeSigned, setCookie, setSignedCookie };