ais_auth_lib 1.0.3 → 1.0.4

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/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./conditions";
2
2
  export * from "./filter";
3
3
  export * from "./interfaces/rule";
4
+ export * from "./propertyFilter";
package/dist/index.js CHANGED
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./conditions"), exports);
18
18
  __exportStar(require("./filter"), exports);
19
19
  __exportStar(require("./interfaces/rule"), exports);
20
+ __exportStar(require("./propertyFilter"), exports);
@@ -0,0 +1,18 @@
1
+ export interface Resource {
2
+ name: string;
3
+ alias: string;
4
+ attributes: Attribute[];
5
+ }
6
+ export interface Attribute {
7
+ name: string;
8
+ alias: string;
9
+ type: string;
10
+ }
11
+ export declare const filterProperties: (objects: any[], rules: {
12
+ resource: string;
13
+ propetiesAccess: {
14
+ property: string;
15
+ read: boolean;
16
+ write: boolean;
17
+ }[];
18
+ }[], resources: Resource[]) => {}[];
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterProperties = void 0;
4
+ const filterProperties = (objects, rules, resources) => {
5
+ var _a;
6
+ if (rules.length > 0) {
7
+ const resource = rules[0].resource;
8
+ const properties = rules
9
+ .map((rule) => rule.propetiesAccess.map((pa) => pa.property))
10
+ .flat();
11
+ const allAttributes = (_a = resources
12
+ .find((r) => r.name === resource)) === null || _a === void 0 ? void 0 : _a.attributes.map((a) => a.name);
13
+ if (allAttributes) {
14
+ return objects.map((object) => {
15
+ return Object.keys(object).reduce((acc, key) => {
16
+ if (properties.includes(key) || !allAttributes.includes(key)) {
17
+ acc[key] = object[key];
18
+ }
19
+ return acc;
20
+ }, {});
21
+ });
22
+ }
23
+ else
24
+ return [];
25
+ }
26
+ return [];
27
+ };
28
+ exports.filterProperties = filterProperties;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ais_auth_lib",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "auth lib for microservices",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",