@autofleet/zehut 2.0.2 → 2.0.3

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.
@@ -0,0 +1,9 @@
1
+ import { AccountType, PartialUserPayload } from '../user/ApiUser';
2
+ export declare type UserCustomAttributes = {
3
+ id?: string;
4
+ accountType?: AccountType;
5
+ elevatedPermissions?: PartialUserPayload;
6
+ permissions?: PartialUserPayload;
7
+ };
8
+ export declare const setIdentityNock: (userAttributes: any) => void;
9
+ export declare const mockRequestAndUser: (app: any, userCustomAttributes: any) => {};
@@ -0,0 +1,34 @@
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.mockRequestAndUser = exports.setIdentityNock = void 0;
7
+ const supertest_1 = __importDefault(require("supertest"));
8
+ const nock_1 = __importDefault(require("nock"));
9
+ const http_1 = __importDefault(require("http"));
10
+ const uuid_1 = require("uuid");
11
+ exports.setIdentityNock = (userAttributes) => {
12
+ nock_1.default(`http://${process.env.IDENTITY_MS_SERVICE_HOST}`)
13
+ .get(`/api/v1/users/${userAttributes.id}/authorization-payload`)
14
+ .reply(200, userAttributes.permissions);
15
+ };
16
+ exports.mockRequestAndUser = (app, userCustomAttributes) => {
17
+ var _a, _b, _c;
18
+ const agent = supertest_1.default.agent(app);
19
+ const userAttributes = {
20
+ id: userCustomAttributes.id || uuid_1.v4(),
21
+ permissions: {
22
+ businessModels: ((_a = userCustomAttributes === null || userCustomAttributes === void 0 ? void 0 : userCustomAttributes.permissions) === null || _a === void 0 ? void 0 : _a.businessModels) || {},
23
+ fleets: ((_b = userCustomAttributes === null || userCustomAttributes === void 0 ? void 0 : userCustomAttributes.permissions) === null || _b === void 0 ? void 0 : _b.fleets) || {},
24
+ demandSources: ((_c = userCustomAttributes === null || userCustomAttributes === void 0 ? void 0 : userCustomAttributes.permissions) === null || _c === void 0 ? void 0 : _c.demandSources) || {},
25
+ },
26
+ };
27
+ agent.set('x-af-user-id', userAttributes.id);
28
+ exports.setIdentityNock(userAttributes);
29
+ const agentObject = {};
30
+ http_1.default.METHODS.forEach((method) => {
31
+ agentObject[method.toLowerCase()] = (path) => agent[method.toLowerCase()](path).set('x-af-user-id', userAttributes.id);
32
+ });
33
+ return agentObject;
34
+ };
@@ -1,4 +1,4 @@
1
- declare type AccountType = 'client' | 'user' | 'service';
1
+ export declare type AccountType = 'client' | 'user' | 'service';
2
2
  interface EntityPermissions {
3
3
  [key: string]: string[];
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/zehut",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "manage user's identity",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -34,8 +34,11 @@
34
34
  "express": "^4.18.1",
35
35
  "jsonwebtoken": "^8.5.1",
36
36
  "merge-deep": "^3.0.3",
37
+ "methods": "^1.1.2",
37
38
  "moment": "^2.29.1",
39
+ "nock": "^13.2.9",
38
40
  "node-cache": "^5.1.2",
41
+ "supertest": "^6.2.4",
39
42
  "uuid": "^8.3.2"
40
43
  },
41
44
  "devDependencies": {