@envelop/generic-auth 4.3.0-alpha-e9434aa.0 → 4.3.0-alpha-05dbec7.0

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.
Files changed (2) hide show
  1. package/esm/index.js +14 -21
  2. package/package.json +3 -3
package/esm/index.js CHANGED
@@ -1,32 +1,26 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useGenericAuth = exports.defaultProtectSingleValidateFn = exports.defaultProtectAllValidateFn = exports.SKIP_AUTH_DIRECTIVE_SDL = exports.DIRECTIVE_SDL = exports.UnauthenticatedError = void 0;
4
- const graphql_1 = require("graphql");
5
- const extended_validation_1 = require("@envelop/extended-validation");
6
- class UnauthenticatedError extends graphql_1.GraphQLError {
1
+ import { getNamedType, GraphQLError, isInterfaceType, isIntrospectionType, isObjectType, isUnionType, } from 'graphql';
2
+ import { useExtendedValidation } from '@envelop/extended-validation';
3
+ export class UnauthenticatedError extends GraphQLError {
7
4
  }
8
- exports.UnauthenticatedError = UnauthenticatedError;
9
- exports.DIRECTIVE_SDL = `
5
+ export const DIRECTIVE_SDL = /* GraphQL */ `
10
6
  directive @auth on FIELD_DEFINITION
11
7
  `;
12
- exports.SKIP_AUTH_DIRECTIVE_SDL = `
8
+ export const SKIP_AUTH_DIRECTIVE_SDL = /* GraphQL */ `
13
9
  directive @skipAuth on FIELD_DEFINITION
14
10
  `;
15
- function defaultProtectAllValidateFn(params) {
11
+ export function defaultProtectAllValidateFn(params) {
16
12
  if (params.user == null && !params.fieldAuthDirectiveNode && !params.fieldAuthExtension) {
17
13
  const schemaCoordinate = `${params.objectType.name}.${params.fieldNode.name.value}`;
18
14
  return new UnauthenticatedError(`Accessing '${schemaCoordinate}' requires authentication.`, [params.fieldNode]);
19
15
  }
20
16
  }
21
- exports.defaultProtectAllValidateFn = defaultProtectAllValidateFn;
22
- function defaultProtectSingleValidateFn(params) {
17
+ export function defaultProtectSingleValidateFn(params) {
23
18
  if (params.user == null && (params.fieldAuthDirectiveNode || params.fieldAuthExtension)) {
24
19
  const schemaCoordinate = `${params.objectType.name}.${params.fieldNode.name.value}`;
25
20
  return new UnauthenticatedError(`Accessing '${schemaCoordinate}' requires authentication.`, [params.fieldNode]);
26
21
  }
27
22
  }
28
- exports.defaultProtectSingleValidateFn = defaultProtectSingleValidateFn;
29
- const useGenericAuth = (options) => {
23
+ export const useGenericAuth = (options) => {
30
24
  var _a, _b;
31
25
  const contextFieldName = options.contextFieldName || 'currentUser';
32
26
  if (options.mode === 'protect-all' || options.mode === 'protect-granular') {
@@ -41,7 +35,7 @@ const useGenericAuth = (options) => {
41
35
  };
42
36
  return {
43
37
  onPluginInit({ addPlugin }) {
44
- addPlugin((0, extended_validation_1.useExtendedValidation)({
38
+ addPlugin(useExtendedValidation({
45
39
  rules: [
46
40
  function AuthorizationExtendedValidationRule(context, args) {
47
41
  const user = args.contextValue[contextFieldName];
@@ -65,19 +59,19 @@ const useGenericAuth = (options) => {
65
59
  };
66
60
  return {
67
61
  Field(node) {
68
- const fieldType = (0, graphql_1.getNamedType)(context.getParentType());
69
- if ((0, graphql_1.isIntrospectionType)(fieldType)) {
62
+ const fieldType = getNamedType(context.getParentType());
63
+ if (isIntrospectionType(fieldType)) {
70
64
  return false;
71
65
  }
72
- if ((0, graphql_1.isObjectType)(fieldType)) {
66
+ if (isObjectType(fieldType)) {
73
67
  handleField(node, fieldType);
74
68
  }
75
- else if ((0, graphql_1.isUnionType)(fieldType)) {
69
+ else if (isUnionType(fieldType)) {
76
70
  for (const objectType of fieldType.getTypes()) {
77
71
  handleField(node, objectType);
78
72
  }
79
73
  }
80
- else if ((0, graphql_1.isInterfaceType)(fieldType)) {
74
+ else if (isInterfaceType(fieldType)) {
81
75
  for (const objectType of args.schema.getImplementations(fieldType).objects) {
82
76
  handleField(node, objectType);
83
77
  }
@@ -109,4 +103,3 @@ const useGenericAuth = (options) => {
109
103
  }
110
104
  return {};
111
105
  };
112
- exports.useGenericAuth = useGenericAuth;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@envelop/generic-auth",
3
- "version": "4.3.0-alpha-e9434aa.0",
3
+ "version": "4.3.0-alpha-05dbec7.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "2.4.0-alpha-e9434aa.0",
6
+ "@envelop/core": "2.4.0-alpha-05dbec7.0",
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "dependencies": {
10
- "@envelop/extended-validation": "1.7.0-alpha-e9434aa.0"
10
+ "@envelop/extended-validation": "1.7.0-alpha-05dbec7.0"
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",