@zenstackhq/runtime 0.6.0-pre.2 → 1.0.0-alpha.19
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 +5 -4
- 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
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { DbOperations, PolicyOperationKind, QueryContext, Service } from '../../types';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a conjunction of a list of query conditions.
|
|
4
|
-
*/
|
|
5
|
-
export declare function and(...conditions: unknown[]): any;
|
|
6
|
-
/**
|
|
7
|
-
* Creates a disjunction of a list of query conditions.
|
|
8
|
-
*/
|
|
9
|
-
export declare function or(...conditions: unknown[]): any;
|
|
10
|
-
/**
|
|
11
|
-
* Wraps a value into array if it's not already one
|
|
12
|
-
*/
|
|
13
|
-
export declare function ensureArray<T>(value: T): Array<T>;
|
|
14
|
-
/**
|
|
15
|
-
* Given a where condition, queries db and returns IDs of result entities
|
|
16
|
-
*/
|
|
17
|
-
export declare function queryIds(model: string, db: Record<string, DbOperations>, where: unknown): Promise<string[]>;
|
|
18
|
-
/**
|
|
19
|
-
* Read model entities w.r.t the given query args. The result list
|
|
20
|
-
* are guaranteed to fully satisfy 'read' policy rules recursively.
|
|
21
|
-
*
|
|
22
|
-
* For to-many relations involved, items not satisfying policy are
|
|
23
|
-
* silently trimmed. For to-one relation, if relation data fails policy
|
|
24
|
-
* an CRUDError is thrown.
|
|
25
|
-
*
|
|
26
|
-
* @param model the model to query for
|
|
27
|
-
* @param queryArgs the Prisma query args
|
|
28
|
-
* @param service the ZenStack service
|
|
29
|
-
* @param context the query context
|
|
30
|
-
* @param db the db (or transaction)
|
|
31
|
-
* @returns
|
|
32
|
-
*/
|
|
33
|
-
export declare function readWithCheck(model: string, queryArgs: any, service: Service, context: QueryContext, db: Record<string, DbOperations>): Promise<unknown[]>;
|
|
34
|
-
/**
|
|
35
|
-
* Validates that a model entity satisfies 'update' policy rules
|
|
36
|
-
* before conducting an update
|
|
37
|
-
*
|
|
38
|
-
* @param model model under update
|
|
39
|
-
* @param id id of entity under update
|
|
40
|
-
* @param updateArgs Prisma update args
|
|
41
|
-
* @param service the ZenStack service
|
|
42
|
-
* @param context the query context
|
|
43
|
-
* @param transaction the db transaction context
|
|
44
|
-
*/
|
|
45
|
-
export declare function preUpdateCheck(model: string, id: string, updateArgs: any, service: Service, context: QueryContext, transaction: Record<string, DbOperations>): Promise<void>;
|
|
46
|
-
/**
|
|
47
|
-
* Given a list of ids for a model, check if they all match policy rules, and if not,
|
|
48
|
-
* throw a CRUDError.
|
|
49
|
-
*
|
|
50
|
-
* @param model the model
|
|
51
|
-
* @param ids the entity ids
|
|
52
|
-
* @param operation the operation to check for
|
|
53
|
-
* @param service the ZenStack service
|
|
54
|
-
* @param context the query context
|
|
55
|
-
* @param db the db or transaction
|
|
56
|
-
*/
|
|
57
|
-
export declare function checkPolicyForIds(model: string, ids: string[], operation: PolicyOperationKind, service: Service, context: QueryContext, db: Record<string, DbOperations>): Promise<void>;
|
|
58
|
-
/**
|
|
59
|
-
* Injects assignment of zenstack_transaction field for all nested
|
|
60
|
-
* update/create in a Prisma update args recursively.
|
|
61
|
-
*
|
|
62
|
-
* @return a tuple containing all model types that are involved in
|
|
63
|
-
* creation or updating, respectively
|
|
64
|
-
*/
|
|
65
|
-
export declare function injectTransactionId(model: string, args: any, operation: PolicyOperationKind, transactionId: string, service: Service): Promise<{
|
|
66
|
-
createdModels: string[];
|
|
67
|
-
updatedModels: string[];
|
|
68
|
-
}>;
|
|
69
|
-
/**
|
|
70
|
-
* Preprocesses the given write args to modify field values (in place) based on
|
|
71
|
-
* attributes like @password
|
|
72
|
-
*/
|
|
73
|
-
export declare function preprocessWritePayload(model: string, args: any, service: Service): Promise<void>;
|
|
@@ -1,447 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.preprocessWritePayload = exports.injectTransactionId = exports.checkPolicyForIds = exports.preUpdateCheck = exports.readWithCheck = exports.queryIds = exports.ensureArray = exports.or = exports.and = void 0;
|
|
16
|
-
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
17
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
18
|
-
const bcryptjs_1 = require("bcryptjs");
|
|
19
|
-
const deepcopy_1 = __importDefault(require("deepcopy"));
|
|
20
|
-
const superjson_1 = __importDefault(require("superjson"));
|
|
21
|
-
const constants_1 = require("../../constants");
|
|
22
|
-
const types_1 = require("../../types");
|
|
23
|
-
const types_2 = require("../types");
|
|
24
|
-
const nested_write_vistor_1 = require("./nested-write-vistor");
|
|
25
|
-
//#region General helpers
|
|
26
|
-
/**
|
|
27
|
-
* Creates a conjunction of a list of query conditions.
|
|
28
|
-
*/
|
|
29
|
-
function and(...conditions) {
|
|
30
|
-
const filtered = conditions.filter((c) => !!c);
|
|
31
|
-
if (filtered.length === 0) {
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
else if (filtered.length === 1) {
|
|
35
|
-
return filtered[0];
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
return { AND: filtered };
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.and = and;
|
|
42
|
-
/**
|
|
43
|
-
* Creates a disjunction of a list of query conditions.
|
|
44
|
-
*/
|
|
45
|
-
function or(...conditions) {
|
|
46
|
-
const filtered = conditions.filter((c) => !!c);
|
|
47
|
-
if (filtered.length === 0) {
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
else if (filtered.length === 1) {
|
|
51
|
-
return filtered[0];
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
return { OR: filtered };
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.or = or;
|
|
58
|
-
/**
|
|
59
|
-
* Wraps a value into array if it's not already one
|
|
60
|
-
*/
|
|
61
|
-
function ensureArray(value) {
|
|
62
|
-
return Array.isArray(value) ? value : [value];
|
|
63
|
-
}
|
|
64
|
-
exports.ensureArray = ensureArray;
|
|
65
|
-
/**
|
|
66
|
-
* Given a where condition, queries db and returns IDs of result entities
|
|
67
|
-
*/
|
|
68
|
-
function queryIds(model, db, where) {
|
|
69
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
const r = yield db[model].findMany({ select: { id: true }, where });
|
|
71
|
-
return r.map((item) => item.id);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
exports.queryIds = queryIds;
|
|
75
|
-
//#endregion
|
|
76
|
-
//#region Policy enforcement helpers
|
|
77
|
-
/**
|
|
78
|
-
* Read model entities w.r.t the given query args. The result list
|
|
79
|
-
* are guaranteed to fully satisfy 'read' policy rules recursively.
|
|
80
|
-
*
|
|
81
|
-
* For to-many relations involved, items not satisfying policy are
|
|
82
|
-
* silently trimmed. For to-one relation, if relation data fails policy
|
|
83
|
-
* an CRUDError is thrown.
|
|
84
|
-
*
|
|
85
|
-
* @param model the model to query for
|
|
86
|
-
* @param queryArgs the Prisma query args
|
|
87
|
-
* @param service the ZenStack service
|
|
88
|
-
* @param context the query context
|
|
89
|
-
* @param db the db (or transaction)
|
|
90
|
-
* @returns
|
|
91
|
-
*/
|
|
92
|
-
function readWithCheck(model, queryArgs, service, context, db) {
|
|
93
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
const args = (0, deepcopy_1.default)(queryArgs);
|
|
95
|
-
args.where = and(args.where, yield service.buildQueryGuard(model, 'read', context));
|
|
96
|
-
// recursively inject read guard conditions into the query args
|
|
97
|
-
yield injectNestedReadConditions(model, args, service, context);
|
|
98
|
-
service.verbose(`Reading with validation for ${model}: ${superjson_1.default.stringify(args)}`);
|
|
99
|
-
const result = yield db[model].findMany(args);
|
|
100
|
-
yield Promise.all(result.map((item) => postProcessForRead(item, model, args, service, context, db, 'read')));
|
|
101
|
-
return result;
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
exports.readWithCheck = readWithCheck;
|
|
105
|
-
function injectNestedReadConditions(model, args, service, context) {
|
|
106
|
-
var _a, _b, _c, _d;
|
|
107
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
-
const injectTarget = (_a = args.select) !== null && _a !== void 0 ? _a : args.include;
|
|
109
|
-
if (!injectTarget) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
for (const field of Object.keys(injectTarget)) {
|
|
113
|
-
const fieldInfo = yield service.resolveField(model, field);
|
|
114
|
-
if (!fieldInfo || !fieldInfo.isDataModel) {
|
|
115
|
-
// only care about relation fields
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
if (fieldInfo.isArray) {
|
|
119
|
-
if (typeof injectTarget[field] !== 'object') {
|
|
120
|
-
injectTarget[field] = {};
|
|
121
|
-
}
|
|
122
|
-
// inject extra condition for to-many relation
|
|
123
|
-
injectTarget[field].where = and(injectTarget.where, yield service.buildQueryGuard(fieldInfo.type, 'read', context));
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
// there's no way of injecting condition for to-one relation, so we
|
|
127
|
-
// make sure 'id' field is selected and check them against query result
|
|
128
|
-
if (((_b = injectTarget[field]) === null || _b === void 0 ? void 0 : _b.select) &&
|
|
129
|
-
((_d = (_c = injectTarget[field]) === null || _c === void 0 ? void 0 : _c.select) === null || _d === void 0 ? void 0 : _d.id) !== true) {
|
|
130
|
-
injectTarget[field].select.id = true;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
// recurse
|
|
134
|
-
yield injectNestedReadConditions(fieldInfo.type, injectTarget[field], service, context);
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Post processing checks for read model entities.
|
|
140
|
-
* Validates to-one relations (which can't be trimmed
|
|
141
|
-
* at query time) and removes fields that should be
|
|
142
|
-
* omitted.
|
|
143
|
-
*/
|
|
144
|
-
function postProcessForRead(entityData, model, args, service, context, db, operation) {
|
|
145
|
-
var _a, _b;
|
|
146
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
if (!(entityData === null || entityData === void 0 ? void 0 : entityData.id)) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
for (const field of Object.keys(entityData)) {
|
|
151
|
-
if (yield shouldOmit(service, model, field)) {
|
|
152
|
-
delete entityData[field];
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
const injectTarget = (_a = args.select) !== null && _a !== void 0 ? _a : args.include;
|
|
156
|
-
if (!injectTarget) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
// to-one relation data cannot be trimmed by injected guards, we have to
|
|
160
|
-
// post-check them
|
|
161
|
-
for (const field of Object.keys(injectTarget)) {
|
|
162
|
-
const fieldInfo = yield service.resolveField(model, field);
|
|
163
|
-
if (!fieldInfo ||
|
|
164
|
-
!fieldInfo.isDataModel ||
|
|
165
|
-
fieldInfo.isArray ||
|
|
166
|
-
!((_b = entityData === null || entityData === void 0 ? void 0 : entityData[field]) === null || _b === void 0 ? void 0 : _b.id)) {
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
service.verbose(`Validating read of to-one relation: ${fieldInfo.type}#${entityData[field].id}`);
|
|
170
|
-
yield checkPolicyForIds(fieldInfo.type, [entityData[field].id], operation, service, context, db);
|
|
171
|
-
// recurse
|
|
172
|
-
yield postProcessForRead(entityData[field], fieldInfo.type, injectTarget[field], service, context, db, operation);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Validates that a model entity satisfies 'update' policy rules
|
|
178
|
-
* before conducting an update
|
|
179
|
-
*
|
|
180
|
-
* @param model model under update
|
|
181
|
-
* @param id id of entity under update
|
|
182
|
-
* @param updateArgs Prisma update args
|
|
183
|
-
* @param service the ZenStack service
|
|
184
|
-
* @param context the query context
|
|
185
|
-
* @param transaction the db transaction context
|
|
186
|
-
*/
|
|
187
|
-
function preUpdateCheck(model, id, updateArgs, service, context, transaction) {
|
|
188
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
189
|
-
// check the entity directly under update first
|
|
190
|
-
yield checkPolicyForIds(model, [id], 'update', service, context, transaction);
|
|
191
|
-
// We need to ensure that all nested updates respect policy rules of
|
|
192
|
-
// the corresponding model.
|
|
193
|
-
//
|
|
194
|
-
// Here we use a visitor to collect all necessary
|
|
195
|
-
// checkes. During visiting, for every update we meet agains a relation,
|
|
196
|
-
// we collect its path (starting from the root object). If the relation
|
|
197
|
-
// is a to-many one, it can carry filter condition that we collect as well.
|
|
198
|
-
//
|
|
199
|
-
// After the visiting, we validate that each collected path satisfies
|
|
200
|
-
// corresponding policy rules by making separate queries.
|
|
201
|
-
const visitor = new nested_write_vistor_1.NestedWriteVisitor(service);
|
|
202
|
-
const state = [];
|
|
203
|
-
const checks = [];
|
|
204
|
-
const visitAction = (fieldInfo, action, fieldData, _parentData, state) => __awaiter(this, void 0, void 0, function* () {
|
|
205
|
-
if (!fieldInfo.isDataModel) {
|
|
206
|
-
return state;
|
|
207
|
-
}
|
|
208
|
-
if (![
|
|
209
|
-
'update',
|
|
210
|
-
'updateMany',
|
|
211
|
-
'upsert',
|
|
212
|
-
'delete',
|
|
213
|
-
'deleteMany',
|
|
214
|
-
].includes(action)) {
|
|
215
|
-
// no more nested writes inside, stop recursion
|
|
216
|
-
return undefined;
|
|
217
|
-
}
|
|
218
|
-
// for to-many relation, a filter condition can be attached
|
|
219
|
-
let condition = undefined;
|
|
220
|
-
if (fieldInfo.isArray) {
|
|
221
|
-
switch (action) {
|
|
222
|
-
case 'update':
|
|
223
|
-
case 'updateMany':
|
|
224
|
-
case 'upsert':
|
|
225
|
-
// condition is wrapped in 'where'
|
|
226
|
-
condition = or(...ensureArray(fieldData).map((d) => d.where));
|
|
227
|
-
break;
|
|
228
|
-
case 'delete':
|
|
229
|
-
case 'deleteMany':
|
|
230
|
-
// condition is not wrapped
|
|
231
|
-
condition = or(...ensureArray(fieldData));
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
// build up a new segment of path
|
|
236
|
-
const selectionPath = [
|
|
237
|
-
...state,
|
|
238
|
-
{ field: fieldInfo, where: condition },
|
|
239
|
-
];
|
|
240
|
-
const operation = [
|
|
241
|
-
'update',
|
|
242
|
-
'updateMany',
|
|
243
|
-
'upsert',
|
|
244
|
-
].includes(action)
|
|
245
|
-
? 'update'
|
|
246
|
-
: 'delete';
|
|
247
|
-
// collect an asynchronous check action
|
|
248
|
-
checks.push(checkPolicyForSelectionPath(model, id, selectionPath, operation, transaction, service, context));
|
|
249
|
-
// recurse down with the current path as the new state
|
|
250
|
-
return selectionPath;
|
|
251
|
-
});
|
|
252
|
-
yield visitor.visit(model, updateArgs.data, undefined, state, visitAction);
|
|
253
|
-
yield Promise.all(checks);
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
exports.preUpdateCheck = preUpdateCheck;
|
|
257
|
-
/**
|
|
258
|
-
* Given a list of ids for a model, check if they all match policy rules, and if not,
|
|
259
|
-
* throw a CRUDError.
|
|
260
|
-
*
|
|
261
|
-
* @param model the model
|
|
262
|
-
* @param ids the entity ids
|
|
263
|
-
* @param operation the operation to check for
|
|
264
|
-
* @param service the ZenStack service
|
|
265
|
-
* @param context the query context
|
|
266
|
-
* @param db the db or transaction
|
|
267
|
-
*/
|
|
268
|
-
function checkPolicyForIds(model, ids, operation, service, context, db) {
|
|
269
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
270
|
-
service.verbose(`Checking policy for ${model}#[${ids.join(', ')}] for ${operation}`);
|
|
271
|
-
// build a query condition with policy injected
|
|
272
|
-
const idCondition = ids.length > 1 ? { id: { in: ids } } : { id: ids[0] };
|
|
273
|
-
const query = {
|
|
274
|
-
where: and(idCondition, yield service.buildQueryGuard(model, operation, context)),
|
|
275
|
-
select: { id: true },
|
|
276
|
-
};
|
|
277
|
-
// query with policy injected
|
|
278
|
-
const filteredResult = (yield db[model].findMany(query));
|
|
279
|
-
// see if we get fewer items with policy, if so, reject with an throw
|
|
280
|
-
const filteredIds = filteredResult.map((item) => item.id);
|
|
281
|
-
if (filteredIds.length < ids.length) {
|
|
282
|
-
const gap = ids.filter((id) => !filteredIds.includes(id));
|
|
283
|
-
throw new types_2.CRUDError(types_1.ServerErrorCode.DENIED_BY_POLICY, `denied by policy: entities failed '${operation}' check, ${model}#[${gap.join(', ')}]`);
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
exports.checkPolicyForIds = checkPolicyForIds;
|
|
288
|
-
/**
|
|
289
|
-
* Given a selection path, check if the entities at the end of path satisfy
|
|
290
|
-
* policy rules. If not, throw an error.
|
|
291
|
-
*/
|
|
292
|
-
function checkPolicyForSelectionPath(model, id, selectionPath, operation, db, service, context) {
|
|
293
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
294
|
-
const targetField = selectionPath[selectionPath.length - 1].field;
|
|
295
|
-
// build a Prisma query for the path
|
|
296
|
-
const query = buildChainedSelectQuery(id, selectionPath);
|
|
297
|
-
service.verbose(`Query for selection path: model ${model}, path ${superjson_1.default.stringify(selectionPath)}, query ${superjson_1.default.stringify(query)}`);
|
|
298
|
-
const r = yield db[model].findUnique(query);
|
|
299
|
-
// collect ids at the end of the path
|
|
300
|
-
const ids = collectTerminalEntityIds(selectionPath, r);
|
|
301
|
-
service.verbose(`Collected leaf ids: ${superjson_1.default.stringify(ids)}`);
|
|
302
|
-
if (ids.length === 0) {
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
// check policies for the collected ids
|
|
306
|
-
yield checkPolicyForIds(targetField.type, ids, operation, service, context, db);
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Builds a Prisma query for the given selection path
|
|
311
|
-
*/
|
|
312
|
-
function buildChainedSelectQuery(id, selectionPath) {
|
|
313
|
-
const query = { where: { id }, select: { id: true } };
|
|
314
|
-
let currSelect = query.select;
|
|
315
|
-
for (const path of selectionPath) {
|
|
316
|
-
const nextSelect = { select: { id: true } };
|
|
317
|
-
currSelect[path.field.name] = nextSelect;
|
|
318
|
-
if (path.where) {
|
|
319
|
-
currSelect[path.field.name].where = path.where;
|
|
320
|
-
}
|
|
321
|
-
currSelect = nextSelect.select;
|
|
322
|
-
}
|
|
323
|
-
return query;
|
|
324
|
-
}
|
|
325
|
-
function collectTerminalEntityIds(selectionPath, data) {
|
|
326
|
-
let curr = data;
|
|
327
|
-
for (const path of selectionPath) {
|
|
328
|
-
curr = curr[path.field.name];
|
|
329
|
-
}
|
|
330
|
-
if (!curr) {
|
|
331
|
-
throw new types_2.CRUDError(types_1.ServerErrorCode.UNKNOWN, 'an unexpected error occurred');
|
|
332
|
-
}
|
|
333
|
-
return Array.isArray(curr)
|
|
334
|
-
? curr.map((item) => item.id)
|
|
335
|
-
: [curr.id];
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Injects assignment of zenstack_transaction field for all nested
|
|
339
|
-
* update/create in a Prisma update args recursively.
|
|
340
|
-
*
|
|
341
|
-
* @return a tuple containing all model types that are involved in
|
|
342
|
-
* creation or updating, respectively
|
|
343
|
-
*/
|
|
344
|
-
function injectTransactionId(model, args, operation, transactionId, service) {
|
|
345
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
346
|
-
const updatedModels = new Set();
|
|
347
|
-
const createdModels = new Set();
|
|
348
|
-
if (args.data) {
|
|
349
|
-
args.data[constants_1.TRANSACTION_FIELD_NAME] = `${transactionId}:${operation}`;
|
|
350
|
-
updatedModels.add(model);
|
|
351
|
-
}
|
|
352
|
-
const visitAction = (fieldInfo, action, fieldData) => __awaiter(this, void 0, void 0, function* () {
|
|
353
|
-
if (fieldInfo.isDataModel && fieldData) {
|
|
354
|
-
switch (action) {
|
|
355
|
-
case 'update':
|
|
356
|
-
case 'updateMany':
|
|
357
|
-
ensureArray(fieldData).forEach((item) => {
|
|
358
|
-
if (fieldInfo.isArray && item.data) {
|
|
359
|
-
item.data[constants_1.TRANSACTION_FIELD_NAME] = `${transactionId}:update`;
|
|
360
|
-
}
|
|
361
|
-
else {
|
|
362
|
-
item[constants_1.TRANSACTION_FIELD_NAME] = `${transactionId}:update`;
|
|
363
|
-
}
|
|
364
|
-
updatedModels.add(fieldInfo.type);
|
|
365
|
-
});
|
|
366
|
-
break;
|
|
367
|
-
case 'upsert':
|
|
368
|
-
ensureArray(fieldData).forEach((item) => {
|
|
369
|
-
item.create[constants_1.TRANSACTION_FIELD_NAME] = `${transactionId}:create`;
|
|
370
|
-
createdModels.add(fieldInfo.type);
|
|
371
|
-
item.update[constants_1.TRANSACTION_FIELD_NAME] = `${transactionId}:update`;
|
|
372
|
-
updatedModels.add(fieldInfo.type);
|
|
373
|
-
});
|
|
374
|
-
break;
|
|
375
|
-
case 'create':
|
|
376
|
-
case 'createMany':
|
|
377
|
-
ensureArray(fieldData).forEach((item) => {
|
|
378
|
-
item[constants_1.TRANSACTION_FIELD_NAME] = `${transactionId}:create`;
|
|
379
|
-
createdModels.add(fieldInfo.type);
|
|
380
|
-
});
|
|
381
|
-
break;
|
|
382
|
-
case 'connectOrCreate':
|
|
383
|
-
ensureArray(fieldData).forEach((item) => {
|
|
384
|
-
item.create[constants_1.TRANSACTION_FIELD_NAME] = `${transactionId}:create`;
|
|
385
|
-
createdModels.add(fieldInfo.type);
|
|
386
|
-
});
|
|
387
|
-
break;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
return true;
|
|
391
|
-
});
|
|
392
|
-
const visitor = new nested_write_vistor_1.NestedWriteVisitor(service);
|
|
393
|
-
yield visitor.visit(model, args.data, undefined, undefined, visitAction);
|
|
394
|
-
return {
|
|
395
|
-
createdModels: Array.from(createdModels),
|
|
396
|
-
updatedModels: Array.from(updatedModels),
|
|
397
|
-
};
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
exports.injectTransactionId = injectTransactionId;
|
|
401
|
-
/**
|
|
402
|
-
* Preprocesses the given write args to modify field values (in place) based on
|
|
403
|
-
* attributes like @password
|
|
404
|
-
*/
|
|
405
|
-
function preprocessWritePayload(model, args, service) {
|
|
406
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
407
|
-
const visitAction = (fieldInfo, _action, fieldData, parentData) => __awaiter(this, void 0, void 0, function* () {
|
|
408
|
-
var _a, _b, _c;
|
|
409
|
-
// process @password field
|
|
410
|
-
const pwdAttr = (_a = fieldInfo.attributes) === null || _a === void 0 ? void 0 : _a.find((attr) => attr.name === '@password');
|
|
411
|
-
if (pwdAttr && fieldInfo.type === 'String') {
|
|
412
|
-
// hash password value
|
|
413
|
-
let salt = (_b = pwdAttr.args.find((arg) => arg.name === 'salt')) === null || _b === void 0 ? void 0 : _b.value;
|
|
414
|
-
if (!salt) {
|
|
415
|
-
salt = (_c = pwdAttr.args.find((arg) => arg.name === 'saltLength')) === null || _c === void 0 ? void 0 : _c.value;
|
|
416
|
-
}
|
|
417
|
-
if (!salt) {
|
|
418
|
-
salt = constants_1.DEFAULT_PASSWORD_SALT_LENGTH;
|
|
419
|
-
}
|
|
420
|
-
parentData[fieldInfo.name] = (0, bcryptjs_1.hashSync)(fieldData, salt);
|
|
421
|
-
}
|
|
422
|
-
// deserialize Buffer field
|
|
423
|
-
if (fieldInfo.type === 'Bytes' && Array.isArray(fieldData.data)) {
|
|
424
|
-
parentData[fieldInfo.name] = Buffer.from(fieldData.data);
|
|
425
|
-
}
|
|
426
|
-
// deserialize BigInt field
|
|
427
|
-
if (fieldInfo.type === 'BigInt' && typeof fieldData === 'string') {
|
|
428
|
-
parentData[fieldInfo.name] = BigInt(fieldData);
|
|
429
|
-
}
|
|
430
|
-
return true;
|
|
431
|
-
});
|
|
432
|
-
const visitor = new nested_write_vistor_1.NestedWriteVisitor(service);
|
|
433
|
-
yield visitor.visit(model, args.data, undefined, undefined, visitAction);
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
exports.preprocessWritePayload = preprocessWritePayload;
|
|
437
|
-
function shouldOmit(service, model, field) {
|
|
438
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
439
|
-
if ([constants_1.TRANSACTION_FIELD_NAME, constants_1.GUARD_FIELD_NAME].includes(field)) {
|
|
440
|
-
return true;
|
|
441
|
-
}
|
|
442
|
-
const fieldInfo = yield service.resolveField(model, field);
|
|
443
|
-
return !!(fieldInfo && fieldInfo.attributes.find((attr) => attr.name === '@omit'));
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
|
-
//#endregion
|
|
447
|
-
//# sourceMappingURL=policy-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"policy-utils.js","sourceRoot":"","sources":["../../../../src/handler/data/policy-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sEAAsE;AACtE,uDAAuD;AACvD,uCAAoC;AACpC,wDAAgC;AAChC,0DAAkC;AAClC,+CAIyB;AACzB,uCAOqB;AACrB,oCAA4D;AAC5D,+DAA2D;AAE3D,yBAAyB;AAEzB;;GAEG;AACH,SAAgB,GAAG,CAAC,GAAG,UAAqB;IACxC,MAAM,QAAQ,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/C,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;QACvB,OAAO,SAAS,CAAC;KACpB;SAAM,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;QAC9B,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;KACtB;SAAM;QACH,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;KAC5B;AACL,CAAC;AATD,kBASC;AAED;;GAEG;AACH,SAAgB,EAAE,CAAC,GAAG,UAAqB;IACvC,MAAM,QAAQ,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/C,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;QACvB,OAAO,SAAS,CAAC;KACpB;SAAM,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;QAC9B,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;KACtB;SAAM;QACH,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC;KAC3B;AACL,CAAC;AATD,gBASC;AAED;;GAEG;AACH,SAAgB,WAAW,CAAI,KAAQ;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AC;QAC3D,OAAO,CAAC,CAAC,CACL,SAAS,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,CAC1E,CAAC;IACN,CAAC;CAAA;AAED,YAAY"}
|
package/lib/handler/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as DataHandler } from './data/handler';
|
package/lib/handler/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DataHandler = void 0;
|
|
7
|
-
var handler_1 = require("./data/handler");
|
|
8
|
-
Object.defineProperty(exports, "DataHandler", { enumerable: true, get: function () { return __importDefault(handler_1).default; } });
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
package/lib/handler/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/handler/index.ts"],"names":[],"mappings":";;;;;;AAAA,0CAAwD;AAA/C,uHAAA,OAAO,OAAe"}
|
package/lib/handler/types.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
-
import { ServerErrorCode } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Defines contract for a Next.js API endpoint handler.
|
|
5
|
-
*/
|
|
6
|
-
export interface RequestHandler {
|
|
7
|
-
/**
|
|
8
|
-
* Handles a request for a given route path.
|
|
9
|
-
*
|
|
10
|
-
* @param req The request
|
|
11
|
-
* @param res The response
|
|
12
|
-
* @param path The route path (with /api/zenstack prefix removed)
|
|
13
|
-
*/
|
|
14
|
-
handle(req: NextApiRequest, res: NextApiResponse, path: string[]): Promise<void>;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Error thrown during CRUD operations
|
|
18
|
-
*/
|
|
19
|
-
export declare class CRUDError extends Error {
|
|
20
|
-
readonly code: ServerErrorCode;
|
|
21
|
-
constructor(code: ServerErrorCode, message?: string);
|
|
22
|
-
toString(): string;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* All write actions supported by Prisma
|
|
26
|
-
*/
|
|
27
|
-
export declare const PrismaWriteActions: readonly ["create", "createMany", "connectOrCreate", "update", "updateMany", "upsert", "delete", "deleteMany", "connect", "none"];
|
|
28
|
-
export type PrismaWriteActionType = typeof PrismaWriteActions[number];
|
package/lib/handler/types.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PrismaWriteActions = exports.CRUDError = void 0;
|
|
4
|
-
const types_1 = require("../types");
|
|
5
|
-
/**
|
|
6
|
-
* Error thrown during CRUD operations
|
|
7
|
-
*/
|
|
8
|
-
class CRUDError extends Error {
|
|
9
|
-
constructor(code, message) {
|
|
10
|
-
message = message
|
|
11
|
-
? `${(0, types_1.getServerErrorMessage)(code)}: ${message}`
|
|
12
|
-
: (0, types_1.getServerErrorMessage)(code);
|
|
13
|
-
super(message);
|
|
14
|
-
this.code = code;
|
|
15
|
-
}
|
|
16
|
-
toString() {
|
|
17
|
-
return `Request handler error: ${this.code}, ${this.message}`;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.CRUDError = CRUDError;
|
|
21
|
-
/**
|
|
22
|
-
* All write actions supported by Prisma
|
|
23
|
-
*/
|
|
24
|
-
exports.PrismaWriteActions = [
|
|
25
|
-
'create',
|
|
26
|
-
'createMany',
|
|
27
|
-
'connectOrCreate',
|
|
28
|
-
'update',
|
|
29
|
-
'updateMany',
|
|
30
|
-
'upsert',
|
|
31
|
-
'delete',
|
|
32
|
-
'deleteMany',
|
|
33
|
-
'connect',
|
|
34
|
-
'none',
|
|
35
|
-
];
|
|
36
|
-
//# sourceMappingURL=types.js.map
|
package/lib/handler/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/handler/types.ts"],"names":[],"mappings":";;;AACA,oCAAkE;AAoBlE;;GAEG;AACH,MAAa,SAAU,SAAQ,KAAK;IAChC,YAA4B,IAAqB,EAAE,OAAgB;QAC/D,OAAO,GAAG,OAAO;YACb,CAAC,CAAC,GAAG,IAAA,6BAAqB,EAAC,IAAI,CAAC,KAAK,OAAO,EAAE;YAC9C,CAAC,CAAC,IAAA,6BAAqB,EAAC,IAAI,CAAC,CAAC;QAClC,KAAK,CAAC,OAAO,CAAC,CAAC;QAJS,SAAI,GAAJ,IAAI,CAAiB;IAKjD,CAAC;IAED,QAAQ;QACJ,OAAO,0BAA0B,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;IAClE,CAAC;CACJ;AAXD,8BAWC;AAED;;GAEG;AACU,QAAA,kBAAkB,GAAG;IAC9B,QAAQ;IACR,YAAY;IACZ,iBAAiB;IACjB,QAAQ;IACR,YAAY;IACZ,QAAQ;IACR,QAAQ;IACR,YAAY;IACZ,SAAS;IACT,MAAM;CACA,CAAC"}
|
package/lib/index.d.ts
DELETED
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,2CAAyB;AACzB,4CAA0B;AAC1B,oDAAkC;AAClC,+CAA6B;AAC7B,2CAAyB"}
|
package/lib/policy.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AuthUser, FieldInfo, PolicyOperationKind, QueryContext } from './types';
|
|
2
|
-
export type WithPolicyContext = {
|
|
3
|
-
user?: AuthUser;
|
|
4
|
-
};
|
|
5
|
-
type PolicyFunc = (context: QueryContext) => any;
|
|
6
|
-
export type PolicyDef = {
|
|
7
|
-
guard: Record<string, Record<PolicyOperationKind, PolicyFunc>>;
|
|
8
|
-
fieldMapping: Record<string, Record<string, FieldInfo>>;
|
|
9
|
-
};
|
|
10
|
-
export declare function withPolicy<DbClient = any>(prisma: DbClient, policy: PolicyDef, context: WithPolicyContext): DbClient;
|
|
11
|
-
export {};
|
package/lib/policy.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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 handler_1 = require("./proxy/handler");
|
|
6
|
-
function withPolicy(prisma, policy, context) {
|
|
7
|
-
return new Proxy(prisma, (0, handler_1.prismaClientProxyHandler)(prisma, policy, context.user));
|
|
8
|
-
}
|
|
9
|
-
exports.withPolicy = withPolicy;
|
|
10
|
-
//# sourceMappingURL=policy.js.map
|