@temporary-name/server 1.9.3-alpha.e098b3d1c5bffbad2fadfda89ba01f6452db46b5 → 1.9.3-alpha.ec3bfb9dce56198911349c322c970208b21b50db
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 +4 -5
- package/dist/adapters/aws-lambda/index.d.ts +4 -5
- package/dist/adapters/aws-lambda/index.mjs +4 -4
- package/dist/adapters/fetch/index.d.mts +8 -85
- package/dist/adapters/fetch/index.d.ts +8 -85
- package/dist/adapters/fetch/index.mjs +16 -155
- package/dist/adapters/node/index.d.mts +8 -62
- package/dist/adapters/node/index.d.ts +8 -62
- package/dist/adapters/node/index.mjs +14 -120
- package/dist/adapters/standard/index.d.mts +5 -6
- package/dist/adapters/standard/index.d.ts +5 -6
- package/dist/adapters/standard/index.mjs +4 -4
- package/dist/helpers/index.mjs +3 -29
- package/dist/index.d.mts +110 -199
- package/dist/index.d.ts +110 -199
- package/dist/index.mjs +140 -153
- package/dist/openapi/index.d.mts +11 -27
- package/dist/openapi/index.d.ts +11 -27
- package/dist/openapi/index.mjs +9 -79
- package/dist/shared/server.C1RJffw4.mjs +30 -0
- package/dist/shared/server.CQIFwyhc.mjs +40 -0
- package/dist/shared/server.CVhIyQ4x.d.mts +41 -0
- package/dist/shared/server.CYa9puL2.mjs +403 -0
- package/dist/shared/server.ChOv1yG3.mjs +319 -0
- package/dist/shared/server.Cj3_Lp61.d.mts +373 -0
- package/dist/shared/server.Cj3_Lp61.d.ts +373 -0
- package/dist/shared/server.Cza0RB3u.mjs +160 -0
- package/dist/shared/server.D8RAzJ_p.d.ts +41 -0
- package/dist/shared/server.YUvuxHty.mjs +48 -0
- package/package.json +10 -28
- package/dist/plugins/index.d.mts +0 -110
- package/dist/plugins/index.d.ts +0 -110
- package/dist/plugins/index.mjs +0 -175
- package/dist/shared/server.7aL9gcoU.d.mts +0 -23
- package/dist/shared/server.BL2R5jcp.d.mts +0 -228
- package/dist/shared/server.BL2R5jcp.d.ts +0 -228
- package/dist/shared/server.CVBLzkro.mjs +0 -255
- package/dist/shared/server.ClhVCxfg.mjs +0 -413
- package/dist/shared/server.D6Qs_UcF.d.mts +0 -55
- package/dist/shared/server.DFptr1Nz.d.ts +0 -23
- package/dist/shared/server.DpoO_ER_.d.ts +0 -55
- package/dist/shared/server.JtIZ8YG7.mjs +0 -237
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporary-name/server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.9.3-alpha.
|
|
4
|
+
"version": "1.9.3-alpha.ec3bfb9dce56198911349c322c970208b21b50db",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://www.stainless.com/",
|
|
7
7
|
"repository": {
|
|
@@ -23,11 +23,6 @@
|
|
|
23
23
|
"import": "./dist/helpers/index.mjs",
|
|
24
24
|
"default": "./dist/helpers/index.mjs"
|
|
25
25
|
},
|
|
26
|
-
"./plugins": {
|
|
27
|
-
"types": "./dist/plugins/index.d.mts",
|
|
28
|
-
"import": "./dist/plugins/index.mjs",
|
|
29
|
-
"default": "./dist/plugins/index.mjs"
|
|
30
|
-
},
|
|
31
26
|
"./standard": {
|
|
32
27
|
"types": "./dist/adapters/standard/index.d.mts",
|
|
33
28
|
"import": "./dist/adapters/standard/index.mjs",
|
|
@@ -57,31 +52,17 @@
|
|
|
57
52
|
"files": [
|
|
58
53
|
"dist"
|
|
59
54
|
],
|
|
60
|
-
"peerDependencies": {
|
|
61
|
-
"drizzle-orm": "^0.44.5",
|
|
62
|
-
"drizzle-zod": "^0.8.3"
|
|
63
|
-
},
|
|
64
|
-
"peerDependenciesMeta": {
|
|
65
|
-
"drizzle-orm": {
|
|
66
|
-
"optional": true
|
|
67
|
-
},
|
|
68
|
-
"drizzle-zod": {
|
|
69
|
-
"optional": true
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
55
|
"dependencies": {
|
|
73
56
|
"cookie": "^1.0.2",
|
|
74
57
|
"rou3": "^0.7.7",
|
|
75
58
|
"zod": "^4.1.12",
|
|
76
|
-
"@temporary-name/
|
|
77
|
-
"@temporary-name/
|
|
78
|
-
"@temporary-name/
|
|
79
|
-
"@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.
|
|
80
|
-
"@temporary-name/standard-server": "1.9.3-alpha.
|
|
81
|
-
"@temporary-name/standard-server-
|
|
82
|
-
"@temporary-name/
|
|
83
|
-
"@temporary-name/shared": "1.9.3-alpha.e098b3d1c5bffbad2fadfda89ba01f6452db46b5",
|
|
84
|
-
"@temporary-name/zod": "1.9.3-alpha.e098b3d1c5bffbad2fadfda89ba01f6452db46b5"
|
|
59
|
+
"@temporary-name/interop": "1.9.3-alpha.ec3bfb9dce56198911349c322c970208b21b50db",
|
|
60
|
+
"@temporary-name/shared": "1.9.3-alpha.ec3bfb9dce56198911349c322c970208b21b50db",
|
|
61
|
+
"@temporary-name/standard-server": "1.9.3-alpha.ec3bfb9dce56198911349c322c970208b21b50db",
|
|
62
|
+
"@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.ec3bfb9dce56198911349c322c970208b21b50db",
|
|
63
|
+
"@temporary-name/standard-server-fetch": "1.9.3-alpha.ec3bfb9dce56198911349c322c970208b21b50db",
|
|
64
|
+
"@temporary-name/standard-server-node": "1.9.3-alpha.ec3bfb9dce56198911349c322c970208b21b50db",
|
|
65
|
+
"@temporary-name/zod": "1.9.3-alpha.ec3bfb9dce56198911349c322c970208b21b50db"
|
|
85
66
|
},
|
|
86
67
|
"devDependencies": {
|
|
87
68
|
"@types/supertest": "^6.0.3",
|
|
@@ -91,6 +72,7 @@
|
|
|
91
72
|
"scripts": {
|
|
92
73
|
"build": "unbuild",
|
|
93
74
|
"build:watch": "pnpm run build --watch",
|
|
94
|
-
"
|
|
75
|
+
"clean": "tsc -b --clean",
|
|
76
|
+
"lint:tsc": "tsc -b"
|
|
95
77
|
}
|
|
96
78
|
}
|
package/dist/plugins/index.d.mts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { Value, Promisable, ORPCError } from '@temporary-name/shared';
|
|
2
|
-
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.D6Qs_UcF.mjs';
|
|
3
|
-
import { C as Context, G as ProcedureClientInterceptorOptions } from '../shared/server.BL2R5jcp.mjs';
|
|
4
|
-
import { Meta } from '@temporary-name/contract';
|
|
5
|
-
|
|
6
|
-
interface CORSOptions<T extends Context> {
|
|
7
|
-
origin?: Value<Promisable<string | readonly string[] | null | undefined>, [
|
|
8
|
-
origin: string,
|
|
9
|
-
options: StandardHandlerInterceptorOptions<T>
|
|
10
|
-
]>;
|
|
11
|
-
timingOrigin?: Value<Promisable<string | readonly string[] | null | undefined>, [
|
|
12
|
-
origin: string,
|
|
13
|
-
options: StandardHandlerInterceptorOptions<T>
|
|
14
|
-
]>;
|
|
15
|
-
allowMethods?: readonly string[];
|
|
16
|
-
allowHeaders?: readonly string[];
|
|
17
|
-
maxAge?: number;
|
|
18
|
-
credentials?: boolean;
|
|
19
|
-
exposeHeaders?: readonly string[];
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* CORSPlugin is a plugin for oRPC that allows you to configure CORS for your API.
|
|
23
|
-
*
|
|
24
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/cors CORS Plugin Docs}
|
|
25
|
-
*/
|
|
26
|
-
declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
27
|
-
private readonly options;
|
|
28
|
-
order: number;
|
|
29
|
-
constructor(options?: CORSOptions<T>);
|
|
30
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface RequestHeadersPluginContext {
|
|
34
|
-
reqHeaders?: Headers;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* The Request Headers Plugin injects a `reqHeaders` instance into the context,
|
|
38
|
-
* allowing access to request headers in oRPC.
|
|
39
|
-
*
|
|
40
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/request-headers Request Headers Plugin Docs}
|
|
41
|
-
*/
|
|
42
|
-
declare class RequestHeadersPlugin<T extends RequestHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
43
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface ResponseHeadersPluginContext {
|
|
47
|
-
resHeaders?: Headers;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* The Response Headers Plugin allows you to set response headers in oRPC.
|
|
51
|
-
* It injects a resHeaders instance into the context, enabling you to modify response headers easily.
|
|
52
|
-
*
|
|
53
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/response-headers Response Headers Plugin Docs}
|
|
54
|
-
*/
|
|
55
|
-
declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
56
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
|
|
60
|
-
/**
|
|
61
|
-
* The name of the header to check.
|
|
62
|
-
*
|
|
63
|
-
* @default 'x-csrf-token'
|
|
64
|
-
*/
|
|
65
|
-
headerName?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
|
|
66
|
-
/**
|
|
67
|
-
* The value of the header to check.
|
|
68
|
-
*
|
|
69
|
-
* @default 'orpc'
|
|
70
|
-
*
|
|
71
|
-
*/
|
|
72
|
-
headerValue?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
|
|
73
|
-
/**
|
|
74
|
-
* Exclude a procedure from the plugin.
|
|
75
|
-
*
|
|
76
|
-
* @default false
|
|
77
|
-
*
|
|
78
|
-
*/
|
|
79
|
-
exclude?: Value<Promisable<boolean>, [
|
|
80
|
-
options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>
|
|
81
|
-
]>;
|
|
82
|
-
/**
|
|
83
|
-
* The error thrown when the CSRF token is invalid.
|
|
84
|
-
*
|
|
85
|
-
* @default new ORPCError('CSRF_TOKEN_MISMATCH', {
|
|
86
|
-
* status: 403,
|
|
87
|
-
* message: 'Invalid CSRF token',
|
|
88
|
-
* })
|
|
89
|
-
*/
|
|
90
|
-
error?: InstanceType<typeof ORPCError>;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* This plugin adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
|
|
94
|
-
* It helps ensure that requests to your procedures originate from JavaScript code,
|
|
95
|
-
* not from other sources like standard HTML forms or direct browser navigation.
|
|
96
|
-
*
|
|
97
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
|
|
98
|
-
*/
|
|
99
|
-
declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
100
|
-
private readonly headerName;
|
|
101
|
-
private readonly headerValue;
|
|
102
|
-
private readonly exclude;
|
|
103
|
-
private readonly error;
|
|
104
|
-
constructor(options?: SimpleCsrfProtectionHandlerPluginOptions<T>);
|
|
105
|
-
order: number;
|
|
106
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export { CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin };
|
|
110
|
-
export type { CORSOptions, RequestHeadersPluginContext, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions };
|
package/dist/plugins/index.d.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { Value, Promisable, ORPCError } from '@temporary-name/shared';
|
|
2
|
-
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.DpoO_ER_.js';
|
|
3
|
-
import { C as Context, G as ProcedureClientInterceptorOptions } from '../shared/server.BL2R5jcp.js';
|
|
4
|
-
import { Meta } from '@temporary-name/contract';
|
|
5
|
-
|
|
6
|
-
interface CORSOptions<T extends Context> {
|
|
7
|
-
origin?: Value<Promisable<string | readonly string[] | null | undefined>, [
|
|
8
|
-
origin: string,
|
|
9
|
-
options: StandardHandlerInterceptorOptions<T>
|
|
10
|
-
]>;
|
|
11
|
-
timingOrigin?: Value<Promisable<string | readonly string[] | null | undefined>, [
|
|
12
|
-
origin: string,
|
|
13
|
-
options: StandardHandlerInterceptorOptions<T>
|
|
14
|
-
]>;
|
|
15
|
-
allowMethods?: readonly string[];
|
|
16
|
-
allowHeaders?: readonly string[];
|
|
17
|
-
maxAge?: number;
|
|
18
|
-
credentials?: boolean;
|
|
19
|
-
exposeHeaders?: readonly string[];
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* CORSPlugin is a plugin for oRPC that allows you to configure CORS for your API.
|
|
23
|
-
*
|
|
24
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/cors CORS Plugin Docs}
|
|
25
|
-
*/
|
|
26
|
-
declare class CORSPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
27
|
-
private readonly options;
|
|
28
|
-
order: number;
|
|
29
|
-
constructor(options?: CORSOptions<T>);
|
|
30
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface RequestHeadersPluginContext {
|
|
34
|
-
reqHeaders?: Headers;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* The Request Headers Plugin injects a `reqHeaders` instance into the context,
|
|
38
|
-
* allowing access to request headers in oRPC.
|
|
39
|
-
*
|
|
40
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/request-headers Request Headers Plugin Docs}
|
|
41
|
-
*/
|
|
42
|
-
declare class RequestHeadersPlugin<T extends RequestHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
43
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface ResponseHeadersPluginContext {
|
|
47
|
-
resHeaders?: Headers;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* The Response Headers Plugin allows you to set response headers in oRPC.
|
|
51
|
-
* It injects a resHeaders instance into the context, enabling you to modify response headers easily.
|
|
52
|
-
*
|
|
53
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/response-headers Response Headers Plugin Docs}
|
|
54
|
-
*/
|
|
55
|
-
declare class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements StandardHandlerPlugin<T> {
|
|
56
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
interface SimpleCsrfProtectionHandlerPluginOptions<T extends Context> {
|
|
60
|
-
/**
|
|
61
|
-
* The name of the header to check.
|
|
62
|
-
*
|
|
63
|
-
* @default 'x-csrf-token'
|
|
64
|
-
*/
|
|
65
|
-
headerName?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
|
|
66
|
-
/**
|
|
67
|
-
* The value of the header to check.
|
|
68
|
-
*
|
|
69
|
-
* @default 'orpc'
|
|
70
|
-
*
|
|
71
|
-
*/
|
|
72
|
-
headerValue?: Value<Promisable<string>, [options: StandardHandlerInterceptorOptions<T>]>;
|
|
73
|
-
/**
|
|
74
|
-
* Exclude a procedure from the plugin.
|
|
75
|
-
*
|
|
76
|
-
* @default false
|
|
77
|
-
*
|
|
78
|
-
*/
|
|
79
|
-
exclude?: Value<Promisable<boolean>, [
|
|
80
|
-
options: ProcedureClientInterceptorOptions<T, Record<never, never>, Meta>
|
|
81
|
-
]>;
|
|
82
|
-
/**
|
|
83
|
-
* The error thrown when the CSRF token is invalid.
|
|
84
|
-
*
|
|
85
|
-
* @default new ORPCError('CSRF_TOKEN_MISMATCH', {
|
|
86
|
-
* status: 403,
|
|
87
|
-
* message: 'Invalid CSRF token',
|
|
88
|
-
* })
|
|
89
|
-
*/
|
|
90
|
-
error?: InstanceType<typeof ORPCError>;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* This plugin adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
|
|
94
|
-
* It helps ensure that requests to your procedures originate from JavaScript code,
|
|
95
|
-
* not from other sources like standard HTML forms or direct browser navigation.
|
|
96
|
-
*
|
|
97
|
-
* @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
|
|
98
|
-
*/
|
|
99
|
-
declare class SimpleCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
100
|
-
private readonly headerName;
|
|
101
|
-
private readonly headerValue;
|
|
102
|
-
private readonly exclude;
|
|
103
|
-
private readonly error;
|
|
104
|
-
constructor(options?: SimpleCsrfProtectionHandlerPluginOptions<T>);
|
|
105
|
-
order: number;
|
|
106
|
-
init(options: StandardHandlerOptions<T>): void;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export { CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin };
|
|
110
|
-
export type { CORSOptions, RequestHeadersPluginContext, ResponseHeadersPluginContext, SimpleCsrfProtectionHandlerPluginOptions };
|
package/dist/plugins/index.mjs
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { value, clone, ORPCError } from '@temporary-name/shared';
|
|
2
|
-
import { flattenHeader } from '@temporary-name/standard-server';
|
|
3
|
-
import { toFetchHeaders } from '@temporary-name/standard-server-fetch';
|
|
4
|
-
|
|
5
|
-
class CORSPlugin {
|
|
6
|
-
options;
|
|
7
|
-
order = 9e6;
|
|
8
|
-
constructor(options = {}) {
|
|
9
|
-
const defaults = {
|
|
10
|
-
origin: (origin) => origin,
|
|
11
|
-
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
|
|
12
|
-
};
|
|
13
|
-
this.options = {
|
|
14
|
-
...defaults,
|
|
15
|
-
...options
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
init(options) {
|
|
19
|
-
options.rootInterceptors ??= [];
|
|
20
|
-
options.rootInterceptors.unshift(async (interceptorOptions) => {
|
|
21
|
-
if (interceptorOptions.request.method === "OPTIONS") {
|
|
22
|
-
const resHeaders = {};
|
|
23
|
-
if (this.options.maxAge !== void 0) {
|
|
24
|
-
resHeaders["access-control-max-age"] = this.options.maxAge.toString();
|
|
25
|
-
}
|
|
26
|
-
if (this.options.allowMethods?.length) {
|
|
27
|
-
resHeaders["access-control-allow-methods"] = flattenHeader(this.options.allowMethods);
|
|
28
|
-
}
|
|
29
|
-
const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
|
|
30
|
-
if (typeof allowHeaders === "string" || allowHeaders?.length) {
|
|
31
|
-
resHeaders["access-control-allow-headers"] = flattenHeader(allowHeaders);
|
|
32
|
-
}
|
|
33
|
-
return {
|
|
34
|
-
matched: true,
|
|
35
|
-
response: {
|
|
36
|
-
status: 204,
|
|
37
|
-
headers: resHeaders,
|
|
38
|
-
body: void 0
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
return interceptorOptions.next();
|
|
43
|
-
});
|
|
44
|
-
options.rootInterceptors.unshift(async (interceptorOptions) => {
|
|
45
|
-
const result = await interceptorOptions.next();
|
|
46
|
-
if (!result.matched) {
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
const origin = flattenHeader(interceptorOptions.request.headers.origin) ?? "";
|
|
50
|
-
const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
|
|
51
|
-
const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
|
|
52
|
-
if (allowedOriginArr.includes("*")) {
|
|
53
|
-
result.response.headers["access-control-allow-origin"] = "*";
|
|
54
|
-
} else {
|
|
55
|
-
if (allowedOriginArr.includes(origin)) {
|
|
56
|
-
result.response.headers["access-control-allow-origin"] = origin;
|
|
57
|
-
}
|
|
58
|
-
result.response.headers.vary = interceptorOptions.request.headers.vary ?? "origin";
|
|
59
|
-
}
|
|
60
|
-
const allowedTimingOrigin = await value(this.options.timingOrigin, origin, interceptorOptions);
|
|
61
|
-
const allowedTimingOriginArr = Array.isArray(allowedTimingOrigin) ? allowedTimingOrigin : [allowedTimingOrigin];
|
|
62
|
-
if (allowedTimingOriginArr.includes("*")) {
|
|
63
|
-
result.response.headers["timing-allow-origin"] = "*";
|
|
64
|
-
} else if (allowedTimingOriginArr.includes(origin)) {
|
|
65
|
-
result.response.headers["timing-allow-origin"] = origin;
|
|
66
|
-
}
|
|
67
|
-
if (this.options.credentials) {
|
|
68
|
-
result.response.headers["access-control-allow-credentials"] = "true";
|
|
69
|
-
}
|
|
70
|
-
if (this.options.exposeHeaders?.length) {
|
|
71
|
-
result.response.headers["access-control-expose-headers"] = flattenHeader(this.options.exposeHeaders);
|
|
72
|
-
}
|
|
73
|
-
return result;
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
class RequestHeadersPlugin {
|
|
79
|
-
init(options) {
|
|
80
|
-
options.rootInterceptors ??= [];
|
|
81
|
-
options.rootInterceptors.push((interceptorOptions) => {
|
|
82
|
-
const reqHeaders = interceptorOptions.context.reqHeaders ?? toFetchHeaders(interceptorOptions.request.headers);
|
|
83
|
-
return interceptorOptions.next({
|
|
84
|
-
...interceptorOptions,
|
|
85
|
-
context: {
|
|
86
|
-
...interceptorOptions.context,
|
|
87
|
-
reqHeaders
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
class ResponseHeadersPlugin {
|
|
95
|
-
init(options) {
|
|
96
|
-
options.rootInterceptors ??= [];
|
|
97
|
-
options.rootInterceptors.push(async (interceptorOptions) => {
|
|
98
|
-
const resHeaders = interceptorOptions.context.resHeaders ?? new Headers();
|
|
99
|
-
const result = await interceptorOptions.next({
|
|
100
|
-
...interceptorOptions,
|
|
101
|
-
context: {
|
|
102
|
-
...interceptorOptions.context,
|
|
103
|
-
resHeaders
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
if (!result.matched) {
|
|
107
|
-
return result;
|
|
108
|
-
}
|
|
109
|
-
const responseHeaders = clone(result.response.headers);
|
|
110
|
-
for (const [key, value] of resHeaders) {
|
|
111
|
-
if (Array.isArray(responseHeaders[key])) {
|
|
112
|
-
responseHeaders[key].push(value);
|
|
113
|
-
} else if (responseHeaders[key] !== void 0) {
|
|
114
|
-
responseHeaders[key] = [responseHeaders[key], value];
|
|
115
|
-
} else {
|
|
116
|
-
responseHeaders[key] = value;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
...result,
|
|
121
|
-
response: {
|
|
122
|
-
...result.response,
|
|
123
|
-
headers: responseHeaders
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL = Symbol("SIMPLE_CSRF_PROTECTION_CONTEXT");
|
|
131
|
-
class SimpleCsrfProtectionHandlerPlugin {
|
|
132
|
-
headerName;
|
|
133
|
-
headerValue;
|
|
134
|
-
exclude;
|
|
135
|
-
error;
|
|
136
|
-
constructor(options = {}) {
|
|
137
|
-
this.headerName = options.headerName ?? "x-csrf-token";
|
|
138
|
-
this.headerValue = options.headerValue ?? "orpc";
|
|
139
|
-
this.exclude = options.exclude ?? false;
|
|
140
|
-
this.error = options.error ?? new ORPCError("CSRF_TOKEN_MISMATCH", {
|
|
141
|
-
status: 403,
|
|
142
|
-
message: "Invalid CSRF token"
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
order = 8e6;
|
|
146
|
-
init(options) {
|
|
147
|
-
options.rootInterceptors ??= [];
|
|
148
|
-
options.clientInterceptors ??= [];
|
|
149
|
-
options.rootInterceptors.unshift(async (options2) => {
|
|
150
|
-
const headerName = await value(this.headerName, options2);
|
|
151
|
-
const headerValue = await value(this.headerValue, options2);
|
|
152
|
-
return options2.next({
|
|
153
|
-
...options2,
|
|
154
|
-
context: {
|
|
155
|
-
...options2.context,
|
|
156
|
-
[SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]: options2.request.headers[headerName] === headerValue
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
options.clientInterceptors.unshift(async (options2) => {
|
|
161
|
-
if (typeof options2.context[SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL] !== "boolean") {
|
|
162
|
-
throw new TypeError(
|
|
163
|
-
"[SimpleCsrfProtectionHandlerPlugin] CSRF protection context has been corrupted or modified by another plugin or interceptor"
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
const excluded = await value(this.exclude, options2);
|
|
167
|
-
if (!excluded && !options2.context[SIMPLE_CSRF_PROTECTION_CONTEXT_SYMBOL]) {
|
|
168
|
-
throw this.error;
|
|
169
|
-
}
|
|
170
|
-
return options2.next();
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export { CORSPlugin, RequestHeadersPlugin, ResponseHeadersPlugin, SimpleCsrfProtectionHandlerPlugin };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { HTTPPath } from '@temporary-name/shared';
|
|
2
|
-
import { C as Context } from './server.BL2R5jcp.mjs';
|
|
3
|
-
import { c as StandardHandleOptions } from './server.D6Qs_UcF.mjs';
|
|
4
|
-
|
|
5
|
-
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
6
|
-
context?: T;
|
|
7
|
-
} : {
|
|
8
|
-
context: T;
|
|
9
|
-
});
|
|
10
|
-
declare function resolveFriendlyStandardHandleOptions<T extends Context>(options: FriendlyStandardHandleOptions<T>): StandardHandleOptions<T>;
|
|
11
|
-
/**
|
|
12
|
-
* {@link https://github.com/unjs/rou3}
|
|
13
|
-
*
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
declare function toRou3Pattern(path: HTTPPath): string;
|
|
17
|
-
/**
|
|
18
|
-
* @internal
|
|
19
|
-
*/
|
|
20
|
-
declare function decodeParams(params: Record<string, string>): Record<string, string>;
|
|
21
|
-
|
|
22
|
-
export { decodeParams as d, resolveFriendlyStandardHandleOptions as r, toRou3Pattern as t };
|
|
23
|
-
export type { FriendlyStandardHandleOptions as F };
|