New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@pothos/plugin-scope-auth

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pothos/plugin-scope-auth - npm Package Compare versions

Comparing version 4.0.2 to 4.1.0

6

CHANGELOG.md
# Change Log
## 4.1.0
### Minor Changes
- 27af377: replace eslint and prettier with biome
## 4.0.2

@@ -4,0 +10,0 @@

2

dts/global-types.d.ts

@@ -1,2 +0,2 @@

import { FieldKind, FieldNullability, FieldOptionsFromKind, FieldRef, InferredFieldOptionKeys, InputFieldMap, InputShapeFromFields, MaybePromise, Normalize, Resolver, RootName, SchemaTypes, ShapeFromTypeParam, TypeParam } from '@pothos/core';
import type { FieldKind, FieldNullability, FieldOptionsFromKind, FieldRef, InferredFieldOptionKeys, InputFieldMap, InputShapeFromFields, MaybePromise, Normalize, Resolver, RootName, SchemaTypes, ShapeFromTypeParam, TypeParam } from '@pothos/core';
import type { AuthScopeMap, ContextForAuth, FieldAuthScopes, FieldGrantScopes, ForbiddenResult, ReplaceContext, ScopeAuthInitializer, ScopeAuthPluginOptions, TypeAuthScopes, TypeGrantScopes, UnauthorizedOptions } from './types';

@@ -3,0 +3,0 @@ import type { PothosScopeAuthPlugin } from '.';

import './global-types';
import './schema-builder';
import './field-builders';
import { GraphQLFieldResolver, GraphQLIsTypeOfFn, GraphQLTypeResolver } from 'graphql';
import { BasePlugin, PothosInterfaceTypeConfig, PothosMutationTypeConfig, PothosObjectTypeConfig, PothosOutputFieldConfig, PothosQueryTypeConfig, PothosSubscriptionTypeConfig, PothosUnionTypeConfig, SchemaTypes } from '@pothos/core';
import { BasePlugin, type PothosInterfaceTypeConfig, type PothosMutationTypeConfig, type PothosObjectTypeConfig, type PothosOutputFieldConfig, type PothosQueryTypeConfig, type PothosSubscriptionTypeConfig, type SchemaTypes } from '@pothos/core';
import type { GraphQLFieldResolver, GraphQLIsTypeOfFn, GraphQLTypeResolver } from 'graphql';
import RequestCache from './request-cache';
import { ResolveStep } from './types';
import type { ResolveStep } from './types';
export { RequestCache };

@@ -16,3 +16,3 @@ export * from './errors';

wrapSubscribe(subscriber: GraphQLFieldResolver<unknown, Types['Context'], object>, fieldConfig: PothosOutputFieldConfig<Types>): GraphQLFieldResolver<unknown, Types['Context'], object>;
wrapResolveType(resolveType: GraphQLTypeResolver<unknown, Types['Context']>, typeConfig: PothosInterfaceTypeConfig | PothosUnionTypeConfig): GraphQLTypeResolver<unknown, Types['Context']>;
wrapResolveType(resolveType: GraphQLTypeResolver<unknown, Types['Context']>): GraphQLTypeResolver<unknown, Types['Context']>;
wrapIsTypeOf(isTypeOf: GraphQLIsTypeOfFn<unknown, Types['Context']> | undefined, typeConfig: PothosObjectTypeConfig): GraphQLIsTypeOfFn<unknown, Types['Context']> | undefined;

@@ -19,0 +19,0 @@ createStepsForType(typeConfig: PothosInterfaceTypeConfig | PothosMutationTypeConfig | PothosObjectTypeConfig | PothosQueryTypeConfig | PothosSubscriptionTypeConfig, { skipTypeScopes, skipInterfaceScopes, forField, }: {

@@ -1,5 +0,5 @@

import { GraphQLIsTypeOfFn, GraphQLResolveInfo } from 'graphql';
import { MaybePromise, SchemaTypes } from '@pothos/core';
import { type MaybePromise, type SchemaTypes } from '@pothos/core';
import type { GraphQLIsTypeOfFn, GraphQLResolveInfo } from 'graphql';
import type { PothosScopeAuthPlugin, ResolveStep } from '.';
export declare function isTypeOfHelper<Types extends SchemaTypes>(steps: ResolveStep<Types>[], plugin: PothosScopeAuthPlugin<Types>, isTypeOf: GraphQLIsTypeOfFn<unknown, Types['Context']> | undefined): (parent: unknown, context: Types["Context"], info: GraphQLResolveInfo) => MaybePromise<boolean>;
//# sourceMappingURL=is-type-of-helper.d.ts.map

@@ -1,4 +0,4 @@

import { GraphQLResolveInfo } from 'graphql';
import { MaybePromise, Path, SchemaTypes } from '@pothos/core';
import { AuthFailure, AuthScopeMap, ScopeLoaderMap, TypeAuthScopesFunction } from './types';
import { type MaybePromise, type Path, type SchemaTypes } from '@pothos/core';
import type { GraphQLResolveInfo } from 'graphql';
import { type AuthFailure, type AuthScopeMap, type ScopeLoaderMap, type TypeAuthScopesFunction } from './types';
export default class RequestCache<Types extends SchemaTypes> {

@@ -5,0 +5,0 @@ builder: PothosSchemaTypes.SchemaBuilder<Types>;

@@ -1,6 +0,6 @@

import { GraphQLResolveInfo } from 'graphql';
import { PothosOutputFieldConfig, SchemaTypes } from '@pothos/core';
import { ResolveStep } from './types';
import { type PothosOutputFieldConfig, type SchemaTypes } from '@pothos/core';
import type { GraphQLResolveInfo } from 'graphql';
import { type ResolveStep } from './types';
import type { PothosScopeAuthPlugin } from '.';
export declare function resolveHelper<Types extends SchemaTypes>(steps: ResolveStep<Types>[], plugin: PothosScopeAuthPlugin<Types>, fieldConfig: PothosOutputFieldConfig<Types>): (parent: unknown, args: {}, context: Types["Context"], info: GraphQLResolveInfo) => unknown;
//# sourceMappingURL=resolve-helper.d.ts.map

@@ -1,4 +0,4 @@

import { GraphQLFieldResolver } from 'graphql';
import { SchemaTypes } from '@pothos/core';
import { FieldAuthScopes, FieldGrantScopes, ResolveStep, TypeAuthScopes, TypeGrantScopes } from './types';
import { type SchemaTypes } from '@pothos/core';
import type { GraphQLFieldResolver } from 'graphql';
import type { FieldAuthScopes, FieldGrantScopes, ResolveStep, TypeAuthScopes, TypeGrantScopes } from './types';
export declare function createTypeAuthScopesStep<Types extends SchemaTypes>(authScopes: TypeAuthScopes<Types, unknown>, type: string): ResolveStep<Types>;

@@ -5,0 +5,0 @@ export declare function createTypeGrantScopesStep<Types extends SchemaTypes>(grantScopes: TypeGrantScopes<Types, unknown>, type: string, forField: boolean): ResolveStep<Types>;

@@ -1,3 +0,3 @@

import { GraphQLResolveInfo } from 'graphql';
import { FieldNullability, InputFieldMap, InputShapeFromFields, MaybePromise, Merge, SchemaTypes, ShapeFromTypeParam, TypeParam, UnionToIntersection } from '@pothos/core';
import type { FieldNullability, InputFieldMap, InputShapeFromFields, MaybePromise, Merge, SchemaTypes, ShapeFromTypeParam, TypeParam, UnionToIntersection } from '@pothos/core';
import type { GraphQLResolveInfo } from 'graphql';
import type RequestCache from './request-cache';

@@ -4,0 +4,0 @@ export interface ScopeAuthPluginOptions<Types extends SchemaTypes> {

@@ -1,2 +0,2 @@

import { Path, PothosFieldConfig, SchemaTypes } from '@pothos/core';
import type { Path, PothosFieldConfig, SchemaTypes } from '@pothos/core';
import type { AuthScopeMap } from '.';

@@ -3,0 +3,0 @@ export declare function canCache<Types extends SchemaTypes>(map: AuthScopeMap<Types>): boolean;

@@ -24,3 +24,2 @@ import { InterfaceFieldBuilder, MutationFieldBuilder, ObjectFieldBuilder, QueryFieldBuilder, SubscriptionFieldBuilder } from '@pothos/core';

const originalCreateField = builder.createField;
// eslint-disable-next-line no-param-reassign
builder.createField = function createField(options) {

@@ -27,0 +26,0 @@ return originalCreateField.call(this, {

@@ -1,2 +0,2 @@

import { FieldKind, FieldNullability, FieldOptionsFromKind, FieldRef, InferredFieldOptionKeys, InputFieldMap, InputShapeFromFields, MaybePromise, Normalize, Resolver, RootName, SchemaTypes, ShapeFromTypeParam, TypeParam } from '@pothos/core';
import type { FieldKind, FieldNullability, FieldOptionsFromKind, FieldRef, InferredFieldOptionKeys, InputFieldMap, InputShapeFromFields, MaybePromise, Normalize, Resolver, RootName, SchemaTypes, ShapeFromTypeParam, TypeParam } from '@pothos/core';
import type { AuthScopeMap, ContextForAuth, FieldAuthScopes, FieldGrantScopes, ForbiddenResult, ReplaceContext, ScopeAuthInitializer, ScopeAuthPluginOptions, TypeAuthScopes, TypeGrantScopes, UnauthorizedOptions } from './types.js';

@@ -3,0 +3,0 @@ import type { PothosScopeAuthPlugin } from './index.js';

@@ -1,2 +0,2 @@

/* eslint-disable @typescript-eslint/no-unused-vars */ export {};
export {};
//# sourceMappingURL=global-types.js.map
import './global-types.js';
import './schema-builder.js';
import './field-builders.js';
import { GraphQLFieldResolver, GraphQLIsTypeOfFn, GraphQLTypeResolver } from 'graphql';
import { BasePlugin, PothosInterfaceTypeConfig, PothosMutationTypeConfig, PothosObjectTypeConfig, PothosOutputFieldConfig, PothosQueryTypeConfig, PothosSubscriptionTypeConfig, PothosUnionTypeConfig, SchemaTypes } from '@pothos/core';
import { BasePlugin, type PothosInterfaceTypeConfig, type PothosMutationTypeConfig, type PothosObjectTypeConfig, type PothosOutputFieldConfig, type PothosQueryTypeConfig, type PothosSubscriptionTypeConfig, type SchemaTypes } from '@pothos/core';
import type { GraphQLFieldResolver, GraphQLIsTypeOfFn, GraphQLTypeResolver } from 'graphql';
import RequestCache from './request-cache.js';
import { ResolveStep } from './types.js';
import type { ResolveStep } from './types.js';
export { RequestCache };

@@ -16,3 +16,3 @@ export * from './errors.js';

wrapSubscribe(subscriber: GraphQLFieldResolver<unknown, Types["Context"], object>, fieldConfig: PothosOutputFieldConfig<Types>): GraphQLFieldResolver<unknown, Types["Context"], object>;
wrapResolveType(resolveType: GraphQLTypeResolver<unknown, Types["Context"]>, typeConfig: PothosInterfaceTypeConfig | PothosUnionTypeConfig): GraphQLTypeResolver<unknown, Types["Context"]>;
wrapResolveType(resolveType: GraphQLTypeResolver<unknown, Types["Context"]>): GraphQLTypeResolver<unknown, Types["Context"]>;
wrapIsTypeOf(isTypeOf: GraphQLIsTypeOfFn<unknown, Types["Context"]> | undefined, typeConfig: PothosObjectTypeConfig): GraphQLIsTypeOfFn<unknown, Types["Context"]> | undefined;

@@ -19,0 +19,0 @@ createStepsForType(typeConfig: PothosInterfaceTypeConfig | PothosMutationTypeConfig | PothosObjectTypeConfig | PothosQueryTypeConfig | PothosSubscriptionTypeConfig, { skipTypeScopes, skipInterfaceScopes, forField, }: {

@@ -53,3 +53,3 @@ import './global-types.js';

}
wrapResolveType(resolveType, typeConfig) {
wrapResolveType(resolveType) {
return (...args) => {

@@ -99,7 +99,7 @@ inResolveType = true;

if (!skipInterfaceScopes && !(typeConfig.kind === "Object" && typeConfig.pothosOptions.skipInterfaceScopes)) {
interfaceConfigs.forEach((interfaceConfig) => {
for (const interfaceConfig of interfaceConfigs) {
if (interfaceConfig.pothosOptions.authScopes) {
steps.push(createTypeAuthScopesStep(interfaceConfig.pothosOptions.authScopes, interfaceConfig.name));
}
});
}
}

@@ -106,0 +106,0 @@ if (parentGrantScopes) {

@@ -1,5 +0,5 @@

import { GraphQLIsTypeOfFn, GraphQLResolveInfo } from 'graphql';
import { MaybePromise, SchemaTypes } from '@pothos/core';
import { type MaybePromise, type SchemaTypes } from '@pothos/core';
import type { GraphQLIsTypeOfFn, GraphQLResolveInfo } from 'graphql';
import type { PothosScopeAuthPlugin, ResolveStep } from './index.js';
export declare function isTypeOfHelper<Types extends SchemaTypes>(steps: ResolveStep<Types>[], plugin: PothosScopeAuthPlugin<Types>, isTypeOf: GraphQLIsTypeOfFn<unknown, Types["Context"]> | undefined): (parent: unknown, context: Types["Context"], info: GraphQLResolveInfo) => MaybePromise<boolean>;
//# sourceMappingURL=is-type-of-helper.d.ts.map

@@ -1,4 +0,4 @@

import { GraphQLResolveInfo } from 'graphql';
import { MaybePromise, Path, SchemaTypes } from '@pothos/core';
import { AuthFailure, AuthScopeMap, ScopeLoaderMap, TypeAuthScopesFunction } from './types.js';
import { type MaybePromise, type Path, type SchemaTypes } from '@pothos/core';
import type { GraphQLResolveInfo } from 'graphql';
import { type AuthFailure, type AuthScopeMap, type ScopeLoaderMap, type TypeAuthScopesFunction } from './types.js';
export default class RequestCache<Types extends SchemaTypes> {

@@ -5,0 +5,0 @@ builder: PothosSchemaTypes.SchemaBuilder<Types>;

@@ -1,2 +0,2 @@

/* eslint-disable @typescript-eslint/promise-function-async */ function _define_property(obj, key, value) {
function _define_property(obj, key, value) {
if (key in obj) {

@@ -15,3 +15,3 @@ Object.defineProperty(obj, key, {

}
import { createContextCache, isThenable, PothosValidationError } from '@pothos/core';
import { PothosValidationError, createContextCache, isThenable } from '@pothos/core';
import { AuthScopeFailureType } from './types.js';

@@ -48,3 +48,5 @@ import { cacheKey, canCache } from './util.js';

const set = this.grantCache.get(key);
scopes.forEach((scope) => set.add(scope));
for (const scope of scopes) {
set.add(scope);
}
}

@@ -248,3 +250,3 @@ else {

let hasSuccess = false;
results.forEach((result) => {
for (const result of results) {
if (result) {

@@ -256,3 +258,3 @@ problems.push(result);

}
});
}
if (forAll) {

@@ -259,0 +261,0 @@ return problems.length > 0 ? failure : null;

@@ -1,6 +0,6 @@

import { GraphQLResolveInfo } from 'graphql';
import { PothosOutputFieldConfig, SchemaTypes } from '@pothos/core';
import { ResolveStep } from './types.js';
import { type PothosOutputFieldConfig, type SchemaTypes } from '@pothos/core';
import type { GraphQLResolveInfo } from 'graphql';
import { type ResolveStep } from './types.js';
import type { PothosScopeAuthPlugin } from './index.js';
export declare function resolveHelper<Types extends SchemaTypes>(steps: ResolveStep<Types>[], plugin: PothosScopeAuthPlugin<Types>, fieldConfig: PothosOutputFieldConfig<Types>): (parent: unknown, args: {}, context: Types["Context"], info: GraphQLResolveInfo) => unknown;
//# sourceMappingURL=resolve-helper.d.ts.map

@@ -13,3 +13,3 @@ import { isThenable } from '@pothos/core';

const globalUnauthorizedError = (_plugin_builder_options_scopeAuth = plugin.builder.options.scopeAuth) === null || _plugin_builder_options_scopeAuth === void 0 ? void 0 : _plugin_builder_options_scopeAuth.unauthorizedError;
const defaultUnauthorizedError = (parent, args, context, info, result) => {
const defaultUnauthorizedError = (parent, _args, context, info, result) => {
if (globalUnauthorizedError) {

@@ -31,3 +31,2 @@ return globalUnauthorizedError(parent, context, info, result);

const { run, errorMessage } = steps[i];
// eslint-disable-next-line @typescript-eslint/no-loop-func
const stepResult = run(cache, parent, args, context, info, (val) => {

@@ -34,0 +33,0 @@ resolvedValue = val;

@@ -5,3 +5,2 @@ import SchemaBuilder, { isThenable } from '@pothos/core';

const schemaBuilderProto = SchemaBuilder.prototype;
// eslint-disable-next-line consistent-return
schemaBuilderProto.runAuthScopes = function runAuthScopes(context, scopes, unauthorizedError = (result) => new ForbiddenError(result.message, result.failure)) {

@@ -8,0 +7,0 @@ const cache = RequestCache.fromContext(context, this);

@@ -1,4 +0,4 @@

import { GraphQLFieldResolver } from 'graphql';
import { SchemaTypes } from '@pothos/core';
import { FieldAuthScopes, FieldGrantScopes, ResolveStep, TypeAuthScopes, TypeGrantScopes } from './types.js';
import { type SchemaTypes } from '@pothos/core';
import type { GraphQLFieldResolver } from 'graphql';
import type { FieldAuthScopes, FieldGrantScopes, ResolveStep, TypeAuthScopes, TypeGrantScopes } from './types.js';
export declare function createTypeAuthScopesStep<Types extends SchemaTypes>(authScopes: TypeAuthScopes<Types, unknown>, type: string): ResolveStep<Types>;

@@ -5,0 +5,0 @@ export declare function createTypeGrantScopesStep<Types extends SchemaTypes>(grantScopes: TypeGrantScopes<Types, unknown>, type: string, forField: boolean): ResolveStep<Types>;

@@ -5,3 +5,3 @@ import { isThenable } from '@pothos/core';

return {
run: (state, parent, args, context, info) => state.evaluateTypeScopeFunction(authScopes, type, parent, info),
run: (state, parent, _args, _context, info) => state.evaluateTypeScopeFunction(authScopes, type, parent, info),
errorMessage: `Not authorized to read fields for ${type}`

@@ -11,3 +11,3 @@ };

return {
run: (state, parent, args, context, info) => state.evaluateScopeMap(authScopes, info),
run: (state, _parent, _args, _context, info) => state.evaluateScopeMap(authScopes, info),
errorMessage: `Not authorized to read fields for ${type}`

@@ -18,3 +18,3 @@ };

return {
run: (state, parent, args, context, info) => state.grantTypeScopes(type, parent, forField ? info.path.prev : info.path, () => grantScopes(parent, context)),
run: (state, parent, _args, context, info) => state.grantTypeScopes(type, parent, forField ? info.path.prev : info.path, () => grantScopes(parent, context)),
errorMessage: `Unknown error creating grants for ${type}`

@@ -26,3 +26,3 @@ };

return {
errorMessage: (parent, args, context, info) => `Not authorized to resolve ${info.parentType}.${info.fieldName}`,
errorMessage: (_parent, _args, _context, info) => `Not authorized to resolve ${info.parentType}.${info.fieldName}`,
run: (state, parent, args, context, info) => {

@@ -38,4 +38,4 @@ const scopeMap = authScopes(parent, args, context, info);

return {
errorMessage: (parent, args, context, info) => `Not authorized to resolve ${info.parentType}.${info.fieldName}`,
run: (state, parent, args, context, info) => state.evaluateScopeMap(authScopes, info)
errorMessage: (_parent, _args, _context, info) => `Not authorized to resolve ${info.parentType}.${info.fieldName}`,
run: (state, _parent, _args, _context, info) => state.evaluateScopeMap(authScopes, info)
};

@@ -45,3 +45,3 @@ }

return {
errorMessage: (parent, args, context, info) => `Unknown issue generating grants for ${info.parentType}.${info.fieldName}`,
errorMessage: (_parent, _args, _context, info) => `Unknown issue generating grants for ${info.parentType}.${info.fieldName}`,
run: (state, parent, args, context, info) => {

@@ -66,4 +66,4 @@ if (typeof grantScopes !== "function") {

return {
errorMessage: (parent, args, context, info) => `Unknown issue resolving ${info.parentType}.${info.fieldName}`,
run: (state, parent, args, context, info, setResolved) => {
errorMessage: (_parent, _args, _context, info) => `Unknown issue resolving ${info.parentType}.${info.fieldName}`,
run: (_state, parent, args, context, info, setResolved) => {
const result = resolver(parent, args, context, info);

@@ -70,0 +70,0 @@ if (isThenable(result)) {

@@ -1,3 +0,3 @@

import { GraphQLResolveInfo } from 'graphql';
import { FieldNullability, InputFieldMap, InputShapeFromFields, MaybePromise, Merge, SchemaTypes, ShapeFromTypeParam, TypeParam, UnionToIntersection } from '@pothos/core';
import type { FieldNullability, InputFieldMap, InputShapeFromFields, MaybePromise, Merge, SchemaTypes, ShapeFromTypeParam, TypeParam, UnionToIntersection } from '@pothos/core';
import type { GraphQLResolveInfo } from 'graphql';
import type RequestCache from './request-cache.js';

@@ -4,0 +4,0 @@ export interface ScopeAuthPluginOptions<Types extends SchemaTypes> {

@@ -1,2 +0,2 @@

import { Path, PothosFieldConfig, SchemaTypes } from '@pothos/core';
import type { Path, PothosFieldConfig, SchemaTypes } from '@pothos/core';
import type { AuthScopeMap } from './index.js';

@@ -3,0 +3,0 @@ export declare function canCache<Types extends SchemaTypes>(map: AuthScopeMap<Types>): boolean;

@@ -28,3 +28,2 @@ "use strict";

const originalCreateField = builder.createField;
// eslint-disable-next-line no-param-reassign
builder.createField = function createField(options) {

@@ -31,0 +30,0 @@ return originalCreateField.call(this, {

@@ -1,2 +0,2 @@

/* eslint-disable @typescript-eslint/no-unused-vars */ "use strict";
"use strict";
Object.defineProperty(exports, "__esModule", {

@@ -3,0 +3,0 @@ value: true

@@ -132,3 +132,3 @@ "use strict";

}
wrapResolveType(resolveType, typeConfig) {
wrapResolveType(resolveType) {
return (...args)=>{

@@ -177,7 +177,7 @@ inResolveType = true;

if (!skipInterfaceScopes && !(typeConfig.kind === 'Object' && typeConfig.pothosOptions.skipInterfaceScopes)) {
interfaceConfigs.forEach((interfaceConfig)=>{
for (const interfaceConfig of interfaceConfigs){
if (interfaceConfig.pothosOptions.authScopes) {
steps.push((0, _steps.createTypeAuthScopesStep)(interfaceConfig.pothosOptions.authScopes, interfaceConfig.name));
}
});
}
}

@@ -184,0 +184,0 @@ if (parentGrantScopes) {

@@ -1,2 +0,2 @@

/* eslint-disable @typescript-eslint/promise-function-async */ "use strict";
"use strict";
Object.defineProperty(exports, "__esModule", {

@@ -56,3 +56,5 @@ value: true

const set = this.grantCache.get(key);
scopes.forEach((scope)=>set.add(scope));
for (const scope of scopes){
set.add(scope);
}
} else {

@@ -243,3 +245,3 @@ this.grantCache.set(key, new Set(scopes));

let hasSuccess = false;
results.forEach((result)=>{
for (const result of results){
if (result) {

@@ -250,3 +252,3 @@ problems.push(result);

}
});
}
if (forAll) {

@@ -253,0 +255,0 @@ return problems.length > 0 ? failure : null;

@@ -28,3 +28,3 @@ "use strict";

const globalUnauthorizedError = (_plugin_builder_options_scopeAuth = plugin.builder.options.scopeAuth) === null || _plugin_builder_options_scopeAuth === void 0 ? void 0 : _plugin_builder_options_scopeAuth.unauthorizedError;
const defaultUnauthorizedError = (parent, args, context, info, result)=>{
const defaultUnauthorizedError = (parent, _args, context, info, result)=>{
if (globalUnauthorizedError) {

@@ -46,3 +46,2 @@ return globalUnauthorizedError(parent, context, info, result);

const { run, errorMessage } = steps[i];
// eslint-disable-next-line @typescript-eslint/no-loop-func
const stepResult = run(cache, parent, args, context, info, (val)=>{

@@ -49,0 +48,0 @@ resolvedValue = val;

@@ -55,3 +55,2 @@ "use strict";

const schemaBuilderProto = _core.default.prototype;
// eslint-disable-next-line consistent-return
schemaBuilderProto.runAuthScopes = function runAuthScopes(context, scopes, unauthorizedError = (result)=>new _errors.ForbiddenError(result.message, result.failure)) {

@@ -58,0 +57,0 @@ const cache = _requestcache.default.fromContext(context, this);

@@ -32,3 +32,3 @@ "use strict";

return {
run: (state, parent, args, context, info)=>state.evaluateTypeScopeFunction(authScopes, type, parent, info),
run: (state, parent, _args, _context, info)=>state.evaluateTypeScopeFunction(authScopes, type, parent, info),
errorMessage: `Not authorized to read fields for ${type}`

@@ -38,3 +38,3 @@ };

return {
run: (state, parent, args, context, info)=>state.evaluateScopeMap(authScopes, info),
run: (state, _parent, _args, _context, info)=>state.evaluateScopeMap(authScopes, info),
errorMessage: `Not authorized to read fields for ${type}`

@@ -45,3 +45,3 @@ };

return {
run: (state, parent, args, context, info)=>state.grantTypeScopes(type, parent, forField ? info.path.prev : info.path, ()=>grantScopes(parent, context)),
run: (state, parent, _args, context, info)=>state.grantTypeScopes(type, parent, forField ? info.path.prev : info.path, ()=>grantScopes(parent, context)),
errorMessage: `Unknown error creating grants for ${type}`

@@ -53,3 +53,3 @@ };

return {
errorMessage: (parent, args, context, info)=>`Not authorized to resolve ${info.parentType}.${info.fieldName}`,
errorMessage: (_parent, _args, _context, info)=>`Not authorized to resolve ${info.parentType}.${info.fieldName}`,
run: (state, parent, args, context, info)=>{

@@ -65,4 +65,4 @@ const scopeMap = authScopes(parent, args, context, info);

return {
errorMessage: (parent, args, context, info)=>`Not authorized to resolve ${info.parentType}.${info.fieldName}`,
run: (state, parent, args, context, info)=>state.evaluateScopeMap(authScopes, info)
errorMessage: (_parent, _args, _context, info)=>`Not authorized to resolve ${info.parentType}.${info.fieldName}`,
run: (state, _parent, _args, _context, info)=>state.evaluateScopeMap(authScopes, info)
};

@@ -72,3 +72,3 @@ }

return {
errorMessage: (parent, args, context, info)=>`Unknown issue generating grants for ${info.parentType}.${info.fieldName}`,
errorMessage: (_parent, _args, _context, info)=>`Unknown issue generating grants for ${info.parentType}.${info.fieldName}`,
run: (state, parent, args, context, info)=>{

@@ -93,4 +93,4 @@ if (typeof grantScopes !== 'function') {

return {
errorMessage: (parent, args, context, info)=>`Unknown issue resolving ${info.parentType}.${info.fieldName}`,
run: (state, parent, args, context, info, setResolved)=>{
errorMessage: (_parent, _args, _context, info)=>`Unknown issue resolving ${info.parentType}.${info.fieldName}`,
run: (_state, parent, args, context, info, setResolved)=>{
const result = resolver(parent, args, context, info);

@@ -97,0 +97,0 @@ if ((0, _core.isThenable)(result)) {

{
"name": "@pothos/plugin-scope-auth",
"version": "4.0.2",
"version": "4.1.0",
"description": "A Pothos plugin for adding scope based authorization checks to your GraphQL Schema",

@@ -44,14 +44,14 @@ "main": "./lib/index.js",

"peerDependencies": {
"@pothos/core": "4.0.2",
"@pothos/core": "*",
"graphql": ">=16.6.0"
},
"devDependencies": {
"@prisma/client": "^5.16.2",
"@prisma/client": "^5.17.0",
"graphql": "^16.8.1",
"graphql-tag": "^2.12.6",
"prisma": "^5.16.2",
"@pothos/core": "4.0.2",
"@pothos/plugin-prisma": "4.0.3",
"@pothos/plugin-relay": "4.0.2",
"@pothos/test-utils": "2.0.1"
"prisma": "^5.17.0",
"@pothos/core": "4.1.0",
"@pothos/plugin-prisma": "4.2.0",
"@pothos/plugin-relay": "4.1.0",
"@pothos/test-utils": "2.1.0"
},

@@ -58,0 +58,0 @@ "gitHead": "9dfe52f1975f41a111e01bf96a20033a914e2acc",

@@ -6,3 +6,3 @@ import {

QueryFieldBuilder,
SchemaTypes,
type SchemaTypes,
SubscriptionFieldBuilder,

@@ -56,3 +56,2 @@ } from '@pothos/core';

// eslint-disable-next-line no-param-reassign
builder.createField = function createField(options) {

@@ -59,0 +58,0 @@ return originalCreateField.call(this, {

@@ -1,3 +0,2 @@

/* eslint-disable @typescript-eslint/no-unused-vars */
import {
import type {
FieldKind,

@@ -4,0 +3,0 @@ FieldNullability,

import './global-types';
import './schema-builder';
import './field-builders';
import { GraphQLFieldResolver, GraphQLIsTypeOfFn, GraphQLTypeResolver } from 'graphql';
import SchemaBuilder, {
BasePlugin,
FieldKind,
PothosInterfaceTypeConfig,
PothosMutationTypeConfig,
PothosObjectTypeConfig,
PothosOutputFieldConfig,
PothosQueryTypeConfig,
type FieldKind,
type PothosInterfaceTypeConfig,
type PothosMutationTypeConfig,
type PothosObjectTypeConfig,
type PothosOutputFieldConfig,
type PothosQueryTypeConfig,
PothosSchemaError,
PothosSubscriptionTypeConfig,
PothosUnionTypeConfig,
type PothosSubscriptionTypeConfig,
type PothosUnionTypeConfig,
RootFieldBuilder,
SchemaTypes,
type SchemaTypes,
} from '@pothos/core';
import type { GraphQLFieldResolver, GraphQLIsTypeOfFn, GraphQLTypeResolver } from 'graphql';
import { isTypeOfHelper } from './is-type-of-helper';

@@ -29,3 +29,3 @@ import RequestCache from './request-cache';

} from './steps';
import { ResolveStep, TypeAuthScopes, TypeGrantScopes } from './types';
import type { ResolveStep, TypeAuthScopes, TypeGrantScopes } from './types';

@@ -124,3 +124,2 @@ export { RequestCache };

resolveType: GraphQLTypeResolver<unknown, Types['Context']>,
typeConfig: PothosInterfaceTypeConfig | PothosUnionTypeConfig,
): GraphQLTypeResolver<unknown, Types['Context']> {

@@ -208,3 +207,3 @@ return (...args) => {

) {
interfaceConfigs.forEach((interfaceConfig) => {
for (const interfaceConfig of interfaceConfigs) {
if (interfaceConfig.pothosOptions.authScopes) {

@@ -218,3 +217,3 @@ steps.push(

}
});
}
}

@@ -221,0 +220,0 @@

@@ -1,3 +0,3 @@

import { GraphQLIsTypeOfFn, GraphQLResolveInfo } from 'graphql';
import { isThenable, MaybePromise, SchemaTypes } from '@pothos/core';
import { type MaybePromise, type SchemaTypes, isThenable } from '@pothos/core';
import type { GraphQLIsTypeOfFn, GraphQLResolveInfo } from 'graphql';
import { ForbiddenError } from './errors';

@@ -4,0 +4,0 @@ import RequestCache from './request-cache';

@@ -1,17 +0,16 @@

/* eslint-disable @typescript-eslint/promise-function-async */
import { GraphQLResolveInfo } from 'graphql';
import {
type MaybePromise,
type Path,
PothosValidationError,
type SchemaTypes,
createContextCache,
isThenable,
MaybePromise,
Path,
PothosValidationError,
SchemaTypes,
} from '@pothos/core';
import type { GraphQLResolveInfo } from 'graphql';
import {
AuthFailure,
type AuthFailure,
AuthScopeFailureType,
AuthScopeMap,
ScopeLoaderMap,
TypeAuthScopesFunction,
type AuthScopeMap,
type ScopeLoaderMap,
type TypeAuthScopesFunction,
} from './types';

@@ -98,3 +97,5 @@ import { cacheKey, canCache } from './util';

scopes.forEach((scope) => set.add(scope));
for (const scope of scopes) {
set.add(scope);
}
} else {

@@ -170,3 +171,3 @@ this.grantCache.set(key, new Set(scopes));

let result;
let result: MaybePromise<boolean>;

@@ -259,3 +260,2 @@ if (this.treatErrorsAsUnauthorized) {

}
// eslint-disable-next-line no-continue
continue;

@@ -362,3 +362,3 @@ }

let hasSuccess = false;
results.forEach((result) => {
for (const result of results) {
if (result) {

@@ -369,3 +369,3 @@ problems.push(result);

}
});
}

@@ -432,3 +432,3 @@ if (forAll) {

if (!cache.has(parent)) {
let result;
let result: ReturnType<TypeAuthScopesFunction<Types, unknown>>;

@@ -435,0 +435,0 @@ if (this.treatErrorsAsUnauthorized) {

@@ -1,6 +0,11 @@

import { GraphQLResolveInfo } from 'graphql';
import { isThenable, MaybePromise, PothosOutputFieldConfig, SchemaTypes } from '@pothos/core';
import {
type MaybePromise,
type PothosOutputFieldConfig,
type SchemaTypes,
isThenable,
} from '@pothos/core';
import type { GraphQLResolveInfo } from 'graphql';
import { ForbiddenError } from './errors';
import RequestCache from './request-cache';
import { AuthScopeFailureType, ResolveStep, UnauthorizedResolver } from './types';
import { AuthScopeFailureType, type ResolveStep, type UnauthorizedResolver } from './types';

@@ -30,3 +35,3 @@ import type { PothosScopeAuthPlugin, UnauthorizedErrorFn } from '.';

parent,
args,
_args,
context,

@@ -63,3 +68,2 @@ info,

// eslint-disable-next-line @typescript-eslint/no-loop-func
const stepResult = run(cache, parent, args, context, info, (val) => {

@@ -66,0 +70,0 @@ resolvedValue = val;

@@ -1,9 +0,8 @@

import SchemaBuilder, { isThenable, MaybePromise, SchemaTypes } from '@pothos/core';
import SchemaBuilder, { isThenable, type MaybePromise, type SchemaTypes } from '@pothos/core';
import { ForbiddenError } from './errors';
import RequestCache from './request-cache';
import { AuthFailure } from './types';
import type { AuthFailure } from './types';
const schemaBuilderProto = SchemaBuilder.prototype as PothosSchemaTypes.SchemaBuilder<SchemaTypes>;
// eslint-disable-next-line consistent-return
schemaBuilderProto.runAuthScopes = function runAuthScopes(

@@ -10,0 +9,0 @@ context,

@@ -1,4 +0,4 @@

import { GraphQLFieldResolver } from 'graphql';
import { isThenable, SchemaTypes } from '@pothos/core';
import {
import { type SchemaTypes, isThenable } from '@pothos/core';
import type { GraphQLFieldResolver } from 'graphql';
import type {
FieldAuthScopes,

@@ -17,3 +17,3 @@ FieldGrantScopes,

return {
run: (state, parent, args, context, info) =>
run: (state, parent, _args, _context, info) =>
state.evaluateTypeScopeFunction(authScopes, type, parent, info),

@@ -25,3 +25,3 @@ errorMessage: `Not authorized to read fields for ${type}`,

return {
run: (state, parent, args, context, info) => state.evaluateScopeMap(authScopes, info),
run: (state, _parent, _args, _context, info) => state.evaluateScopeMap(authScopes, info),
errorMessage: `Not authorized to read fields for ${type}`,

@@ -37,3 +37,3 @@ };

return {
run: (state, parent, args, context, info) =>
run: (state, parent, _args, context, info) =>
state.grantTypeScopes(type, parent, forField ? info.path.prev : info.path, () =>

@@ -51,3 +51,3 @@ grantScopes(parent, context),

return {
errorMessage: (parent, args, context, info) =>
errorMessage: (_parent, _args, _context, info) =>
`Not authorized to resolve ${info.parentType}.${info.fieldName}`,

@@ -67,5 +67,5 @@ run: (state, parent, args, context, info) => {

return {
errorMessage: (parent, args, context, info) =>
errorMessage: (_parent, _args, _context, info) =>
`Not authorized to resolve ${info.parentType}.${info.fieldName}`,
run: (state, parent, args, context, info) => state.evaluateScopeMap(authScopes, info),
run: (state, _parent, _args, _context, info) => state.evaluateScopeMap(authScopes, info),
};

@@ -78,3 +78,3 @@ }

return {
errorMessage: (parent, args, context, info) =>
errorMessage: (_parent, _args, _context, info) =>
`Unknown issue generating grants for ${info.parentType}.${info.fieldName}`,

@@ -108,5 +108,5 @@ run: (state, parent, args, context, info) => {

return {
errorMessage: (parent, args, context, info) =>
errorMessage: (_parent, _args, _context, info) =>
`Unknown issue resolving ${info.parentType}.${info.fieldName}`,
run: (state, parent, args, context, info, setResolved) => {
run: (_state, parent, args, context, info, setResolved) => {
const result: unknown = resolver(parent, args, context, info);

@@ -113,0 +113,0 @@

@@ -1,3 +0,2 @@

import { GraphQLResolveInfo } from 'graphql';
import {
import type {
FieldNullability,

@@ -13,2 +12,3 @@ InputFieldMap,

} from '@pothos/core';
import type { GraphQLResolveInfo } from 'graphql';
import type RequestCache from './request-cache';

@@ -157,2 +157,3 @@

type ContextForAuthUnion<Types extends SchemaTypes, Scopes> = Scopes extends (
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
...args: any[]

@@ -159,0 +160,0 @@ ) => infer R

@@ -1,2 +0,2 @@

import { Path, PothosFieldConfig, SchemaTypes } from '@pothos/core';
import type { Path, PothosFieldConfig, SchemaTypes } from '@pothos/core';

@@ -3,0 +3,0 @@ import type { AuthScopeMap } from '.';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc