@envelop/generic-auth 4.0.0-alpha-7aee595.0 → 4.0.0-alpha-4519bb8.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.
- package/index.d.ts +5 -5
- package/index.js +4 -4
- package/index.mjs +4 -4
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -39,10 +39,10 @@ export declare type GenericAuthPluginOptions<UserType extends {} = {}, ContextTy
|
|
|
39
39
|
*/
|
|
40
40
|
mode: 'protect-all';
|
|
41
41
|
/**
|
|
42
|
-
* Overrides the default directive name
|
|
42
|
+
* Overrides the default directive name or extension field for marking a field available for unauthorized users.
|
|
43
43
|
* @default skipAuth
|
|
44
44
|
*/
|
|
45
|
-
|
|
45
|
+
directiveOrExtensionFieldName?: 'skipAuth' | string;
|
|
46
46
|
/**
|
|
47
47
|
* Customize how the user is validated. E.g. apply authorization role based validation.
|
|
48
48
|
* The validation is applied during the extended validation phase.
|
|
@@ -60,12 +60,12 @@ export declare type GenericAuthPluginOptions<UserType extends {} = {}, ContextTy
|
|
|
60
60
|
* resolves the user and inject to authenticated user into the `context`.
|
|
61
61
|
* And checks for `@auth` directives usages to run validation automatically.
|
|
62
62
|
*/
|
|
63
|
-
mode: 'protect-
|
|
63
|
+
mode: 'protect-granular';
|
|
64
64
|
/**
|
|
65
|
-
* Overrides the default directive name
|
|
65
|
+
* Overrides the default directive name or extension field for marking a field available only for authorized users.
|
|
66
66
|
* @default auth
|
|
67
67
|
*/
|
|
68
|
-
|
|
68
|
+
directiveOrExtensionFieldName?: 'auth' | string;
|
|
69
69
|
/**
|
|
70
70
|
* Customize how the user is validated. E.g. apply authorization role based validation.
|
|
71
71
|
* The validation is applied during the extended validation phase.
|
package/index.js
CHANGED
|
@@ -28,14 +28,14 @@ function defaultProtectSingleValidateFn(params) {
|
|
|
28
28
|
const useGenericAuth = (options) => {
|
|
29
29
|
var _a, _b;
|
|
30
30
|
const contextFieldName = options.contextFieldName || 'currentUser';
|
|
31
|
-
if (options.mode === 'protect-all' || options.mode === 'protect-
|
|
32
|
-
const
|
|
31
|
+
if (options.mode === 'protect-all' || options.mode === 'protect-granular') {
|
|
32
|
+
const directiveOrExtensionFieldName = (_a = options.directiveOrExtensionFieldName) !== null && _a !== void 0 ? _a : (options.mode === 'protect-all' ? 'skipAuth' : 'auth');
|
|
33
33
|
const validateUser = (_b = options.validateUser) !== null && _b !== void 0 ? _b : (options.mode === 'protect-all' ? defaultProtectAllValidateFn : defaultProtectSingleValidateFn);
|
|
34
34
|
const extractAuthMeta = (input) => {
|
|
35
35
|
var _a, _b, _c;
|
|
36
36
|
return {
|
|
37
|
-
fieldAuthExtension: (_a = input.extensions) === null || _a === void 0 ? void 0 : _a[
|
|
38
|
-
fieldAuthDirectiveNode: (_c = (_b = input.astNode) === null || _b === void 0 ? void 0 : _b.directives) === null || _c === void 0 ? void 0 : _c.find(directive => directive.name.value ===
|
|
37
|
+
fieldAuthExtension: (_a = input.extensions) === null || _a === void 0 ? void 0 : _a[directiveOrExtensionFieldName],
|
|
38
|
+
fieldAuthDirectiveNode: (_c = (_b = input.astNode) === null || _b === void 0 ? void 0 : _b.directives) === null || _c === void 0 ? void 0 : _c.find(directive => directive.name.value === directiveOrExtensionFieldName),
|
|
39
39
|
};
|
|
40
40
|
};
|
|
41
41
|
return {
|
package/index.mjs
CHANGED
|
@@ -24,14 +24,14 @@ function defaultProtectSingleValidateFn(params) {
|
|
|
24
24
|
const useGenericAuth = (options) => {
|
|
25
25
|
var _a, _b;
|
|
26
26
|
const contextFieldName = options.contextFieldName || 'currentUser';
|
|
27
|
-
if (options.mode === 'protect-all' || options.mode === 'protect-
|
|
28
|
-
const
|
|
27
|
+
if (options.mode === 'protect-all' || options.mode === 'protect-granular') {
|
|
28
|
+
const directiveOrExtensionFieldName = (_a = options.directiveOrExtensionFieldName) !== null && _a !== void 0 ? _a : (options.mode === 'protect-all' ? 'skipAuth' : 'auth');
|
|
29
29
|
const validateUser = (_b = options.validateUser) !== null && _b !== void 0 ? _b : (options.mode === 'protect-all' ? defaultProtectAllValidateFn : defaultProtectSingleValidateFn);
|
|
30
30
|
const extractAuthMeta = (input) => {
|
|
31
31
|
var _a, _b, _c;
|
|
32
32
|
return {
|
|
33
|
-
fieldAuthExtension: (_a = input.extensions) === null || _a === void 0 ? void 0 : _a[
|
|
34
|
-
fieldAuthDirectiveNode: (_c = (_b = input.astNode) === null || _b === void 0 ? void 0 : _b.directives) === null || _c === void 0 ? void 0 : _c.find(directive => directive.name.value ===
|
|
33
|
+
fieldAuthExtension: (_a = input.extensions) === null || _a === void 0 ? void 0 : _a[directiveOrExtensionFieldName],
|
|
34
|
+
fieldAuthDirectiveNode: (_c = (_b = input.astNode) === null || _b === void 0 ? void 0 : _b.directives) === null || _c === void 0 ? void 0 : _c.find(directive => directive.name.value === directiveOrExtensionFieldName),
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
37
|
return {
|