import type { FieldKind, FieldNullability, FieldOptionsFromKind, FieldRef, InferredFieldOptionKeys, InputFieldMap, InputShapeFromFields, MaybePromise, Normalize, Resolver, RootName, SchemaTypes, ShapeFromTypeParam, TypeParam, } from '@pothos/core'; import type { PothosScopeAuthPlugin } from '.'; import type { AuthScopeMap, ContextForAuth, FieldAuthScopes, FieldGrantScopes, ForbiddenResult, ReplaceContext, ScopeAuthInitializer, ScopeAuthPluginOptions, TypeAuthScopes, TypeGrantScopes, UnauthorizedOptions, } from './types'; declare global { export namespace PothosSchemaTypes { export interface Plugins { scopeAuth: PothosScopeAuthPlugin; } export interface SchemaBuilderOptions { scopeAuth: ScopeAuthPluginOptions; } export interface V3SchemaBuilderOptions { scopeAuth: never; scopeAuthOptions?: Omit, 'authScopes'>; authScopes: ScopeAuthInitializer; } export interface SchemaBuilder { runAuthScopes: ( context: Types['Context'], scopes: AuthScopeMap, unauthorizedError?: (result: ForbiddenResult) => Error | string, ) => MaybePromise; } export interface BuildSchemaOptions { disableScopeAuth?: boolean; } export interface UserSchemaTypes { AuthScopes: {}; AuthContexts: {}; DefaultAuthStrategy: 'all' | 'any'; } export interface ExtendDefaultTypes> { AuthScopes: PartialTypes['AuthScopes'] & {}; AuthContexts: PartialTypes['AuthContexts'] & {}; DefaultAuthStrategy: undefined extends PartialTypes['DefaultAuthStrategy'] ? 'any' : PartialTypes['DefaultAuthStrategy'] & string; } export interface RootTypeOptions { authScopes?: TypeAuthScopes; grantScopes?: TypeGrantScopes; } export interface ObjectTypeOptions { authScopes?: TypeAuthScopes; grantScopes?: TypeGrantScopes; runScopesOnType?: boolean; skipInterfaceScopes?: boolean; } export interface InterfaceTypeOptions { authScopes?: TypeAuthScopes; grantScopes?: TypeGrantScopes; runScopesOnType?: boolean; } export interface FieldOptions< Types extends SchemaTypes, ParentShape, Type extends TypeParam, Nullable extends FieldNullability, Args extends InputFieldMap, ResolveShape, ResolveReturnShape, > extends UnauthorizedOptions { authScopes?: FieldAuthScopes>; grantScopes?: FieldGrantScopes>; skipTypeScopes?: boolean; } export interface ObjectFieldOptions< Types extends SchemaTypes, ParentShape, Type extends TypeParam, Nullable extends FieldNullability, Args extends InputFieldMap, ResolveReturnShape, > extends FieldOptions< Types, ParentShape, Type, Nullable, Args, ParentShape, ResolveReturnShape > { skipInterfaceScopes?: boolean; } export interface InterfaceFieldOptions< Types extends SchemaTypes, ParentShape, Type extends TypeParam, Nullable extends FieldNullability, Args extends InputFieldMap, ResolveReturnShape, > extends FieldOptions< Types, ParentShape, Type, Nullable, Args, ParentShape, ResolveReturnShape > { skipInterfaceScopes?: boolean; } export interface RootFieldBuilder< Types extends SchemaTypes, ParentShape, Kind extends FieldKind = FieldKind, > { authField: < Args extends InputFieldMap, Type extends TypeParam, Scopes extends FieldAuthScopes>, ResolveShape, ResolveReturnShape, Nullable extends FieldNullability = Types['DefaultFieldNullability'], >( options: Normalize< Omit< FieldOptionsFromKind< Types, ParentShape, Type, Nullable, Args, Kind, ResolveShape, ResolveReturnShape >, InferredFieldOptionKeys > & { authScopes: Scopes; resolve: Resolver< ParentShape, InputShapeFromFields, ContextForAuth, ShapeFromTypeParam, ResolveReturnShape >; } >, ) => FieldRef, Kind>; } export interface QueryFieldBuilder { withAuth: >>( scopes: Scopes, ) => QueryFieldBuilder< ReplaceContext & object>, ParentShape >; } export interface MutationFieldBuilder { withAuth: >>( scopes: Scopes, ) => MutationFieldBuilder< ReplaceContext & object>, ParentShape >; } export interface SubscriptionFieldBuilder { withAuth: >>( scopes: Scopes, ) => SubscriptionFieldBuilder< ReplaceContext & object>, ParentShape >; } export interface ObjectFieldBuilder { withAuth: >>( scopes: Scopes, ) => ObjectFieldBuilder< ReplaceContext & object>, ParentShape >; } export interface InterfaceFieldBuilder { withAuth: >>( scopes: Scopes, ) => InterfaceFieldBuilder< ReplaceContext & object>, ParentShape >; } export interface ScopeAuthFieldAuthScopes< Types extends SchemaTypes, Parent, Args extends {} = {}, > { Scopes: FieldAuthScopes; } export interface ScopeAuthContextForAuth { Context: ContextForAuth; } } }