@zenstackhq/runtime 0.3.10 → 0.3.12
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/{LICENSE.md → LICENSE} +0 -0
- package/client/index.d.ts +4 -0
- package/client/index.js +7 -0
- package/lib/client.d.ts +3 -0
- package/lib/client.js +34 -0
- package/lib/client.js.map +1 -0
- package/lib/config.d.ts +14 -0
- package/lib/config.js +3 -0
- package/lib/config.js.map +1 -0
- package/lib/constants.d.ts +12 -0
- package/lib/constants.js +16 -0
- package/lib/constants.js.map +1 -0
- package/lib/handler/data/handler.d.ts +19 -0
- package/lib/handler/data/handler.js +306 -0
- package/lib/handler/data/handler.js.map +1 -0
- package/lib/handler/data/nested-write-vistor.d.ts +31 -0
- package/lib/handler/data/nested-write-vistor.js +67 -0
- package/lib/handler/data/nested-write-vistor.js.map +1 -0
- package/lib/handler/data/policy-utils.d.ts +73 -0
- package/lib/handler/data/policy-utils.js +477 -0
- package/lib/handler/data/policy-utils.js.map +1 -0
- package/lib/handler/index.d.ts +1 -0
- package/lib/handler/index.js +9 -0
- package/lib/handler/index.js.map +1 -0
- package/lib/handler/types.d.ts +28 -0
- package/lib/handler/types.js +36 -0
- package/lib/handler/types.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +22 -0
- package/lib/index.js.map +1 -0
- package/lib/request-handler.d.ts +21 -0
- package/lib/request-handler.js +37 -0
- package/lib/request-handler.js.map +1 -0
- package/lib/request.d.ts +16 -0
- package/lib/request.js +171 -0
- package/lib/request.js.map +1 -0
- package/lib/service.d.ts +32 -0
- package/lib/service.js +185 -0
- package/lib/service.js.map +1 -0
- package/lib/types.d.ts +168 -0
- package/lib/types.js +59 -0
- package/lib/types.js.map +1 -0
- package/lib/validation.d.ts +12 -0
- package/lib/validation.js +26 -0
- package/lib/validation.js.map +1 -0
- package/package.json +34 -8
- package/{auth.d.ts → server/auth.d.ts} +0 -0
- package/{auth.js → server/auth.js} +0 -0
- package/server/index.d.ts +16 -0
- package/server/index.js +7 -0
- package/{types.d.ts → types/index.d.ts} +0 -0
- package/{types.js → types/index.js} +0 -0
- package/README.md +0 -5
- package/client.d.ts +0 -1
- package/client.js +0 -3
- package/hooks.d.ts +0 -10
- package/hooks.js +0 -3
- package/index.d.ts +0 -3
- package/index.js +0 -1
- package/server.d.ts +0 -1
- package/server.js +0 -3
package/lib/types.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getServerErrorMessage = exports.ServerErrorCode = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Error codes for errors on server side
|
|
6
|
+
*/
|
|
7
|
+
var ServerErrorCode;
|
|
8
|
+
(function (ServerErrorCode) {
|
|
9
|
+
/**
|
|
10
|
+
* The specified entity cannot be found
|
|
11
|
+
*/
|
|
12
|
+
ServerErrorCode["ENTITY_NOT_FOUND"] = "ENTITY_NOT_FOUND";
|
|
13
|
+
/**
|
|
14
|
+
* The request parameter is invalid, either containing invalid fields or missing required fields
|
|
15
|
+
*/
|
|
16
|
+
ServerErrorCode["INVALID_REQUEST_PARAMS"] = "INVALID_REQUEST_PARAMS";
|
|
17
|
+
/**
|
|
18
|
+
* The request is rejected by policy checks
|
|
19
|
+
*/
|
|
20
|
+
ServerErrorCode["DENIED_BY_POLICY"] = "DENIED_BY_POLICY";
|
|
21
|
+
/**
|
|
22
|
+
* Violation of database unique constraints
|
|
23
|
+
*/
|
|
24
|
+
ServerErrorCode["UNIQUE_CONSTRAINT_VIOLATION"] = "UNIQUE_CONSTRAINT_VIOLATION";
|
|
25
|
+
/**
|
|
26
|
+
* Violation of database reference constraint (aka. foreign key constraints)
|
|
27
|
+
*/
|
|
28
|
+
ServerErrorCode["REFERENCE_CONSTRAINT_VIOLATION"] = "REFERENCE_CONSTRAINT_VIOLATION";
|
|
29
|
+
/**
|
|
30
|
+
* A write operation succeeded but the result cannot be read back due to policy control
|
|
31
|
+
*/
|
|
32
|
+
ServerErrorCode["READ_BACK_AFTER_WRITE_DENIED"] = "READ_BACK_AFTER_WRITE_DENIED";
|
|
33
|
+
/**
|
|
34
|
+
* Unknown error
|
|
35
|
+
*/
|
|
36
|
+
ServerErrorCode["UNKNOWN"] = "UNKNOWN";
|
|
37
|
+
})(ServerErrorCode = exports.ServerErrorCode || (exports.ServerErrorCode = {}));
|
|
38
|
+
function getServerErrorMessage(code) {
|
|
39
|
+
switch (code) {
|
|
40
|
+
case ServerErrorCode.ENTITY_NOT_FOUND:
|
|
41
|
+
return 'the requested entity is not found';
|
|
42
|
+
case ServerErrorCode.INVALID_REQUEST_PARAMS:
|
|
43
|
+
return 'request parameters are invalid';
|
|
44
|
+
case ServerErrorCode.DENIED_BY_POLICY:
|
|
45
|
+
return 'the request was denied due to access policy violation';
|
|
46
|
+
case ServerErrorCode.UNIQUE_CONSTRAINT_VIOLATION:
|
|
47
|
+
return 'the request failed because of database unique constraint violation';
|
|
48
|
+
case ServerErrorCode.REFERENCE_CONSTRAINT_VIOLATION:
|
|
49
|
+
return 'the request failed because of database foreign key constraint violation';
|
|
50
|
+
case ServerErrorCode.READ_BACK_AFTER_WRITE_DENIED:
|
|
51
|
+
return 'the write operation succeeded, but the data cannot be read back due to access policy violation';
|
|
52
|
+
case ServerErrorCode.UNKNOWN:
|
|
53
|
+
return 'an unknown error occurred';
|
|
54
|
+
default:
|
|
55
|
+
return `generic error: ${code}`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.getServerErrorMessage = getServerErrorMessage;
|
|
59
|
+
//# sourceMappingURL=types.js.map
|
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAqIA;;GAEG;AACH,IAAY,eAmCX;AAnCD,WAAY,eAAe;IACvB;;OAEG;IACH,wDAAqC,CAAA;IAErC;;OAEG;IACH,oEAAiD,CAAA;IAEjD;;OAEG;IACH,wDAAqC,CAAA;IAErC;;OAEG;IACH,8EAA2D,CAAA;IAE3D;;OAEG;IACH,oFAAiE,CAAA;IAEjE;;OAEG;IACH,gFAA6D,CAAA;IAE7D;;OAEG;IACH,sCAAmB,CAAA;AACvB,CAAC,EAnCW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAmC1B;AAED,SAAgB,qBAAqB,CAAC,IAAqB;IACvD,QAAQ,IAAI,EAAE;QACV,KAAK,eAAe,CAAC,gBAAgB;YACjC,OAAO,mCAAmC,CAAC;QAE/C,KAAK,eAAe,CAAC,sBAAsB;YACvC,OAAO,gCAAgC,CAAC;QAE5C,KAAK,eAAe,CAAC,gBAAgB;YACjC,OAAO,uDAAuD,CAAC;QAEnE,KAAK,eAAe,CAAC,2BAA2B;YAC5C,OAAO,oEAAoE,CAAC;QAEhF,KAAK,eAAe,CAAC,8BAA8B;YAC/C,OAAO,yEAAyE,CAAC;QAErF,KAAK,eAAe,CAAC,4BAA4B;YAC7C,OAAO,gGAAgG,CAAC;QAE5G,KAAK,eAAe,CAAC,OAAO;YACxB,OAAO,2BAA2B,CAAC;QAEvC;YACI,OAAO,kBAAkB,IAAI,EAAE,CAAC;KACvC;AACL,CAAC;AA1BD,sDA0BC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Error indicating violations of field-level constraints
|
|
4
|
+
*/
|
|
5
|
+
export declare class ValidationError {
|
|
6
|
+
readonly message: string;
|
|
7
|
+
constructor(message: string);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Validate the given data with the given zod schema (for field-level constraints)
|
|
11
|
+
*/
|
|
12
|
+
export declare function validate(validator: z.ZodType, data: unknown): void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validate = exports.ValidationError = void 0;
|
|
4
|
+
const zod_validation_error_1 = require("zod-validation-error");
|
|
5
|
+
/**
|
|
6
|
+
* Error indicating violations of field-level constraints
|
|
7
|
+
*/
|
|
8
|
+
class ValidationError {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
this.message = message;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.ValidationError = ValidationError;
|
|
14
|
+
/**
|
|
15
|
+
* Validate the given data with the given zod schema (for field-level constraints)
|
|
16
|
+
*/
|
|
17
|
+
function validate(validator, data) {
|
|
18
|
+
try {
|
|
19
|
+
validator.parse(data);
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
throw new ValidationError((0, zod_validation_error_1.fromZodError)(err).message);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.validate = validate;
|
|
26
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":";;;AACA,+DAAoD;AAEpD;;GAEG;AACH,MAAa,eAAe;IACxB,YAA4B,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;IAAG,CAAC;CAClD;AAFD,0CAEC;AAED;;GAEG;AACH,SAAgB,QAAQ,CAAC,SAAoB,EAAE,IAAa;IACxD,IAAI;QACA,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;KACzB;IAAC,OAAO,GAAG,EAAE;QACV,MAAM,IAAI,eAAe,CAAC,IAAA,mCAAY,EAAC,GAAiB,CAAC,CAAC,OAAO,CAAC,CAAC;KACtE;AACL,CAAC;AAND,4BAMC"}
|
package/package.json
CHANGED
|
@@ -1,23 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenstackhq/runtime",
|
|
3
3
|
"displayName": "ZenStack Runtime Library",
|
|
4
|
-
"version": "0.3.
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "0.3.12",
|
|
5
|
+
"description": "Runtime of ZenStack for both client-side and server-side environments.",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/zenstackhq/zenstack"
|
|
9
9
|
},
|
|
10
|
-
"
|
|
11
|
-
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"directory": "dist",
|
|
12
|
+
"linkDirectory": true
|
|
13
|
+
},
|
|
12
14
|
"dependencies": {
|
|
13
|
-
"
|
|
15
|
+
"colors": "1.4.0",
|
|
16
|
+
"cuid": "^2.1.8",
|
|
17
|
+
"decimal.js": "^10.4.2",
|
|
18
|
+
"deepcopy": "^2.1.0",
|
|
19
|
+
"swr": "^1.3.0",
|
|
20
|
+
"tslib": "^2.4.1",
|
|
21
|
+
"@types/bcryptjs": "^2.4.2",
|
|
22
|
+
"bcryptjs": "^2.4.3",
|
|
23
|
+
"zod": "^3.19.1",
|
|
24
|
+
"zod-validation-error": "^0.2.1"
|
|
14
25
|
},
|
|
15
26
|
"peerDependencies": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
27
|
+
"next": "^12.3.1 || ^13",
|
|
28
|
+
"react": "^17.0.2 || ^18",
|
|
29
|
+
"react-dom": "^17.0.2 || ^18"
|
|
18
30
|
},
|
|
19
31
|
"author": {
|
|
20
32
|
"name": "ZenStack Team"
|
|
21
33
|
},
|
|
22
|
-
"license": "MIT"
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/bcryptjs": "^2.4.2",
|
|
37
|
+
"@types/jest": "^29.0.3",
|
|
38
|
+
"@types/node": "^14.18.29",
|
|
39
|
+
"rimraf": "^3.0.2",
|
|
40
|
+
"typescript": "^4.9.3"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"clean": "rimraf dist",
|
|
44
|
+
"build": "npm run clean && tsc && cp -r pre/* dist/ && cp ./package.json dist/",
|
|
45
|
+
"watch": "tsc --watch",
|
|
46
|
+
"lint": "eslint src --ext ts",
|
|
47
|
+
"publish-dev": "pnpm publish --tag dev"
|
|
48
|
+
}
|
|
23
49
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import service from '.zenstack/lib';
|
|
2
|
+
|
|
3
|
+
export type {
|
|
4
|
+
FieldInfo,
|
|
5
|
+
PolicyKind,
|
|
6
|
+
PolicyOperationKind,
|
|
7
|
+
RuntimeAttribute,
|
|
8
|
+
QueryContext,
|
|
9
|
+
} from '../lib/types';
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
requestHandler,
|
|
13
|
+
type RequestHandlerOptions,
|
|
14
|
+
} from '../lib/request-handler';
|
|
15
|
+
|
|
16
|
+
export default service;
|
package/server/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
|
|
3
|
+
exports.default = require('.zenstack/lib').default;
|
|
4
|
+
|
|
5
|
+
const exportStar = require('tslib').__exportStar;
|
|
6
|
+
exportStar(require('../lib/types'), exports);
|
|
7
|
+
exportStar(require('../lib/request-handler'), exports);
|
|
File without changes
|
|
File without changes
|
package/README.md
DELETED
package/client.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@zenstackhq/internal/lib/client';
|
package/client.js
DELETED
package/hooks.d.ts
DELETED
package/hooks.js
DELETED
package/index.d.ts
DELETED
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('.zenstack/lib').default;
|
package/server.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@zenstackhq/internal';
|
package/server.js
DELETED