@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,278 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.PolicyProxyHandler = void 0;
|
|
14
|
+
const runtime_1 = require("@prisma/client/runtime");
|
|
15
|
+
const util_1 = require("util");
|
|
16
|
+
const logger_1 = require("./logger");
|
|
17
|
+
const policy_utils_1 = require("./policy-utils");
|
|
18
|
+
/**
|
|
19
|
+
* Prisma proxy handler for injecting access policy check.
|
|
20
|
+
*/
|
|
21
|
+
class PolicyProxyHandler {
|
|
22
|
+
constructor(prisma, policy, modelMeta, model, user) {
|
|
23
|
+
this.prisma = prisma;
|
|
24
|
+
this.policy = policy;
|
|
25
|
+
this.modelMeta = modelMeta;
|
|
26
|
+
this.model = model;
|
|
27
|
+
this.user = user;
|
|
28
|
+
this.logger = new logger_1.Logger(prisma);
|
|
29
|
+
this.utils = new policy_utils_1.PolicyUtil(this.prisma, this.modelMeta, this.policy, this.user);
|
|
30
|
+
}
|
|
31
|
+
get modelClient() {
|
|
32
|
+
return this.prisma[this.model];
|
|
33
|
+
}
|
|
34
|
+
findUnique(args) {
|
|
35
|
+
var _a;
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
if (!args) {
|
|
38
|
+
throw new runtime_1.PrismaClientValidationError('query argument is required');
|
|
39
|
+
}
|
|
40
|
+
if (!args.where) {
|
|
41
|
+
throw new runtime_1.PrismaClientValidationError('where field is required in query argument');
|
|
42
|
+
}
|
|
43
|
+
const entities = yield this.utils.readWithCheck(this.model, args);
|
|
44
|
+
return (_a = entities[0]) !== null && _a !== void 0 ? _a : null;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
findUniqueOrThrow(args) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const entity = yield this.findUnique(args);
|
|
50
|
+
if (!entity) {
|
|
51
|
+
throw this.utils.notFound(this.model);
|
|
52
|
+
}
|
|
53
|
+
return entity;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
findFirst(args) {
|
|
57
|
+
var _a;
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const entities = yield this.utils.readWithCheck(this.model, args);
|
|
60
|
+
return (_a = entities[0]) !== null && _a !== void 0 ? _a : null;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
findFirstOrThrow(args) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const entity = yield this.findFirst(args);
|
|
66
|
+
if (!entity) {
|
|
67
|
+
throw this.utils.notFound(this.model);
|
|
68
|
+
}
|
|
69
|
+
return entity;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
findMany(args) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
return this.utils.readWithCheck(this.model, args);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
create(args) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
if (!args) {
|
|
80
|
+
throw new runtime_1.PrismaClientValidationError('query argument is required');
|
|
81
|
+
}
|
|
82
|
+
if (!args.data) {
|
|
83
|
+
throw new runtime_1.PrismaClientValidationError('data field is required in query argument');
|
|
84
|
+
}
|
|
85
|
+
yield this.tryReject('create');
|
|
86
|
+
const origArgs = args;
|
|
87
|
+
args = this.utils.clone(args);
|
|
88
|
+
// use a transaction to wrap the write so it can be reverted if the created
|
|
89
|
+
// entity fails access policies
|
|
90
|
+
const result = yield this.utils.processWrite(this.model, 'create', args, (dbOps, writeArgs) => dbOps.create(writeArgs));
|
|
91
|
+
if (!this.utils.getEntityId(this.model, result)) {
|
|
92
|
+
throw this.utils.unknownError(`unexpected error: create didn't return an id`);
|
|
93
|
+
}
|
|
94
|
+
return this.checkReadback(origArgs, this.utils.getEntityId(this.model, result), 'create', 'create');
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
createMany(args, skipDuplicates) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
if (!args) {
|
|
100
|
+
throw new runtime_1.PrismaClientValidationError('query argument is required');
|
|
101
|
+
}
|
|
102
|
+
if (!args.data) {
|
|
103
|
+
throw new runtime_1.PrismaClientValidationError('data field is required and must be an array');
|
|
104
|
+
}
|
|
105
|
+
yield this.tryReject('create');
|
|
106
|
+
args = this.utils.clone(args);
|
|
107
|
+
// use a transaction to wrap the write so it can be reverted if any created
|
|
108
|
+
// entity fails access policies
|
|
109
|
+
const result = yield this.utils.processWrite(this.model, 'create', args, (dbOps, writeArgs) => dbOps.createMany(writeArgs, skipDuplicates));
|
|
110
|
+
return result;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
update(args) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
if (!args) {
|
|
116
|
+
throw new runtime_1.PrismaClientValidationError('query argument is required');
|
|
117
|
+
}
|
|
118
|
+
if (!args.where) {
|
|
119
|
+
throw new runtime_1.PrismaClientValidationError('where field is required in query argument');
|
|
120
|
+
}
|
|
121
|
+
if (!args.data) {
|
|
122
|
+
throw new runtime_1.PrismaClientValidationError('data field is required in query argument');
|
|
123
|
+
}
|
|
124
|
+
yield this.tryReject('update');
|
|
125
|
+
const origArgs = args;
|
|
126
|
+
args = this.utils.clone(args);
|
|
127
|
+
// use a transaction to wrap the write so it can be reverted if any nested
|
|
128
|
+
// create fails access policies
|
|
129
|
+
const result = yield this.utils.processWrite(this.model, 'update', args, (dbOps, writeArgs) => dbOps.update(writeArgs));
|
|
130
|
+
if (!this.utils.getEntityId(this.model, result)) {
|
|
131
|
+
throw this.utils.unknownError(`unexpected error: update didn't return an id`);
|
|
132
|
+
}
|
|
133
|
+
return this.checkReadback(origArgs, this.utils.getEntityId(this.model, result), 'update', 'update');
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
updateMany(args) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
if (!args) {
|
|
139
|
+
throw new runtime_1.PrismaClientValidationError('query argument is required');
|
|
140
|
+
}
|
|
141
|
+
if (!args.data) {
|
|
142
|
+
throw new runtime_1.PrismaClientValidationError('data field is required in query argument');
|
|
143
|
+
}
|
|
144
|
+
yield this.tryReject('update');
|
|
145
|
+
args = this.utils.clone(args);
|
|
146
|
+
// use a transaction to wrap the write so it can be reverted if any nested
|
|
147
|
+
// create fails access policies
|
|
148
|
+
const result = yield this.utils.processWrite(this.model, 'updateMany', args, (dbOps, writeArgs) => dbOps.updateMany(writeArgs));
|
|
149
|
+
return result;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
upsert(args) {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
if (!args) {
|
|
155
|
+
throw new runtime_1.PrismaClientValidationError('query argument is required');
|
|
156
|
+
}
|
|
157
|
+
if (!args.where) {
|
|
158
|
+
throw new runtime_1.PrismaClientValidationError('where field is required in query argument');
|
|
159
|
+
}
|
|
160
|
+
if (!args.create) {
|
|
161
|
+
throw new runtime_1.PrismaClientValidationError('create field is required in query argument');
|
|
162
|
+
}
|
|
163
|
+
if (!args.update) {
|
|
164
|
+
throw new runtime_1.PrismaClientValidationError('update field is required in query argument');
|
|
165
|
+
}
|
|
166
|
+
const origArgs = args;
|
|
167
|
+
args = this.utils.clone(args);
|
|
168
|
+
yield this.tryReject('create');
|
|
169
|
+
yield this.tryReject('update');
|
|
170
|
+
// use a transaction to wrap the write so it can be reverted if any nested
|
|
171
|
+
// create fails access policies
|
|
172
|
+
const result = yield this.utils.processWrite(this.model, 'upsert', args, (dbOps, writeArgs) => dbOps.upsert(writeArgs));
|
|
173
|
+
if (!this.utils.getEntityId(this.model, result)) {
|
|
174
|
+
throw this.utils.unknownError(`unexpected error: upsert didn't return an id`);
|
|
175
|
+
}
|
|
176
|
+
return this.checkReadback(origArgs, this.utils.getEntityId(this.model, result), 'upsert', 'update');
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
delete(args) {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
if (!args) {
|
|
182
|
+
throw new runtime_1.PrismaClientValidationError('query argument is required');
|
|
183
|
+
}
|
|
184
|
+
if (!args.where) {
|
|
185
|
+
throw new runtime_1.PrismaClientValidationError('where field is required in query argument');
|
|
186
|
+
}
|
|
187
|
+
yield this.tryReject('delete');
|
|
188
|
+
// ensures the item under deletion passes policy check
|
|
189
|
+
yield this.utils.checkPolicyForFilter(this.model, args.where, 'delete', this.prisma);
|
|
190
|
+
// read the entity under deletion with respect to read policies
|
|
191
|
+
let readResult;
|
|
192
|
+
try {
|
|
193
|
+
const items = yield this.utils.readWithCheck(this.model, args);
|
|
194
|
+
readResult = items[0];
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
// not readable
|
|
198
|
+
readResult = undefined;
|
|
199
|
+
}
|
|
200
|
+
// conduct the deletion
|
|
201
|
+
this.logger.info(`Conducting delete ${this.model}:\n${(0, util_1.format)(args)}`);
|
|
202
|
+
yield this.modelClient.delete(args);
|
|
203
|
+
if (!readResult) {
|
|
204
|
+
throw this.utils.deniedByPolicy(this.model, 'delete', 'result not readable');
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
return readResult;
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
deleteMany(args) {
|
|
212
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
213
|
+
yield this.tryReject('delete');
|
|
214
|
+
// inject policy conditions
|
|
215
|
+
args = args !== null && args !== void 0 ? args : {};
|
|
216
|
+
yield this.utils.injectAuthGuard(args, this.model, 'delete');
|
|
217
|
+
// conduct the deletion
|
|
218
|
+
this.logger.info(`Conducting deleteMany ${this.model}:\n${(0, util_1.format)(args)}`);
|
|
219
|
+
return this.modelClient.deleteMany(args);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
aggregate(args) {
|
|
223
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
if (!args) {
|
|
225
|
+
throw new runtime_1.PrismaClientValidationError('query argument is required');
|
|
226
|
+
}
|
|
227
|
+
yield this.tryReject('read');
|
|
228
|
+
// inject policy conditions
|
|
229
|
+
yield this.utils.injectAuthGuard(args, this.model, 'read');
|
|
230
|
+
return this.modelClient.aggregate(args);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
groupBy(args) {
|
|
234
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
235
|
+
if (!args) {
|
|
236
|
+
throw new runtime_1.PrismaClientValidationError('query argument is required');
|
|
237
|
+
}
|
|
238
|
+
yield this.tryReject('read');
|
|
239
|
+
// inject policy conditions
|
|
240
|
+
yield this.utils.injectAuthGuard(args, this.model, 'read');
|
|
241
|
+
return this.modelClient.groupBy(args);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
count(args) {
|
|
245
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
246
|
+
yield this.tryReject('read');
|
|
247
|
+
// inject policy conditions
|
|
248
|
+
args = args !== null && args !== void 0 ? args : {};
|
|
249
|
+
yield this.utils.injectAuthGuard(args, this.model, 'read');
|
|
250
|
+
return this.modelClient.count(args);
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
tryReject(operation) {
|
|
254
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
255
|
+
const guard = yield this.utils.getAuthGuard(this.model, operation);
|
|
256
|
+
if (guard === false) {
|
|
257
|
+
throw this.utils.deniedByPolicy(this.model, operation);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
checkReadback(origArgs, id, action, operation) {
|
|
262
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
263
|
+
const idField = this.utils.getIdField(this.model);
|
|
264
|
+
const readArgs = { select: origArgs.select, include: origArgs.include, where: { [idField.name]: id } };
|
|
265
|
+
const result = yield this.utils.readWithCheck(this.model, readArgs);
|
|
266
|
+
if (result.length === 0) {
|
|
267
|
+
this.logger.warn(`${action} result cannot be read back`);
|
|
268
|
+
throw this.utils.deniedByPolicy(this.model, operation, 'result not readable');
|
|
269
|
+
}
|
|
270
|
+
else if (result.length > 1) {
|
|
271
|
+
throw this.utils.unknownError('write unexpected resulted in multiple readback entities');
|
|
272
|
+
}
|
|
273
|
+
return result[0];
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
exports.PolicyProxyHandler = PolicyProxyHandler;
|
|
278
|
+
//# sourceMappingURL=handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/enhancements/policy/handler.ts"],"names":[],"mappings":";AAAA,uDAAuD;;;;;;;;;;;;AAEvD,oDAAqE;AACrE,+BAA8B;AAI9B,qCAAkC;AAClC,iDAA4C;AAE5C;;GAEG;AACH,MAAa,kBAAkB;IAI3B,YACqB,MAAgB,EAChB,MAAiB,EACjB,SAAoB,EACpB,KAAa,EACb,IAAe;QAJf,WAAM,GAAN,MAAM,CAAU;QAChB,WAAM,GAAN,MAAM,CAAW;QACjB,cAAS,GAAT,SAAS,CAAW;QACpB,UAAK,GAAL,KAAK,CAAQ;QACb,SAAI,GAAJ,IAAI,CAAW;QAEhC,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,IAAI,yBAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACrF,CAAC;IAED,IAAY,WAAW;QACnB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAEK,UAAU,CAAC,IAAS;;;YACtB,IAAI,CAAC,IAAI,EAAE;gBACP,MAAM,IAAI,qCAA2B,CAAC,4BAA4B,CAAC,CAAC;aACvE;YACD,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;gBACb,MAAM,IAAI,qCAA2B,CAAC,2CAA2C,CAAC,CAAC;aACtF;YAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC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CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAClD,MAAM,QAAQ,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC;YACvG,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YACpE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;gBACrB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,6BAA6B,CAAC,CAAC;gBACzD,MAAM,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,qBAAqB,CAAC,CAAC;aACjF;iBAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC1B,MAAM,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,yDAAyD,CAAC,CAAC;aAC5F;YACD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;QACrB,CAAC;KAAA;CACJ;AA5RD,gDA4RC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AuthUser } from '../../types';
|
|
2
|
+
import { ModelMeta, PolicyDef } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Context for evaluating access policies
|
|
5
|
+
*/
|
|
6
|
+
export type WithPolicyContext = {
|
|
7
|
+
user?: AuthUser;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Gets an enhanced Prisma client with access policy check.
|
|
11
|
+
*
|
|
12
|
+
* @param prisma The original Prisma client
|
|
13
|
+
* @param context The policy evaluation context
|
|
14
|
+
* @param policy The policy definition, will be loaded from default location if not provided
|
|
15
|
+
* @param modelMeta The model metadata, will be loaded from default location if not provided
|
|
16
|
+
*/
|
|
17
|
+
export declare function withPolicy<DbClient extends object>(prisma: DbClient, context?: WithPolicyContext, policy?: PolicyDef, modelMeta?: ModelMeta): DbClient;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.withPolicy = void 0;
|
|
5
|
+
const model_meta_1 = require("../model-meta");
|
|
6
|
+
const proxy_1 = require("../proxy");
|
|
7
|
+
const handler_1 = require("./handler");
|
|
8
|
+
/**
|
|
9
|
+
* Gets an enhanced Prisma client with access policy check.
|
|
10
|
+
*
|
|
11
|
+
* @param prisma The original Prisma client
|
|
12
|
+
* @param context The policy evaluation context
|
|
13
|
+
* @param policy The policy definition, will be loaded from default location if not provided
|
|
14
|
+
* @param modelMeta The model metadata, will be loaded from default location if not provided
|
|
15
|
+
*/
|
|
16
|
+
function withPolicy(prisma, context, policy, modelMeta) {
|
|
17
|
+
const _policy = policy !== null && policy !== void 0 ? policy : getDefaultPolicy();
|
|
18
|
+
const _modelMeta = modelMeta !== null && modelMeta !== void 0 ? modelMeta : (0, model_meta_1.getDefaultModelMeta)();
|
|
19
|
+
return (0, proxy_1.makeProxy)(prisma, _modelMeta, (_prisma, model) => new handler_1.PolicyProxyHandler(_prisma, _policy, _modelMeta, model, context === null || context === void 0 ? void 0 : context.user), 'policy');
|
|
20
|
+
}
|
|
21
|
+
exports.withPolicy = withPolicy;
|
|
22
|
+
function getDefaultPolicy() {
|
|
23
|
+
try {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
25
|
+
return require('.zenstack/policy').default;
|
|
26
|
+
}
|
|
27
|
+
catch (_a) {
|
|
28
|
+
throw new Error('Policy definition cannot be loaded from default location');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/enhancements/policy/index.ts"],"names":[],"mappings":";AAAA,uDAAuD;;;AAGvD,8CAAoD;AACpD,oCAAqC;AAErC,uCAA+C;AAS/C;;;;;;;GAOG;AACH,SAAgB,UAAU,CACtB,MAAgB,EAChB,OAA2B,EAC3B,MAAkB,EAClB,SAAqB;IAErB,MAAM,OAAO,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,gBAAgB,EAAE,CAAC;IAC7C,MAAM,UAAU,GAAG,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,IAAA,gCAAmB,GAAE,CAAC;IACtD,OAAO,IAAA,iBAAS,EACZ,MAAM,EACN,UAAU,EACV,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CACf,IAAI,4BAAkB,CAAC,OAA2B,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,CAAC,EAClG,QAAQ,CACX,CAAC;AACN,CAAC;AAfD,gCAeC;AAED,SAAS,gBAAgB;IACrB,IAAI;QACA,8DAA8D;QAC9D,OAAO,OAAO,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAAC;KAC9C;IAAC,WAAM;QACJ,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;KAC/E;AACL,CAAC"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.Logger = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* A logger that uses an existing Prisma client to emit.
|
|
7
|
+
*/
|
|
4
8
|
class Logger {
|
|
5
9
|
constructor(prisma) {
|
|
6
10
|
this.prisma = prisma;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/enhancements/policy/logger.ts"],"names":[],"mappings":";AAAA,uDAAuD;;;AAIvD;;GAEG;AACH,MAAa,MAAM;IACf,YAA6B,MAAW;QAAX,WAAM,GAAN,MAAM,CAAK;IAAG,CAAC;IAE5C,IAAY,OAAO;QACf,MAAM,MAAM,GAAI,IAAI,CAAC,MAAc,CAAC,SAAS,EAAE,CAAC;QAChD,OAAO,MAAM,CAAC,CAAC,CAAE,MAAM,CAAC,UAA2B,CAAC,CAAC,CAAC,SAAS,CAAC;IACpE,CAAC;IAEM,GAAG,CAAC,KAAgC,EAAE,OAAe;;QACxD,MAAA,IAAI,CAAC,OAAO,0CAAE,IAAI,CAAC,KAAK,EAAE;YACtB,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,OAAO;YACP,MAAM,EAAE,UAAU;SACrB,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACI,IAAI,CAAC,OAAe;QACvB,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACI,IAAI,CAAC,OAAe;QACvB,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,OAAe;QACxB,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC/B,CAAC;CACJ;AApCD,wBAoCC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { PrismaClientKnownRequestError, PrismaClientUnknownRequestError } from '@prisma/client/runtime';
|
|
2
|
+
import { AuthUser, DbClientContract, DbOperations, FieldInfo, PolicyOperationKind, PrismaWriteActionType } from '../../types';
|
|
3
|
+
import { ModelMeta, PolicyDef } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Access policy enforcement utilities
|
|
6
|
+
*/
|
|
7
|
+
export declare class PolicyUtil {
|
|
8
|
+
private readonly db;
|
|
9
|
+
private readonly modelMeta;
|
|
10
|
+
private readonly policy;
|
|
11
|
+
private readonly user?;
|
|
12
|
+
private readonly logger;
|
|
13
|
+
constructor(db: DbClientContract, modelMeta: ModelMeta, policy: PolicyDef, user?: AuthUser | undefined);
|
|
14
|
+
/**
|
|
15
|
+
* Creates a conjunction of a list of query conditions.
|
|
16
|
+
*/
|
|
17
|
+
and(...conditions: (boolean | object)[]): any;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a disjunction of a list of query conditions.
|
|
20
|
+
*/
|
|
21
|
+
or(...conditions: (boolean | object)[]): any;
|
|
22
|
+
/**
|
|
23
|
+
* Gets pregenerated authorization guard object for a given model and operation.
|
|
24
|
+
*
|
|
25
|
+
* @returns true if operation is unconditionally allowed, false if unconditionally denied,
|
|
26
|
+
* otherwise returns a guard object
|
|
27
|
+
*/
|
|
28
|
+
getAuthGuard(model: string, operation: PolicyOperationKind, preValue?: any): Promise<boolean | object>;
|
|
29
|
+
private getPreValueSelect;
|
|
30
|
+
private getModelSchema;
|
|
31
|
+
/**
|
|
32
|
+
* Injects model auth guard as where clause.
|
|
33
|
+
*/
|
|
34
|
+
injectAuthGuard(args: any, model: string, operation: PolicyOperationKind): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Read model entities w.r.t the given query args. The result list
|
|
37
|
+
* are guaranteed to fully satisfy 'read' policy rules recursively.
|
|
38
|
+
*
|
|
39
|
+
* For to-many relations involved, items not satisfying policy are
|
|
40
|
+
* silently trimmed. For to-one relation, if relation data fails policy
|
|
41
|
+
* an error is thrown.
|
|
42
|
+
*/
|
|
43
|
+
readWithCheck(model: string, args: any): Promise<unknown[]>;
|
|
44
|
+
private injectNestedReadConditions;
|
|
45
|
+
/**
|
|
46
|
+
* Post processing checks for read model entities. Validates to-one relations
|
|
47
|
+
* (which can't be trimmed at query time) and removes fields that should be
|
|
48
|
+
* omitted.
|
|
49
|
+
*/
|
|
50
|
+
postProcessForRead(entityData: any, model: string, args: any, operation: PolicyOperationKind): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Process Prisma write actions.
|
|
53
|
+
*/
|
|
54
|
+
processWrite(model: string, action: PrismaWriteActionType, args: any, writeAction: (dbOps: DbOperations, writeArgs: any) => Promise<unknown>): Promise<any>;
|
|
55
|
+
private transaction;
|
|
56
|
+
deniedByPolicy(model: string, operation: PolicyOperationKind, extra?: string): PrismaClientKnownRequestError;
|
|
57
|
+
notFound(model: string): PrismaClientKnownRequestError;
|
|
58
|
+
unknownError(message: string): PrismaClientUnknownRequestError;
|
|
59
|
+
/**
|
|
60
|
+
* Given a filter, check if applying access policy filtering will result
|
|
61
|
+
* in data being trimmed, and if so, throw an error.
|
|
62
|
+
*/
|
|
63
|
+
checkPolicyForFilter(model: string, filter: any, operation: PolicyOperationKind, db: Record<string, DbOperations>): Promise<void>;
|
|
64
|
+
private checkPostUpdate;
|
|
65
|
+
private isToOneRelation;
|
|
66
|
+
/**
|
|
67
|
+
* Clones an object and makes sure it's not empty.
|
|
68
|
+
*/
|
|
69
|
+
clone(value: unknown): {};
|
|
70
|
+
/**
|
|
71
|
+
* Gets "id" field for a given model.
|
|
72
|
+
*/
|
|
73
|
+
getIdField(model: string): FieldInfo;
|
|
74
|
+
/**
|
|
75
|
+
* Gets id field value from an entity.
|
|
76
|
+
*/
|
|
77
|
+
getEntityId(model: string, entityData: any): any;
|
|
78
|
+
}
|