@autofleet/zehut 0.0.1-test-gery → 1.0.0-gery-ba-beta-1
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/README.md +63 -31
- package/lib/app-auth.d.ts +2 -0
- package/lib/app-auth.js +14 -0
- package/lib/check-permission.d.ts +6 -0
- package/lib/check-permission.js +35 -0
- package/lib/errors.d.ts +5 -0
- package/lib/errors.js +12 -0
- package/lib/exceptions/appDoesNotExist.d.ts +3 -0
- package/lib/exceptions/appDoesNotExist.js +5 -0
- package/lib/index.d.ts +48 -306
- package/lib/index.js +80 -2
- package/lib/secret-getter.d.ts +2 -0
- package/lib/secret-getter.js +30 -0
- package/lib/secret-getter.test.d.ts +1 -0
- package/lib/secret-getter.test.js +90 -0
- package/lib/services.d.ts +2 -0
- package/lib/services.js +27 -0
- package/lib/test-helpers/index.d.ts +9 -0
- package/lib/test-helpers/index.js +35 -0
- package/lib/tracer.d.ts +21 -0
- package/lib/tracer.js +73 -0
- package/lib/user/ApiUser.d.ts +48 -0
- package/lib/user/ApiUser.js +159 -0
- package/lib/user/api-user-flows.test.d.ts +1 -0
- package/lib/user/api-user-flows.test.js +125 -0
- package/lib/user/index.d.ts +19 -0
- package/lib/user/index.js +209 -0
- package/lib/utils.d.ts +5 -0
- package/lib/utils.js +99 -0
- package/package.json +35 -45
- package/lib/chunk-fqrStKt4.js +0 -1
- package/lib/index.cjs +0 -2
- package/lib/index.cjs.map +0 -1
- package/lib/index.d.cts +0 -310
- package/lib/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,45 +1,77 @@
|
|
|
1
|
-
# AutoFleet
|
|
1
|
+
# AutoFleet Node Common
|
|
2
|
+
This respostory is made in order have as much of common code as we can.
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
Each line of code used in wrriten in this repo will be used in the enetire AutoFleet system.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
Make sure you have:
|
|
7
|
+
* Tests
|
|
8
|
+
* Docs
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
## Consts
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
Currently we suppurt:
|
|
13
|
+
```
|
|
14
|
+
{
|
|
15
|
+
'OK'
|
|
16
|
+
'ERROR'
|
|
17
|
+
'FAIL'
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Network
|
|
22
|
+
Server 2 Servers communication.
|
|
23
|
+
|
|
24
|
+
Implemented:
|
|
25
|
+
* Retriving service urls from environment
|
|
26
|
+
* Retry - Using https://github.com/softonic/axios-retry
|
|
27
|
+
* Caching - TBD
|
|
28
|
+
* Syntatic response for fail - TBD
|
|
29
|
+
* Circuit Breaking - TBD
|
|
10
30
|
|
|
11
|
-
|
|
12
|
-
When upgrading from V3 to V4, the tracing system has been de-duped to use outbreak v2.
|
|
13
|
-
Historically, `zehut` and `outbreak` both added a layer of `async_hooks`, which each had a context that could store data.
|
|
14
|
-
The 2 had a nearly identical API, but did not communicate with each other, nor did they share data.
|
|
15
|
-
This version removes the trace added by `zehut` and only uses the `outbreak` one. This means that the context of the trace is now spread onto the headers of any outgoing HTTP request.
|
|
16
|
-
In order to allow keeping data in the context, without having `outbreak` add it to the headers, a new context has been added to the `outbreak` traces - `nonHeaderContext`.
|
|
17
|
-
Using the `getUser` function will keep working regularly, but reading anything else from the context will work only if you read from the correct context.
|
|
31
|
+
The API is just like [axios](https://github.com/axios/axios) api but the creation of new instance **must** have either `serviceName` or `serviceUrl` in options.
|
|
18
32
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
+ const user = zehut.getUser();
|
|
33
|
+
In case `serviceName` used the constractor will look for an environment varible with the the name `<SERVICE_NAME>_SERVICE_HOST`.
|
|
34
|
+
|
|
35
|
+
For Example:
|
|
23
36
|
```
|
|
37
|
+
const { Network } = require('@autofleet/node-common');
|
|
38
|
+
|
|
39
|
+
n = new Network({ serviceName: 'TEST' });
|
|
24
40
|
|
|
25
|
-
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
41
|
+
n.get('/posts/1');
|
|
42
|
+
```
|
|
43
|
+
.env file:
|
|
44
|
+
```
|
|
45
|
+
RIDE_SERVICE_HOST=jsonplaceholder.typicode.com
|
|
30
46
|
```
|
|
31
47
|
|
|
48
|
+
To learn more [click here](https://blog.risingstack.com/designing-microservices-architecture-for-failure/).
|
|
32
49
|
|
|
33
|
-
|
|
50
|
+
## Settings
|
|
34
51
|
|
|
35
|
-
|
|
36
|
-
|
|
52
|
+
### Adding settings
|
|
53
|
+
For adding new setting you need to add it to the map.js file, please specify
|
|
54
|
+
* name - descriptive name
|
|
55
|
+
* description - few words about what it does + unit
|
|
56
|
+
* type - supportable types: 'number', 'string', 'json'
|
|
57
|
+
* defaultValue - default value
|
|
58
|
+
* context - 'security' and 'operation' will not show in the simulator configuration
|
|
37
59
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
-
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
See example.
|
|
61
|
+
|
|
62
|
+
## DeLorean
|
|
63
|
+
|
|
64
|
+
Use this model to mock time on server - more info TBD.
|
|
65
|
+
|
|
66
|
+
## Publish package
|
|
67
|
+
|
|
68
|
+
bump the version number in package.json
|
|
69
|
+
and run
|
|
45
70
|
```
|
|
71
|
+
npm publish
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
# Environment Variables
|
|
75
|
+
|
|
76
|
+
when using this package locally or outside autofleet-prod project you must set INTEGRATION_MS_SERVICE_HOST in .env file
|
|
77
|
+
# zehut
|
package/lib/app-auth.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getClientSecret = exports.decodeAppBearer = void 0;
|
|
4
|
+
const services_1 = require("./services");
|
|
5
|
+
const decodeAppBearer = async (bearer, appId) => {
|
|
6
|
+
const { data: decoded } = await services_1.AutofleetApiNetwork.post('/api/v1/auth', { bearer, appId });
|
|
7
|
+
return decoded;
|
|
8
|
+
};
|
|
9
|
+
exports.decodeAppBearer = decodeAppBearer;
|
|
10
|
+
const getClientSecret = async (appId) => {
|
|
11
|
+
const { data: secret } = await services_1.AutofleetApiNetwork.get(`/api/v1/auth/client-secret/${appId}`);
|
|
12
|
+
return secret;
|
|
13
|
+
};
|
|
14
|
+
exports.getClientSecret = getClientSecret;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import ApiUser from './user/ApiUser';
|
|
2
|
+
export declare const getUser: () => ApiUser | undefined;
|
|
3
|
+
export declare const isUserExist: () => string;
|
|
4
|
+
export declare const checkFleetPermission: (fleetId: any) => boolean;
|
|
5
|
+
export declare const checkBusinessModelPermission: (businessModelId: any) => boolean;
|
|
6
|
+
export declare const checkDemandSourcePermission: (demandSourceId: any) => boolean;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkDemandSourcePermission = exports.checkBusinessModelPermission = exports.checkFleetPermission = exports.isUserExist = exports.getUser = void 0;
|
|
4
|
+
const tracer_1 = require("./tracer");
|
|
5
|
+
const getUser = () => (0, tracer_1.getCurrentTrace)()?.context?.get('userObject');
|
|
6
|
+
exports.getUser = getUser;
|
|
7
|
+
const isUserExist = () => {
|
|
8
|
+
const u = (0, exports.getUser)();
|
|
9
|
+
return u && u.id;
|
|
10
|
+
};
|
|
11
|
+
exports.isUserExist = isUserExist;
|
|
12
|
+
const checkFleetPermission = (fleetId) => {
|
|
13
|
+
if ((0, exports.isUserExist)()) {
|
|
14
|
+
const user = (0, exports.getUser)();
|
|
15
|
+
return !user || Object.keys(user.permissions.fleets).includes(fleetId);
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
};
|
|
19
|
+
exports.checkFleetPermission = checkFleetPermission;
|
|
20
|
+
const checkBusinessModelPermission = (businessModelId) => {
|
|
21
|
+
if ((0, exports.isUserExist)()) {
|
|
22
|
+
const user = (0, exports.getUser)();
|
|
23
|
+
return !user || Object.keys(user.permissions.businessModels).includes(businessModelId);
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
};
|
|
27
|
+
exports.checkBusinessModelPermission = checkBusinessModelPermission;
|
|
28
|
+
const checkDemandSourcePermission = (demandSourceId) => {
|
|
29
|
+
if ((0, exports.isUserExist)()) {
|
|
30
|
+
const user = (0, exports.getUser)();
|
|
31
|
+
return !user || Object.keys(user.permissions.demandSources).includes(demandSourceId);
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
};
|
|
35
|
+
exports.checkDemandSourcePermission = checkDemandSourcePermission;
|
package/lib/errors.d.ts
ADDED
package/lib/errors.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnauthorizedAccessError = void 0;
|
|
4
|
+
// eslint-disable-next-line import/prefer-default-export
|
|
5
|
+
class UnauthorizedAccessError extends Error {
|
|
6
|
+
constructor(user = null, message = 'UnauthorizedAccessError') {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'UnauthorizedAccessError';
|
|
9
|
+
this.user = user;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.UnauthorizedAccessError = UnauthorizedAccessError;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,308 +1,50 @@
|
|
|
1
|
-
import * as outbreak from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type EntityPermissions = Record<string, string[]>;
|
|
10
|
-
declare const CONTEXTS_IDS_HEADER = "x-af-context-ids";
|
|
11
|
-
interface UserExternalData {
|
|
12
|
-
element?: {
|
|
13
|
-
internalUser: boolean;
|
|
14
|
-
};
|
|
15
|
-
[key: string]: any;
|
|
16
|
-
}
|
|
17
|
-
interface UserPayload {
|
|
18
|
-
businessModels: EntityPermissions;
|
|
19
|
-
fleets: EntityPermissions;
|
|
20
|
-
demandSources: EntityPermissions;
|
|
21
|
-
businessAccounts?: EntityPermissions;
|
|
22
|
-
accountType?: AccountType;
|
|
23
|
-
contexts?: EntityPermissions;
|
|
24
|
-
createdAt?: string;
|
|
25
|
-
externalData?: UserExternalData | null;
|
|
26
|
-
}
|
|
27
|
-
interface PartialUserPayload {
|
|
28
|
-
businessModels?: EntityPermissions;
|
|
29
|
-
fleets?: EntityPermissions;
|
|
30
|
-
demandSources?: EntityPermissions;
|
|
31
|
-
vehicles?: EntityPermissions;
|
|
32
|
-
drivers?: EntityPermissions;
|
|
33
|
-
businessAccounts?: EntityPermissions;
|
|
34
|
-
}
|
|
35
|
-
declare class ApiUser {
|
|
36
|
-
id?: string | undefined;
|
|
37
|
-
accountType?: AccountType | undefined;
|
|
38
|
-
contextIds?: string[] | undefined;
|
|
39
|
-
private privatePermissions;
|
|
40
|
-
private readonly privateElevatedPermissionsHash;
|
|
41
|
-
private privatePermissionsLegacy;
|
|
42
|
-
private readonly appPermission;
|
|
43
|
-
readonly emptyUser: boolean;
|
|
44
|
-
constructor(id?: string | undefined, accountType?: AccountType | undefined, elevatedPermissions?: PartialUserPayload, contextIds?: string[] | undefined);
|
|
45
|
-
getUserPermissions(): Promise<UserPayload>;
|
|
46
|
-
useCustomPermissionLoader(customPermissionLoader: (userId: string) => UserPayload | PromiseLike<UserPayload>): Promise<UserPayload>;
|
|
47
|
-
get businessModels(): string[];
|
|
48
|
-
get fleets(): string[];
|
|
49
|
-
get demandSources(): string[];
|
|
50
|
-
private getUserProperty;
|
|
51
|
-
get elevatedPermissions(): UserPayload;
|
|
52
|
-
get permissions(): UserPayload | undefined;
|
|
53
|
-
elevatePermissions(addedPermissions: PartialUserPayload): (() => void) & {
|
|
54
|
-
[Symbol.dispose]: () => void;
|
|
55
|
-
};
|
|
56
|
-
getUserPermissionsLegacy(): Promise<unknown>;
|
|
57
|
-
get permissionsLegacy(): any;
|
|
58
|
-
getUserAppPermissions(appId: string, clientSecret: string): Promise<UserPayload | undefined>;
|
|
59
|
-
extendRequiredContexts(contextIdsToAdd?: string[]): void;
|
|
60
|
-
}
|
|
61
|
-
//#endregion
|
|
62
|
-
//#region src/user/common.d.ts
|
|
63
|
-
type CustomPermissionLoader = (userId: string) => Promise<UserPayload>;
|
|
64
|
-
interface AuthFromUserIdHeaderOptions {
|
|
65
|
-
eagerLoadUserPermissions?: boolean;
|
|
66
|
-
eagerLoadUserPermissionsLegacy?: boolean;
|
|
67
|
-
customPermissionLoader?: CustomPermissionLoader;
|
|
68
|
-
}
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region src/user/index.d.ts
|
|
71
|
-
declare module "express-serve-static-core" {
|
|
72
|
-
interface Request {
|
|
73
|
-
user: ApiUser;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
type Asyncify<T extends (...a: any[]) => any> = (...a: Parameters<T>) => Promise<Awaited<ReturnType<T>>>;
|
|
77
|
-
declare const middleware: (options?: AuthFromUserIdHeaderOptions) => Asyncify<Handler>;
|
|
78
|
-
declare const middlewareWithDecode: (options?: {
|
|
79
|
-
eagerLoadUserPermissions?: boolean;
|
|
80
|
-
eagerLoadUserPermissionsLegacy?: boolean;
|
|
81
|
-
returnErrorIfNoToken?: boolean;
|
|
82
|
-
appSecret?: string;
|
|
83
|
-
}) => Asyncify<Handler>;
|
|
84
|
-
declare const appMiddleware: (options: {
|
|
85
|
-
appId: string;
|
|
86
|
-
clientSecret: string;
|
|
87
|
-
}) => Asyncify<Handler>;
|
|
88
|
-
declare const eagerLoadPermissionsMiddleware: Asyncify<Handler>;
|
|
89
|
-
declare const getDecodedBearer: (req: Request, appSecret?: string) => any;
|
|
90
|
-
declare const createOrSetRabbitTrace: (trace: ReturnType<typeof newTrace$1> | undefined, userId: string | undefined, contextIds?: string[]) => Promise<void>;
|
|
91
|
-
//#endregion
|
|
92
|
-
//#region src/user/fastify.d.ts
|
|
93
|
-
declare module "fastify" {
|
|
94
|
-
interface FastifyRequest {
|
|
95
|
-
user?: ApiUser;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
declare const authFromUserIdHeaderPlugin: FastifyPluginCallback<AuthFromUserIdHeaderOptions>;
|
|
99
|
-
//#endregion
|
|
100
|
-
//#region src/check-permission.d.ts
|
|
101
|
-
declare const getUser: () => ApiUser | undefined;
|
|
102
|
-
declare const isUserExist: () => string | undefined;
|
|
103
|
-
declare const checkFleetPermission: (fleetId: string) => boolean;
|
|
104
|
-
declare const checkBusinessModelPermission: (businessModelId: string) => boolean;
|
|
105
|
-
declare const checkDemandSourcePermission: (demandSourceId: string) => boolean;
|
|
106
|
-
//#endregion
|
|
107
|
-
//#region src/errors.d.ts
|
|
108
|
-
declare class UnauthorizedAccessError extends Error {
|
|
109
|
-
user: ApiUser | null;
|
|
110
|
-
constructor(user?: ApiUser | null, message?: string);
|
|
111
|
-
}
|
|
112
|
-
//#endregion
|
|
113
|
-
//#region src/secret-getter.d.ts
|
|
114
|
-
declare const getRefreshTokenSecret: (token?: string) => string;
|
|
115
|
-
declare const getTokenSecret: (token?: string) => string;
|
|
116
|
-
//#endregion
|
|
117
|
-
//#region src/authorization.d.ts
|
|
118
|
-
declare const AUTHORIZATION_METHODS: {
|
|
119
|
-
NONE: string;
|
|
120
|
-
BASIC: string;
|
|
121
|
-
JWT: string;
|
|
1
|
+
import * as outbreak from '@autofleet/outbreak';
|
|
2
|
+
import User, { middleware, eagerLoadPermissionsMiddleware, middlewareWithDecode, getDecodedBearer, appMiddleware, createOrSetRabbitTrace } from './user';
|
|
3
|
+
import { newTrace, traceTypes } from './tracer';
|
|
4
|
+
import { checkFleetPermission, checkBusinessModelPermission, checkDemandSourcePermission, isUserExist, getUser } from './check-permission';
|
|
5
|
+
import { UnauthorizedAccessError } from './errors';
|
|
6
|
+
import { getRefreshTokenSecret, getTokenSecret } from './secret-getter';
|
|
7
|
+
declare const getCurrentPayload: () => import("./tracer").Trace | {
|
|
8
|
+
[x: string]: never;
|
|
122
9
|
};
|
|
123
|
-
declare const
|
|
124
|
-
|
|
125
|
-
} | undefined) => string | undefined;
|
|
126
|
-
//#endregion
|
|
127
|
-
//#region src/permissions/SDK/consts.d.ts
|
|
128
|
-
declare const PERMISSIONS_EVALUATION_OPERATORS: {
|
|
129
|
-
AND: string;
|
|
130
|
-
OR: string;
|
|
131
|
-
};
|
|
132
|
-
declare const PERMISSION_ERROR_TYPES: {
|
|
133
|
-
USER_NOT_FOUND: string;
|
|
134
|
-
INSUFFICIENT_PERMISSIONS: string;
|
|
135
|
-
VALIDATION_ERROR: string;
|
|
136
|
-
API_ERROR: string;
|
|
137
|
-
NO_REQUIRED_PERMISSIONS: string;
|
|
138
|
-
UNAUTHORIZED: string;
|
|
139
|
-
BAD_REQUEST: string;
|
|
140
|
-
INTERNAL_ERROR: string;
|
|
141
|
-
};
|
|
142
|
-
//#endregion
|
|
143
|
-
//#region src/permissions/SDK/errors.d.ts
|
|
144
|
-
type PermissionErrorType = typeof PERMISSION_ERROR_TYPES[keyof typeof PERMISSION_ERROR_TYPES];
|
|
145
|
-
//#endregion
|
|
146
|
-
//#region src/permissions/SDK/types.d.ts
|
|
147
|
-
interface Logger {
|
|
148
|
-
debug: (message: string, meta?: unknown) => void;
|
|
149
|
-
info: (message: string, meta?: unknown) => void;
|
|
150
|
-
warn: (message: string, meta?: unknown) => void;
|
|
151
|
-
error: (message: string, meta?: unknown) => void;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* The operator to use when evaluating permissions
|
|
155
|
-
* - AND: All required permissions must be present
|
|
156
|
-
* - OR: At least one required permission must be present
|
|
157
|
-
*/
|
|
158
|
-
type PermissionsEvaluationOperator = typeof PERMISSIONS_EVALUATION_OPERATORS[keyof typeof PERMISSIONS_EVALUATION_OPERATORS];
|
|
159
|
-
/**
|
|
160
|
-
* Options for evaluating permissions
|
|
161
|
-
* - requireAll: If true, all contexts must have the required permissions for the user to be considered authorized (default: true)
|
|
162
|
-
* - timeout: Optional - timeout in milliseconds for the permissions evaluation (default: 10 seconds)
|
|
163
|
-
* - enforce: Optional - If true, the permissions evaluation will throw an error if the user does not have the required permissions (default: false)
|
|
164
|
-
* - permissionsEvaluationOperator: Optional - If set, the permissions evaluation will use this operator to evaluate the permissions (default: AND)
|
|
165
|
-
*/
|
|
166
|
-
interface EvaluatePermissionsOpts {
|
|
167
|
-
requireAll?: boolean;
|
|
168
|
-
timeout?: number;
|
|
169
|
-
enforce?: boolean;
|
|
170
|
-
permissionsEvaluationOperator?: PermissionsEvaluationOperator;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Parameters for evaluating permissions for a user across multiple contexts
|
|
174
|
-
* - requiredPermissions: The required permissions to check against the user
|
|
175
|
-
* - contextIds: The context IDs to check the permissions against
|
|
176
|
-
* - logger: logger instance for logging
|
|
177
|
-
* - options: Options for evaluating permissions {@link EvaluatePermissionsOpts}
|
|
178
|
-
* - userId: The user id, if not provided, we will get the user from the current context
|
|
179
|
-
*/
|
|
180
|
-
interface EvaluatePermissionsParams {
|
|
181
|
-
requiredPermissions: string[];
|
|
182
|
-
contextIds: string[];
|
|
183
|
-
logger?: Logger;
|
|
184
|
-
options: EvaluatePermissionsOpts;
|
|
185
|
-
userId?: string;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* The permissions evaluation result for a specific context
|
|
189
|
-
* - permissions: The full list of permissions the user has in the context
|
|
190
|
-
* - hasRequiredPermissions: Whether the user has the required permissions in the context
|
|
191
|
-
*/
|
|
192
|
-
interface PermissionsEvaluation {
|
|
193
|
-
permissions: string[];
|
|
194
|
-
hasRequiredPermissions: boolean;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* A mapping of context IDs to their corresponding permissions evaluation results
|
|
198
|
-
*/
|
|
199
|
-
type PermissionsEvaluationByContextId = Record<string, PermissionsEvaluation>;
|
|
200
|
-
/**
|
|
201
|
-
* A mapping of context IDs to the list of permissions the user has in that context
|
|
202
|
-
* - isAuthorized: Whether the user has the required permissions in any of the contexts
|
|
203
|
-
* - userId: The ID of the user
|
|
204
|
-
* - resolvedPermissions: The detailed permissions evaluation results by context ID
|
|
205
|
-
* - requiredPermissions: The list of permissions that were required for the evaluation
|
|
206
|
-
* - contextIds: The list of context IDs that were evaluated
|
|
207
|
-
* - error: Optional error type if the evaluation failed
|
|
208
|
-
* - message: Optional error message if the evaluation failed
|
|
209
|
-
*/
|
|
210
|
-
interface PermissionCheckResult {
|
|
211
|
-
isAuthorized: boolean;
|
|
212
|
-
userId?: string;
|
|
213
|
-
resolvedPermissions: PermissionsEvaluationByContextId;
|
|
214
|
-
requiredPermissions: string[];
|
|
215
|
-
contextIds: string[];
|
|
216
|
-
error?: PermissionErrorType;
|
|
217
|
-
message?: string;
|
|
218
|
-
}
|
|
219
|
-
//#endregion
|
|
220
|
-
//#region src/permissions/SDK/evaluatePermissions.d.ts
|
|
221
|
-
/**
|
|
222
|
-
* Main SDK function to evaluate user permissions
|
|
223
|
-
* Checks both cached and API-resolved permissions to determine access
|
|
224
|
-
* @param params - {@link EvaluatePermissionsParams}
|
|
225
|
-
* @returns {@link PermissionCheckResult} Detailed permission check result with access status and context
|
|
226
|
-
*/
|
|
227
|
-
declare const evaluatePermissions: ({
|
|
228
|
-
requiredPermissions,
|
|
229
|
-
contextIds,
|
|
230
|
-
logger,
|
|
231
|
-
userId,
|
|
232
|
-
options: {
|
|
233
|
-
requireAll,
|
|
234
|
-
permissionsEvaluationOperator,
|
|
235
|
-
timeout
|
|
236
|
-
}
|
|
237
|
-
}: EvaluatePermissionsParams) => Promise<PermissionCheckResult>;
|
|
238
|
-
//#endregion
|
|
239
|
-
//#region src/permissions/middleware/requirePermissions.d.ts
|
|
240
|
-
interface RequirePermissionsOptions extends EvaluatePermissionsOpts {
|
|
241
|
-
logger?: LoggerInstanceManager;
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Express middleware that requires specific permissions for route access
|
|
245
|
-
*
|
|
246
|
-
* @param requiredPermissions - Array of permissions required to access the route
|
|
247
|
-
* @param options - Configuration options for permission checking
|
|
248
|
-
* @returns Express middleware function
|
|
249
|
-
*/
|
|
250
|
-
declare const requirePermissions: (requiredPermissions: string[], options?: RequirePermissionsOptions) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
251
|
-
declare namespace index_d_exports {
|
|
252
|
-
export { _default as default, middlewares, sdk };
|
|
253
|
-
}
|
|
254
|
-
interface SdkExports {
|
|
255
|
-
evaluatePermissions: typeof evaluatePermissions;
|
|
256
|
-
}
|
|
257
|
-
interface MiddlewareExports {
|
|
258
|
-
requirePermissions: typeof requirePermissions;
|
|
259
|
-
}
|
|
260
|
-
interface PermissionsModule {
|
|
261
|
-
sdk: SdkExports;
|
|
262
|
-
middlewares: MiddlewareExports;
|
|
263
|
-
}
|
|
264
|
-
declare const sdk: SdkExports;
|
|
265
|
-
declare const middlewares: MiddlewareExports;
|
|
266
|
-
declare const _default: PermissionsModule;
|
|
267
|
-
//#endregion
|
|
268
|
-
//#region src/index.d.ts
|
|
269
|
-
declare const getCurrentPayload: typeof outbreak.getCurrentContext;
|
|
270
|
-
type OutbreakOptions = Parameters<typeof outbreak.default>[0];
|
|
271
|
-
type LoggerWithContextMiddleware = Partial<Pick<LoggerInstanceManager, "addContextMiddleware">>;
|
|
272
|
-
declare const enableTracing: ({
|
|
273
|
-
outbreakOptions,
|
|
274
|
-
logger
|
|
275
|
-
}?: {
|
|
276
|
-
outbreakOptions?: OutbreakOptions;
|
|
277
|
-
logger?: LoggerWithContextMiddleware;
|
|
10
|
+
declare const enableTracing: ({ outbreakOptions }?: {
|
|
11
|
+
outbreakOptions?: {};
|
|
278
12
|
}) => void;
|
|
279
|
-
|
|
280
|
-
declare const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
13
|
+
export { traceTypes, newTrace, enableTracing, User, middleware, middlewareWithDecode, eagerLoadPermissionsMiddleware, getCurrentPayload, getDecodedBearer, checkFleetPermission, checkBusinessModelPermission, checkDemandSourcePermission, isUserExist, getUser, getRefreshTokenSecret, getTokenSecret, UnauthorizedAccessError, appMiddleware, createOrSetRabbitTrace, outbreak, };
|
|
14
|
+
declare const _default: {
|
|
15
|
+
traceTypes: {
|
|
16
|
+
HTTP_REQUEST: string;
|
|
17
|
+
WEB_SOCKET: string;
|
|
18
|
+
RABBIT: string;
|
|
19
|
+
};
|
|
20
|
+
newTrace: (type: any) => import("./tracer").Trace;
|
|
21
|
+
User: typeof User;
|
|
22
|
+
middleware: (options?: {
|
|
23
|
+
eagerLoadUserPermissions?: boolean;
|
|
24
|
+
eagerLoadUserPermissionsLegacy?: boolean;
|
|
25
|
+
customPermissionLoader?: import("./user/ApiUser").CustomPermissionLoader;
|
|
26
|
+
}) => (req: any, res: any, next: any) => Promise<any>;
|
|
27
|
+
middlewareWithDecode: (options?: {
|
|
28
|
+
eagerLoadUserPermissions?: boolean;
|
|
29
|
+
eagerLoadUserPermissionsLegacy?: boolean;
|
|
30
|
+
returnErrorIfNoToken?: boolean;
|
|
31
|
+
}) => (req: any, res: any, next: any) => Promise<void>;
|
|
32
|
+
eagerLoadPermissionsMiddleware: (req: any, res: any, next: any) => Promise<any>;
|
|
33
|
+
getCurrentPayload: () => import("./tracer").Trace | {
|
|
34
|
+
[x: string]: never;
|
|
35
|
+
};
|
|
36
|
+
getDecodedBearer: (req: any) => any;
|
|
37
|
+
checkFleetPermission: (fleetId: any) => boolean;
|
|
38
|
+
checkBusinessModelPermission: (businessModelId: any) => boolean;
|
|
39
|
+
checkDemandSourcePermission: (demandSourceId: any) => boolean;
|
|
40
|
+
isUserExist: () => string;
|
|
41
|
+
getUser: () => User;
|
|
42
|
+
UnauthorizedAccessError: typeof UnauthorizedAccessError;
|
|
43
|
+
appMiddleware: (options: {
|
|
44
|
+
appId: string;
|
|
45
|
+
clientSecret: string;
|
|
46
|
+
}) => (req: any, res: any, next: any) => Promise<void>;
|
|
47
|
+
createOrSetRabbitTrace: (trace: any, userId: any) => Promise<void>;
|
|
48
|
+
outbreak: typeof outbreak;
|
|
49
|
+
};
|
|
50
|
+
export default _default;
|