@zenstackhq/runtime 0.6.0-pre.2 → 1.0.0-alpha.20
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/constants.d.ts +4 -0
- package/constants.js +8 -0
- package/constants.js.map +1 -0
- package/enhancements/index.d.ts +4 -0
- package/enhancements/index.js +21 -0
- package/enhancements/index.js.map +1 -0
- package/enhancements/model-meta.d.ts +9 -0
- package/enhancements/model-meta.js +25 -0
- package/enhancements/model-meta.js.map +1 -0
- package/enhancements/nested-write-vistor.d.ts +65 -0
- package/enhancements/nested-write-vistor.js +155 -0
- package/enhancements/nested-write-vistor.js.map +1 -0
- package/enhancements/omit.d.ts +5 -0
- package/enhancements/omit.js +60 -0
- package/enhancements/omit.js.map +1 -0
- package/enhancements/password.d.ts +5 -0
- package/enhancements/password.js +66 -0
- package/enhancements/password.js.map +1 -0
- package/enhancements/policy/handler.d.ts +36 -0
- package/enhancements/policy/handler.js +278 -0
- package/enhancements/policy/handler.js.map +1 -0
- package/enhancements/policy/index.d.ts +17 -0
- package/enhancements/policy/index.js +31 -0
- package/enhancements/policy/index.js.map +1 -0
- package/{lib/proxy → enhancements/policy}/logger.d.ts +3 -0
- package/{lib/proxy → enhancements/policy}/logger.js +4 -0
- package/enhancements/policy/logger.js.map +1 -0
- package/enhancements/policy/policy-utils.d.ts +78 -0
- package/enhancements/policy/policy-utils.js +575 -0
- package/enhancements/policy/policy-utils.js.map +1 -0
- package/enhancements/preset.d.ts +16 -0
- package/enhancements/preset.js +24 -0
- package/enhancements/preset.js.map +1 -0
- package/enhancements/proxy.d.ts +75 -0
- package/enhancements/proxy.js +196 -0
- package/enhancements/proxy.js.map +1 -0
- package/enhancements/types.d.ts +24 -0
- package/{lib/config.js → enhancements/types.js} +1 -1
- package/enhancements/types.js.map +1 -0
- package/enhancements/utils.d.ts +16 -0
- package/enhancements/utils.js +31 -0
- package/enhancements/utils.js.map +1 -0
- package/error.d.ts +10 -0
- package/error.js +17 -0
- package/error.js.map +1 -0
- package/index.d.ts +5 -0
- package/{lib/index.js → index.js} +3 -4
- package/index.js.map +1 -0
- package/package.json +7 -5
- package/{lib/serialization-utils.d.ts → serialization-utils.d.ts} +0 -0
- package/{lib/serialization-utils.js → serialization-utils.js} +0 -0
- package/serialization-utils.js.map +1 -0
- package/types.d.ts +73 -0
- package/types.js +14 -0
- package/types.js.map +1 -0
- package/{lib/validation.d.ts → validation.d.ts} +0 -0
- package/{lib/validation.js → validation.js} +0 -0
- package/validation.js.map +1 -0
- package/{lib/version.d.ts → version.d.ts} +0 -0
- package/{lib/version.js → version.js} +6 -1
- package/version.js.map +1 -0
- package/client/index.d.ts +0 -3
- package/client/index.js +0 -11
- package/lib/config.d.ts +0 -14
- package/lib/config.js.map +0 -1
- package/lib/constants.d.ts +0 -12
- package/lib/constants.js +0 -16
- package/lib/constants.js.map +0 -1
- package/lib/handler/data/crud.d.ts +0 -17
- package/lib/handler/data/crud.js +0 -255
- package/lib/handler/data/crud.js.map +0 -1
- package/lib/handler/data/handler.d.ts +0 -20
- package/lib/handler/data/handler.js +0 -150
- package/lib/handler/data/handler.js.map +0 -1
- package/lib/handler/data/nested-write-vistor.d.ts +0 -31
- package/lib/handler/data/nested-write-vistor.js +0 -67
- package/lib/handler/data/nested-write-vistor.js.map +0 -1
- package/lib/handler/data/policy-utils.d.ts +0 -73
- package/lib/handler/data/policy-utils.js +0 -447
- package/lib/handler/data/policy-utils.js.map +0 -1
- package/lib/handler/index.d.ts +0 -1
- package/lib/handler/index.js +0 -9
- package/lib/handler/index.js.map +0 -1
- package/lib/handler/types.d.ts +0 -28
- package/lib/handler/types.js +0 -36
- package/lib/handler/types.js.map +0 -1
- package/lib/index.d.ts +0 -6
- package/lib/index.js.map +0 -1
- package/lib/policy.d.ts +0 -11
- package/lib/policy.js +0 -10
- package/lib/policy.js.map +0 -1
- package/lib/proxy/handler.d.ts +0 -37
- package/lib/proxy/handler.js +0 -333
- package/lib/proxy/handler.js.map +0 -1
- package/lib/proxy/logger.js.map +0 -1
- package/lib/proxy/nested-write-vistor.d.ts +0 -30
- package/lib/proxy/nested-write-vistor.js +0 -69
- package/lib/proxy/nested-write-vistor.js.map +0 -1
- package/lib/proxy/policy-utils.d.ts +0 -78
- package/lib/proxy/policy-utils.js +0 -508
- package/lib/proxy/policy-utils.js.map +0 -1
- package/lib/request-handler.d.ts +0 -21
- package/lib/request-handler.js +0 -37
- package/lib/request-handler.js.map +0 -1
- package/lib/request.d.ts +0 -37
- package/lib/request.js +0 -164
- package/lib/request.js.map +0 -1
- package/lib/serialization-utils.js.map +0 -1
- package/lib/service.d.ts +0 -32
- package/lib/service.js +0 -184
- package/lib/service.js.map +0 -1
- package/lib/types.d.ts +0 -185
- package/lib/types.js +0 -71
- package/lib/types.js.map +0 -1
- package/lib/validation.js.map +0 -1
- package/lib/version.js.map +0 -1
- package/server/index.d.ts +0 -16
- package/server/index.js +0 -6
- package/types/index.d.ts +0 -1
- package/types/index.js +0 -3
|
@@ -0,0 +1,575 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.PolicyUtil = void 0;
|
|
17
|
+
const runtime_1 = require("@prisma/client/runtime");
|
|
18
|
+
const sdk_1 = require("@zenstackhq/sdk");
|
|
19
|
+
const change_case_1 = require("change-case");
|
|
20
|
+
const cuid_1 = __importDefault(require("cuid"));
|
|
21
|
+
const deepcopy_1 = __importDefault(require("deepcopy"));
|
|
22
|
+
const util_1 = require("util");
|
|
23
|
+
const zod_validation_error_1 = require("zod-validation-error");
|
|
24
|
+
const version_1 = require("../../version");
|
|
25
|
+
const model_meta_1 = require("../model-meta");
|
|
26
|
+
const nested_write_vistor_1 = require("../nested-write-vistor");
|
|
27
|
+
const utils_1 = require("../utils");
|
|
28
|
+
const logger_1 = require("./logger");
|
|
29
|
+
/**
|
|
30
|
+
* Access policy enforcement utilities
|
|
31
|
+
*/
|
|
32
|
+
class PolicyUtil {
|
|
33
|
+
constructor(db, modelMeta, policy, user) {
|
|
34
|
+
this.db = db;
|
|
35
|
+
this.modelMeta = modelMeta;
|
|
36
|
+
this.policy = policy;
|
|
37
|
+
this.user = user;
|
|
38
|
+
this.logger = new logger_1.Logger(db);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates a conjunction of a list of query conditions.
|
|
42
|
+
*/
|
|
43
|
+
and(...conditions) {
|
|
44
|
+
if (conditions.includes(false)) {
|
|
45
|
+
// always false
|
|
46
|
+
return { id: { in: [] } };
|
|
47
|
+
}
|
|
48
|
+
const filtered = conditions.filter((c) => typeof c === 'object' && !!c && Object.keys(c).length > 0);
|
|
49
|
+
if (filtered.length === 0) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
else if (filtered.length === 1) {
|
|
53
|
+
return filtered[0];
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
return { AND: filtered };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Creates a disjunction of a list of query conditions.
|
|
61
|
+
*/
|
|
62
|
+
or(...conditions) {
|
|
63
|
+
if (conditions.includes(true)) {
|
|
64
|
+
// always true
|
|
65
|
+
return { id: { notIn: [] } };
|
|
66
|
+
}
|
|
67
|
+
const filtered = conditions.filter((c) => typeof c === 'object' && !!c);
|
|
68
|
+
if (filtered.length === 0) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
else if (filtered.length === 1) {
|
|
72
|
+
return filtered[0];
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return { OR: filtered };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Gets pregenerated authorization guard object for a given model and operation.
|
|
80
|
+
*
|
|
81
|
+
* @returns true if operation is unconditionally allowed, false if unconditionally denied,
|
|
82
|
+
* otherwise returns a guard object
|
|
83
|
+
*/
|
|
84
|
+
getAuthGuard(model, operation, preValue) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const guard = this.policy.guard[(0, change_case_1.camelCase)(model)];
|
|
87
|
+
if (!guard) {
|
|
88
|
+
throw this.unknownError(`unable to load policy guard for ${model}`);
|
|
89
|
+
}
|
|
90
|
+
const provider = guard[operation];
|
|
91
|
+
if (typeof provider === 'boolean') {
|
|
92
|
+
return provider;
|
|
93
|
+
}
|
|
94
|
+
if (!provider) {
|
|
95
|
+
throw this.unknownError(`zenstack: unable to load authorization guard for ${model}`);
|
|
96
|
+
}
|
|
97
|
+
return provider({ user: this.user, preValue });
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
getPreValueSelect(model) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
const guard = this.policy.guard[(0, change_case_1.camelCase)(model)];
|
|
103
|
+
if (!guard) {
|
|
104
|
+
throw this.unknownError(`unable to load policy guard for ${model}`);
|
|
105
|
+
}
|
|
106
|
+
return guard.preValueSelect;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
getModelSchema(model) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
return this.policy.schema[(0, change_case_1.camelCase)(model)];
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Injects model auth guard as where clause.
|
|
116
|
+
*/
|
|
117
|
+
injectAuthGuard(args, model, operation) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
const guard = yield this.getAuthGuard(model, operation);
|
|
120
|
+
args.where = this.and(args.where, guard);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Read model entities w.r.t the given query args. The result list
|
|
125
|
+
* are guaranteed to fully satisfy 'read' policy rules recursively.
|
|
126
|
+
*
|
|
127
|
+
* For to-many relations involved, items not satisfying policy are
|
|
128
|
+
* silently trimmed. For to-one relation, if relation data fails policy
|
|
129
|
+
* an error is thrown.
|
|
130
|
+
*/
|
|
131
|
+
readWithCheck(model, args) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
args = this.clone(args);
|
|
134
|
+
yield this.injectAuthGuard(args, model, 'read');
|
|
135
|
+
// recursively inject read guard conditions into the query args
|
|
136
|
+
yield this.injectNestedReadConditions(model, args);
|
|
137
|
+
this.logger.info(`Reading with validation for ${model}: ${(0, util_1.format)(args)}`);
|
|
138
|
+
const result = yield this.db[model].findMany(args);
|
|
139
|
+
yield Promise.all(result.map((item) => this.postProcessForRead(item, model, args, 'read')));
|
|
140
|
+
return result;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
injectNestedReadConditions(model, args) {
|
|
144
|
+
var _a, _b, _c, _d;
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
const injectTarget = (_a = args.select) !== null && _a !== void 0 ? _a : args.include;
|
|
147
|
+
if (!injectTarget) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const idField = this.getIdField(model);
|
|
151
|
+
for (const field of (0, utils_1.getModelFields)(injectTarget)) {
|
|
152
|
+
const fieldInfo = (0, model_meta_1.resolveField)(this.modelMeta, model, field);
|
|
153
|
+
if (!fieldInfo || !fieldInfo.isDataModel) {
|
|
154
|
+
// only care about relation fields
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (fieldInfo.isArray) {
|
|
158
|
+
if (typeof injectTarget[field] !== 'object') {
|
|
159
|
+
injectTarget[field] = {};
|
|
160
|
+
}
|
|
161
|
+
// inject extra condition for to-many relation
|
|
162
|
+
const guard = yield this.getAuthGuard(fieldInfo.type, 'read');
|
|
163
|
+
injectTarget[field].where = this.and(injectTarget.where, guard);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
// there's no way of injecting condition for to-one relation, so we
|
|
167
|
+
// make sure 'id' field is selected and check them against query result
|
|
168
|
+
if (((_b = injectTarget[field]) === null || _b === void 0 ? void 0 : _b.select) && ((_d = (_c = injectTarget[field]) === null || _c === void 0 ? void 0 : _c.select) === null || _d === void 0 ? void 0 : _d[idField.name]) !== true) {
|
|
169
|
+
injectTarget[field].select[idField.name] = true;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// recurse
|
|
173
|
+
yield this.injectNestedReadConditions(fieldInfo.type, injectTarget[field]);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Post processing checks for read model entities. Validates to-one relations
|
|
179
|
+
* (which can't be trimmed at query time) and removes fields that should be
|
|
180
|
+
* omitted.
|
|
181
|
+
*/
|
|
182
|
+
postProcessForRead(entityData, model, args, operation) {
|
|
183
|
+
var _a, _b;
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
if (!this.getEntityId(model, entityData)) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
// strip auxiliary fields
|
|
189
|
+
for (const auxField of sdk_1.AUXILIARY_FIELDS) {
|
|
190
|
+
if (auxField in entityData) {
|
|
191
|
+
delete entityData[auxField];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const injectTarget = (_a = args.select) !== null && _a !== void 0 ? _a : args.include;
|
|
195
|
+
if (!injectTarget) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
// to-one relation data cannot be trimmed by injected guards, we have to
|
|
199
|
+
// post-check them
|
|
200
|
+
for (const field of (0, utils_1.getModelFields)(injectTarget)) {
|
|
201
|
+
const fieldInfo = (0, model_meta_1.resolveField)(this.modelMeta, model, field);
|
|
202
|
+
if (!fieldInfo || !fieldInfo.isDataModel || fieldInfo.isArray) {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
const idField = this.getIdField(fieldInfo.type);
|
|
206
|
+
const relatedEntityId = (_b = entityData === null || entityData === void 0 ? void 0 : entityData[field]) === null || _b === void 0 ? void 0 : _b[idField.name];
|
|
207
|
+
if (!relatedEntityId) {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
this.logger.info(`Validating read of to-one relation: ${fieldInfo.type}#${relatedEntityId}`);
|
|
211
|
+
yield this.checkPolicyForFilter(fieldInfo.type, { [idField.name]: relatedEntityId }, operation, this.db);
|
|
212
|
+
// recurse
|
|
213
|
+
yield this.postProcessForRead(entityData[field], fieldInfo.type, injectTarget[field], operation);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Process Prisma write actions.
|
|
219
|
+
*/
|
|
220
|
+
processWrite(model, action, args, writeAction) {
|
|
221
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
222
|
+
// record model types for which new entities are created
|
|
223
|
+
// so we can post-check if they satisfy 'create' policies
|
|
224
|
+
const createdModels = new Set();
|
|
225
|
+
// record model entities that are updated, together with their
|
|
226
|
+
// values before update, so we can post-check if they satisfy
|
|
227
|
+
// model => id => entity value
|
|
228
|
+
const updatedModels = new Map();
|
|
229
|
+
const idField = this.getIdField(model);
|
|
230
|
+
if (args.select && !args.select[idField.name]) {
|
|
231
|
+
// make sure 'id' field is selected, we need it to
|
|
232
|
+
// read back the updated entity
|
|
233
|
+
args.select[idField.name] = true;
|
|
234
|
+
}
|
|
235
|
+
// use a transaction to conduct write, so in case any create or nested create
|
|
236
|
+
// fails access policies, we can roll back the entire operation
|
|
237
|
+
const transactionId = (0, cuid_1.default)();
|
|
238
|
+
// args processor for create
|
|
239
|
+
const processCreate = (model, args) => __awaiter(this, void 0, void 0, function* () {
|
|
240
|
+
const guard = yield this.getAuthGuard(model, 'create');
|
|
241
|
+
const schema = yield this.getModelSchema(model);
|
|
242
|
+
if (guard === false) {
|
|
243
|
+
throw this.deniedByPolicy(model, 'create');
|
|
244
|
+
}
|
|
245
|
+
else if (guard !== true || schema) {
|
|
246
|
+
// mark the create with a transaction tag so we can check them later
|
|
247
|
+
args[sdk_1.TRANSACTION_FIELD_NAME] = `${transactionId}:create`;
|
|
248
|
+
createdModels.add(model);
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
// build a reversed query for fetching entities affected by nested updates
|
|
252
|
+
const buildReversedQuery = (context) => __awaiter(this, void 0, void 0, function* () {
|
|
253
|
+
let result, currQuery;
|
|
254
|
+
let currField;
|
|
255
|
+
for (let i = context.nestingPath.length - 1; i >= 0; i--) {
|
|
256
|
+
const { field, where } = context.nestingPath[i];
|
|
257
|
+
if (!result) {
|
|
258
|
+
// first segment (bottom), just use its where clause
|
|
259
|
+
result = currQuery = Object.assign({}, where);
|
|
260
|
+
currField = field;
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
if (!currField) {
|
|
264
|
+
throw this.unknownError(`missing field in nested path`);
|
|
265
|
+
}
|
|
266
|
+
if (!currField.backLink) {
|
|
267
|
+
throw this.unknownError(`field ${currField.type}.${currField.name} doesn't have a backLink`);
|
|
268
|
+
}
|
|
269
|
+
currQuery[currField.backLink] = Object.assign({}, where);
|
|
270
|
+
currQuery = currQuery[currField.backLink];
|
|
271
|
+
currField = field;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return result;
|
|
275
|
+
});
|
|
276
|
+
// args processor for update/upsert
|
|
277
|
+
const processUpdate = (model, args, context) => __awaiter(this, void 0, void 0, function* () {
|
|
278
|
+
const preGuard = yield this.getAuthGuard(model, 'update');
|
|
279
|
+
if (preGuard === false) {
|
|
280
|
+
throw this.deniedByPolicy(model, 'update');
|
|
281
|
+
}
|
|
282
|
+
else if (preGuard !== true) {
|
|
283
|
+
if (this.isToOneRelation(context.field)) {
|
|
284
|
+
// To-one relation field is complicated because there's no way to
|
|
285
|
+
// filter it during update (args doesn't carry a 'where' clause).
|
|
286
|
+
//
|
|
287
|
+
// We need to recursively walk up its hierarcy in the query args
|
|
288
|
+
// to construct a reversed query to identify the nested entity
|
|
289
|
+
// under update, and then check if it satisfies policy.
|
|
290
|
+
//
|
|
291
|
+
// E.g.:
|
|
292
|
+
// A - B - C
|
|
293
|
+
//
|
|
294
|
+
// update A with:
|
|
295
|
+
// {
|
|
296
|
+
// where: { id: 'aId' },
|
|
297
|
+
// data: {
|
|
298
|
+
// b: {
|
|
299
|
+
// c: { value: 1 }
|
|
300
|
+
// }
|
|
301
|
+
// }
|
|
302
|
+
// }
|
|
303
|
+
//
|
|
304
|
+
// To check if the update to 'c' field is permitted, we
|
|
305
|
+
// reverse the query stack into a filter for C model, like:
|
|
306
|
+
// {
|
|
307
|
+
// where: {
|
|
308
|
+
// b: { a: { id: 'aId' } }
|
|
309
|
+
// }
|
|
310
|
+
// }
|
|
311
|
+
// , and with this we can filter out the C entity that's going
|
|
312
|
+
// to be nestedly updated, and check if it's allowed.
|
|
313
|
+
//
|
|
314
|
+
// The same logic applies to nested delete.
|
|
315
|
+
const subQuery = yield buildReversedQuery(context);
|
|
316
|
+
yield this.checkPolicyForFilter(model, subQuery, 'update', this.db);
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
// non-nested update, check policies directly
|
|
320
|
+
if (!args.where) {
|
|
321
|
+
throw this.unknownError(`Missing 'where' in update args`);
|
|
322
|
+
}
|
|
323
|
+
yield this.checkPolicyForFilter(model, args.where, 'update', this.db);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
yield preparePostUpdateCheck(model, context);
|
|
327
|
+
});
|
|
328
|
+
// args processor for updateMany
|
|
329
|
+
const processUpdateMany = (model, args, context) => __awaiter(this, void 0, void 0, function* () {
|
|
330
|
+
const guard = yield this.getAuthGuard(model, 'update');
|
|
331
|
+
if (guard === false) {
|
|
332
|
+
throw this.deniedByPolicy(model, 'update');
|
|
333
|
+
}
|
|
334
|
+
else if (guard !== true) {
|
|
335
|
+
// inject policy filter
|
|
336
|
+
yield this.injectAuthGuard(args, model, 'update');
|
|
337
|
+
}
|
|
338
|
+
yield preparePostUpdateCheck(model, context);
|
|
339
|
+
});
|
|
340
|
+
// for models with post-update rules, we need to read and store
|
|
341
|
+
// entity values before the update for post-update check
|
|
342
|
+
const preparePostUpdateCheck = (model, context) => __awaiter(this, void 0, void 0, function* () {
|
|
343
|
+
const postGuard = yield this.getAuthGuard(model, 'postUpdate');
|
|
344
|
+
const schema = yield this.getModelSchema(model);
|
|
345
|
+
// post-update check is needed if there's post-update rule or validation schema
|
|
346
|
+
if (postGuard !== true || schema) {
|
|
347
|
+
let modelEntities = updatedModels.get(model);
|
|
348
|
+
if (!modelEntities) {
|
|
349
|
+
modelEntities = new Map();
|
|
350
|
+
updatedModels.set(model, modelEntities);
|
|
351
|
+
}
|
|
352
|
+
// fetch preValue selection (analyzed from the post-update rules)
|
|
353
|
+
const preValueSelect = yield this.getPreValueSelect(model);
|
|
354
|
+
const filter = yield buildReversedQuery(context);
|
|
355
|
+
const idField = this.getIdField(model);
|
|
356
|
+
const query = { where: filter, select: Object.assign(Object.assign({}, preValueSelect), { [idField.name]: true }) };
|
|
357
|
+
this.logger.info(`fetching pre-update entities for ${model}: ${(0, util_1.format)(query)})}`);
|
|
358
|
+
const entities = yield this.db[model].findMany(query);
|
|
359
|
+
entities.forEach((entity) => modelEntities === null || modelEntities === void 0 ? void 0 : modelEntities.set(this.getEntityId(model, entity), entity));
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
// args processor for delete
|
|
363
|
+
const processDelete = (model, args, context) => __awaiter(this, void 0, void 0, function* () {
|
|
364
|
+
const guard = yield this.getAuthGuard(model, 'delete');
|
|
365
|
+
if (guard === false) {
|
|
366
|
+
throw this.deniedByPolicy(model, 'delete');
|
|
367
|
+
}
|
|
368
|
+
else if (guard !== true) {
|
|
369
|
+
if (this.isToOneRelation(context.field)) {
|
|
370
|
+
// see comments in processUpdate
|
|
371
|
+
const subQuery = yield buildReversedQuery(context);
|
|
372
|
+
yield this.checkPolicyForFilter(model, subQuery, 'delete', this.db);
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
yield this.checkPolicyForFilter(model, args, 'delete', this.db);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
// use a visitor to process args before conducting the write action
|
|
380
|
+
const visitor = new nested_write_vistor_1.NestedWriteVisitor(this.modelMeta, {
|
|
381
|
+
create: (model, args) => __awaiter(this, void 0, void 0, function* () {
|
|
382
|
+
for (const oneArgs of (0, utils_1.enumerate)(args)) {
|
|
383
|
+
yield processCreate(model, oneArgs);
|
|
384
|
+
}
|
|
385
|
+
}),
|
|
386
|
+
connectOrCreate: (model, args) => __awaiter(this, void 0, void 0, function* () {
|
|
387
|
+
for (const oneArgs of (0, utils_1.enumerate)(args)) {
|
|
388
|
+
if (oneArgs.create) {
|
|
389
|
+
yield processCreate(model, oneArgs.create);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}),
|
|
393
|
+
update: (model, args, context) => __awaiter(this, void 0, void 0, function* () {
|
|
394
|
+
for (const oneArgs of (0, utils_1.enumerate)(args)) {
|
|
395
|
+
yield processUpdate(model, oneArgs, context);
|
|
396
|
+
}
|
|
397
|
+
}),
|
|
398
|
+
updateMany: (model, args, context) => __awaiter(this, void 0, void 0, function* () {
|
|
399
|
+
for (const oneArgs of (0, utils_1.enumerate)(args)) {
|
|
400
|
+
yield processUpdateMany(model, oneArgs, context);
|
|
401
|
+
}
|
|
402
|
+
}),
|
|
403
|
+
upsert: (model, args, context) => __awaiter(this, void 0, void 0, function* () {
|
|
404
|
+
for (const oneArgs of (0, utils_1.enumerate)(args)) {
|
|
405
|
+
if (oneArgs.create) {
|
|
406
|
+
yield processCreate(model, oneArgs.create);
|
|
407
|
+
}
|
|
408
|
+
if (oneArgs.update) {
|
|
409
|
+
yield processUpdate(model, { where: oneArgs.where, data: oneArgs.update }, context);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}),
|
|
413
|
+
delete: (model, args, context) => __awaiter(this, void 0, void 0, function* () {
|
|
414
|
+
for (const oneArgs of (0, utils_1.enumerate)(args)) {
|
|
415
|
+
yield processDelete(model, oneArgs, context);
|
|
416
|
+
}
|
|
417
|
+
}),
|
|
418
|
+
deleteMany: (model, args, context) => __awaiter(this, void 0, void 0, function* () {
|
|
419
|
+
const guard = yield this.getAuthGuard(model, 'delete');
|
|
420
|
+
if (guard === false) {
|
|
421
|
+
throw this.deniedByPolicy(model, 'delete');
|
|
422
|
+
}
|
|
423
|
+
else if (guard !== true) {
|
|
424
|
+
if (Array.isArray(args)) {
|
|
425
|
+
context.parent.deleteMany = args.map((oneArgs) => this.and(oneArgs, guard));
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
context.parent.deleteMany = this.and(args, guard);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}),
|
|
432
|
+
});
|
|
433
|
+
yield visitor.visit(model, action, args);
|
|
434
|
+
if (createdModels.size === 0 && updatedModels.size === 0) {
|
|
435
|
+
// no post-check needed, we can proceed with the write without transaction
|
|
436
|
+
return yield writeAction(this.db[model], args);
|
|
437
|
+
}
|
|
438
|
+
else {
|
|
439
|
+
return yield this.transaction(this.db, (tx) => __awaiter(this, void 0, void 0, function* () {
|
|
440
|
+
// proceed with the update (with args processed)
|
|
441
|
+
const result = yield writeAction(tx[model], args);
|
|
442
|
+
if (createdModels.size > 0) {
|
|
443
|
+
// do post-check on created entities
|
|
444
|
+
yield Promise.all([...createdModels].map((model) => this.checkPolicyForFilter(model, { [sdk_1.TRANSACTION_FIELD_NAME]: `${transactionId}:create` }, 'create', tx)));
|
|
445
|
+
}
|
|
446
|
+
if (updatedModels.size > 0) {
|
|
447
|
+
// do post-check on updated entities
|
|
448
|
+
yield Promise.all([...updatedModels.entries()]
|
|
449
|
+
.map(([model, modelEntities]) => [...modelEntities.entries()].map(([id, preValue]) => __awaiter(this, void 0, void 0, function* () { return this.checkPostUpdate(model, id, tx, preValue); })))
|
|
450
|
+
.flat());
|
|
451
|
+
}
|
|
452
|
+
return result;
|
|
453
|
+
}));
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
transaction(db, action) {
|
|
458
|
+
if (db.__zenstack_tx) {
|
|
459
|
+
// already in transaction, don't nest
|
|
460
|
+
return action(db);
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
return db.$transaction((tx) => action(tx));
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
deniedByPolicy(model, operation, extra) {
|
|
467
|
+
return new runtime_1.PrismaClientKnownRequestError(`denied by policy: ${model} entities failed '${operation}' check${extra ? ', ' + extra : ''}`, { clientVersion: (0, version_1.getVersion)(), code: 'P2004' });
|
|
468
|
+
}
|
|
469
|
+
notFound(model) {
|
|
470
|
+
return new runtime_1.PrismaClientKnownRequestError(`entity not found for model ${model}`, {
|
|
471
|
+
clientVersion: (0, version_1.getVersion)(),
|
|
472
|
+
code: 'P2025',
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
unknownError(message) {
|
|
476
|
+
return new runtime_1.PrismaClientUnknownRequestError(message, {
|
|
477
|
+
clientVersion: (0, version_1.getVersion)(),
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Given a filter, check if applying access policy filtering will result
|
|
482
|
+
* in data being trimmed, and if so, throw an error.
|
|
483
|
+
*/
|
|
484
|
+
checkPolicyForFilter(model, filter, operation, db) {
|
|
485
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
486
|
+
this.logger.info(`Checking policy for ${model}#${JSON.stringify(filter)} for ${operation}`);
|
|
487
|
+
const count = (yield db[model].count({ where: filter }));
|
|
488
|
+
const guard = yield this.getAuthGuard(model, operation);
|
|
489
|
+
// build a query condition with policy injected
|
|
490
|
+
const guardedQuery = { where: this.and(filter, guard) };
|
|
491
|
+
const schema = (operation === 'create' || operation === 'update') && (yield this.getModelSchema(model));
|
|
492
|
+
if (schema) {
|
|
493
|
+
// we've got schemas, so have to fetch entities and validate them
|
|
494
|
+
const entities = yield db[model].findMany(guardedQuery);
|
|
495
|
+
if (entities.length < count) {
|
|
496
|
+
this.logger.info(`entity ${model} failed policy check for operation ${operation}`);
|
|
497
|
+
throw this.deniedByPolicy(model, operation, `${count - entities.length} entities failed policy check`);
|
|
498
|
+
}
|
|
499
|
+
// TODO: push down schema check to the database
|
|
500
|
+
const schemaCheckErrors = entities.map((entity) => schema.safeParse(entity)).filter((r) => !r.success);
|
|
501
|
+
if (schemaCheckErrors.length > 0) {
|
|
502
|
+
const error = schemaCheckErrors.map((r) => !r.success && (0, zod_validation_error_1.fromZodError)(r.error).message).join(', ');
|
|
503
|
+
this.logger.info(`entity ${model} failed schema check for operation ${operation}: ${error}`);
|
|
504
|
+
throw this.deniedByPolicy(model, operation, `entities failed schema check: [${error}]`);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
// count entities with policy injected and see if any of them are filtered out
|
|
509
|
+
const guardedCount = (yield db[model].count(guardedQuery));
|
|
510
|
+
if (guardedCount < count) {
|
|
511
|
+
this.logger.info(`entity ${model} failed policy check for operation ${operation}`);
|
|
512
|
+
throw this.deniedByPolicy(model, operation, `${count - guardedCount} entities failed policy check`);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
checkPostUpdate(model, id, db, preValue) {
|
|
518
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
519
|
+
this.logger.info(`Checking post-update policy for ${model}#${id}, preValue: ${(0, util_1.format)(preValue)}`);
|
|
520
|
+
const guard = yield this.getAuthGuard(model, 'postUpdate', preValue);
|
|
521
|
+
// build a query condition with policy injected
|
|
522
|
+
const idField = this.getIdField(model);
|
|
523
|
+
const guardedQuery = { where: this.and({ [idField.name]: id }, guard) };
|
|
524
|
+
// query with policy injected
|
|
525
|
+
const entity = yield db[model].findFirst(guardedQuery);
|
|
526
|
+
// see if we get fewer items with policy, if so, reject with an throw
|
|
527
|
+
if (!entity) {
|
|
528
|
+
this.logger.info(`entity ${model} failed policy check for operation postUpdate`);
|
|
529
|
+
throw this.deniedByPolicy(model, 'postUpdate');
|
|
530
|
+
}
|
|
531
|
+
// TODO: push down schema check to the database
|
|
532
|
+
const schema = yield this.getModelSchema(model);
|
|
533
|
+
if (schema) {
|
|
534
|
+
const schemaCheckResult = schema.safeParse(entity);
|
|
535
|
+
if (!schemaCheckResult.success) {
|
|
536
|
+
const error = (0, zod_validation_error_1.fromZodError)(schemaCheckResult.error).message;
|
|
537
|
+
this.logger.info(`entity ${model} failed schema check for operation postUpdate: ${error}`);
|
|
538
|
+
throw this.deniedByPolicy(model, 'postUpdate', `entity failed schema check: ${error}`);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
isToOneRelation(field) {
|
|
544
|
+
return !!field && field.isDataModel && !field.isArray;
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Clones an object and makes sure it's not empty.
|
|
548
|
+
*/
|
|
549
|
+
clone(value) {
|
|
550
|
+
return value ? (0, deepcopy_1.default)(value) : {};
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Gets "id" field for a given model.
|
|
554
|
+
*/
|
|
555
|
+
getIdField(model) {
|
|
556
|
+
const fields = this.modelMeta.fields[(0, change_case_1.camelCase)(model)];
|
|
557
|
+
if (!fields) {
|
|
558
|
+
throw this.unknownError(`Unable to load fields for ${model}`);
|
|
559
|
+
}
|
|
560
|
+
const result = Object.values(fields).find((f) => f.isId);
|
|
561
|
+
if (!result) {
|
|
562
|
+
throw this.unknownError(`model ${model} does not have an id field`);
|
|
563
|
+
}
|
|
564
|
+
return result;
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Gets id field value from an entity.
|
|
568
|
+
*/
|
|
569
|
+
getEntityId(model, entityData) {
|
|
570
|
+
const idField = this.getIdField(model);
|
|
571
|
+
return entityData[idField.name];
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
exports.PolicyUtil = PolicyUtil;
|
|
575
|
+
//# sourceMappingURL=policy-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-utils.js","sourceRoot":"","sources":["../../../src/enhancements/policy/policy-utils.ts"],"names":[],"mappings":";AAAA,uDAAuD;;;;;;;;;;;;;;;AAEvD,oDAAwG;AACxG,yCAA2E;AAC3E,6CAAwC;AACxC,gDAAwB;AACxB,wDAAgC;AAChC,+BAA8B;AAC9B,+DAAoD;AASpD,2CAA2C;AAC3C,8CAA6C;AAC7C,gEAA4E;AAE5E,oCAAqD;AACrD,qCAAkC;AAElC;;GAEG;AACH,MAAa,UAAU;IAGnB,YACqB,EAAoB,EACpB,SAAoB,EACpB,MAAiB,EACjB,IAAe;QAHf,OAAE,GAAF,EAAE,CAAkB;QACpB,cAAS,GAAT,SAAS,CAAW;QACpB,WAAM,GAAN,MAAM,CAAW;QACjB,SAAI,GAAJ,IAAI,CAAW;QAEhC,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,EAAE,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,GAAG,UAAgC;QACnC,IAAI,UAAU,CAAC,QAAQ,CAAC,KAAK,CAA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AAa,EAAE,UAAe;QACtC,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACvC,OAAO,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;CACJ;AAtmBD,gCAsmBC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { WithPolicyContext } from './policy';
|
|
2
|
+
import { ModelMeta, PolicyDef } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Gets a Prisma client enhanced with all essential behaviors, including access
|
|
5
|
+
* policy, field validation, field omission and password hashing.
|
|
6
|
+
*
|
|
7
|
+
* It's a shortcut for calling withOmit(withPassword(withPolicy(prisma, options))).
|
|
8
|
+
*
|
|
9
|
+
* @param prisma The Prisma client to enhance.
|
|
10
|
+
* @param context The context to for evaluating access policies.
|
|
11
|
+
* @param policy The access policy data, generated by @zenstack/access-policy plugin.
|
|
12
|
+
* You only need to pass it if you configured the plugin to generate into custom location.
|
|
13
|
+
* @param modelMeta The model metadata, generated by @zenstack/model-meta plugin.
|
|
14
|
+
* You only need to pass it if you configured the plugin to generate into custom location.
|
|
15
|
+
*/
|
|
16
|
+
export declare function withPresets<DbClient extends object>(prisma: DbClient, context?: WithPolicyContext, policy?: PolicyDef, modelMeta?: ModelMeta): DbClient;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withPresets = void 0;
|
|
4
|
+
const omit_1 = require("./omit");
|
|
5
|
+
const password_1 = require("./password");
|
|
6
|
+
const policy_1 = require("./policy");
|
|
7
|
+
/**
|
|
8
|
+
* Gets a Prisma client enhanced with all essential behaviors, including access
|
|
9
|
+
* policy, field validation, field omission and password hashing.
|
|
10
|
+
*
|
|
11
|
+
* It's a shortcut for calling withOmit(withPassword(withPolicy(prisma, options))).
|
|
12
|
+
*
|
|
13
|
+
* @param prisma The Prisma client to enhance.
|
|
14
|
+
* @param context The context to for evaluating access policies.
|
|
15
|
+
* @param policy The access policy data, generated by @zenstack/access-policy plugin.
|
|
16
|
+
* You only need to pass it if you configured the plugin to generate into custom location.
|
|
17
|
+
* @param modelMeta The model metadata, generated by @zenstack/model-meta plugin.
|
|
18
|
+
* You only need to pass it if you configured the plugin to generate into custom location.
|
|
19
|
+
*/
|
|
20
|
+
function withPresets(prisma, context, policy, modelMeta) {
|
|
21
|
+
return (0, policy_1.withPolicy)((0, omit_1.withOmit)((0, password_1.withPassword)(prisma, modelMeta), modelMeta), context, policy, modelMeta);
|
|
22
|
+
}
|
|
23
|
+
exports.withPresets = withPresets;
|
|
24
|
+
//# sourceMappingURL=preset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preset.js","sourceRoot":"","sources":["../../src/enhancements/preset.ts"],"names":[],"mappings":";;;AAAA,iCAAkC;AAClC,yCAA0C;AAC1C,qCAAyD;AAGzD;;;;;;;;;;;;GAYG;AACH,SAAgB,WAAW,CACvB,MAAgB,EAChB,OAA2B,EAC3B,MAAkB,EAClB,SAAqB;IAErB,OAAO,IAAA,mBAAU,EAAC,IAAA,eAAQ,EAAC,IAAA,uBAAY,EAAC,MAAM,EAAE,SAAS,CAAC,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AACxG,CAAC;AAPD,kCAOC"}
|