@zenstackhq/runtime 2.1.2 → 2.2.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.
@@ -3,7 +3,7 @@ import { CrudFailureReason } from '../../constants';
3
3
  import { CrudContract, DbClientContract, PolicyCrudKind, PolicyOperationKind } from '../../types';
4
4
  import type { EnhancementContext, InternalEnhancementOptions } from '../create-enhancement';
5
5
  import { QueryUtils } from '../query-utils';
6
- import type { CheckerFunc } from '../types';
6
+ import type { EntityChecker, PermissionCheckerFunc } from '../types';
7
7
  /**
8
8
  * Access policy enforcement utilities
9
9
  */
@@ -34,8 +34,9 @@ export declare class PolicyUtil extends QueryUtils {
34
34
  private makeTrue;
35
35
  private makeFalse;
36
36
  private reduce;
37
- private readonly FULLY_OPEN_AUTH_GUARD;
38
- private getModelAuthGuard;
37
+ private readonly FULL_OPEN_MODEL_POLICY;
38
+ private getModelPolicyDef;
39
+ private getModelGuardForOperation;
39
40
  /**
40
41
  * Gets pregenerated authorization guard object for a given model and operation.
41
42
  *
@@ -43,6 +44,10 @@ export declare class PolicyUtil extends QueryUtils {
43
44
  * otherwise returns a guard object
44
45
  */
45
46
  getAuthGuard(db: CrudContract, model: string, operation: PolicyOperationKind, preValue?: any): object;
47
+ /**
48
+ * Get field-level read auth guard
49
+ */
50
+ getFieldReadAuthGuard(db: CrudContract, model: string, field: string): object;
46
51
  /**
47
52
  * Get field-level read auth guard that overrides the model-level
48
53
  */
@@ -73,9 +78,9 @@ export declare class PolicyUtil extends QueryUtils {
73
78
  * Injects model auth guard as where clause.
74
79
  */
75
80
  injectAuthGuardAsWhere(db: CrudContract, args: any, model: string, operation: PolicyOperationKind): boolean;
76
- private injectGuardForRelationFields;
77
- private injectGuardForToManyField;
78
- private injectGuardForToOneField;
81
+ private injectReadGuardForRelationFields;
82
+ private injectReadGuardForToManyField;
83
+ private injectReadGuardForToOneField;
79
84
  /**
80
85
  * Injects auth guard for read operations.
81
86
  */
@@ -83,8 +88,7 @@ export declare class PolicyUtil extends QueryUtils {
83
88
  /**
84
89
  * Gets checker constraints for the given model and operation.
85
90
  */
86
- getCheckerConstraint(model: string, operation: PolicyCrudKind): ReturnType<CheckerFunc> | boolean;
87
- private getModelChecker;
91
+ getCheckerConstraint(model: string, operation: PolicyCrudKind): ReturnType<PermissionCheckerFunc> | boolean;
88
92
  /**
89
93
  * Gets unique constraints for the given model.
90
94
  */
@@ -95,8 +99,11 @@ export declare class PolicyUtil extends QueryUtils {
95
99
  * Rejects with an error if not allowed.
96
100
  */
97
101
  checkPolicyForUnique(model: string, uniqueFilter: any, operation: PolicyOperationKind, db: CrudContract, args: any, preValue?: any): Promise<void>;
102
+ getEntityChecker(model: string, operation: PolicyOperationKind, field?: string): EntityChecker | undefined;
103
+ getUpdateOverrideEntityCheckerForField(model: string, field: string): EntityChecker | undefined;
98
104
  private getFieldReadGuards;
99
105
  private getFieldUpdateGuards;
106
+ private combineEntityChecker;
100
107
  /**
101
108
  * Tries rejecting a request based on static "false" policy.
102
109
  */
@@ -116,8 +123,8 @@ export declare class PolicyUtil extends QueryUtils {
116
123
  error?: Error;
117
124
  }>;
118
125
  /**
119
- * Injects field selection needed for checking field-level read policy into query args.
120
- * @returns
126
+ * Injects field selection needed for checking field-level read policy check and evaluating
127
+ * entity checker into query args.
121
128
  */
122
129
  injectReadCheckSelect(model: string, args: any): void;
123
130
  private doInjectReadCheckSelect;
@@ -128,7 +135,7 @@ export declare class PolicyUtil extends QueryUtils {
128
135
  * Gets field selection for fetching pre-update entity values for the given model.
129
136
  */
130
137
  getPreValueSelect(model: string): object | undefined;
131
- private getReadFieldSelect;
138
+ private getFieldReadCheckSelector;
132
139
  private checkReadField;
133
140
  private hasFieldValidation;
134
141
  private hasFieldLevelPolicy;
@@ -141,7 +148,7 @@ export declare class PolicyUtil extends QueryUtils {
141
148
  /**
142
149
  * Post processing checks and clean-up for read model entities.
143
150
  */
144
- postProcessForRead(data: any, model: string, queryArgs: any): void;
151
+ postProcessForRead(data: any, model: string, queryArgs: any): any;
145
152
  private doPostProcessForRead;
146
153
  /**
147
154
  * Clones an object and makes sure it's not empty.
@@ -156,7 +163,6 @@ export declare class PolicyUtil extends QueryUtils {
156
163
  */
157
164
  pick<T>(value: T, ...props: (keyof T)[]): Pick<T, (typeof props)[number]>;
158
165
  private mergeWhereClause;
159
- private requireGuard;
160
166
  /**
161
167
  * Given an entity data, returns an object only containing id fields.
162
168
  */