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 3.9.1 to 3.10.0

dts/field-builders.d.ts

11

CHANGELOG.md
# Change Log
## 3.10.0
### Minor Changes
- 7311904e: Add withAuth method to return a field builder to allow custom auth context with other
plugin methods
### Patch Changes
- 7311904e: Update dev deps
## 3.9.1

@@ -4,0 +15,0 @@

23

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

@@ -59,4 +59,25 @@ declare global {

}
interface QueryFieldBuilder<Types extends SchemaTypes, ParentShape> {
withAuth: <Scopes extends FieldAuthScopes<Types, ParentShape, Record<string, unknown>>>(scopes: Scopes) => QueryFieldBuilder<ReplaceContext<Types, ContextForAuth<Types, Scopes> & object>, ParentShape>;
}
interface MutationFieldBuilder<Types extends SchemaTypes, ParentShape> {
withAuth: <Scopes extends FieldAuthScopes<Types, ParentShape, Record<string, unknown>>>(scopes: Scopes) => MutationFieldBuilder<ReplaceContext<Types, ContextForAuth<Types, Scopes> & object>, ParentShape>;
}
interface SubscriptionFieldBuilder<Types extends SchemaTypes, ParentShape> {
withAuth: <Scopes extends FieldAuthScopes<Types, ParentShape, Record<string, unknown>>>(scopes: Scopes) => SubscriptionFieldBuilder<ReplaceContext<Types, ContextForAuth<Types, Scopes> & object>, ParentShape>;
}
interface ObjectFieldBuilder<Types extends SchemaTypes, ParentShape> {
withAuth: <Scopes extends FieldAuthScopes<Types, ParentShape, Record<string, unknown>>>(scopes: Scopes) => ObjectFieldBuilder<ReplaceContext<Types, ContextForAuth<Types, Scopes> & object>, ParentShape>;
}
interface InterfaceFieldBuilder<Types extends SchemaTypes, ParentShape> {
withAuth: <Scopes extends FieldAuthScopes<Types, ParentShape, Record<string, unknown>>>(scopes: Scopes) => InterfaceFieldBuilder<ReplaceContext<Types, ContextForAuth<Types, Scopes> & object>, ParentShape>;
}
interface ScopeAuthFieldAuthScopes<Types extends SchemaTypes, Parent, Args extends {} = {}> {
Scopes: FieldAuthScopes<Types, Parent, Args>;
}
interface ScopeAuthContextForAuth<Types extends SchemaTypes, Scopes extends {}> {
Context: ContextForAuth<Types, Scopes>;
}
}
}
//# sourceMappingURL=global-types.d.ts.map
import './global-types';
import './schema-builder';
import './field-builders';
import { GraphQLFieldResolver, GraphQLIsTypeOfFn, GraphQLTypeResolver } from 'graphql';

@@ -4,0 +5,0 @@ import { BasePlugin, PothosInterfaceTypeConfig, PothosMutationTypeConfig, PothosObjectTypeConfig, PothosOutputFieldConfig, PothosQueryTypeConfig, PothosSubscriptionTypeConfig, PothosUnionTypeConfig, SchemaTypes } from '@pothos/core';

@@ -72,2 +72,5 @@ import { GraphQLResolveInfo } from 'graphql';

}
export declare type ReplaceContext<Types extends SchemaTypes, Context extends object> = Omit<Types, 'Context'> & {
Context: Context;
};
//# sourceMappingURL=types.d.ts.map

11

esm/index.js
import './global-types.js';
import './schema-builder.js';
import './field-builders.js';
import SchemaBuilder, { BasePlugin, RootFieldBuilder } from '@pothos/core';

@@ -43,8 +44,8 @@ import { isTypeOfHelper } from './is-type-of-helper.js';

wrapIsTypeOf(isTypeOf, typeConfig) {
var ref3;
var ref;
if (this.options.disableScopeAuth) {
return isTypeOf;
}
var _runScopesOnType, ref2;
const shouldRunTypeScopes = (ref2 = (_runScopesOnType = typeConfig.pothosOptions.runScopesOnType) !== null && _runScopesOnType !== void 0 ? _runScopesOnType : (ref3 = this.builder.options.scopeAuthOptions) === null || ref3 === void 0 ? void 0 : ref3.runScopesOnType) !== null && ref2 !== void 0 ? ref2 : false;
var _runScopesOnType, ref1;
const shouldRunTypeScopes = (ref1 = (_runScopesOnType = typeConfig.pothosOptions.runScopesOnType) !== null && _runScopesOnType !== void 0 ? _runScopesOnType : (ref = this.builder.options.scopeAuthOptions) === null || ref === void 0 ? void 0 : ref.runScopesOnType) !== null && ref1 !== void 0 ? ref1 : false;
if (!shouldRunTypeScopes) {

@@ -89,6 +90,6 @@ return isTypeOf;

createResolveSteps(fieldConfig, typeConfig, resolver, shouldRunTypeScopes) {
var ref, ref4;
var ref, ref1;
const stepsForType = shouldRunTypeScopes ? this.createStepsForType(typeConfig, {
skipTypeScopes: (ref = (fieldConfig.graphqlKind === "Interface" || fieldConfig.graphqlKind === "Object") && fieldConfig.pothosOptions.skipTypeScopes) !== null && ref !== void 0 ? ref : false,
skipInterfaceScopes: (ref4 = (fieldConfig.graphqlKind === "Interface" || fieldConfig.kind === "Object") && fieldConfig.pothosOptions.skipInterfaceScopes) !== null && ref4 !== void 0 ? ref4 : false,
skipInterfaceScopes: (ref1 = (fieldConfig.graphqlKind === "Interface" || fieldConfig.kind === "Object") && fieldConfig.pothosOptions.skipInterfaceScopes) !== null && ref1 !== void 0 ? ref1 : false,
forField: true

@@ -95,0 +96,0 @@ }) : [];

@@ -185,11 +185,11 @@ import { isThenable } from '@pothos/core';

for (const [loaderName, arg] of loaderList) {
const result = this.evaluateScopeLoader(scopes, loaderName, arg);
if (isThenable(result)) {
promises.push(result);
const result1 = this.evaluateScopeLoader(scopes, loaderName, arg);
if (isThenable(result1)) {
promises.push(result1);
}
else if (result === null && !forAll) {
else if (result1 === null && !forAll) {
return resolveAndReturn(null);
}
else if (result) {
problems.push(result);
else if (result1) {
problems.push(result1);
if (forAll) {

@@ -196,0 +196,0 @@ return resolveAndReturn(failure);

@@ -5,3 +5,7 @@ "use strict";

});
var _ = require(".");
Object.defineProperty(exports, "ForbiddenError", {
get: ()=>ForbiddenError,
enumerable: true
});
const _ = require(".");
class ForbiddenError extends Error {

@@ -20,4 +24,3 @@ constructor(message, result){

}
exports.ForbiddenError = ForbiddenError;
//# sourceMappingURL=errors.js.map

@@ -5,36 +5,32 @@ "use strict";

});
var _exportNames = {
PothosScopeAuthPlugin: true
};
exports.default = void 0;
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
get: all[name],
enumerable: true
});
}
_export(exports, {
PothosScopeAuthPlugin: ()=>PothosScopeAuthPlugin,
default: ()=>_default
});
require("./global-types");
require("./schema-builder");
var _core = _interopRequireWildcard(require("@pothos/core"));
var _isTypeOfHelper = require("./is-type-of-helper");
var _resolveHelper = require("./resolve-helper");
var _steps = require("./steps");
var _errors = _interopRequireWildcard(require("./errors"));
Object.keys(_errors).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _errors[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _errors[key];
}
require("./field-builders");
const _core = _interopRequireWildcard(require("@pothos/core"));
const _isTypeOfHelper = require("./is-type-of-helper");
const _resolveHelper = require("./resolve-helper");
const _steps = require("./steps");
_exportStar(require("./errors"), exports);
_exportStar(require("./types"), exports);
function _exportStar(from, to) {
Object.keys(from).forEach(function(k) {
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
enumerable: true,
get: function() {
return from[k];
}
});
});
});
var _types = _interopRequireWildcard(require("./types"));
Object.keys(_types).forEach(function(key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
if (key in exports && exports[key] === _types[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function() {
return _types[key];
}
});
});
return from;
}
function _getRequireWildcardCache() {

@@ -81,3 +77,2 @@ if (typeof WeakMap !== "function") return null;

var _default = pluginName;
exports.default = _default;
let inResolveType = false;

@@ -99,3 +94,3 @@ class PothosScopeAuthPlugin extends _core.BasePlugin {

if (steps.length > 1) {
return (0, _resolveHelper).resolveHelper(steps, this, fieldConfig);
return (0, _resolveHelper.resolveHelper)(steps, this, fieldConfig);
}

@@ -115,8 +110,8 @@ return resolver;

wrapIsTypeOf(isTypeOf, typeConfig) {
var ref3;
var ref;
if (this.options.disableScopeAuth) {
return isTypeOf;
}
var _runScopesOnType, ref2;
const shouldRunTypeScopes = (ref2 = (_runScopesOnType = typeConfig.pothosOptions.runScopesOnType) !== null && _runScopesOnType !== void 0 ? _runScopesOnType : (ref3 = this.builder.options.scopeAuthOptions) === null || ref3 === void 0 ? void 0 : ref3.runScopesOnType) !== null && ref2 !== void 0 ? ref2 : false;
var _runScopesOnType, ref1;
const shouldRunTypeScopes = (ref1 = (_runScopesOnType = typeConfig.pothosOptions.runScopesOnType) !== null && _runScopesOnType !== void 0 ? _runScopesOnType : (ref = this.builder.options.scopeAuthOptions) === null || ref === void 0 ? void 0 : ref.runScopesOnType) !== null && ref1 !== void 0 ? ref1 : false;
if (!shouldRunTypeScopes) {

@@ -131,3 +126,3 @@ return isTypeOf;

}
const runSteps = (0, _isTypeOfHelper).isTypeOfHelper(steps, this, isTypeOf);
const runSteps = (0, _isTypeOfHelper.isTypeOfHelper)(steps, this, isTypeOf);
return (source, context, info)=>{

@@ -147,3 +142,3 @@ if (inResolveType) {

if (parentAuthScope && !skipTypeScopes) {
steps.push((0, _steps).createTypeAuthScopesStep(parentAuthScope, typeConfig.name));
steps.push((0, _steps.createTypeAuthScopesStep)(parentAuthScope, typeConfig.name));
}

@@ -153,3 +148,3 @@ if (!skipInterfaceScopes && !(typeConfig.kind === 'Object' && typeConfig.pothosOptions.skipInterfaceScopes)) {

if (interfaceConfig.pothosOptions.authScopes) {
steps.push((0, _steps).createTypeAuthScopesStep(interfaceConfig.pothosOptions.authScopes, interfaceConfig.name));
steps.push((0, _steps.createTypeAuthScopesStep)(interfaceConfig.pothosOptions.authScopes, interfaceConfig.name));
}

@@ -159,3 +154,3 @@ });

if (parentGrantScopes) {
steps.push((0, _steps).createTypeGrantScopesStep(parentGrantScopes, typeConfig.name, forField));
steps.push((0, _steps.createTypeGrantScopesStep)(parentGrantScopes, typeConfig.name, forField));
}

@@ -165,6 +160,6 @@ return steps;

createResolveSteps(fieldConfig, typeConfig, resolver, shouldRunTypeScopes) {
var ref, ref4;
var ref, ref1;
const stepsForType = shouldRunTypeScopes ? this.createStepsForType(typeConfig, {
skipTypeScopes: (ref = (fieldConfig.graphqlKind === 'Interface' || fieldConfig.graphqlKind === 'Object') && fieldConfig.pothosOptions.skipTypeScopes) !== null && ref !== void 0 ? ref : false,
skipInterfaceScopes: (ref4 = (fieldConfig.graphqlKind === 'Interface' || fieldConfig.kind === 'Object') && fieldConfig.pothosOptions.skipInterfaceScopes) !== null && ref4 !== void 0 ? ref4 : false,
skipInterfaceScopes: (ref1 = (fieldConfig.graphqlKind === 'Interface' || fieldConfig.kind === 'Object') && fieldConfig.pothosOptions.skipInterfaceScopes) !== null && ref1 !== void 0 ? ref1 : false,
forField: true

@@ -178,7 +173,7 @@ }) : [];

if (fieldAuthScopes) {
steps.push((0, _steps).createFieldAuthScopesStep(fieldAuthScopes));
steps.push((0, _steps.createFieldAuthScopesStep)(fieldAuthScopes));
}
steps.push((0, _steps).createResolveStep(resolver));
steps.push((0, _steps.createResolveStep)(resolver));
if (fieldGrantScopes) {
steps.push((0, _steps).createFieldGrantScopesStep(fieldGrantScopes));
steps.push((0, _steps.createFieldGrantScopesStep)(fieldGrantScopes));
}

@@ -188,3 +183,2 @@ return steps;

}
exports.PothosScopeAuthPlugin = PothosScopeAuthPlugin;
const fieldBuilderProto = _core.RootFieldBuilder.prototype;

@@ -191,0 +185,0 @@ fieldBuilderProto.authField = function authField(options) {

@@ -5,6 +5,9 @@ "use strict";

});
exports.isTypeOfHelper = isTypeOfHelper;
var _core = require("@pothos/core");
var _requestCache = _interopRequireDefault(require("./request-cache"));
var _ = require(".");
Object.defineProperty(exports, "isTypeOfHelper", {
get: ()=>isTypeOfHelper,
enumerable: true
});
const _core = require("@pothos/core");
const _requestCache = _interopRequireDefault(require("./request-cache"));
const _ = require(".");
function _interopRequireDefault(obj) {

@@ -25,3 +28,3 @@ return obj && obj.__esModule ? obj : {

const stepResult = run(cache, parent, {}, context, info, ()=>{});
if ((0, _core).isThenable(stepResult)) {
if ((0, _core.isThenable)(stepResult)) {
return stepResult.then((result)=>{

@@ -28,0 +31,0 @@ if (result) {

@@ -5,6 +5,9 @@ "use strict";

});
exports.default = void 0;
var _core = require("@pothos/core");
var _util = require("./util");
var _ = require(".");
Object.defineProperty(exports, "default", {
get: ()=>RequestCache,
enumerable: true
});
const _core = require("@pothos/core");
const _util = require("./util");
const _ = require(".");
// eslint-disable-next-line @typescript-eslint/no-explicit-any

@@ -23,3 +26,3 @@ const requestCache = new WeakMap();

const scopes = this.builder.options.authScopes(this.context);
this.scopes = (0, _core).isThenable(scopes) ? scopes.then((resolved)=>{
this.scopes = (0, _core.isThenable)(scopes) ? scopes.then((resolved)=>{
this.scopes = resolved;

@@ -33,3 +36,3 @@ return resolved;

const scopes = this.getScopes();
if ((0, _core).isThenable(scopes)) {
if ((0, _core.isThenable)(scopes)) {
return scopes.then((resolvedScopes)=>cb(resolvedScopes));

@@ -40,3 +43,3 @@ }

saveGrantedScopes(scopes, path) {
const key = (0, _util).cacheKey(path);
const key = (0, _util.cacheKey)(path);
if (this.grantCache.has(key)) {

@@ -52,6 +55,6 @@ const set = this.grantCache.get(key);

var ref, ref1, ref2;
if ((ref = this.grantCache.get((0, _util).cacheKey(path.prev))) === null || ref === void 0 ? void 0 : ref.has(scope)) {
if ((ref = this.grantCache.get((0, _util.cacheKey)(path.prev))) === null || ref === void 0 ? void 0 : ref.has(scope)) {
return true;
}
if (typeof ((ref1 = path.prev) === null || ref1 === void 0 ? void 0 : ref1.key) === 'number' && ((ref2 = this.grantCache.get((0, _util).cacheKey(path.prev.prev))) === null || ref2 === void 0 ? void 0 : ref2.has(scope))) {
if (typeof ((ref1 = path.prev) === null || ref1 === void 0 ? void 0 : ref1.key) === 'number' && ((ref2 = this.grantCache.get((0, _util.cacheKey)(path.prev.prev))) === null || ref2 === void 0 ? void 0 : ref2.has(scope))) {
return true;

@@ -68,3 +71,3 @@ }

const result = cb();
if ((0, _core).isThenable(result)) {
if ((0, _core.isThenable)(result)) {
cache.set(parent, result.then((resolved)=>this.saveGrantedScopes(resolved, path)));

@@ -89,3 +92,3 @@ } else {

const result = loader(arg);
if ((0, _core).isThenable(result)) {
if ((0, _core.isThenable)(result)) {
cache.set(key, result.then((r)=>r ? null : {

@@ -163,3 +166,3 @@ kind: _.AuthScopeFailureType.AuthScope,

const anyResult = this.evaluateScopeMap($any, info);
if ((0, _core).isThenable(anyResult)) {
if ((0, _core.isThenable)(anyResult)) {
promises.push(anyResult);

@@ -177,3 +180,3 @@ } else if (anyResult === null && !forAll) {

const allResult = this.evaluateScopeMap($all, info, true);
if ((0, _core).isThenable(allResult)) {
if ((0, _core.isThenable)(allResult)) {
promises.push(allResult);

@@ -190,9 +193,9 @@ } else if (allResult === null && !forAll) {

for (const [loaderName, arg] of loaderList){
const result = this.evaluateScopeLoader(scopes, loaderName, arg);
if ((0, _core).isThenable(result)) {
promises.push(result);
} else if (result === null && !forAll) {
const result1 = this.evaluateScopeLoader(scopes, loaderName, arg);
if ((0, _core.isThenable)(result1)) {
promises.push(result1);
} else if (result1 === null && !forAll) {
return resolveAndReturn(null);
} else if (result) {
problems.push(result);
} else if (result1) {
problems.push(result1);
if (forAll) {

@@ -235,3 +238,3 @@ return resolveAndReturn(failure);

const result = this.withScopes((scopes)=>this.evaluateScopeMapWithScopes(map, scopes, info, forAll));
if ((0, _util).canCache(map)) {
if ((0, _util.canCache)(map)) {
this.mapCache.set(map, result);

@@ -251,3 +254,3 @@ }

const result = authScopes(parent, this.context);
if ((0, _core).isThenable(result)) {
if ((0, _core.isThenable)(result)) {
cache.set(parent, result.then((resolved)=>this.evaluateScopeMap(resolved, info)));

@@ -272,4 +275,3 @@ } else {

}
exports.default = RequestCache;
//# sourceMappingURL=request-cache.js.map

@@ -5,6 +5,9 @@ "use strict";

});
exports.resolveHelper = resolveHelper;
var _core = require("@pothos/core");
var _errors = require("./errors");
var _requestCache = _interopRequireDefault(require("./request-cache"));
Object.defineProperty(exports, "resolveHelper", {
get: ()=>resolveHelper,
enumerable: true
});
const _core = require("@pothos/core");
const _errors = require("./errors");
const _requestCache = _interopRequireDefault(require("./request-cache"));
function _interopRequireDefault(obj) {

@@ -36,3 +39,3 @@ return obj && obj.__esModule ? obj : {

});
if ((0, _core).isThenable(stepResult)) {
if ((0, _core.isThenable)(stepResult)) {
return stepResult.then((result)=>{

@@ -39,0 +42,0 @@ if (result) {

"use strict";
var _core = _interopRequireWildcard(require("@pothos/core"));
var _requestCache = _interopRequireDefault(require("./request-cache"));
var _ = require(".");
Object.defineProperty(exports, "__esModule", {
value: true
});
const _core = _interopRequireWildcard(require("@pothos/core"));
const _requestCache = _interopRequireDefault(require("./request-cache"));
const _ = require(".");
function _interopRequireDefault(obj) {

@@ -54,3 +57,3 @@ return obj && obj.__esModule ? obj : {

const resultOrPromise = cache.evaluateScopeMap(scopes);
if ((0, _core).isThenable(resultOrPromise)) {
if ((0, _core.isThenable)(resultOrPromise)) {
return resultOrPromise.then(handleScopeResult);

@@ -57,0 +60,0 @@ }

@@ -5,8 +5,16 @@ "use strict";

});
exports.createTypeAuthScopesStep = createTypeAuthScopesStep;
exports.createTypeGrantScopesStep = createTypeGrantScopesStep;
exports.createFieldAuthScopesStep = createFieldAuthScopesStep;
exports.createFieldGrantScopesStep = createFieldGrantScopesStep;
exports.createResolveStep = createResolveStep;
var _core = require("@pothos/core");
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
get: all[name],
enumerable: true
});
}
_export(exports, {
createFieldAuthScopesStep: ()=>createFieldAuthScopesStep,
createFieldGrantScopesStep: ()=>createFieldGrantScopesStep,
createResolveStep: ()=>createResolveStep,
createTypeAuthScopesStep: ()=>createTypeAuthScopesStep,
createTypeGrantScopesStep: ()=>createTypeGrantScopesStep
});
const _core = require("@pothos/core");
function createTypeAuthScopesStep(authScopes, type) {

@@ -36,3 +44,3 @@ if (typeof authScopes === 'function') {

const scopeMap = authScopes(parent, args, context, info);
if ((0, _core).isThenable(scopeMap)) {
if ((0, _core.isThenable)(scopeMap)) {
return scopeMap.then((resolved)=>state.evaluateScopeMap(resolved, info));

@@ -58,3 +66,3 @@ }

const result = grantScopes(parent, args, context, info);
if ((0, _core).isThenable(result)) {
if ((0, _core.isThenable)(result)) {
return result.then((resolved)=>{

@@ -75,3 +83,3 @@ state.saveGrantedScopes(resolved, info.path);

const result = resolver(parent, args, context, info);
if ((0, _core).isThenable(result)) {
if ((0, _core.isThenable)(result)) {
return result.then((resolved)=>{

@@ -78,0 +86,0 @@ setResolved(resolved);

@@ -5,5 +5,7 @@ "use strict";

});
exports.AuthScopeFailureType = void 0;
Object.defineProperty(exports, "AuthScopeFailureType", {
get: ()=>AuthScopeFailureType,
enumerable: true
});
var AuthScopeFailureType;
exports.AuthScopeFailureType = AuthScopeFailureType;
(function(AuthScopeFailureType) {

@@ -16,4 +18,4 @@ AuthScopeFailureType["AuthScope"] = "AuthScope";

AuthScopeFailureType["Unknown"] = "Unknown";
})(AuthScopeFailureType || (exports.AuthScopeFailureType = AuthScopeFailureType = {}));
})(AuthScopeFailureType || (AuthScopeFailureType = {}));
//# sourceMappingURL=types.js.map

@@ -5,5 +5,13 @@ "use strict";

});
exports.canCache = canCache;
exports.cacheKey = cacheKey;
exports.isObjectOrInterface = isObjectOrInterface;
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
get: all[name],
enumerable: true
});
}
_export(exports, {
cacheKey: ()=>cacheKey,
canCache: ()=>canCache,
isObjectOrInterface: ()=>isObjectOrInterface
});
function canCache(map) {

@@ -10,0 +18,0 @@ if (map.$granted) {

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

@@ -32,2 +32,5 @@ "main": "./lib/index.js",

],
"prisma": {
"seed": "node prisma/seed.mjs"
},
"publishConfig": {

@@ -41,6 +44,9 @@ "access": "public"

"devDependencies": {
"@pothos/core": "3.11.1",
"@pothos/test-utils": "1.2.2",
"@pothos/core": "3.12.1",
"@pothos/test-utils": "1.2.3",
"@pothos/plugin-prisma": "3.13.0",
"@prisma/client": "^4.0.0",
"graphql": "16.5.0",
"graphql-tag": "^2.12.6"
"graphql-tag": "^2.12.6",
"prisma": "^4.0.0"
},

@@ -56,4 +62,5 @@ "gitHead": "9dfe52f1975f41a111e01bf96a20033a914e2acc",

"esm:extensions": "TS_NODE_PROJECT=../../tsconfig.json node -r @swc-node/register ../../.config/esm-transformer.ts",
"generate": "prisma generate",
"test": "pnpm jest --runInBand"
}
}

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

# Scope Auth Plugin for Pothos
# Auth Plugin

@@ -453,2 +453,42 @@ The scope auth plugin aims to be a general purpose authorization plugin that can handle a wide

Some plugins contribute field builder methods with additional functionality that may not work with
`t.authField`. In order to work with those methods, there is also a `t.withAuth` method that can be
used to return a field builder with authScopes predefined.
```typescript
type Context = {
user: User | null;
};
const builder = new SchemaBuilder<{
Context: Context;
AuthScopes: {
loggedIn: boolean;
};
AuthContexts: {
loggedIn: Context & { user: User };
};
}>({
plugins: [ScopeAuthPlugin],
authScopes: async (context) => ({
loggedIn: !!context.user,
}),
});
builder.queryField('viewer', (t) =>
t
.withAuth({
loggedIn: true,
})
.prismaField({
type: User,
resolve: (query, root, args, ctx) =>
prisma.findUniqueOrThrow({
...query,
where: { id: ctx.user.id },
}),
}),
);
```
### Logical operations on auth scopes \(any/all\)

@@ -455,0 +495,0 @@

@@ -20,2 +20,3 @@ /* eslint-disable @typescript-eslint/no-unused-vars */

FieldGrantScopes,
ReplaceContext,
ScopeAuthInitializer,

@@ -176,3 +177,59 @@ ScopeAuthPluginOptions,

}
export interface QueryFieldBuilder<Types extends SchemaTypes, ParentShape> {
withAuth: <Scopes extends FieldAuthScopes<Types, ParentShape, Record<string, unknown>>>(
scopes: Scopes,
) => QueryFieldBuilder<
ReplaceContext<Types, ContextForAuth<Types, Scopes> & object>,
ParentShape
>;
}
export interface MutationFieldBuilder<Types extends SchemaTypes, ParentShape> {
withAuth: <Scopes extends FieldAuthScopes<Types, ParentShape, Record<string, unknown>>>(
scopes: Scopes,
) => MutationFieldBuilder<
ReplaceContext<Types, ContextForAuth<Types, Scopes> & object>,
ParentShape
>;
}
export interface SubscriptionFieldBuilder<Types extends SchemaTypes, ParentShape> {
withAuth: <Scopes extends FieldAuthScopes<Types, ParentShape, Record<string, unknown>>>(
scopes: Scopes,
) => SubscriptionFieldBuilder<
ReplaceContext<Types, ContextForAuth<Types, Scopes> & object>,
ParentShape
>;
}
export interface ObjectFieldBuilder<Types extends SchemaTypes, ParentShape> {
withAuth: <Scopes extends FieldAuthScopes<Types, ParentShape, Record<string, unknown>>>(
scopes: Scopes,
) => ObjectFieldBuilder<
ReplaceContext<Types, ContextForAuth<Types, Scopes> & object>,
ParentShape
>;
}
export interface InterfaceFieldBuilder<Types extends SchemaTypes, ParentShape> {
withAuth: <Scopes extends FieldAuthScopes<Types, ParentShape, Record<string, unknown>>>(
scopes: Scopes,
) => InterfaceFieldBuilder<
ReplaceContext<Types, ContextForAuth<Types, Scopes> & object>,
ParentShape
>;
}
export interface ScopeAuthFieldAuthScopes<
Types extends SchemaTypes,
Parent,
Args extends {} = {},
> {
Scopes: FieldAuthScopes<Types, Parent, Args>;
}
export interface ScopeAuthContextForAuth<Types extends SchemaTypes, Scopes extends {}> {
Context: ContextForAuth<Types, Scopes>;
}
}
}
import './global-types';
import './schema-builder';
import './field-builders';
import { GraphQLFieldResolver, GraphQLIsTypeOfFn, GraphQLTypeResolver } from 'graphql';

@@ -4,0 +5,0 @@ import SchemaBuilder, {

@@ -189,1 +189,8 @@ import { GraphQLResolveInfo } from 'graphql';

}
export type ReplaceContext<Types extends SchemaTypes, Context extends object> = Omit<
Types,
'Context'
> & {
Context: Context;
};

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