@temporary-name/server 1.9.3-alpha.592ae1e02e18c5274906b132313b083116248636 → 1.9.3-alpha.5dc8b200530586870ac736830d4584e0333cfd05
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/adapters/aws-lambda/index.d.mts +3 -4
- package/dist/adapters/aws-lambda/index.d.ts +3 -4
- package/dist/adapters/aws-lambda/index.mjs +4 -6
- package/dist/adapters/fetch/index.d.mts +3 -4
- package/dist/adapters/fetch/index.d.ts +3 -4
- package/dist/adapters/fetch/index.mjs +4 -6
- package/dist/adapters/node/index.d.mts +3 -4
- package/dist/adapters/node/index.d.ts +3 -4
- package/dist/adapters/node/index.mjs +4 -6
- package/dist/adapters/standard/index.d.mts +20 -32
- package/dist/adapters/standard/index.d.ts +20 -32
- package/dist/adapters/standard/index.mjs +5 -7
- package/dist/helpers/index.mjs +3 -29
- package/dist/index.d.mts +71 -339
- package/dist/index.d.ts +71 -339
- package/dist/index.mjs +218 -355
- package/dist/openapi/index.d.mts +1 -1
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/index.mjs +60 -77
- package/dist/plugins/index.d.mts +4 -80
- package/dist/plugins/index.d.ts +4 -80
- package/dist/plugins/index.mjs +17 -189
- package/dist/shared/{server.CQyYNJ1H.d.ts → server.B-meye9-.d.ts} +2 -4
- package/dist/shared/{server.DLsti1Pv.mjs → server.Ba0Z2fNc.mjs} +58 -97
- package/dist/shared/server.C1RJffw4.mjs +30 -0
- package/dist/shared/server.DkYpsO6W.d.mts +251 -0
- package/dist/shared/server.DkYpsO6W.d.ts +251 -0
- package/dist/shared/{server.SLLuK6_v.d.ts → server.DwNnHUZP.d.ts} +2 -2
- package/dist/shared/{server.BeuTpcmO.d.mts → server.I-tTl_ce.d.mts} +2 -2
- package/dist/shared/{server.BEHw7Eyx.mjs → server.JtIZ8YG7.mjs} +1 -11
- package/dist/shared/server.miXh-9wo.mjs +416 -0
- package/dist/shared/{server.C1fnTLq0.d.mts → server.vLcMd_kA.d.mts} +2 -4
- package/package.json +10 -21
- package/dist/shared/server.BKSOrA6h.d.mts +0 -192
- package/dist/shared/server.BKSOrA6h.d.ts +0 -192
- package/dist/shared/server.BKh8I1Ny.mjs +0 -239
package/dist/openapi/index.d.mts
CHANGED
|
@@ -55,7 +55,7 @@ interface SchemaConvertOptions {
|
|
|
55
55
|
minStructureDepthForRef?: number;
|
|
56
56
|
}
|
|
57
57
|
interface SchemaConverter {
|
|
58
|
-
convert(
|
|
58
|
+
convert(schemas: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
59
59
|
}
|
|
60
60
|
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
61
61
|
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
package/dist/openapi/index.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ interface SchemaConvertOptions {
|
|
|
55
55
|
minStructureDepthForRef?: number;
|
|
56
56
|
}
|
|
57
57
|
interface SchemaConverter {
|
|
58
|
-
convert(
|
|
58
|
+
convert(schemas: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
|
|
59
59
|
}
|
|
60
60
|
interface ConditionalSchemaConverter extends SchemaConverter {
|
|
61
61
|
condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
|
package/dist/openapi/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isProcedure, resolveContractProcedures, ORPCError, createRouterClient } from '@temporary-name/server';
|
|
2
|
-
import { fallbackContractConfig, getEventIteratorSchemaDetails } from '@temporary-name/contract';
|
|
2
|
+
import { standardizeHTTPPath, fallbackContractConfig, getDynamicParams, getEventIteratorSchemaDetails } from '@temporary-name/contract';
|
|
3
3
|
import { isObject, stringifyJSON, findDeepMatches, toArray, clone, value, toHttpPath, isORPCErrorStatus, fallbackORPCErrorStatus, fallbackORPCErrorMessage, resolveMaybeOptionalOptions, createORPCErrorFromJson } from '@temporary-name/shared';
|
|
4
|
-
import {
|
|
4
|
+
import { j as jsonSerialize, d as deserialize, s as serialize } from '../shared/server.JtIZ8YG7.mjs';
|
|
5
5
|
import '@temporary-name/standard-server';
|
|
6
6
|
import { TypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
7
7
|
export { ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from '@temporary-name/interop/json-schema-typed/draft-2020-12';
|
|
@@ -530,94 +530,77 @@ ${errors.join("\n\n")}`
|
|
|
530
530
|
}
|
|
531
531
|
async #request(doc, ref, def, baseSchemaConvertOptions) {
|
|
532
532
|
const method = fallbackContractConfig("defaultMethod", def.route.method);
|
|
533
|
-
const details = getEventIteratorSchemaDetails(def.inputSchema);
|
|
534
|
-
if (details) {
|
|
535
|
-
ref.requestBody = {
|
|
536
|
-
required: true,
|
|
537
|
-
content: toOpenAPIEventIteratorContent(
|
|
538
|
-
await this.converter.convert(details.yields, { ...baseSchemaConvertOptions, strategy: "input" }),
|
|
539
|
-
await this.converter.convert(details.returns, { ...baseSchemaConvertOptions, strategy: "input" })
|
|
540
|
-
)
|
|
541
|
-
};
|
|
542
|
-
return;
|
|
543
|
-
}
|
|
544
533
|
const dynamicParams = getDynamicParams(def.route.path)?.map((v) => v.name);
|
|
545
|
-
const
|
|
546
|
-
let [required, schema] = await this.converter.convert(def.inputSchema, {
|
|
534
|
+
const [_pathRequired, pathSchema] = await this.converter.convert(def.schemas.pathSchema, {
|
|
547
535
|
...baseSchemaConvertOptions,
|
|
548
536
|
strategy: "input",
|
|
549
|
-
minStructureDepthForRef:
|
|
537
|
+
minStructureDepthForRef: 1
|
|
550
538
|
});
|
|
551
|
-
if (
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
);
|
|
559
|
-
if (!isObjectSchema(schema)) {
|
|
560
|
-
throw error2;
|
|
561
|
-
}
|
|
562
|
-
const [paramsSchema, rest] = separateObjectSchema(schema, dynamicParams);
|
|
563
|
-
schema = rest;
|
|
564
|
-
required = rest.required ? rest.required.length !== 0 : false;
|
|
565
|
-
if (!checkParamsSchema(paramsSchema, dynamicParams)) {
|
|
566
|
-
throw error2;
|
|
567
|
-
}
|
|
568
|
-
ref.parameters ??= [];
|
|
569
|
-
ref.parameters.push(...toOpenAPIParameters(paramsSchema, "path"));
|
|
539
|
+
if (dynamicParams?.length) {
|
|
540
|
+
const error = new OpenAPIGeneratorError(
|
|
541
|
+
// TODO: fix this error
|
|
542
|
+
'When input structure is "compact", and path has dynamic params, input schema must be an object with all dynamic params as required.'
|
|
543
|
+
);
|
|
544
|
+
if (!isObjectSchema(pathSchema)) {
|
|
545
|
+
throw error;
|
|
570
546
|
}
|
|
571
|
-
if (
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
547
|
+
if (!checkParamsSchema(pathSchema, dynamicParams)) {
|
|
548
|
+
throw error;
|
|
549
|
+
}
|
|
550
|
+
ref.parameters ??= [];
|
|
551
|
+
ref.parameters.push(...toOpenAPIParameters(pathSchema, "path"));
|
|
552
|
+
} else {
|
|
553
|
+
const error = new OpenAPIGeneratorError("Params set via path do not match those on the route");
|
|
554
|
+
if (!isObjectSchema(pathSchema)) {
|
|
555
|
+
console.log("FOO", pathSchema);
|
|
556
|
+
throw error;
|
|
557
|
+
}
|
|
558
|
+
if (!checkParamsSchema(pathSchema, [])) {
|
|
559
|
+
console.log("BAR", pathSchema);
|
|
560
|
+
throw error;
|
|
585
561
|
}
|
|
586
|
-
return;
|
|
587
|
-
}
|
|
588
|
-
const error = new OpenAPIGeneratorError(
|
|
589
|
-
'When input structure is "detailed", input schema must satisfy: { params?: Record<string, unknown>, query?: Record<string, unknown>, headers?: Record<string, unknown>, body?: unknown }'
|
|
590
|
-
);
|
|
591
|
-
if (!isObjectSchema(schema)) {
|
|
592
|
-
throw error;
|
|
593
562
|
}
|
|
594
|
-
const
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
563
|
+
const [_queryRequired, querySchema] = await this.converter.convert(def.schemas.querySchema, {
|
|
564
|
+
...baseSchemaConvertOptions,
|
|
565
|
+
strategy: "input",
|
|
566
|
+
minStructureDepthForRef: 0
|
|
567
|
+
});
|
|
568
|
+
if (!isAnySchema(querySchema)) {
|
|
569
|
+
const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, querySchema);
|
|
570
|
+
if (!isObjectSchema(resolvedSchema)) {
|
|
571
|
+
throw new OpenAPIGeneratorError("Query param schema must satisfy: object | any | unknown");
|
|
572
|
+
}
|
|
573
|
+
ref.parameters ??= [];
|
|
574
|
+
ref.parameters.push(...toOpenAPIParameters(resolvedSchema, "query"));
|
|
599
575
|
}
|
|
600
|
-
|
|
601
|
-
const
|
|
602
|
-
if (
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
576
|
+
if (method !== "GET") {
|
|
577
|
+
const details = getEventIteratorSchemaDetails(def.schemas.bodySchema);
|
|
578
|
+
if (details) {
|
|
579
|
+
ref.requestBody = {
|
|
580
|
+
required: true,
|
|
581
|
+
content: toOpenAPIEventIteratorContent(
|
|
582
|
+
await this.converter.convert(details.yields, { ...baseSchemaConvertOptions, strategy: "input" }),
|
|
583
|
+
await this.converter.convert(details.returns, { ...baseSchemaConvertOptions, strategy: "input" })
|
|
584
|
+
)
|
|
585
|
+
};
|
|
586
|
+
} else {
|
|
587
|
+
const [bodyRequired, bodySchema] = await this.converter.convert(def.schemas.bodySchema, {
|
|
588
|
+
...baseSchemaConvertOptions,
|
|
589
|
+
strategy: "input",
|
|
590
|
+
minStructureDepthForRef: 0
|
|
591
|
+
});
|
|
592
|
+
if (isAnySchema(bodySchema)) {
|
|
593
|
+
return;
|
|
606
594
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
595
|
+
ref.requestBody = {
|
|
596
|
+
required: bodyRequired,
|
|
597
|
+
content: toOpenAPIContent(bodySchema)
|
|
598
|
+
};
|
|
610
599
|
}
|
|
611
600
|
}
|
|
612
|
-
if (schema.properties?.body !== void 0) {
|
|
613
|
-
ref.requestBody = {
|
|
614
|
-
required: schema.required?.includes("body"),
|
|
615
|
-
content: toOpenAPIContent(schema.properties.body)
|
|
616
|
-
};
|
|
617
|
-
}
|
|
618
601
|
}
|
|
619
602
|
async #successResponse(doc, ref, def, baseSchemaConvertOptions) {
|
|
620
|
-
const outputSchema = def.outputSchema;
|
|
603
|
+
const outputSchema = def.schemas.outputSchema;
|
|
621
604
|
const status = fallbackContractConfig("defaultSuccessStatus", def.route.successStatus);
|
|
622
605
|
const description = fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription);
|
|
623
606
|
const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(outputSchema);
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,58 +1,8 @@
|
|
|
1
1
|
import { Value, Promisable, ORPCError } from '@temporary-name/shared';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.C1fnTLq0.mjs';
|
|
5
|
-
import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.BKSOrA6h.mjs';
|
|
2
|
+
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.vLcMd_kA.mjs';
|
|
3
|
+
import { C as Context, N as ProcedureClientInterceptorOptions } from '../shared/server.DkYpsO6W.mjs';
|
|
6
4
|
import { Meta } from '@temporary-name/contract';
|
|
7
5
|
|
|
8
|
-
interface BatchHandlerOptions<T extends Context> {
|
|
9
|
-
/**
|
|
10
|
-
* The max size of the batch allowed.
|
|
11
|
-
*
|
|
12
|
-
* @default 10
|
|
13
|
-
*/
|
|
14
|
-
maxSize?: Value<Promisable<number>, [StandardHandlerInterceptorOptions<T>]>;
|
|
15
|
-
/**
|
|
16
|
-
* Map the request before processing it.
|
|
17
|
-
*
|
|
18
|
-
* @default merged back batch request headers into the request
|
|
19
|
-
*/
|
|
20
|
-
mapRequestItem?(request: StandardRequest, batchOptions: StandardHandlerInterceptorOptions<T>): StandardRequest;
|
|
21
|
-
/**
|
|
22
|
-
* Success batch response status code.
|
|
23
|
-
*
|
|
24
|
-
* @default 207
|
|
25
|
-
*/
|
|
26
|
-
successStatus?: Value<Promisable<number>, [
|
|
27
|
-
responses: Promise<BatchResponseBodyItem>[],
|
|
28
|
-
batchOptions: StandardHandlerInterceptorOptions<T>
|
|
29
|
-
]>;
|
|
30
|
-
/**
|
|
31
|
-
* success batch response headers.
|
|
32
|
-
*
|
|
33
|
-
* @default {}
|
|
34
|
-
*/
|
|
35
|
-
headers?: Value<Promisable<StandardHeaders>, [
|
|
36
|
-
responses: Promise<BatchResponseBodyItem>[],
|
|
37
|
-
batchOptions: StandardHandlerInterceptorOptions<T>
|
|
38
|
-
]>;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
|
|
42
|
-
* reducing the overhead of sending each one separately.
|
|
43
|
-
*
|
|
44
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs}
|
|
45
|
-
*/
|
|
46
|
-
declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
47
|
-
private readonly maxSize;
|
|
48
|
-
private readonly mapRequestItem;
|
|
49
|
-
private readonly successStatus;
|
|
50
|
-
private readonly headers;
|
|
51
|
-
order: number;
|
|
52
|
-
constructor(options?: BatchHandlerOptions<T>);
|
|
53
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
6
|
interface CORSOptions<T extends Context> {
|
|
57
7
|
origin?: Value<Promisable<string | readonly string[] | null | undefined>, [
|
|
58
8
|
origin: string,
|
|
@@ -80,32 +30,6 @@ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T>
|
|
|
80
30
|
init(options: StandardHandlerOptions<T>): void;
|
|
81
31
|
}
|
|
82
32
|
|
|
83
|
-
interface RequestHeadersPluginContext {
|
|
84
|
-
reqHeaders?: Headers;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* The Request Headers Plugin injects a `reqHeaders` instance into the context,
|
|
88
|
-
* allowing access to request headers in oRPC.
|
|
89
|
-
*
|
|
90
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/request-headers Request Headers Plugin Docs}
|
|
91
|
-
*/
|
|
92
|
-
declare class RequestHeadersPlugin<T extends RequestHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
93
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
interface ResponseHeadersPluginContext {
|
|
97
|
-
resHeaders?: Headers;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* The Response Headers Plugin allows you to set response headers in oRPC.
|
|
101
|
-
* It injects a resHeaders instance into the context, enabling you to modify response headers easily.
|
|
102
|
-
*
|
|
103
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/response-headers Response Headers Plugin Docs}
|
|
104
|
-
*/
|
|
105
|
-
declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
106
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
33
|
interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
|
|
110
34
|
/**
|
|
111
35
|
* The name of the header to check.
|
|
@@ -156,5 +80,5 @@ declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements St
|
|
|
156
80
|
init(options: StandardHandlerOptions<T>): void;
|
|
157
81
|
}
|
|
158
82
|
|
|
159
|
-
export {
|
|
160
|
-
export type {
|
|
83
|
+
export { CORSPlugin, SimpleCsrfProtectionHandlerPlugin };
|
|
84
|
+
export type { CORSOptions, SimpleCsrfProtectionHandlerPluginOptions };
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,58 +1,8 @@
|
|
|
1
1
|
import { Value, Promisable, ORPCError } from '@temporary-name/shared';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.CQyYNJ1H.js';
|
|
5
|
-
import { C as Context, E as ProcedureClientInterceptorOptions } from '../shared/server.BKSOrA6h.js';
|
|
2
|
+
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.B-meye9-.js';
|
|
3
|
+
import { C as Context, N as ProcedureClientInterceptorOptions } from '../shared/server.DkYpsO6W.js';
|
|
6
4
|
import { Meta } from '@temporary-name/contract';
|
|
7
5
|
|
|
8
|
-
interface BatchHandlerOptions<T extends Context> {
|
|
9
|
-
/**
|
|
10
|
-
* The max size of the batch allowed.
|
|
11
|
-
*
|
|
12
|
-
* @default 10
|
|
13
|
-
*/
|
|
14
|
-
maxSize?: Value<Promisable<number>, [StandardHandlerInterceptorOptions<T>]>;
|
|
15
|
-
/**
|
|
16
|
-
* Map the request before processing it.
|
|
17
|
-
*
|
|
18
|
-
* @default merged back batch request headers into the request
|
|
19
|
-
*/
|
|
20
|
-
mapRequestItem?(request: StandardRequest, batchOptions: StandardHandlerInterceptorOptions<T>): StandardRequest;
|
|
21
|
-
/**
|
|
22
|
-
* Success batch response status code.
|
|
23
|
-
*
|
|
24
|
-
* @default 207
|
|
25
|
-
*/
|
|
26
|
-
successStatus?: Value<Promisable<number>, [
|
|
27
|
-
responses: Promise<BatchResponseBodyItem>[],
|
|
28
|
-
batchOptions: StandardHandlerInterceptorOptions<T>
|
|
29
|
-
]>;
|
|
30
|
-
/**
|
|
31
|
-
* success batch response headers.
|
|
32
|
-
*
|
|
33
|
-
* @default {}
|
|
34
|
-
*/
|
|
35
|
-
headers?: Value<Promisable<StandardHeaders>, [
|
|
36
|
-
responses: Promise<BatchResponseBodyItem>[],
|
|
37
|
-
batchOptions: StandardHandlerInterceptorOptions<T>
|
|
38
|
-
]>;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
|
|
42
|
-
* reducing the overhead of sending each one separately.
|
|
43
|
-
*
|
|
44
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs}
|
|
45
|
-
*/
|
|
46
|
-
declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
47
|
-
private readonly maxSize;
|
|
48
|
-
private readonly mapRequestItem;
|
|
49
|
-
private readonly successStatus;
|
|
50
|
-
private readonly headers;
|
|
51
|
-
order: number;
|
|
52
|
-
constructor(options?: BatchHandlerOptions<T>);
|
|
53
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
6
|
interface CORSOptions<T extends Context> {
|
|
57
7
|
origin?: Value<Promisable<string | readonly string[] | null | undefined>, [
|
|
58
8
|
origin: string,
|
|
@@ -80,32 +30,6 @@ declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T>
|
|
|
80
30
|
init(options: StandardHandlerOptions<T>): void;
|
|
81
31
|
}
|
|
82
32
|
|
|
83
|
-
interface RequestHeadersPluginContext {
|
|
84
|
-
reqHeaders?: Headers;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* The Request Headers Plugin injects a `reqHeaders` instance into the context,
|
|
88
|
-
* allowing access to request headers in oRPC.
|
|
89
|
-
*
|
|
90
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/request-headers Request Headers Plugin Docs}
|
|
91
|
-
*/
|
|
92
|
-
declare class RequestHeadersPlugin<T extends RequestHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
93
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
interface ResponseHeadersPluginContext {
|
|
97
|
-
resHeaders?: Headers;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* The Response Headers Plugin allows you to set response headers in oRPC.
|
|
101
|
-
* It injects a resHeaders instance into the context, enabling you to modify response headers easily.
|
|
102
|
-
*
|
|
103
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/response-headers Response Headers Plugin Docs}
|
|
104
|
-
*/
|
|
105
|
-
declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
106
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
33
|
interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
|
|
110
34
|
/**
|
|
111
35
|
* The name of the header to check.
|
|
@@ -156,5 +80,5 @@ declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements St
|
|
|
156
80
|
init(options: StandardHandlerOptions<T>): void;
|
|
157
81
|
}
|
|
158
82
|
|
|
159
|
-
export {
|
|
160
|
-
export type {
|
|
83
|
+
export { CORSPlugin, SimpleCsrfProtectionHandlerPlugin };
|
|
84
|
+
export type { CORSOptions, SimpleCsrfProtectionHandlerPluginOptions };
|
package/dist/plugins/index.mjs
CHANGED
|
@@ -1,119 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { parseBatchRequest, toBatchResponse } from '@temporary-name/standard-server/batch';
|
|
4
|
-
import { toFetchHeaders } from '@temporary-name/standard-server-fetch';
|
|
5
|
-
|
|
6
|
-
class BatchHandlerPlugin {
|
|
7
|
-
maxSize;
|
|
8
|
-
mapRequestItem;
|
|
9
|
-
successStatus;
|
|
10
|
-
headers;
|
|
11
|
-
order = 5e6;
|
|
12
|
-
constructor(options = {}) {
|
|
13
|
-
this.maxSize = options.maxSize ?? 10;
|
|
14
|
-
this.mapRequestItem = options.mapRequestItem ?? ((request, { request: batchRequest }) => ({
|
|
15
|
-
...request,
|
|
16
|
-
headers: {
|
|
17
|
-
...batchRequest.headers,
|
|
18
|
-
...request.headers
|
|
19
|
-
}
|
|
20
|
-
}));
|
|
21
|
-
this.successStatus = options.successStatus ?? 207;
|
|
22
|
-
this.headers = options.headers ?? {};
|
|
23
|
-
}
|
|
24
|
-
init(options) {
|
|
25
|
-
options.rootInterceptors ??= [];
|
|
26
|
-
options.rootInterceptors.unshift(async (options2) => {
|
|
27
|
-
const xHeader = flattenHeader(options2.request.headers["x-orpc-batch"]);
|
|
28
|
-
if (xHeader === void 0) {
|
|
29
|
-
return options2.next();
|
|
30
|
-
}
|
|
31
|
-
let isParsing = false;
|
|
32
|
-
try {
|
|
33
|
-
return await runWithSpan({ name: "handle_batch_request" }, async (span) => {
|
|
34
|
-
const mode = xHeader === "buffered" ? "buffered" : "streaming";
|
|
35
|
-
isParsing = true;
|
|
36
|
-
const parsed = parseBatchRequest({ ...options2.request, body: await options2.request.body() });
|
|
37
|
-
isParsing = false;
|
|
38
|
-
span?.setAttribute("batch.mode", mode);
|
|
39
|
-
span?.setAttribute("batch.size", parsed.length);
|
|
40
|
-
const maxSize = await value(this.maxSize, options2);
|
|
41
|
-
if (parsed.length > maxSize) {
|
|
42
|
-
const message = "Batch request size exceeds the maximum allowed size";
|
|
43
|
-
setSpanError(span, message);
|
|
44
|
-
return {
|
|
45
|
-
matched: true,
|
|
46
|
-
response: {
|
|
47
|
-
status: 413,
|
|
48
|
-
headers: {},
|
|
49
|
-
body: message
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
const responses = parsed.map((request, index) => {
|
|
54
|
-
const mapped = this.mapRequestItem(request, options2);
|
|
55
|
-
return options2.next({ ...options2, request: { ...mapped, body: () => Promise.resolve(mapped.body) } }).then(({ response: response2, matched }) => {
|
|
56
|
-
span?.addEvent(`response.${index}.${matched ? "success" : "not_matched"}`);
|
|
57
|
-
if (matched) {
|
|
58
|
-
if (response2.body instanceof Blob || response2.body instanceof FormData || isAsyncIteratorObject(response2.body)) {
|
|
59
|
-
return {
|
|
60
|
-
index,
|
|
61
|
-
status: 500,
|
|
62
|
-
headers: {},
|
|
63
|
-
body: "Batch responses do not support file/blob, or event-iterator. Please call this procedure separately outside of the batch request."
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
return { ...response2, index };
|
|
67
|
-
}
|
|
68
|
-
return { index, status: 404, headers: {}, body: "No procedure matched" };
|
|
69
|
-
}).catch((err) => {
|
|
70
|
-
Promise.reject(err);
|
|
71
|
-
return { index, status: 500, headers: {}, body: "Internal server error" };
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
await Promise.race(responses);
|
|
75
|
-
const status = await value(this.successStatus, responses, options2);
|
|
76
|
-
const headers = await value(this.headers, responses, options2);
|
|
77
|
-
const promises = [...responses];
|
|
78
|
-
const response = await toBatchResponse({
|
|
79
|
-
status,
|
|
80
|
-
headers,
|
|
81
|
-
mode,
|
|
82
|
-
body: new AsyncIteratorClass(
|
|
83
|
-
async () => {
|
|
84
|
-
const handling = promises.filter((p) => p !== void 0);
|
|
85
|
-
if (handling.length <= 0) {
|
|
86
|
-
return { done: true, value: void 0 };
|
|
87
|
-
}
|
|
88
|
-
const value2 = await Promise.race(handling);
|
|
89
|
-
promises[value2.index] = void 0;
|
|
90
|
-
return { done: false, value: value2 };
|
|
91
|
-
},
|
|
92
|
-
async () => {
|
|
93
|
-
}
|
|
94
|
-
)
|
|
95
|
-
});
|
|
96
|
-
return {
|
|
97
|
-
matched: true,
|
|
98
|
-
response
|
|
99
|
-
};
|
|
100
|
-
});
|
|
101
|
-
} catch (cause) {
|
|
102
|
-
if (isParsing) {
|
|
103
|
-
return {
|
|
104
|
-
matched: true,
|
|
105
|
-
response: {
|
|
106
|
-
status: 400,
|
|
107
|
-
headers: {},
|
|
108
|
-
body: "Invalid batch request, this could be caused by a malformed request body or a missing header"
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
throw cause;
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
1
|
+
import { value, ORPCError } from '@temporary-name/shared';
|
|
2
|
+
import { maybeSetHeader } from '@temporary-name/standard-server';
|
|
117
3
|
|
|
118
4
|
class CORSPlugin {
|
|
119
5
|
options;
|
|
@@ -132,17 +18,13 @@ class CORSPlugin {
|
|
|
132
18
|
options.rootInterceptors ??= [];
|
|
133
19
|
options.rootInterceptors.unshift(async (interceptorOptions) => {
|
|
134
20
|
if (interceptorOptions.request.method === "OPTIONS") {
|
|
135
|
-
const resHeaders =
|
|
21
|
+
const resHeaders = new Headers();
|
|
136
22
|
if (this.options.maxAge !== void 0) {
|
|
137
|
-
resHeaders
|
|
138
|
-
}
|
|
139
|
-
if (this.options.allowMethods?.length) {
|
|
140
|
-
resHeaders["access-control-allow-methods"] = flattenHeader(this.options.allowMethods);
|
|
141
|
-
}
|
|
142
|
-
const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
|
|
143
|
-
if (typeof allowHeaders === "string" || allowHeaders?.length) {
|
|
144
|
-
resHeaders["access-control-allow-headers"] = flattenHeader(allowHeaders);
|
|
23
|
+
resHeaders.set("access-control-max-age", this.options.maxAge.toString());
|
|
145
24
|
}
|
|
25
|
+
maybeSetHeader(resHeaders, "access-control-allow-methods", this.options.allowMethods);
|
|
26
|
+
const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers.get("access-control-request-headers");
|
|
27
|
+
maybeSetHeader(resHeaders, "access-control-allow-headers", allowHeaders);
|
|
146
28
|
return {
|
|
147
29
|
matched: true,
|
|
148
30
|
response: {
|
|
@@ -159,87 +41,33 @@ class CORSPlugin {
|
|
|
159
41
|
if (!result.matched) {
|
|
160
42
|
return result;
|
|
161
43
|
}
|
|
162
|
-
const origin =
|
|
44
|
+
const origin = interceptorOptions.request.headers.get("origin") ?? "";
|
|
163
45
|
const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
|
|
164
46
|
const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
|
|
165
47
|
if (allowedOriginArr.includes("*")) {
|
|
166
|
-
result.response.headers
|
|
48
|
+
result.response.headers.set("access-control-allow-origin", "*");
|
|
167
49
|
} else {
|
|
168
50
|
if (allowedOriginArr.includes(origin)) {
|
|
169
|
-
result.response.headers
|
|
51
|
+
result.response.headers.set("access-control-allow-origin", origin);
|
|
170
52
|
}
|
|
171
|
-
result.response.headers.vary
|
|
53
|
+
result.response.headers.set("vary", interceptorOptions.request.headers.get("vary") ?? "origin");
|
|
172
54
|
}
|
|
173
55
|
const allowedTimingOrigin = await value(this.options.timingOrigin, origin, interceptorOptions);
|
|
174
56
|
const allowedTimingOriginArr = Array.isArray(allowedTimingOrigin) ? allowedTimingOrigin : [allowedTimingOrigin];
|
|
175
57
|
if (allowedTimingOriginArr.includes("*")) {
|
|
176
|
-
result.response.headers
|
|
58
|
+
result.response.headers.set("timing-allow-origin", "*");
|
|
177
59
|
} else if (allowedTimingOriginArr.includes(origin)) {
|
|
178
|
-
result.response.headers
|
|
60
|
+
result.response.headers.set("timing-allow-origin", origin);
|
|
179
61
|
}
|
|
180
62
|
if (this.options.credentials) {
|
|
181
|
-
result.response.headers
|
|
182
|
-
}
|
|
183
|
-
if (this.options.exposeHeaders?.length) {
|
|
184
|
-
result.response.headers["access-control-expose-headers"] = flattenHeader(this.options.exposeHeaders);
|
|
63
|
+
result.response.headers.set("access-control-allow-credentials", "true");
|
|
185
64
|
}
|
|
65
|
+
maybeSetHeader(result.response.headers, "access-control-expose-headers", this.options.exposeHeaders);
|
|
186
66
|
return result;
|
|
187
67
|
});
|
|
188
68
|
}
|
|
189
69
|
}
|
|
190
70
|
|
|
191
|
-
class RequestHeadersPlugin {
|
|
192
|
-
init(options) {
|
|
193
|
-
options.rootInterceptors ??= [];
|
|
194
|
-
options.rootInterceptors.push((interceptorOptions) => {
|
|
195
|
-
const reqHeaders = interceptorOptions.context.reqHeaders ?? toFetchHeaders(interceptorOptions.request.headers);
|
|
196
|
-
return interceptorOptions.next({
|
|
197
|
-
...interceptorOptions,
|
|
198
|
-
context: {
|
|
199
|
-
...interceptorOptions.context,
|
|
200
|
-
reqHeaders
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
class ResponseHeadersPlugin {
|
|
208
|
-
init(options) {
|
|
209
|
-
options.rootInterceptors ??= [];
|
|
210
|
-
options.rootInterceptors.push(async (interceptorOptions) => {
|
|
211
|
-
const resHeaders = interceptorOptions.context.resHeaders ?? new Headers();
|
|
212
|
-
const result = await interceptorOptions.next({
|
|
213
|
-
...interceptorOptions,
|
|
214
|
-
context: {
|
|
215
|
-
...interceptorOptions.context,
|
|
216
|
-
resHeaders
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
if (!result.matched) {
|
|
220
|
-
return result;
|
|
221
|
-
}
|
|
222
|
-
const responseHeaders = clone(result.response.headers);
|
|
223
|
-
for (const [key, value] of resHeaders) {
|
|
224
|
-
if (Array.isArray(responseHeaders[key])) {
|
|
225
|
-
responseHeaders[key].push(value);
|
|
226
|
-
} else if (responseHeaders[key] !== void 0) {
|
|
227
|
-
responseHeaders[key] = [responseHeaders[key], value];
|
|
228
|
-
} else {
|
|
229
|
-
responseHeaders[key] = value;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return {
|
|
233
|
-
...result,
|
|
234
|
-
response: {
|
|
235
|
-
...result.response,
|
|
236
|
-
headers: responseHeaders
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
71
|
const SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL = Symbol("SIMPLE_CSRF_PROTECTION_CONTEXT");
|
|
244
72
|
class SimpleCsrfProtectionHandlerPlugin {
|
|
245
73
|
headerName;
|
|
@@ -266,7 +94,7 @@ class SimpleCsrfProtectionHandlerPlugin {
|
|
|
266
94
|
...options2,
|
|
267
95
|
context: {
|
|
268
96
|
...options2.context,
|
|
269
|
-
[SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]: options2.request.headers
|
|
97
|
+
[SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]: options2.request.headers.get(headerName) === headerValue
|
|
270
98
|
}
|
|
271
99
|
});
|
|
272
100
|
});
|
|
@@ -285,4 +113,4 @@ class SimpleCsrfProtectionHandlerPlugin {
|
|
|
285
113
|
}
|
|
286
114
|
}
|
|
287
115
|
|
|
288
|
-
export {
|
|
116
|
+
export { CORSPlugin, SimpleCsrfProtectionHandlerPlugin };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Meta } from '@temporary-name/contract';
|
|
2
|
-
import { HTTPPath, Interceptor } from '@temporary-name/shared';
|
|
3
|
-
import {
|
|
4
|
-
import { C as Context, R as Router, E as ProcedureClientInterceptorOptions } from './server.BKSOrA6h.js';
|
|
2
|
+
import { HTTPPath, StandardLazyRequest, Interceptor, StandardResponse } from '@temporary-name/shared';
|
|
3
|
+
import { C as Context, R as Router, N as ProcedureClientInterceptorOptions } from './server.DkYpsO6W.js';
|
|
5
4
|
|
|
6
5
|
interface StandardHandlerPlugin<T extends Context> {
|
|
7
6
|
order?: number;
|
|
@@ -48,7 +47,6 @@ declare class StandardHandler<T extends Context> {
|
|
|
48
47
|
private readonly clientInterceptors;
|
|
49
48
|
private readonly rootInterceptors;
|
|
50
49
|
private readonly matcher;
|
|
51
|
-
private readonly codec;
|
|
52
50
|
constructor(router: Router<any, T>, options: NoInfer<StandardHandlerOptions<T>>);
|
|
53
51
|
handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
|
|
54
52
|
}
|