@temporary-name/server 1.9.3-alpha.bb3867758271e7fcf8c191f9693365d655697e7f → 1.9.3-alpha.ce6ed5061c5dc25f4390f71c2c5c5411546e85c1
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 -3
- package/dist/adapters/aws-lambda/index.d.ts +3 -3
- package/dist/adapters/aws-lambda/index.mjs +2 -2
- package/dist/adapters/fetch/index.d.mts +3 -3
- package/dist/adapters/fetch/index.d.ts +3 -3
- package/dist/adapters/fetch/index.mjs +2 -2
- package/dist/adapters/node/index.d.mts +3 -3
- package/dist/adapters/node/index.d.ts +3 -3
- package/dist/adapters/node/index.mjs +2 -2
- package/dist/adapters/standard/index.d.mts +3 -3
- package/dist/adapters/standard/index.d.ts +3 -3
- package/dist/adapters/standard/index.mjs +2 -2
- package/dist/helpers/index.mjs +3 -29
- package/dist/index.d.mts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.mjs +92 -4
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/index.d.ts +2 -2
- package/dist/shared/{server.DpoO_ER_.d.ts → server.B-meye9-.d.ts} +1 -1
- package/dist/shared/{server.DwbIdsnK.mjs → server.Ba0Z2fNc.mjs} +1 -1
- package/dist/shared/server.C1RJffw4.mjs +30 -0
- package/dist/shared/{server.BL2R5jcp.d.mts → server.DkYpsO6W.d.mts} +53 -30
- package/dist/shared/{server.BL2R5jcp.d.ts → server.DkYpsO6W.d.ts} +53 -30
- package/dist/shared/{server.DFptr1Nz.d.ts → server.DwNnHUZP.d.ts} +2 -2
- package/dist/shared/{server.7aL9gcoU.d.mts → server.I-tTl_ce.d.mts} +2 -2
- package/dist/shared/{server.C61o1Zch.mjs → server.miXh-9wo.mjs} +3 -0
- package/dist/shared/{server.D6Qs_UcF.d.mts → server.vLcMd_kA.d.mts} +1 -1
- package/package.json +10 -22
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MaybeOptionalOptions } from '@temporary-name/shared';
|
|
2
2
|
import { SendStandardResponseOptions, APIGatewayProxyEventV2, ResponseStream } from '@temporary-name/standard-server-aws-lambda';
|
|
3
|
-
import { C as Context, R as Router } from '../../shared/server.
|
|
4
|
-
import { b as StandardHandlerOptions } from '../../shared/server.
|
|
5
|
-
import { F as FriendlyStandardHandleOptions } from '../../shared/server.
|
|
3
|
+
import { C as Context, R as Router } from '../../shared/server.DkYpsO6W.mjs';
|
|
4
|
+
import { b as StandardHandlerOptions } from '../../shared/server.vLcMd_kA.mjs';
|
|
5
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.I-tTl_ce.mjs';
|
|
6
6
|
import '@temporary-name/contract';
|
|
7
7
|
|
|
8
8
|
interface AwsLambdaHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, SendStandardResponseOptions {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MaybeOptionalOptions } from '@temporary-name/shared';
|
|
2
2
|
import { SendStandardResponseOptions, APIGatewayProxyEventV2, ResponseStream } from '@temporary-name/standard-server-aws-lambda';
|
|
3
|
-
import { C as Context, R as Router } from '../../shared/server.
|
|
4
|
-
import { b as StandardHandlerOptions } from '../../shared/server.
|
|
5
|
-
import { F as FriendlyStandardHandleOptions } from '../../shared/server.
|
|
3
|
+
import { C as Context, R as Router } from '../../shared/server.DkYpsO6W.js';
|
|
4
|
+
import { b as StandardHandlerOptions } from '../../shared/server.B-meye9-.js';
|
|
5
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.DwNnHUZP.js';
|
|
6
6
|
import '@temporary-name/contract';
|
|
7
7
|
|
|
8
8
|
interface AwsLambdaHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, SendStandardResponseOptions {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { resolveMaybeOptionalOptions } from '@temporary-name/shared';
|
|
2
2
|
import { toStandardLazyRequest, sendStandardResponse } from '@temporary-name/standard-server-aws-lambda';
|
|
3
|
-
import { S as StandardHandler, r as resolveFriendlyStandardHandleOptions } from '../../shared/server.
|
|
3
|
+
import { S as StandardHandler, r as resolveFriendlyStandardHandleOptions } from '../../shared/server.Ba0Z2fNc.mjs';
|
|
4
4
|
import '@temporary-name/contract';
|
|
5
5
|
import '@temporary-name/standard-server';
|
|
6
6
|
import '@temporary-name/server';
|
|
7
7
|
import 'rou3';
|
|
8
|
-
import '../../shared/server.
|
|
8
|
+
import '../../shared/server.miXh-9wo.mjs';
|
|
9
9
|
import '@temporary-name/zod';
|
|
10
10
|
import '../../shared/server.JtIZ8YG7.mjs';
|
|
11
11
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { C as Context, R as Router } from '../../shared/server.
|
|
1
|
+
import { C as Context, R as Router } from '../../shared/server.DkYpsO6W.mjs';
|
|
2
2
|
import { Interceptor, MaybeOptionalOptions } from '@temporary-name/shared';
|
|
3
3
|
import { ToFetchResponseOptions } from '@temporary-name/standard-server-fetch';
|
|
4
|
-
import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, b as StandardHandlerOptions, c as StandardHandleOptions } from '../../shared/server.
|
|
5
|
-
import { F as FriendlyStandardHandleOptions } from '../../shared/server.
|
|
4
|
+
import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, b as StandardHandlerOptions, c as StandardHandleOptions } from '../../shared/server.vLcMd_kA.mjs';
|
|
5
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.I-tTl_ce.mjs';
|
|
6
6
|
import '@temporary-name/contract';
|
|
7
7
|
|
|
8
8
|
interface FetchHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { C as Context, R as Router } from '../../shared/server.
|
|
1
|
+
import { C as Context, R as Router } from '../../shared/server.DkYpsO6W.js';
|
|
2
2
|
import { Interceptor, MaybeOptionalOptions } from '@temporary-name/shared';
|
|
3
3
|
import { ToFetchResponseOptions } from '@temporary-name/standard-server-fetch';
|
|
4
|
-
import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, b as StandardHandlerOptions, c as StandardHandleOptions } from '../../shared/server.
|
|
5
|
-
import { F as FriendlyStandardHandleOptions } from '../../shared/server.
|
|
4
|
+
import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, b as StandardHandlerOptions, c as StandardHandleOptions } from '../../shared/server.B-meye9-.js';
|
|
5
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.DwNnHUZP.js';
|
|
6
6
|
import '@temporary-name/contract';
|
|
7
7
|
|
|
8
8
|
interface FetchHandlerPlugin<T extends Context> extends StandardHandlerPlugin<T> {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ORPCError, toArray, intercept, resolveMaybeOptionalOptions } from '@temporary-name/shared';
|
|
2
2
|
import { toStandardLazyRequest, toFetchResponse } from '@temporary-name/standard-server-fetch';
|
|
3
|
-
import { C as CompositeStandardHandlerPlugin, S as StandardHandler, r as resolveFriendlyStandardHandleOptions } from '../../shared/server.
|
|
3
|
+
import { C as CompositeStandardHandlerPlugin, S as StandardHandler, r as resolveFriendlyStandardHandleOptions } from '../../shared/server.Ba0Z2fNc.mjs';
|
|
4
4
|
import '@temporary-name/contract';
|
|
5
5
|
import '@temporary-name/standard-server';
|
|
6
6
|
import '@temporary-name/server';
|
|
7
7
|
import 'rou3';
|
|
8
8
|
import '@temporary-name/zod';
|
|
9
|
-
import '../../shared/server.
|
|
9
|
+
import '../../shared/server.miXh-9wo.mjs';
|
|
10
10
|
import '../../shared/server.JtIZ8YG7.mjs';
|
|
11
11
|
|
|
12
12
|
class BodyLimitPlugin {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { C as Context, R as Router } from '../../shared/server.
|
|
1
|
+
import { C as Context, R as Router } from '../../shared/server.DkYpsO6W.mjs';
|
|
2
2
|
import { Interceptor, MaybeOptionalOptions } from '@temporary-name/shared';
|
|
3
3
|
import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@temporary-name/standard-server-node';
|
|
4
|
-
import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, b as StandardHandlerOptions, c as StandardHandleOptions } from '../../shared/server.
|
|
5
|
-
import { F as FriendlyStandardHandleOptions } from '../../shared/server.
|
|
4
|
+
import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, b as StandardHandlerOptions, c as StandardHandleOptions } from '../../shared/server.vLcMd_kA.mjs';
|
|
5
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.I-tTl_ce.mjs';
|
|
6
6
|
import compression from '@temporary-name/interop/compression';
|
|
7
7
|
import '@temporary-name/contract';
|
|
8
8
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { C as Context, R as Router } from '../../shared/server.
|
|
1
|
+
import { C as Context, R as Router } from '../../shared/server.DkYpsO6W.js';
|
|
2
2
|
import { Interceptor, MaybeOptionalOptions } from '@temporary-name/shared';
|
|
3
3
|
import { SendStandardResponseOptions, NodeHttpRequest, NodeHttpResponse } from '@temporary-name/standard-server-node';
|
|
4
|
-
import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, b as StandardHandlerOptions, c as StandardHandleOptions } from '../../shared/server.
|
|
5
|
-
import { F as FriendlyStandardHandleOptions } from '../../shared/server.
|
|
4
|
+
import { a as StandardHandlerPlugin, C as CompositeStandardHandlerPlugin, b as StandardHandlerOptions, c as StandardHandleOptions } from '../../shared/server.B-meye9-.js';
|
|
5
|
+
import { F as FriendlyStandardHandleOptions } from '../../shared/server.DwNnHUZP.js';
|
|
6
6
|
import compression from '@temporary-name/interop/compression';
|
|
7
7
|
import '@temporary-name/contract';
|
|
8
8
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { once, ORPCError, toArray, intercept, resolveMaybeOptionalOptions } from '@temporary-name/shared';
|
|
2
2
|
import compression from '@temporary-name/interop/compression';
|
|
3
3
|
import { toStandardLazyRequest, sendStandardResponse } from '@temporary-name/standard-server-node';
|
|
4
|
-
import { C as CompositeStandardHandlerPlugin, S as StandardHandler, r as resolveFriendlyStandardHandleOptions } from '../../shared/server.
|
|
4
|
+
import { C as CompositeStandardHandlerPlugin, S as StandardHandler, r as resolveFriendlyStandardHandleOptions } from '../../shared/server.Ba0Z2fNc.mjs';
|
|
5
5
|
import '@temporary-name/contract';
|
|
6
6
|
import '@temporary-name/standard-server';
|
|
7
7
|
import '@temporary-name/server';
|
|
8
8
|
import 'rou3';
|
|
9
9
|
import '@temporary-name/zod';
|
|
10
|
-
import '../../shared/server.
|
|
10
|
+
import '../../shared/server.miXh-9wo.mjs';
|
|
11
11
|
import '../../shared/server.JtIZ8YG7.mjs';
|
|
12
12
|
|
|
13
13
|
class BodyLimitPlugin {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { C as CompositeStandardHandlerPlugin, c as StandardHandleOptions, d as StandardHandleResult, e as StandardHandler, S as StandardHandlerInterceptorOptions, b as StandardHandlerOptions, a as StandardHandlerPlugin } from '../../shared/server.
|
|
1
|
+
export { C as CompositeStandardHandlerPlugin, c as StandardHandleOptions, d as StandardHandleResult, e as StandardHandler, S as StandardHandlerInterceptorOptions, b as StandardHandlerOptions, a as StandardHandlerPlugin } from '../../shared/server.vLcMd_kA.mjs';
|
|
2
2
|
import { AnyProcedure, AnyRouter } from '@temporary-name/server';
|
|
3
3
|
import { StandardLazyRequest, StandardResponse, ORPCError, HTTPPath } from '@temporary-name/shared';
|
|
4
|
-
export { F as FriendlyStandardHandleOptions, d as decodeParams, r as resolveFriendlyStandardHandleOptions, t as toRou3Pattern } from '../../shared/server.
|
|
4
|
+
export { F as FriendlyStandardHandleOptions, d as decodeParams, r as resolveFriendlyStandardHandleOptions, t as toRou3Pattern } from '../../shared/server.I-tTl_ce.mjs';
|
|
5
5
|
import '@temporary-name/contract';
|
|
6
|
-
import '../../shared/server.
|
|
6
|
+
import '../../shared/server.DkYpsO6W.mjs';
|
|
7
7
|
|
|
8
8
|
declare function decode(request: StandardLazyRequest, pathParams: Record<string, string> | undefined): Promise<{
|
|
9
9
|
path: unknown;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { C as CompositeStandardHandlerPlugin, c as StandardHandleOptions, d as StandardHandleResult, e as StandardHandler, S as StandardHandlerInterceptorOptions, b as StandardHandlerOptions, a as StandardHandlerPlugin } from '../../shared/server.
|
|
1
|
+
export { C as CompositeStandardHandlerPlugin, c as StandardHandleOptions, d as StandardHandleResult, e as StandardHandler, S as StandardHandlerInterceptorOptions, b as StandardHandlerOptions, a as StandardHandlerPlugin } from '../../shared/server.B-meye9-.js';
|
|
2
2
|
import { AnyProcedure, AnyRouter } from '@temporary-name/server';
|
|
3
3
|
import { StandardLazyRequest, StandardResponse, ORPCError, HTTPPath } from '@temporary-name/shared';
|
|
4
|
-
export { F as FriendlyStandardHandleOptions, d as decodeParams, r as resolveFriendlyStandardHandleOptions, t as toRou3Pattern } from '../../shared/server.
|
|
4
|
+
export { F as FriendlyStandardHandleOptions, d as decodeParams, r as resolveFriendlyStandardHandleOptions, t as toRou3Pattern } from '../../shared/server.DwNnHUZP.js';
|
|
5
5
|
import '@temporary-name/contract';
|
|
6
|
-
import '../../shared/server.
|
|
6
|
+
import '../../shared/server.DkYpsO6W.js';
|
|
7
7
|
|
|
8
8
|
declare function decode(request: StandardLazyRequest, pathParams: Record<string, string> | undefined): Promise<{
|
|
9
9
|
path: unknown;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { C as CompositeStandardHandlerPlugin, S as StandardHandler, b as StandardOpenAPIMatcher, d as decode, c as decodeParams, e as encode, a as encodeError, r as resolveFriendlyStandardHandleOptions, t as toRou3Pattern } from '../../shared/server.
|
|
1
|
+
export { C as CompositeStandardHandlerPlugin, S as StandardHandler, b as StandardOpenAPIMatcher, d as decode, c as decodeParams, e as encode, a as encodeError, r as resolveFriendlyStandardHandleOptions, t as toRou3Pattern } from '../../shared/server.Ba0Z2fNc.mjs';
|
|
2
2
|
import '@temporary-name/shared';
|
|
3
|
-
import '../../shared/server.
|
|
3
|
+
import '../../shared/server.miXh-9wo.mjs';
|
|
4
4
|
import '@temporary-name/contract';
|
|
5
5
|
import '@temporary-name/standard-server';
|
|
6
6
|
import '@temporary-name/zod';
|
package/dist/helpers/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
export { d as deleteCookie, g as getCookie, s as setCookie } from '../shared/server.C1RJffw4.mjs';
|
|
2
|
+
import 'cookie';
|
|
2
3
|
|
|
3
4
|
function encodeBase64url(data) {
|
|
4
5
|
const chunkSize = 8192;
|
|
@@ -30,33 +31,6 @@ function decodeBase64url(base64url) {
|
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
function setCookie(headers, name, value, options = {}) {
|
|
34
|
-
if (headers === void 0) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const cookieString = serialize(name, value, {
|
|
38
|
-
path: "/",
|
|
39
|
-
...options
|
|
40
|
-
});
|
|
41
|
-
headers.append("Set-Cookie", cookieString);
|
|
42
|
-
}
|
|
43
|
-
function getCookie(headers, name, options = {}) {
|
|
44
|
-
if (headers === void 0) {
|
|
45
|
-
return void 0;
|
|
46
|
-
}
|
|
47
|
-
const cookieHeader = headers.get("cookie");
|
|
48
|
-
if (cookieHeader === null) {
|
|
49
|
-
return void 0;
|
|
50
|
-
}
|
|
51
|
-
return parse(cookieHeader, options)[name];
|
|
52
|
-
}
|
|
53
|
-
function deleteCookie(headers, name, options = {}) {
|
|
54
|
-
return setCookie(headers, name, "", {
|
|
55
|
-
...options,
|
|
56
|
-
maxAge: 0
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
34
|
const PBKDF2_CONFIG = {
|
|
61
35
|
name: "PBKDF2",
|
|
62
36
|
iterations: 6e4,
|
|
@@ -165,4 +139,4 @@ function getSignedValue(signedValue) {
|
|
|
165
139
|
return signedValue.slice(0, lastDotIndex);
|
|
166
140
|
}
|
|
167
141
|
|
|
168
|
-
export { decodeBase64url, decrypt,
|
|
142
|
+
export { decodeBase64url, decrypt, encodeBase64url, encrypt, getSignedValue, sign, unsign };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Schemas, ErrorMap, Meta, ContractProcedure, MergedErrorMap, AnyShape, MergedSchemas, WrapShape, UnionToIntersection, AnySchema, Route, InferHandlerInputs, InferSchemaInput, ContractRouter, ContractProcedureDef, InitialSchemas, AnyContractRouter, InferContractRouterErrorMap, InferContractRouterMeta, AnyContractProcedure, InferProcedureClientInputs, InferSchemaOutput, ErrorFromErrorMap, Schema } from '@temporary-name/contract';
|
|
2
2
|
export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, MergedErrorMap, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
|
|
3
|
-
import { ClientContext, MaybeOptionalOptions, HTTPEndpoint, IntersectPick, HTTPPath, ClientOptions, ClientPromiseResult } from '@temporary-name/shared';
|
|
3
|
+
import { ClientContext, MaybeOptionalOptions, HTTPEndpoint, IntersectPick, OptionalIfEmpty, HTTPPath, ClientOptions, ClientPromiseResult } from '@temporary-name/shared';
|
|
4
4
|
export { AsyncIteratorClass, ClientContext, EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, HTTPMethod, HTTPPath, IntersectPick, ORPCError, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
5
|
+
import { C as Context, P as Procedure, a as CreateProcedureClientOptions, b as ProcedureClient, M as Middleware, O as ORPCErrorConstructorMap, c as MergedInitialContext, d as MergedCurrentContext, A as AuthType, V as ValidatedAuthContext, e as AuthConfig, B as BuildContextWithAuth, f as ProcedureHandler, E as EnhanceRouterOptions, R as Router, g as EnhancedRouter, h as MapInputMiddleware, i as AnyMiddleware, T as TypedAuthConfig, L as Lazy, j as AnyProcedure, k as Lazyable, l as AnyRouter, I as InferRouterInitialContext } from './shared/server.DkYpsO6W.mjs';
|
|
6
|
+
export { Z as AccessibleLazyRouter, a2 as ContractProcedureCallbackOptions, G as DefaultProcedureHandlerOptions, U as InferRouterCurrentContexts, S as InferRouterInitialContexts, W as InferRouterInputs, X as InferRouterOutputs, q as LAZY_SYMBOL, r as LazyMeta, a3 as LazyTraverseContractProceduresOptions, y as MiddlewareNextFn, D as MiddlewareOptions, z as MiddlewareOutputFn, x as MiddlewareResult, o as ORPCErrorConstructorMapItem, n as ORPCErrorConstructorMapItemOptions, N as ProcedureClientInterceptorOptions, J as ProcedureDef, H as ProcedureHandlerOptions, a1 as TraverseContractProcedureCallbackOptions, a0 as TraverseContractProceduresOptions, a6 as UnlaziedRouter, _ as createAccessibleLazyRouter, p as createORPCErrorConstructorMap, Q as createProcedureClient, $ as enhanceRouter, v as getLazyMeta, Y as getRouter, u as isLazy, K as isProcedure, t as lazy, s as lazyInternal, m as mergeCurrentContext, F as middlewareOutputFn, a5 as resolveContractProcedures, a4 as traverseContractProcedures, w as unlazy, a7 as unlazyRouter } from './shared/server.DkYpsO6W.mjs';
|
|
5
7
|
import { SchemaClass, core } from '@temporary-name/zod';
|
|
6
|
-
import { C as Context, P as Procedure, a as CreateProcedureClientOptions, b as ProcedureClient, M as Middleware, O as ORPCErrorConstructorMap, c as MergedInitialContext, d as MergedCurrentContext, e as ProcedureHandler, E as EnhanceRouterOptions, R as Router, f as EnhancedRouter, g as MapInputMiddleware, A as AnyMiddleware, L as Lazy, h as AnyProcedure, i as Lazyable, j as AnyRouter, I as InferRouterInitialContext } from './shared/server.BL2R5jcp.mjs';
|
|
7
|
-
export { T as AccessibleLazyRouter, Y as ContractProcedureCallbackOptions, K as InferRouterCurrentContexts, J as InferRouterInitialContexts, N as InferRouterInputs, Q as InferRouterOutputs, o as LAZY_SYMBOL, p as LazyMeta, Z as LazyTraverseContractProceduresOptions, w as MiddlewareNextFn, y as MiddlewareOptions, x as MiddlewareOutputFn, v as MiddlewareResult, l as ORPCErrorConstructorMapItem, k as ORPCErrorConstructorMapItemOptions, G as ProcedureClientInterceptorOptions, D as ProcedureDef, B as ProcedureHandlerOptions, X as TraverseContractProcedureCallbackOptions, W as TraverseContractProceduresOptions, a0 as UnlaziedRouter, U as createAccessibleLazyRouter, n as createORPCErrorConstructorMap, H as createProcedureClient, V as enhanceRouter, t as getLazyMeta, S as getRouter, s as isLazy, F as isProcedure, r as lazy, q as lazyInternal, m as mergeCurrentContext, z as middlewareOutputFn, $ as resolveContractProcedures, _ as traverseContractProcedures, u as unlazy, a1 as unlazyRouter } from './shared/server.BL2R5jcp.mjs';
|
|
8
8
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
9
9
|
|
|
10
10
|
declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta> {
|
|
@@ -74,6 +74,7 @@ declare class ProcedureBuilder<TInitialContext extends Context, TCurrentContext
|
|
|
74
74
|
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
75
75
|
*/
|
|
76
76
|
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TSchemas, TErrorMap, TMeta, TGateName>;
|
|
77
|
+
useAuth<const TAuthType extends AuthType & {}, TAuthContext extends ValidatedAuthContext = false>(type: TAuthType, ...rest: OptionalIfEmpty<AuthConfig<TAuthType, TAuthContext>>): ProcedureBuilder<TInitialContext, BuildContextWithAuth<TCurrentContext, TAuthContext>, TSchemas, TErrorMap, TMeta, TGateName>;
|
|
77
78
|
useGating<const TInferredGateName extends string>(gates: TInferredGateName[], isGateEnabled: (gate: TInferredGateName, ctx: TCurrentContext) => boolean): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, Context, TCurrentContext>, MergedCurrentContext<TCurrentContext, {
|
|
78
79
|
isGateEnabled: typeof isGateEnabled;
|
|
79
80
|
}>, TSchemas, TErrorMap, TMeta, TInferredGateName>;
|
|
@@ -139,6 +140,7 @@ declare function decorateMiddleware<TInContext extends Context, TOutContext exte
|
|
|
139
140
|
|
|
140
141
|
interface BuilderDef<TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TSchemas, TErrorMap, TMeta>, EnhanceRouterOptions<TErrorMap> {
|
|
141
142
|
middlewares: readonly AnyMiddleware[];
|
|
143
|
+
authConfigs: TypedAuthConfig[];
|
|
142
144
|
inputValidationIndex: number;
|
|
143
145
|
outputValidationIndex: number;
|
|
144
146
|
}
|
|
@@ -329,5 +331,5 @@ declare function createRouterClient<T extends AnyRouter, TClientContext extends
|
|
|
329
331
|
declare function setHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: AnyContractRouter): T;
|
|
330
332
|
declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContractRouter>): AnyContractRouter | undefined;
|
|
331
333
|
|
|
332
|
-
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, BuilderWithMiddlewares, Context, CreateProcedureClientOptions, DecoratedProcedure, EnhanceRouterOptions, EnhancedRouter, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureBuilder, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, getHiddenRouterContract, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, setHiddenRouterContract };
|
|
334
|
+
export { AnyMiddleware, AnyProcedure, AnyRouter, BuildContextWithAuth, Builder, BuilderWithMiddlewares, Context, CreateProcedureClientOptions, DecoratedProcedure, EnhanceRouterOptions, EnhancedRouter, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureBuilder, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, getHiddenRouterContract, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, setHiddenRouterContract };
|
|
333
335
|
export type { ApiBuilder, BuilderDef, DecoratedMiddleware, ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, ProcedureImplementer, RouterBuilder, RouterClient, RouterImplementer, RouterImplementerWithMiddlewares };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Schemas, ErrorMap, Meta, ContractProcedure, MergedErrorMap, AnyShape, MergedSchemas, WrapShape, UnionToIntersection, AnySchema, Route, InferHandlerInputs, InferSchemaInput, ContractRouter, ContractProcedureDef, InitialSchemas, AnyContractRouter, InferContractRouterErrorMap, InferContractRouterMeta, AnyContractProcedure, InferProcedureClientInputs, InferSchemaOutput, ErrorFromErrorMap, Schema } from '@temporary-name/contract';
|
|
2
2
|
export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, MergedErrorMap, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
|
|
3
|
-
import { ClientContext, MaybeOptionalOptions, HTTPEndpoint, IntersectPick, HTTPPath, ClientOptions, ClientPromiseResult } from '@temporary-name/shared';
|
|
3
|
+
import { ClientContext, MaybeOptionalOptions, HTTPEndpoint, IntersectPick, OptionalIfEmpty, HTTPPath, ClientOptions, ClientPromiseResult } from '@temporary-name/shared';
|
|
4
4
|
export { AsyncIteratorClass, ClientContext, EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, HTTPMethod, HTTPPath, IntersectPick, ORPCError, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
5
|
+
import { C as Context, P as Procedure, a as CreateProcedureClientOptions, b as ProcedureClient, M as Middleware, O as ORPCErrorConstructorMap, c as MergedInitialContext, d as MergedCurrentContext, A as AuthType, V as ValidatedAuthContext, e as AuthConfig, B as BuildContextWithAuth, f as ProcedureHandler, E as EnhanceRouterOptions, R as Router, g as EnhancedRouter, h as MapInputMiddleware, i as AnyMiddleware, T as TypedAuthConfig, L as Lazy, j as AnyProcedure, k as Lazyable, l as AnyRouter, I as InferRouterInitialContext } from './shared/server.DkYpsO6W.js';
|
|
6
|
+
export { Z as AccessibleLazyRouter, a2 as ContractProcedureCallbackOptions, G as DefaultProcedureHandlerOptions, U as InferRouterCurrentContexts, S as InferRouterInitialContexts, W as InferRouterInputs, X as InferRouterOutputs, q as LAZY_SYMBOL, r as LazyMeta, a3 as LazyTraverseContractProceduresOptions, y as MiddlewareNextFn, D as MiddlewareOptions, z as MiddlewareOutputFn, x as MiddlewareResult, o as ORPCErrorConstructorMapItem, n as ORPCErrorConstructorMapItemOptions, N as ProcedureClientInterceptorOptions, J as ProcedureDef, H as ProcedureHandlerOptions, a1 as TraverseContractProcedureCallbackOptions, a0 as TraverseContractProceduresOptions, a6 as UnlaziedRouter, _ as createAccessibleLazyRouter, p as createORPCErrorConstructorMap, Q as createProcedureClient, $ as enhanceRouter, v as getLazyMeta, Y as getRouter, u as isLazy, K as isProcedure, t as lazy, s as lazyInternal, m as mergeCurrentContext, F as middlewareOutputFn, a5 as resolveContractProcedures, a4 as traverseContractProcedures, w as unlazy, a7 as unlazyRouter } from './shared/server.DkYpsO6W.js';
|
|
5
7
|
import { SchemaClass, core } from '@temporary-name/zod';
|
|
6
|
-
import { C as Context, P as Procedure, a as CreateProcedureClientOptions, b as ProcedureClient, M as Middleware, O as ORPCErrorConstructorMap, c as MergedInitialContext, d as MergedCurrentContext, e as ProcedureHandler, E as EnhanceRouterOptions, R as Router, f as EnhancedRouter, g as MapInputMiddleware, A as AnyMiddleware, L as Lazy, h as AnyProcedure, i as Lazyable, j as AnyRouter, I as InferRouterInitialContext } from './shared/server.BL2R5jcp.js';
|
|
7
|
-
export { T as AccessibleLazyRouter, Y as ContractProcedureCallbackOptions, K as InferRouterCurrentContexts, J as InferRouterInitialContexts, N as InferRouterInputs, Q as InferRouterOutputs, o as LAZY_SYMBOL, p as LazyMeta, Z as LazyTraverseContractProceduresOptions, w as MiddlewareNextFn, y as MiddlewareOptions, x as MiddlewareOutputFn, v as MiddlewareResult, l as ORPCErrorConstructorMapItem, k as ORPCErrorConstructorMapItemOptions, G as ProcedureClientInterceptorOptions, D as ProcedureDef, B as ProcedureHandlerOptions, X as TraverseContractProcedureCallbackOptions, W as TraverseContractProceduresOptions, a0 as UnlaziedRouter, U as createAccessibleLazyRouter, n as createORPCErrorConstructorMap, H as createProcedureClient, V as enhanceRouter, t as getLazyMeta, S as getRouter, s as isLazy, F as isProcedure, r as lazy, q as lazyInternal, m as mergeCurrentContext, z as middlewareOutputFn, $ as resolveContractProcedures, _ as traverseContractProcedures, u as unlazy, a1 as unlazyRouter } from './shared/server.BL2R5jcp.js';
|
|
8
8
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
9
9
|
|
|
10
10
|
declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TSchemas, TErrorMap, TMeta> {
|
|
@@ -74,6 +74,7 @@ declare class ProcedureBuilder<TInitialContext extends Context, TCurrentContext
|
|
|
74
74
|
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
75
75
|
*/
|
|
76
76
|
use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TSchemas, TErrorMap, TMeta, TGateName>;
|
|
77
|
+
useAuth<const TAuthType extends AuthType & {}, TAuthContext extends ValidatedAuthContext = false>(type: TAuthType, ...rest: OptionalIfEmpty<AuthConfig<TAuthType, TAuthContext>>): ProcedureBuilder<TInitialContext, BuildContextWithAuth<TCurrentContext, TAuthContext>, TSchemas, TErrorMap, TMeta, TGateName>;
|
|
77
78
|
useGating<const TInferredGateName extends string>(gates: TInferredGateName[], isGateEnabled: (gate: TInferredGateName, ctx: TCurrentContext) => boolean): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, Context, TCurrentContext>, MergedCurrentContext<TCurrentContext, {
|
|
78
79
|
isGateEnabled: typeof isGateEnabled;
|
|
79
80
|
}>, TSchemas, TErrorMap, TMeta, TInferredGateName>;
|
|
@@ -139,6 +140,7 @@ declare function decorateMiddleware<TInContext extends Context, TOutContext exte
|
|
|
139
140
|
|
|
140
141
|
interface BuilderDef<TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TSchemas, TErrorMap, TMeta>, EnhanceRouterOptions<TErrorMap> {
|
|
141
142
|
middlewares: readonly AnyMiddleware[];
|
|
143
|
+
authConfigs: TypedAuthConfig[];
|
|
142
144
|
inputValidationIndex: number;
|
|
143
145
|
outputValidationIndex: number;
|
|
144
146
|
}
|
|
@@ -329,5 +331,5 @@ declare function createRouterClient<T extends AnyRouter, TClientContext extends
|
|
|
329
331
|
declare function setHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: AnyContractRouter): T;
|
|
330
332
|
declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContractRouter>): AnyContractRouter | undefined;
|
|
331
333
|
|
|
332
|
-
export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, BuilderWithMiddlewares, Context, CreateProcedureClientOptions, DecoratedProcedure, EnhanceRouterOptions, EnhancedRouter, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureBuilder, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, getHiddenRouterContract, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, setHiddenRouterContract };
|
|
334
|
+
export { AnyMiddleware, AnyProcedure, AnyRouter, BuildContextWithAuth, Builder, BuilderWithMiddlewares, Context, CreateProcedureClientOptions, DecoratedProcedure, EnhanceRouterOptions, EnhancedRouter, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureBuilder, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, getHiddenRouterContract, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, setHiddenRouterContract };
|
|
333
335
|
export type { ApiBuilder, BuilderDef, DecoratedMiddleware, ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, ProcedureImplementer, RouterBuilder, RouterClient, RouterImplementer, RouterImplementerWithMiddlewares };
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,64 @@
|
|
|
1
1
|
import { mergePrefix, mergeTags, ContractProcedure, mergeErrorMap, mergeMeta, parseEndpointDefinition, mergeRoute, prefixRoute, initialSchemas, isContractProcedure, getContractRouter } from '@temporary-name/contract';
|
|
2
2
|
export { ValidationError, eventIterator, validateORPCError } from '@temporary-name/contract';
|
|
3
|
-
import { onError, resolveMaybeOptionalOptions } from '@temporary-name/shared';
|
|
3
|
+
import { assertNever, splitFirst, ORPCError, onError, resolveMaybeOptionalOptions } from '@temporary-name/shared';
|
|
4
4
|
export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
|
|
5
5
|
import { SchemaClass, object, core, gatingContext } from '@temporary-name/zod';
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import { g as getCookie } from './shared/server.C1RJffw4.mjs';
|
|
7
|
+
import { P as Procedure, c as createProcedureClient, e as enhanceRouter, a as addMiddleware, s as setHiddenRouterContract, l as lazyInternal, g as getLazyMeta, u as unlazy, i as isProcedure, b as isLazy, d as getRouter } from './shared/server.miXh-9wo.mjs';
|
|
8
|
+
export { L as LAZY_SYMBOL, p as createAccessibleLazyRouter, f as createORPCErrorConstructorMap, o as getHiddenRouterContract, k as isStartWithMiddlewares, h as lazy, m as mergeCurrentContext, n as mergeMiddlewares, j as middlewareOutputFn, r as resolveContractProcedures, t as traverseContractProcedures, q as unlazyRouter } from './shared/server.miXh-9wo.mjs';
|
|
8
9
|
export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
|
|
10
|
+
import 'cookie';
|
|
11
|
+
|
|
12
|
+
function validateTokenPrefix(prefix, token) {
|
|
13
|
+
if (prefix && !token.startsWith(prefix)) {
|
|
14
|
+
throw new ORPCError("UNAUTHORIZED", { message: `Invalid auth token. It must start with "${prefix}"` });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function validateTokenAuth(config, token, options) {
|
|
18
|
+
const { tokenPrefix, validate } = config;
|
|
19
|
+
validateTokenPrefix(tokenPrefix, token);
|
|
20
|
+
return validate(token, options);
|
|
21
|
+
}
|
|
22
|
+
function authByQuery(config, options) {
|
|
23
|
+
const { name, tokenPrefix, validate } = config;
|
|
24
|
+
const query = options.request.url.searchParams;
|
|
25
|
+
const token = query.get(name);
|
|
26
|
+
if (!token) return void 0;
|
|
27
|
+
validateTokenPrefix(tokenPrefix, token);
|
|
28
|
+
return validate(token, options);
|
|
29
|
+
}
|
|
30
|
+
function authByHeader(config, options) {
|
|
31
|
+
const authHeader = options.request.headers.get(config.name);
|
|
32
|
+
return authHeader ? validateTokenAuth(config, authHeader, options) : void 0;
|
|
33
|
+
}
|
|
34
|
+
function authByCookie(config, options) {
|
|
35
|
+
const cookie = getCookie(options.request.headers, config.name);
|
|
36
|
+
return cookie ? validateTokenAuth(config, cookie, options) : void 0;
|
|
37
|
+
}
|
|
38
|
+
function authByBearer(config, options) {
|
|
39
|
+
const authHeader = options.request.headers.get("Authorization");
|
|
40
|
+
if (!authHeader) return void 0;
|
|
41
|
+
const [authType, bearer] = splitFirst(authHeader, " ");
|
|
42
|
+
return authType === "Bearer" ? validateTokenAuth(config, bearer, options) : void 0;
|
|
43
|
+
}
|
|
44
|
+
function authByBasic(config, options) {
|
|
45
|
+
const authHeader = options.request.headers.get("Authorization");
|
|
46
|
+
if (!authHeader) return void 0;
|
|
47
|
+
const [authType, encoded] = splitFirst(authHeader, " ");
|
|
48
|
+
if (authType !== "Basic") return void 0;
|
|
49
|
+
const decoded = Buffer.from(encoded, "base64").toString("utf-8");
|
|
50
|
+
const [username, password] = splitFirst(decoded, ":");
|
|
51
|
+
validateTokenPrefix(config.tokenPrefix, password);
|
|
52
|
+
return config.validate(username, password, options);
|
|
53
|
+
}
|
|
54
|
+
function authByType(config, options) {
|
|
55
|
+
const { type } = config;
|
|
56
|
+
return type === "header" ? authByHeader(config, options) : type === "query" ? authByQuery(config, options) : type === "cookie" ? authByCookie(config, options) : type === "bearer" ? authByBearer(config, options) : type === "basic" ? authByBasic(config, options) : type === "none" ? false : assertNever(type);
|
|
57
|
+
}
|
|
58
|
+
function authDescription(config) {
|
|
59
|
+
const { type } = config;
|
|
60
|
+
return type === "basic" ? "a Basic Authentication header" : type === "bearer" ? "a Bearer Authentication header" : type === "header" ? `a header named "${config.name}"` : type === "query" ? `a query parameter named "${config.name}"` : type === "cookie" ? `a cookie named "${config.name}"` : type === "none" ? "no authentication" : assertNever(type);
|
|
61
|
+
}
|
|
9
62
|
|
|
10
63
|
class DecoratedProcedure extends Procedure {
|
|
11
64
|
/**
|
|
@@ -132,6 +185,36 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
132
185
|
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
133
186
|
});
|
|
134
187
|
}
|
|
188
|
+
// `& {}` is so AuthType will be expanded in parameter info tooltips.
|
|
189
|
+
// The default of false for ValidatedAuthContext is used when you pass in the type 'none'. We use false
|
|
190
|
+
// because we can't use null or undefined (see ValidatedAuthContext) but we still want it to be falsy.
|
|
191
|
+
useAuth(type, ...rest) {
|
|
192
|
+
const config = { type, ...rest[0] };
|
|
193
|
+
const middleware = os.$context().middleware(async (options) => {
|
|
194
|
+
const { next, context } = options;
|
|
195
|
+
if (context.auth) return next();
|
|
196
|
+
const auth = await authByType(config, options);
|
|
197
|
+
if (auth === void 0) {
|
|
198
|
+
const { authConfigs } = options.procedure["~orpc"];
|
|
199
|
+
if (context.auth !== false && config === authConfigs.at(-1)) {
|
|
200
|
+
let authDescriptions = authConfigs.map(authDescription).join(", ");
|
|
201
|
+
if (authConfigs.length > 1) {
|
|
202
|
+
authDescriptions = `one of: ${authDescriptions}`;
|
|
203
|
+
}
|
|
204
|
+
throw new ORPCError("UNAUTHORIZED", {
|
|
205
|
+
message: `Authentication required. You must provide ${authDescriptions}`
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
return next();
|
|
209
|
+
}
|
|
210
|
+
return next({ context: { auth } });
|
|
211
|
+
});
|
|
212
|
+
return new this.constructor({
|
|
213
|
+
...this["~orpc"],
|
|
214
|
+
authConfigs: [...this["~orpc"].authConfigs, config],
|
|
215
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
|
|
216
|
+
});
|
|
217
|
+
}
|
|
135
218
|
useGating(gates, isGateEnabled) {
|
|
136
219
|
return this.use(({ next, context }) => {
|
|
137
220
|
return gatingContext.run(
|
|
@@ -146,6 +229,9 @@ class ProcedureBuilder extends ContractProcedure {
|
|
|
146
229
|
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
147
230
|
*/
|
|
148
231
|
handler(handler) {
|
|
232
|
+
if (this["~orpc"].schemas.outputSchema === initialSchemas.outputSchema) {
|
|
233
|
+
throw new Error("You must call .output() before calling .handler()");
|
|
234
|
+
}
|
|
149
235
|
return new DecoratedProcedure({
|
|
150
236
|
...this["~orpc"],
|
|
151
237
|
handler
|
|
@@ -258,7 +344,8 @@ function createApiBuilder(opts = {}) {
|
|
|
258
344
|
schemas: initialSchemas,
|
|
259
345
|
// NB: this is a relic from orpc -- I'm not convinced there's a need for this (or if there is, that it's
|
|
260
346
|
// the best solution). For now I've removed the interface to configure it externally.
|
|
261
|
-
dedupeLeadingMiddlewares: true
|
|
347
|
+
dedupeLeadingMiddlewares: true,
|
|
348
|
+
authConfigs: []
|
|
262
349
|
});
|
|
263
350
|
}
|
|
264
351
|
const os = createApiBuilder();
|
|
@@ -268,6 +355,7 @@ function implementerInternal(contract, middlewares) {
|
|
|
268
355
|
const impl2 = new Builder({
|
|
269
356
|
...contract["~orpc"],
|
|
270
357
|
middlewares,
|
|
358
|
+
authConfigs: [],
|
|
271
359
|
inputValidationIndex: middlewares.length,
|
|
272
360
|
outputValidationIndex: middlewares.length,
|
|
273
361
|
dedupeLeadingMiddlewares: true
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Value, Promisable, ORPCError } from '@temporary-name/shared';
|
|
2
|
-
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.
|
|
3
|
-
import { C as Context,
|
|
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';
|
|
4
4
|
import { Meta } from '@temporary-name/contract';
|
|
5
5
|
|
|
6
6
|
interface CORSOptions<T extends Context> {
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Value, Promisable, ORPCError } from '@temporary-name/shared';
|
|
2
|
-
import { S as StandardHandlerInterceptorOptions, a as StandardHandlerPlugin, b as StandardHandlerOptions } from '../shared/server.
|
|
3
|
-
import { C as Context,
|
|
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';
|
|
4
4
|
import { Meta } from '@temporary-name/contract';
|
|
5
5
|
|
|
6
6
|
interface CORSOptions<T extends Context> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Meta } from '@temporary-name/contract';
|
|
2
2
|
import { HTTPPath, StandardLazyRequest, Interceptor, StandardResponse } from '@temporary-name/shared';
|
|
3
|
-
import { C as Context, R as Router,
|
|
3
|
+
import { C as Context, R as Router, N as ProcedureClientInterceptorOptions } from './server.DkYpsO6W.js';
|
|
4
4
|
|
|
5
5
|
interface StandardHandlerPlugin<T extends Context> {
|
|
6
6
|
order?: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { stringifyJSON, isObject, isORPCErrorStatus, tryDecodeURIComponent, toHttpPath, toArray, intercept, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, setSpanError, ORPCError, toORPCError } from '@temporary-name/shared';
|
|
2
|
-
import { c as createProcedureClient } from './server.
|
|
2
|
+
import { c as createProcedureClient } from './server.miXh-9wo.mjs';
|
|
3
3
|
import { fallbackContractConfig, standardizeHTTPPath } from '@temporary-name/contract';
|
|
4
4
|
import { d as deserialize, b as bracketNotationDeserialize, s as serialize } from './server.JtIZ8YG7.mjs';
|
|
5
5
|
import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@temporary-name/server';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { parse, serialize } from 'cookie';
|
|
2
|
+
|
|
3
|
+
function setCookie(headers, name, value, options = {}) {
|
|
4
|
+
if (headers === void 0) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const cookieString = serialize(name, value, {
|
|
8
|
+
path: "/",
|
|
9
|
+
...options
|
|
10
|
+
});
|
|
11
|
+
headers.append("Set-Cookie", cookieString);
|
|
12
|
+
}
|
|
13
|
+
function getCookie(headers, name, options = {}) {
|
|
14
|
+
if (headers === void 0) {
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
const cookieHeader = headers.get("cookie");
|
|
18
|
+
if (cookieHeader === null) {
|
|
19
|
+
return void 0;
|
|
20
|
+
}
|
|
21
|
+
return parse(cookieHeader, options)[name];
|
|
22
|
+
}
|
|
23
|
+
function deleteCookie(headers, name, options = {}) {
|
|
24
|
+
return setCookie(headers, name, "", {
|
|
25
|
+
...options,
|
|
26
|
+
maxAge: 0
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { deleteCookie as d, getCookie as g, setCookie as s };
|
|
@@ -4,6 +4,9 @@ import { ORPCErrorCode, MaybeOptionalOptions, ORPCErrorOptions, ORPCError, Promi
|
|
|
4
4
|
type Context = Record<PropertyKey, any>;
|
|
5
5
|
type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
|
|
6
6
|
type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
|
|
7
|
+
type BuildContextWithAuth<TContext extends Context, TAuthContext> = MergedCurrentContext<TContext, {
|
|
8
|
+
auth: TAuthContext | ('auth' extends keyof TContext ? TContext['auth'] : never);
|
|
9
|
+
}>;
|
|
7
10
|
declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
|
|
8
11
|
|
|
9
12
|
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
|
@@ -13,6 +16,36 @@ type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
|
|
13
16
|
};
|
|
14
17
|
declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
|
|
15
18
|
|
|
19
|
+
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
|
20
|
+
output: TOutput;
|
|
21
|
+
context: TOutContext;
|
|
22
|
+
}>;
|
|
23
|
+
interface MiddlewareNextFn<TOutput> {
|
|
24
|
+
<U extends Context = {}>(options?: {
|
|
25
|
+
context?: U;
|
|
26
|
+
}): MiddlewareResult<U, TOutput>;
|
|
27
|
+
}
|
|
28
|
+
interface MiddlewareOutputFn<TOutput> {
|
|
29
|
+
(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
|
30
|
+
}
|
|
31
|
+
interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> extends ProcedureHandlerOptions<TInContext, TErrorConstructorMap, TMeta> {
|
|
32
|
+
next: MiddlewareNextFn<TOutput>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A function that represents a middleware.
|
|
36
|
+
*
|
|
37
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
38
|
+
*/
|
|
39
|
+
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
|
40
|
+
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
|
41
|
+
}
|
|
42
|
+
type AnyMiddleware = Middleware<any, any, any, any, any, any>;
|
|
43
|
+
interface MapInputMiddleware<TInput, TMappedInput> {
|
|
44
|
+
(input: TInput): TMappedInput;
|
|
45
|
+
}
|
|
46
|
+
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
|
47
|
+
|
|
48
|
+
type DefaultProcedureHandlerOptions = ProcedureHandlerOptions<Context, ORPCErrorConstructorMap<ErrorMap>, Meta>;
|
|
16
49
|
interface ProcedureHandlerOptions<TCurrentContext extends Context, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
|
17
50
|
context: TCurrentContext;
|
|
18
51
|
path: readonly string[];
|
|
@@ -32,6 +65,7 @@ interface ProcedureHandler<TCurrentContext extends Context, TInput extends {
|
|
|
32
65
|
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TSchemas, TErrorMap, TMeta> {
|
|
33
66
|
__initialContext?: (type: TInitialContext) => unknown;
|
|
34
67
|
middlewares: readonly AnyMiddleware[];
|
|
68
|
+
authConfigs: TypedAuthConfig[];
|
|
35
69
|
inputValidationIndex: number;
|
|
36
70
|
outputValidationIndex: number;
|
|
37
71
|
handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
|
|
@@ -51,34 +85,23 @@ declare class Procedure<TInitialContext extends Context, TCurrentContext extends
|
|
|
51
85
|
type AnyProcedure = Procedure<any, any, Schemas, any, any>;
|
|
52
86
|
declare function isProcedure(item: unknown): item is AnyProcedure;
|
|
53
87
|
|
|
54
|
-
type
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
interface
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
*
|
|
72
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
73
|
-
*/
|
|
74
|
-
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
|
75
|
-
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
|
76
|
-
}
|
|
77
|
-
type AnyMiddleware = Middleware<any, any, any, any, any, any>;
|
|
78
|
-
interface MapInputMiddleware<TInput, TMappedInput> {
|
|
79
|
-
(input: TInput): TMappedInput;
|
|
80
|
-
}
|
|
81
|
-
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
|
88
|
+
type ValidatedAuthContext = {};
|
|
89
|
+
interface BasicAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> {
|
|
90
|
+
tokenPrefix?: string;
|
|
91
|
+
validate: (username: string, password: string, options: ProcedureHandlerOptions<TCurrentContext, ORPCErrorConstructorMap<any>, TMeta>) => Promisable<TAuthContext>;
|
|
92
|
+
}
|
|
93
|
+
interface TokenAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> {
|
|
94
|
+
tokenPrefix?: string;
|
|
95
|
+
validate: (token: string, options: ProcedureHandlerOptions<TCurrentContext, ORPCErrorConstructorMap<any>, TMeta>) => Promisable<TAuthContext>;
|
|
96
|
+
}
|
|
97
|
+
interface NamedTokenAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends TokenAuthConfig<TAuthContext, TCurrentContext, TMeta> {
|
|
98
|
+
name: string;
|
|
99
|
+
}
|
|
100
|
+
type AuthType = 'header' | 'query' | 'cookie' | 'bearer' | 'basic' | 'none';
|
|
101
|
+
type AuthConfig<TAuthType extends AuthType, TAuthContext extends ValidatedAuthContext = ValidatedAuthContext, TCurrentContext extends Context = Context, TMeta extends Meta = Meta> = TAuthType extends 'basic' ? BasicAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'bearer' ? TokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'header' ? NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'query' ? NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'cookie' ? NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'none' ? {} : never;
|
|
102
|
+
type TypedAuthConfig<TAuthType extends AuthType = AuthType> = {
|
|
103
|
+
type: TAuthType;
|
|
104
|
+
} & AuthConfig<TAuthType, object>;
|
|
82
105
|
|
|
83
106
|
/**
|
|
84
107
|
* Represents a router, which defines a hierarchical structure of procedures.
|
|
@@ -224,5 +247,5 @@ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema
|
|
|
224
247
|
*/
|
|
225
248
|
declare function createProcedureClient<TInitialContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TSchemas, TErrorMap, TMeta>>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TSchemas['outputSchema'], TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TSchemas, TErrorMap>;
|
|
226
249
|
|
|
227
|
-
export {
|
|
228
|
-
export type {
|
|
250
|
+
export { enhanceRouter as $, middlewareOutputFn as F, isProcedure as K, Procedure as P, createProcedureClient as Q, getRouter as Y, createAccessibleLazyRouter as _, traverseContractProcedures as a4, resolveContractProcedures as a5, unlazyRouter as a7, mergeCurrentContext as m, createORPCErrorConstructorMap as p, LAZY_SYMBOL as q, lazyInternal as s, lazy as t, isLazy as u, getLazyMeta as v, unlazy as w };
|
|
251
|
+
export type { AuthType as A, BuildContextWithAuth as B, Context as C, MiddlewareOptions as D, EnhanceRouterOptions as E, DefaultProcedureHandlerOptions as G, ProcedureHandlerOptions as H, InferRouterInitialContext as I, ProcedureDef as J, Lazy as L, Middleware as M, ProcedureClientInterceptorOptions as N, ORPCErrorConstructorMap as O, Router as R, InferRouterInitialContexts as S, TypedAuthConfig as T, InferRouterCurrentContexts as U, ValidatedAuthContext as V, InferRouterInputs as W, InferRouterOutputs as X, AccessibleLazyRouter as Z, CreateProcedureClientOptions as a, TraverseContractProceduresOptions as a0, TraverseContractProcedureCallbackOptions as a1, ContractProcedureCallbackOptions as a2, LazyTraverseContractProceduresOptions as a3, UnlaziedRouter as a6, ProcedureClient as b, MergedInitialContext as c, MergedCurrentContext as d, AuthConfig as e, ProcedureHandler as f, EnhancedRouter as g, MapInputMiddleware as h, AnyMiddleware as i, AnyProcedure as j, Lazyable as k, AnyRouter as l, ORPCErrorConstructorMapItemOptions as n, ORPCErrorConstructorMapItem as o, LazyMeta as r, MiddlewareResult as x, MiddlewareNextFn as y, MiddlewareOutputFn as z };
|
|
@@ -4,6 +4,9 @@ import { ORPCErrorCode, MaybeOptionalOptions, ORPCErrorOptions, ORPCError, Promi
|
|
|
4
4
|
type Context = Record<PropertyKey, any>;
|
|
5
5
|
type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
|
|
6
6
|
type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
|
|
7
|
+
type BuildContextWithAuth<TContext extends Context, TAuthContext> = MergedCurrentContext<TContext, {
|
|
8
|
+
auth: TAuthContext | ('auth' extends keyof TContext ? TContext['auth'] : never);
|
|
9
|
+
}>;
|
|
7
10
|
declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
|
|
8
11
|
|
|
9
12
|
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'defined' | 'status'>;
|
|
@@ -13,6 +16,36 @@ type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
|
|
13
16
|
};
|
|
14
17
|
declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
|
|
15
18
|
|
|
19
|
+
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
|
20
|
+
output: TOutput;
|
|
21
|
+
context: TOutContext;
|
|
22
|
+
}>;
|
|
23
|
+
interface MiddlewareNextFn<TOutput> {
|
|
24
|
+
<U extends Context = {}>(options?: {
|
|
25
|
+
context?: U;
|
|
26
|
+
}): MiddlewareResult<U, TOutput>;
|
|
27
|
+
}
|
|
28
|
+
interface MiddlewareOutputFn<TOutput> {
|
|
29
|
+
(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
|
30
|
+
}
|
|
31
|
+
interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> extends ProcedureHandlerOptions<TInContext, TErrorConstructorMap, TMeta> {
|
|
32
|
+
next: MiddlewareNextFn<TOutput>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A function that represents a middleware.
|
|
36
|
+
*
|
|
37
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
38
|
+
*/
|
|
39
|
+
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
|
40
|
+
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
|
41
|
+
}
|
|
42
|
+
type AnyMiddleware = Middleware<any, any, any, any, any, any>;
|
|
43
|
+
interface MapInputMiddleware<TInput, TMappedInput> {
|
|
44
|
+
(input: TInput): TMappedInput;
|
|
45
|
+
}
|
|
46
|
+
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
|
47
|
+
|
|
48
|
+
type DefaultProcedureHandlerOptions = ProcedureHandlerOptions<Context, ORPCErrorConstructorMap<ErrorMap>, Meta>;
|
|
16
49
|
interface ProcedureHandlerOptions<TCurrentContext extends Context, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
|
17
50
|
context: TCurrentContext;
|
|
18
51
|
path: readonly string[];
|
|
@@ -32,6 +65,7 @@ interface ProcedureHandler<TCurrentContext extends Context, TInput extends {
|
|
|
32
65
|
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TSchemas, TErrorMap, TMeta> {
|
|
33
66
|
__initialContext?: (type: TInitialContext) => unknown;
|
|
34
67
|
middlewares: readonly AnyMiddleware[];
|
|
68
|
+
authConfigs: TypedAuthConfig[];
|
|
35
69
|
inputValidationIndex: number;
|
|
36
70
|
outputValidationIndex: number;
|
|
37
71
|
handler: ProcedureHandler<TCurrentContext, any, any, any, any>;
|
|
@@ -51,34 +85,23 @@ declare class Procedure<TInitialContext extends Context, TCurrentContext extends
|
|
|
51
85
|
type AnyProcedure = Procedure<any, any, Schemas, any, any>;
|
|
52
86
|
declare function isProcedure(item: unknown): item is AnyProcedure;
|
|
53
87
|
|
|
54
|
-
type
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
interface
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
*
|
|
72
|
-
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
73
|
-
*/
|
|
74
|
-
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
|
75
|
-
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
|
76
|
-
}
|
|
77
|
-
type AnyMiddleware = Middleware<any, any, any, any, any, any>;
|
|
78
|
-
interface MapInputMiddleware<TInput, TMappedInput> {
|
|
79
|
-
(input: TInput): TMappedInput;
|
|
80
|
-
}
|
|
81
|
-
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
|
88
|
+
type ValidatedAuthContext = {};
|
|
89
|
+
interface BasicAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> {
|
|
90
|
+
tokenPrefix?: string;
|
|
91
|
+
validate: (username: string, password: string, options: ProcedureHandlerOptions<TCurrentContext, ORPCErrorConstructorMap<any>, TMeta>) => Promisable<TAuthContext>;
|
|
92
|
+
}
|
|
93
|
+
interface TokenAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> {
|
|
94
|
+
tokenPrefix?: string;
|
|
95
|
+
validate: (token: string, options: ProcedureHandlerOptions<TCurrentContext, ORPCErrorConstructorMap<any>, TMeta>) => Promisable<TAuthContext>;
|
|
96
|
+
}
|
|
97
|
+
interface NamedTokenAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends TokenAuthConfig<TAuthContext, TCurrentContext, TMeta> {
|
|
98
|
+
name: string;
|
|
99
|
+
}
|
|
100
|
+
type AuthType = 'header' | 'query' | 'cookie' | 'bearer' | 'basic' | 'none';
|
|
101
|
+
type AuthConfig<TAuthType extends AuthType, TAuthContext extends ValidatedAuthContext = ValidatedAuthContext, TCurrentContext extends Context = Context, TMeta extends Meta = Meta> = TAuthType extends 'basic' ? BasicAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'bearer' ? TokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'header' ? NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'query' ? NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'cookie' ? NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta> : TAuthType extends 'none' ? {} : never;
|
|
102
|
+
type TypedAuthConfig<TAuthType extends AuthType = AuthType> = {
|
|
103
|
+
type: TAuthType;
|
|
104
|
+
} & AuthConfig<TAuthType, object>;
|
|
82
105
|
|
|
83
106
|
/**
|
|
84
107
|
* Represents a router, which defines a hierarchical structure of procedures.
|
|
@@ -224,5 +247,5 @@ type CreateProcedureClientOptions<TInitialContext extends Context, TOutputSchema
|
|
|
224
247
|
*/
|
|
225
248
|
declare function createProcedureClient<TInitialContext extends Context, TSchemas extends Schemas, TErrorMap extends ErrorMap, TMeta extends Meta, TClientContext extends ClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TSchemas, TErrorMap, TMeta>>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<TInitialContext, TSchemas['outputSchema'], TErrorMap, TMeta, TClientContext>>): ProcedureClient<TClientContext, TSchemas, TErrorMap>;
|
|
226
249
|
|
|
227
|
-
export {
|
|
228
|
-
export type {
|
|
250
|
+
export { enhanceRouter as $, middlewareOutputFn as F, isProcedure as K, Procedure as P, createProcedureClient as Q, getRouter as Y, createAccessibleLazyRouter as _, traverseContractProcedures as a4, resolveContractProcedures as a5, unlazyRouter as a7, mergeCurrentContext as m, createORPCErrorConstructorMap as p, LAZY_SYMBOL as q, lazyInternal as s, lazy as t, isLazy as u, getLazyMeta as v, unlazy as w };
|
|
251
|
+
export type { AuthType as A, BuildContextWithAuth as B, Context as C, MiddlewareOptions as D, EnhanceRouterOptions as E, DefaultProcedureHandlerOptions as G, ProcedureHandlerOptions as H, InferRouterInitialContext as I, ProcedureDef as J, Lazy as L, Middleware as M, ProcedureClientInterceptorOptions as N, ORPCErrorConstructorMap as O, Router as R, InferRouterInitialContexts as S, TypedAuthConfig as T, InferRouterCurrentContexts as U, ValidatedAuthContext as V, InferRouterInputs as W, InferRouterOutputs as X, AccessibleLazyRouter as Z, CreateProcedureClientOptions as a, TraverseContractProceduresOptions as a0, TraverseContractProcedureCallbackOptions as a1, ContractProcedureCallbackOptions as a2, LazyTraverseContractProceduresOptions as a3, UnlaziedRouter as a6, ProcedureClient as b, MergedInitialContext as c, MergedCurrentContext as d, AuthConfig as e, ProcedureHandler as f, EnhancedRouter as g, MapInputMiddleware as h, AnyMiddleware as i, AnyProcedure as j, Lazyable as k, AnyRouter as l, ORPCErrorConstructorMapItemOptions as n, ORPCErrorConstructorMapItem as o, LazyMeta as r, MiddlewareResult as x, MiddlewareNextFn as y, MiddlewareOutputFn as z };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HTTPPath } from '@temporary-name/shared';
|
|
2
|
-
import { C as Context } from './server.
|
|
3
|
-
import { c as StandardHandleOptions } from './server.
|
|
2
|
+
import { C as Context } from './server.DkYpsO6W.js';
|
|
3
|
+
import { c as StandardHandleOptions } from './server.B-meye9-.js';
|
|
4
4
|
|
|
5
5
|
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
6
6
|
context?: T;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HTTPPath } from '@temporary-name/shared';
|
|
2
|
-
import { C as Context } from './server.
|
|
3
|
-
import { c as StandardHandleOptions } from './server.
|
|
2
|
+
import { C as Context } from './server.DkYpsO6W.mjs';
|
|
3
|
+
import { c as StandardHandleOptions } from './server.vLcMd_kA.mjs';
|
|
4
4
|
|
|
5
5
|
type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
|
|
6
6
|
context?: T;
|
|
@@ -390,6 +390,9 @@ async function executeProcedureInternal(procedure, input, options) {
|
|
|
390
390
|
const nextContext = nextOptions?.context ?? {};
|
|
391
391
|
return {
|
|
392
392
|
output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
|
|
393
|
+
// NB: Pretty sure this isn't used (or meant to be used) at runtime, it's just there
|
|
394
|
+
// to get type inference in the builder (via the caller returning the output of next() in
|
|
395
|
+
// the middleware function)
|
|
393
396
|
context: nextContext
|
|
394
397
|
};
|
|
395
398
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Meta } from '@temporary-name/contract';
|
|
2
2
|
import { HTTPPath, StandardLazyRequest, Interceptor, StandardResponse } from '@temporary-name/shared';
|
|
3
|
-
import { C as Context, R as Router,
|
|
3
|
+
import { C as Context, R as Router, N as ProcedureClientInterceptorOptions } from './server.DkYpsO6W.mjs';
|
|
4
4
|
|
|
5
5
|
interface StandardHandlerPlugin<T extends Context> {
|
|
6
6
|
order?: number;
|
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.ce6ed5061c5dc25f4390f71c2c5c5411546e85c1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://www.stainless.com/",
|
|
7
7
|
"repository": {
|
|
@@ -57,31 +57,19 @@
|
|
|
57
57
|
"files": [
|
|
58
58
|
"dist"
|
|
59
59
|
],
|
|
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
60
|
"dependencies": {
|
|
73
61
|
"cookie": "^1.0.2",
|
|
74
62
|
"rou3": "^0.7.7",
|
|
75
63
|
"zod": "^4.1.12",
|
|
76
|
-
"@temporary-name/contract": "1.9.3-alpha.
|
|
77
|
-
"@temporary-name/
|
|
78
|
-
"@temporary-name/
|
|
79
|
-
"@temporary-name/
|
|
80
|
-
"@temporary-name/standard-server": "1.9.3-alpha.
|
|
81
|
-
"@temporary-name/
|
|
82
|
-
"@temporary-name/standard-server-
|
|
83
|
-
"@temporary-name/
|
|
84
|
-
"@temporary-name/
|
|
64
|
+
"@temporary-name/contract": "1.9.3-alpha.ce6ed5061c5dc25f4390f71c2c5c5411546e85c1",
|
|
65
|
+
"@temporary-name/interop": "1.9.3-alpha.ce6ed5061c5dc25f4390f71c2c5c5411546e85c1",
|
|
66
|
+
"@temporary-name/json-schema": "1.9.3-alpha.ce6ed5061c5dc25f4390f71c2c5c5411546e85c1",
|
|
67
|
+
"@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.ce6ed5061c5dc25f4390f71c2c5c5411546e85c1",
|
|
68
|
+
"@temporary-name/standard-server-fetch": "1.9.3-alpha.ce6ed5061c5dc25f4390f71c2c5c5411546e85c1",
|
|
69
|
+
"@temporary-name/shared": "1.9.3-alpha.ce6ed5061c5dc25f4390f71c2c5c5411546e85c1",
|
|
70
|
+
"@temporary-name/standard-server-node": "1.9.3-alpha.ce6ed5061c5dc25f4390f71c2c5c5411546e85c1",
|
|
71
|
+
"@temporary-name/standard-server": "1.9.3-alpha.ce6ed5061c5dc25f4390f71c2c5c5411546e85c1",
|
|
72
|
+
"@temporary-name/zod": "1.9.3-alpha.ce6ed5061c5dc25f4390f71c2c5c5411546e85c1"
|
|
85
73
|
},
|
|
86
74
|
"devDependencies": {
|
|
87
75
|
"@types/supertest": "^6.0.3",
|