@medusajs/framework 2.22.2 → 2.22.3-snapshot-20261103230838
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/AGENTS.md +1 -1
- package/dist/build-tools/compiler.d.ts.map +1 -1
- package/dist/build-tools/compiler.js +2 -2
- package/dist/build-tools/compiler.js.map +1 -1
- package/dist/http/index.d.ts +3 -0
- package/dist/http/index.d.ts.map +1 -1
- package/dist/http/index.js +3 -0
- package/dist/http/index.js.map +1 -1
- package/dist/http/middleware-file-loader.d.ts.map +1 -1
- package/dist/http/middleware-file-loader.js +6 -15
- package/dist/http/middleware-file-loader.js.map +1 -1
- package/dist/http/middlewares/authorize.d.ts +73 -0
- package/dist/http/middlewares/authorize.d.ts.map +1 -0
- package/dist/http/middlewares/authorize.js +131 -0
- package/dist/http/middlewares/authorize.js.map +1 -0
- package/dist/http/middlewares/index.d.ts +1 -1
- package/dist/http/middlewares/index.d.ts.map +1 -1
- package/dist/http/middlewares/index.js +1 -1
- package/dist/http/middlewares/index.js.map +1 -1
- package/dist/http/router.d.ts.map +1 -1
- package/dist/http/router.js +29 -18
- package/dist/http/router.js.map +1 -1
- package/dist/http/routes-loader.d.ts.map +1 -1
- package/dist/http/routes-loader.js +14 -5
- package/dist/http/routes-loader.js.map +1 -1
- package/dist/http/types.d.ts +9 -160
- package/dist/http/types.d.ts.map +1 -1
- package/dist/http/types.js.map +1 -1
- package/dist/http/utils/build-authz-context.d.ts +16 -0
- package/dist/http/utils/build-authz-context.d.ts.map +1 -0
- package/dist/http/utils/build-authz-context.js +44 -0
- package/dist/http/utils/build-authz-context.js.map +1 -0
- package/dist/http/utils/get-actor-permissions.d.ts +16 -0
- package/dist/http/utils/get-actor-permissions.d.ts.map +1 -0
- package/dist/http/utils/get-actor-permissions.js +22 -0
- package/dist/http/utils/get-actor-permissions.js.map +1 -0
- package/dist/http/utils/get-query-config.d.ts +3 -4
- package/dist/http/utils/get-query-config.d.ts.map +1 -1
- package/dist/http/utils/get-query-config.js +17 -4
- package/dist/http/utils/get-query-config.js.map +1 -1
- package/dist/http/utils/policies/rbac-field-filter.d.ts +8 -8
- package/dist/http/utils/policies/rbac-field-filter.d.ts.map +1 -1
- package/dist/http/utils/policies/rbac-field-filter.js +10 -21
- package/dist/http/utils/policies/rbac-field-filter.js.map +1 -1
- package/dist/http/utils/resolve-roles.d.ts +13 -0
- package/dist/http/utils/resolve-roles.d.ts.map +1 -0
- package/dist/http/utils/resolve-roles.js +54 -0
- package/dist/http/utils/resolve-roles.js.map +1 -0
- package/dist/policies/has-permission.d.ts +52 -0
- package/dist/policies/has-permission.d.ts.map +1 -1
- package/dist/policies/has-permission.js +121 -56
- package/dist/policies/has-permission.js.map +1 -1
- package/dist/policies/index.d.ts +0 -1
- package/dist/policies/index.d.ts.map +1 -1
- package/dist/policies/index.js +0 -1
- package/dist/policies/index.js.map +1 -1
- package/dist/types/container.d.ts +1 -1
- package/dist/types/container.d.ts.map +1 -1
- package/package.json +13 -13
- package/dist/http/middlewares/check-permissions.d.ts +0 -15
- package/dist/http/middlewares/check-permissions.d.ts.map +0 -1
- package/dist/http/middlewares/check-permissions.js +0 -54
- package/dist/http/middlewares/check-permissions.js.map +0 -1
- package/dist/policies/policy-loader.d.ts +0 -6
- package/dist/policies/policy-loader.d.ts.map +0 -1
- package/dist/policies/policy-loader.js +0 -17
- package/dist/policies/policy-loader.js.map +0 -1
|
@@ -41,6 +41,12 @@ const PARAM_SEGMENT_MATCHER = /\[(\w+)\]/;
|
|
|
41
41
|
const ADMIN_ROUTE_MATCH = /(\/admin$|\/admin\/)/;
|
|
42
42
|
const STORE_ROUTE_MATCH = /(\/store$|\/store\/)/;
|
|
43
43
|
const AUTH_ROUTE_MATCH = /(\/auth$|\/auth\/)/;
|
|
44
|
+
/**
|
|
45
|
+
* The "/rbac" routes are not admin routes (they authenticate any actor type
|
|
46
|
+
* allowed by "http.rbacActorTypes"), but they are consumed by the admin
|
|
47
|
+
* dashboard and therefore share its CORS configuration.
|
|
48
|
+
*/
|
|
49
|
+
const RBAC_ROUTE_MATCH = /^\/rbac(\/|$)/;
|
|
44
50
|
/**
|
|
45
51
|
* Exposes to API to register routes manually or by scanning the filesystem from a
|
|
46
52
|
* source directory.
|
|
@@ -186,11 +192,13 @@ async function _RoutesLoader_getRoutesForFile(routePath, absolutePath) {
|
|
|
186
192
|
*/
|
|
187
193
|
const routeType = ADMIN_ROUTE_MATCH.test(routePath)
|
|
188
194
|
? "admin"
|
|
189
|
-
:
|
|
190
|
-
? "
|
|
191
|
-
:
|
|
192
|
-
? "
|
|
193
|
-
:
|
|
195
|
+
: RBAC_ROUTE_MATCH.test(routePath)
|
|
196
|
+
? "rbac"
|
|
197
|
+
: STORE_ROUTE_MATCH.test(routePath)
|
|
198
|
+
? "store"
|
|
199
|
+
: AUTH_ROUTE_MATCH.test(routePath)
|
|
200
|
+
? "auth"
|
|
201
|
+
: undefined;
|
|
194
202
|
/**
|
|
195
203
|
* Check if the route file has decided to opt-out of authentication
|
|
196
204
|
*/
|
|
@@ -226,6 +234,7 @@ async function _RoutesLoader_getRoutesForFile(routePath, absolutePath) {
|
|
|
226
234
|
shouldAppendAdminCors: shouldApplyCors && routeType === "admin",
|
|
227
235
|
shouldAppendAuthCors: shouldApplyCors && routeType === "auth",
|
|
228
236
|
shouldAppendStoreCors: shouldApplyCors && routeType === "store",
|
|
237
|
+
shouldAppendRbacCors: shouldApplyCors && routeType === "rbac",
|
|
229
238
|
};
|
|
230
239
|
});
|
|
231
240
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes-loader.js","sourceRoot":"","sources":["../../src/http/routes-loader.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgF;AAChF,+BAAuC;AACvC,sCAAkC;AAClC,mCAA4E;AAE5E;;GAEG;AACH,MAAM,UAAU,GAAG,OAAO,CAAA;AAE1B;;;GAGG;AACH,MAAM,qBAAqB,GAAG,cAAc,CAAA;AAE5C;;;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AAC,EAAE,CAAC;YAC7C,eAAM,CAAC,KAAK,CACV,oBAAoB,GAAG,OAAO,YAAY,0BAA0B,GAAG,GAAG,CAC3E,CAAA;YACD,OAAO,KAAK,CAAA;QACd,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QACX,OAAO;YACL,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,SAAS;YAClB,MAAM,EAAE,GAAgB;YACxB,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC;YAC1B,cAAc,EAAE,CAAC,kBAAkB;YACnC,qBAAqB,EAAE,eAAe,IAAI,SAAS,KAAK,OAAO;YAC/D,oBAAoB,EAAE,eAAe,IAAI,SAAS,KAAK,MAAM;YAC7D,qBAAqB,EAAE,eAAe,IAAI,SAAS,KAAK,OAAO;YAC/D,oBAAoB,EAAE,eAAe,IAAI,SAAS,KAAK,MAAM;SACpC,CAAA;IAC7B,CAAC,CAAC,CAAA;AACN,CAAC"}
|
package/dist/http/types.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { ZodNullable, ZodObject, ZodOptional, ZodRawShape } from "@medusajs/deps/zod";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import type { MedusaNextFunction, MedusaRequest, MedusaRequestHandler, MedusaResponse } from "@medusajs/types";
|
|
3
|
+
/**
|
|
4
|
+
* The HTTP request/response types were moved to`@medusajs/types`.
|
|
5
|
+
* They are re-exported here to keep `@medusajs/framework/http` import paths
|
|
6
|
+
* working.
|
|
7
|
+
*/
|
|
8
|
+
export type { AuthContext, AuthenticatedMedusaRequest, MedusaNextFunction, MedusaRequest, MedusaRequestHandler, MedusaResponse, MedusaStoreRequest, PublishableKeyContext, RestrictedFieldsSet, SecretKeyContext, } from "@medusajs/types";
|
|
7
9
|
/**
|
|
8
10
|
* List of all the supported HTTP methods
|
|
9
11
|
*/
|
|
@@ -30,14 +32,6 @@ export type MiddlewareRoute = {
|
|
|
30
32
|
bodyParser?: ParserConfig;
|
|
31
33
|
additionalDataValidator?: ZodRawShape;
|
|
32
34
|
middlewares?: MiddlewareFunction[];
|
|
33
|
-
/** @ignore */
|
|
34
|
-
policies?: {
|
|
35
|
-
resource: string;
|
|
36
|
-
operation: string;
|
|
37
|
-
} | Array<{
|
|
38
|
-
resource: string;
|
|
39
|
-
operation: string | string[];
|
|
40
|
-
}>;
|
|
41
35
|
};
|
|
42
36
|
export type MiddlewaresConfig = {
|
|
43
37
|
errorHandler?: false | MedusaErrorHandlerFunction;
|
|
@@ -54,12 +48,13 @@ export type RouteDescriptor = {
|
|
|
54
48
|
handler: RouteHandler;
|
|
55
49
|
optedOutOfAuth: boolean;
|
|
56
50
|
isRoute: true;
|
|
57
|
-
routeType?: "admin" | "store" | "auth";
|
|
51
|
+
routeType?: "admin" | "store" | "auth" | "rbac";
|
|
58
52
|
absolutePath?: string;
|
|
59
53
|
relativePath?: string;
|
|
60
54
|
shouldAppendAdminCors: boolean;
|
|
61
55
|
shouldAppendStoreCors: boolean;
|
|
62
56
|
shouldAppendAuthCors: boolean;
|
|
57
|
+
shouldAppendRbacCors: boolean;
|
|
63
58
|
};
|
|
64
59
|
/**
|
|
65
60
|
* Represents a middleware
|
|
@@ -68,13 +63,6 @@ export type MiddlewareDescriptor = {
|
|
|
68
63
|
matcher: string | RegExp;
|
|
69
64
|
methods?: MiddlewareVerb | MiddlewareVerb[];
|
|
70
65
|
handler: MiddlewareFunction;
|
|
71
|
-
policies?: {
|
|
72
|
-
resource: string;
|
|
73
|
-
operation: string;
|
|
74
|
-
} | Array<{
|
|
75
|
-
resource: string;
|
|
76
|
-
operation: string | string[];
|
|
77
|
-
}>;
|
|
78
66
|
};
|
|
79
67
|
export type BodyParserConfigRoute = {
|
|
80
68
|
matcher: string | RegExp;
|
|
@@ -90,143 +78,4 @@ export type AdditionalDataValidatorRoute = {
|
|
|
90
78
|
export type GlobalMiddlewareDescriptor = {
|
|
91
79
|
config?: MiddlewaresConfig;
|
|
92
80
|
};
|
|
93
|
-
export interface MedusaRequest<Body = unknown, QueryFields = Record<string, unknown>> extends Request<{
|
|
94
|
-
[key: string]: string;
|
|
95
|
-
}, any, Body> {
|
|
96
|
-
validatedBody: Body;
|
|
97
|
-
validatedQuery: RequestQueryFields & QueryFields;
|
|
98
|
-
/**
|
|
99
|
-
* TODO: shouldn't this correspond to returnable fields instead of allowed fields? also it is used by the cleanResponseData util
|
|
100
|
-
*/
|
|
101
|
-
allowedProperties: string[];
|
|
102
|
-
/**
|
|
103
|
-
* An object containing the select, relation, skip, take and order to be used with medusa internal services
|
|
104
|
-
*/
|
|
105
|
-
listConfig: FindConfig<unknown>;
|
|
106
|
-
/**
|
|
107
|
-
* An object containing the select, relation to be used with medusa internal services
|
|
108
|
-
*/
|
|
109
|
-
retrieveConfig: FindConfig<unknown>;
|
|
110
|
-
/**
|
|
111
|
-
* An object containing fields and variables to be used with the remoteQuery
|
|
112
|
-
*
|
|
113
|
-
* @since 2.2.0
|
|
114
|
-
*/
|
|
115
|
-
queryConfig: {
|
|
116
|
-
fields: string[];
|
|
117
|
-
pagination: {
|
|
118
|
-
order?: Record<string, string>;
|
|
119
|
-
skip: number;
|
|
120
|
-
take?: number;
|
|
121
|
-
};
|
|
122
|
-
withDeleted?: boolean;
|
|
123
|
-
};
|
|
124
|
-
/**
|
|
125
|
-
* @deprecated Use {@link queryConfig} instead.
|
|
126
|
-
*/
|
|
127
|
-
remoteQueryConfig: MedusaRequest["queryConfig"];
|
|
128
|
-
/**
|
|
129
|
-
* An object containing the fields that are filterable e.g `{ id: Any<String> }`
|
|
130
|
-
*/
|
|
131
|
-
filterableFields: QueryFields;
|
|
132
|
-
includes?: Record<string, boolean>;
|
|
133
|
-
/**
|
|
134
|
-
* An array of fields and relations that are allowed to be queried, this can be set by the
|
|
135
|
-
* consumer as part of a middleware and it will take precedence over the req.allowed set
|
|
136
|
-
* by the api
|
|
137
|
-
*
|
|
138
|
-
* Initialized per request, so add to it with `req.allowed.push(field)` — several
|
|
139
|
-
* middlewares can each contribute that way. Reassigning the array discards what other
|
|
140
|
-
* middlewares granted. To disallow an allowed field use {@link disallowed}, which is
|
|
141
|
-
* applied after this list.
|
|
142
|
-
*/
|
|
143
|
-
allowed: string[];
|
|
144
|
-
/**
|
|
145
|
-
* An array of fields and relations that must never be resolved, this can be set by the
|
|
146
|
-
* consumer as part of a global middleware and it replaces the disallowed fields
|
|
147
|
-
* configured by the route's query configuration
|
|
148
|
-
*
|
|
149
|
-
* Since disallowed fields are a security boundary that keeps sensitive relations off an
|
|
150
|
-
* endpoint, set this to the route's configured fields minus the ones you need, rather
|
|
151
|
-
* than to a short list of your own. An empty array removes the boundary entirely.
|
|
152
|
-
*
|
|
153
|
-
* @since v2.21.0
|
|
154
|
-
*/
|
|
155
|
-
disallowed?: (string | RegExp)[];
|
|
156
|
-
errors: string[];
|
|
157
|
-
scope: MedusaContainer;
|
|
158
|
-
session?: any;
|
|
159
|
-
rawBody?: any;
|
|
160
|
-
requestId?: string;
|
|
161
|
-
restrictedFields?: RestrictedFields;
|
|
162
|
-
/**
|
|
163
|
-
* The maximum number of relations that can be expanded by the request. It is only set for
|
|
164
|
-
* routes under the `/store` prefix, and can be overridden by a route's query configuration.
|
|
165
|
-
*
|
|
166
|
-
* @since v2.20.0
|
|
167
|
-
*/
|
|
168
|
-
storeRelationsLimit?: number;
|
|
169
|
-
/**
|
|
170
|
-
* An object that carries the context that is used to calculate prices for variants
|
|
171
|
-
*/
|
|
172
|
-
pricingContext?: MedusaPricingContext;
|
|
173
|
-
/**
|
|
174
|
-
* A generic context object that can be used across the request lifecycle
|
|
175
|
-
*/
|
|
176
|
-
context?: Record<string, any>;
|
|
177
|
-
/**
|
|
178
|
-
* Custom validator to validate the `additional_data` property in
|
|
179
|
-
* requests that allows for additional_data
|
|
180
|
-
*/
|
|
181
|
-
additionalDataValidator?: ZodOptional<ZodNullable<ZodObject<any, any>>>;
|
|
182
|
-
/**
|
|
183
|
-
* The locale for the current request, resolved from:
|
|
184
|
-
* 1. Query parameter `?locale=`
|
|
185
|
-
* 2. x-medusa-locale header
|
|
186
|
-
* 3. Store's default locale
|
|
187
|
-
*/
|
|
188
|
-
locale?: string;
|
|
189
|
-
}
|
|
190
|
-
export interface AuthContext {
|
|
191
|
-
actor_id: string;
|
|
192
|
-
actor_type: string;
|
|
193
|
-
auth_identity_id: string;
|
|
194
|
-
auth_provider?: string;
|
|
195
|
-
app_metadata: Record<string, unknown>;
|
|
196
|
-
user_metadata: Record<string, unknown>;
|
|
197
|
-
entity_id?: string;
|
|
198
|
-
purpose?: string;
|
|
199
|
-
jti?: string;
|
|
200
|
-
/**
|
|
201
|
-
* Whether the auth identity had an enabled MFA factor when the token was issued.
|
|
202
|
-
*/
|
|
203
|
-
mfa_enabled?: boolean;
|
|
204
|
-
/**
|
|
205
|
-
* When the MFA challenge was completed, or null when it has not been. Routes
|
|
206
|
-
* can require a recent completion to gate elevated actions.
|
|
207
|
-
*/
|
|
208
|
-
mfa_challenge_completed_at?: string | null;
|
|
209
|
-
}
|
|
210
|
-
export interface PublishableKeyContext {
|
|
211
|
-
key: string;
|
|
212
|
-
sales_channel_ids: string[];
|
|
213
|
-
}
|
|
214
|
-
export interface SecretKeyContext {
|
|
215
|
-
created_by: string;
|
|
216
|
-
}
|
|
217
|
-
export interface AuthenticatedMedusaRequest<Body = unknown, QueryFields = Record<string, unknown>> extends MedusaRequest<Body, QueryFields> {
|
|
218
|
-
auth_context: AuthContext;
|
|
219
|
-
publishable_key_context?: PublishableKeyContext;
|
|
220
|
-
secret_key_context?: SecretKeyContext;
|
|
221
|
-
policies?: PolicyAction[];
|
|
222
|
-
}
|
|
223
|
-
export interface MedusaStoreRequest<Body = unknown, QueryFields = Record<string, unknown>> extends MedusaRequest<Body, QueryFields> {
|
|
224
|
-
auth_context?: AuthContext;
|
|
225
|
-
publishable_key_context: PublishableKeyContext;
|
|
226
|
-
policies?: PolicyAction | PolicyAction[];
|
|
227
|
-
}
|
|
228
|
-
export type MedusaResponse<Body = unknown> = Response<Body>;
|
|
229
|
-
export type MedusaNextFunction = NextFunction;
|
|
230
|
-
export type MedusaRequestHandler<Body = unknown, Res = unknown> = (req: MedusaRequest<Body>, res: MedusaResponse<Res>, next: MedusaNextFunction) => Promise<void> | void;
|
|
231
|
-
export {};
|
|
232
81
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/http/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/http/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,WAAW,EACX,WAAW,EACZ,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/http/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,WAAW,EACX,WAAW,EACZ,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,oBAAoB,EACpB,cAAc,EACf,MAAM,iBAAiB,CAAA;AAExB;;;;GAIG;AACH,YAAY,EACV,WAAW,EACX,0BAA0B,EAC1B,kBAAkB,EAClB,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,iBAAiB,CAAA;AAExB;;GAEG;AACH,eAAO,MAAM,YAAY,uEAQf,CAAA;AAEV,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAA;AACrD,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,KAAK,GAAG,SAAS,CAAA;AAEtD,KAAK,gBAAgB,GAAG,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,KAAK,IAAI,CAAA;AA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,OAAO,EAAE,YAAY,CAAA;IACrB,cAAc,EAAE,OAAO,CAAA;IACvB,OAAO,EAAE,IAAI,CAAA;IACb,SAAS,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,qBAAqB,EAAE,OAAO,CAAA;IAC9B,qBAAqB,EAAE,OAAO,CAAA;IAC9B,oBAAoB,EAAE,OAAO,CAAA;IAC7B,oBAAoB,EAAE,OAAO,CAAA;CAC9B,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,OAAO,CAAC,EAAE,cAAc,GAAG,cAAc,EAAE,CAAA;IAC3C,OAAO,EAAE,kBAAkB,CAAA;CAC5B,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE,CAAA;IAC1C,MAAM,EAAE,YAAY,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,4BAA4B,GAAG;IACzC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE,CAAA;IAC1C,MAAM,EAAE,WAAW,CAAA;IACnB,SAAS,EAAE,WAAW,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;CACzD,CAAA;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,MAAM,CAAC,EAAE,iBAAiB,CAAA;CAC3B,CAAA"}
|
package/dist/http/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/http/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/http/types.ts"],"names":[],"mappings":";;;AAgCA;;GAEG;AACU,QAAA,YAAY,GAAG;IAC1B,KAAK;IACL,MAAM;IACN,KAAK;IACL,OAAO;IACP,QAAQ;IACR,SAAS;IACT,MAAM;CACE,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AuthzContextConfig, MedusaContainer } from "@medusajs/types";
|
|
2
|
+
type AuthzContextInput = {
|
|
3
|
+
actor_type: string;
|
|
4
|
+
actor_id: string;
|
|
5
|
+
config: AuthzContextConfig;
|
|
6
|
+
container: MedusaContainer;
|
|
7
|
+
};
|
|
8
|
+
type AuthzContext = {
|
|
9
|
+
grantees: {
|
|
10
|
+
type: string;
|
|
11
|
+
id: string;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
export declare function buildAuthzContext({ actor_type, actor_id, config, container, }: AuthzContextInput): Promise<AuthzContext>;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=build-authz-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-authz-context.d.ts","sourceRoot":"","sources":["../../../src/http/utils/build-authz-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAGrE,KAAK,iBAAiB,GAAG;IACvB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,kBAAkB,CAAA;IAC1B,SAAS,EAAE,eAAe,CAAA;CAC3B,CAAA;AAED,KAAK,YAAY,GAAG;IAClB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAA;QACZ,EAAE,EAAE,MAAM,CAAA;KACX,EAAE,CAAA;CACJ,CAAA;AA2BD,wBAAsB,iBAAiB,CAAC,EACtC,UAAU,EACV,QAAQ,EACR,MAAM,EACN,SAAS,GACV,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAyB3C"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildAuthzContext = buildAuthzContext;
|
|
4
|
+
const utils_1 = require("@medusajs/utils");
|
|
5
|
+
/**
|
|
6
|
+
* Walks `path` from `root`, flattening to-many relations (arrays) at any
|
|
7
|
+
* level, and returns every id reached. Null/missing intermediates are
|
|
8
|
+
* skipped; non-string leaves are dropped.
|
|
9
|
+
*/
|
|
10
|
+
const collect = (root, path) => {
|
|
11
|
+
const walk = (node, segments) => {
|
|
12
|
+
if (node == null) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(node)) {
|
|
16
|
+
return node.flatMap((item) => walk(item, segments));
|
|
17
|
+
}
|
|
18
|
+
if (!segments.length) {
|
|
19
|
+
return [node];
|
|
20
|
+
}
|
|
21
|
+
const [head, ...rest] = segments;
|
|
22
|
+
return walk(node[head], rest);
|
|
23
|
+
};
|
|
24
|
+
return walk(root, path.split(".")).filter((value) => typeof value === "string");
|
|
25
|
+
};
|
|
26
|
+
async function buildAuthzContext({ actor_type, actor_id, config, container, }) {
|
|
27
|
+
const query = container.resolve(utils_1.ContainerRegistrationKeys.QUERY);
|
|
28
|
+
const fields = (0, utils_1.deduplicate)(config.grantees.map((grantee) => grantee.path));
|
|
29
|
+
const { data: [root], } = await query.graph({
|
|
30
|
+
entity: config.actor_entity ?? actor_type,
|
|
31
|
+
fields,
|
|
32
|
+
filters: { id: actor_id },
|
|
33
|
+
});
|
|
34
|
+
if (!root) {
|
|
35
|
+
return { grantees: [] };
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
grantees: config.grantees.flatMap((grantee) => collect(root, grantee.path).map((id) => ({
|
|
39
|
+
type: grantee.entity,
|
|
40
|
+
id,
|
|
41
|
+
}))),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=build-authz-context.js.map
|
|
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O,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;IAE1E,MAAM,EACJ,IAAI,EAAE,CAAC,IAAI,CAAC,GACb,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC;QACpB,MAAM,EAAE,MAAM,CAAC,YAAY,IAAI,UAAU;QACzC,MAAM;QACN,OAAO,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE;KAC1B,CAAC,CAAA;IAEF,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAA;IACzB,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAC5C,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;YACvC,IAAI,EAAE,OAAO,CAAC,MAAM;YACpB,EAAE;SACH,CAAC,CAAC,CACJ;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AuthContext, MedusaContainer, RbacScope } from "@medusajs/types";
|
|
2
|
+
import { PermissionSet } from "../../policies/has-permission";
|
|
3
|
+
/**
|
|
4
|
+
* The permissions an actor holds, as `resource:operation` keys with wildcards
|
|
5
|
+
* kept as stored. Check them with `isGranted`.
|
|
6
|
+
*
|
|
7
|
+
* The actor's unscoped role assignments always count. Those scoped to `scope`
|
|
8
|
+
* only count when it is provided, so without a scope the result is the
|
|
9
|
+
* actor's unscoped privileges.
|
|
10
|
+
*/
|
|
11
|
+
export declare const getActorPermissions: ({ authContext, container, scope, }: {
|
|
12
|
+
authContext: Pick<AuthContext, "actor_type" | "actor_id">;
|
|
13
|
+
container: MedusaContainer;
|
|
14
|
+
scope?: RbacScope;
|
|
15
|
+
}) => Promise<PermissionSet>;
|
|
16
|
+
//# sourceMappingURL=get-actor-permissions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-actor-permissions.d.ts","sourceRoot":"","sources":["../../../src/http/utils/get-actor-permissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AACzE,OAAO,EAEL,aAAa,EACd,MAAM,+BAA+B,CAAA;AAGtC;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,GAAU,oCAIvC;IACD,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,YAAY,GAAG,UAAU,CAAC,CAAA;IACzD,SAAS,EAAE,eAAe,CAAA;IAC1B,KAAK,CAAC,EAAE,SAAS,CAAA;CAClB,KAAG,OAAO,CAAC,aAAa,CAQxB,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getActorPermissions = void 0;
|
|
4
|
+
const has_permission_1 = require("../../policies/has-permission");
|
|
5
|
+
const resolve_roles_1 = require("./resolve-roles");
|
|
6
|
+
/**
|
|
7
|
+
* The permissions an actor holds, as `resource:operation` keys with wildcards
|
|
8
|
+
* kept as stored. Check them with `isGranted`.
|
|
9
|
+
*
|
|
10
|
+
* The actor's unscoped role assignments always count. Those scoped to `scope`
|
|
11
|
+
* only count when it is provided, so without a scope the result is the
|
|
12
|
+
* actor's unscoped privileges.
|
|
13
|
+
*/
|
|
14
|
+
const getActorPermissions = async ({ authContext, container, scope, }) => {
|
|
15
|
+
const roles = await (0, resolve_roles_1.resolveRoles)({ authContext, container, scope });
|
|
16
|
+
if (!roles.length) {
|
|
17
|
+
return new Set();
|
|
18
|
+
}
|
|
19
|
+
return new Set(await (0, has_permission_1.listRolePermissions)({ roles, container }));
|
|
20
|
+
};
|
|
21
|
+
exports.getActorPermissions = getActorPermissions;
|
|
22
|
+
//# sourceMappingURL=get-actor-permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-actor-permissions.js","sourceRoot":"","sources":["../../../src/http/utils/get-actor-permissions.ts"],"names":[],"mappings":";;;AACA,kEAGsC;AACtC,mDAA8C;AAE9C;;;;;;;GAOG;AACI,MAAM,mBAAmB,GAAG,KAAK,EAAE,EACxC,WAAW,EACX,SAAS,EACT,KAAK,GAKN,EAA0B,EAAE;IAC3B,MAAM,KAAK,GAAG,MAAM,IAAA,4BAAY,EAAC,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAA;IAEnE,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QAClB,OAAO,IAAI,GAAG,EAAE,CAAA;IAClB,CAAC;IAED,OAAO,IAAI,GAAG,CAAC,MAAM,IAAA,oCAAmB,EAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;AACjE,CAAC,CAAA;AAhBY,QAAA,mBAAmB,uBAgB/B"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { FindConfig, QueryConfig, RequestQueryFields } from "@medusajs/types";
|
|
2
|
-
import { PolicyDefinition } from "@medusajs/utils";
|
|
1
|
+
import { FindConfig, QueryConfig, RbacContext, RequestQueryFields } from "@medusajs/types";
|
|
3
2
|
import { AuthContext, MedusaRequest } from "../types";
|
|
4
3
|
export declare function pickByConfig<TModel>(obj: TModel | TModel[], config: FindConfig<TModel>): Partial<TModel> | Partial<TModel>[];
|
|
5
4
|
export declare function prepareListQuery<T extends RequestQueryFields, TEntity>(validated: T, queryConfig?: QueryConfig<TEntity> & {
|
|
6
5
|
restricted?: string[];
|
|
7
6
|
}, req?: MedusaRequest & {
|
|
8
|
-
policies?: PolicyDefinition[];
|
|
9
7
|
auth_context?: AuthContext;
|
|
8
|
+
rbac_context?: RbacContext;
|
|
10
9
|
}): Promise<{
|
|
11
10
|
listConfig: {
|
|
12
11
|
select: string[] | undefined;
|
|
@@ -34,8 +33,8 @@ export declare function prepareListQuery<T extends RequestQueryFields, TEntity>(
|
|
|
34
33
|
export declare function prepareRetrieveQuery<T extends RequestQueryFields, TEntity>(validated: T, queryConfig?: QueryConfig<TEntity> & {
|
|
35
34
|
restricted?: string[];
|
|
36
35
|
}, req?: MedusaRequest & {
|
|
37
|
-
policies?: PolicyDefinition[];
|
|
38
36
|
auth_context?: AuthContext;
|
|
37
|
+
rbac_context?: RbacContext;
|
|
39
38
|
}): Promise<{
|
|
40
39
|
retrieveConfig: {
|
|
41
40
|
select: string[] | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-query-config.d.ts","sourceRoot":"","sources":["../../../src/http/utils/get-query-config.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"get-query-config.d.ts","sourceRoot":"","sources":["../../../src/http/utils/get-query-config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,WAAW,EACX,WAAW,EACX,kBAAkB,EACnB,MAAM,iBAAiB,CAAA;AAaxB,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAWrD,wBAAgB,YAAY,CAAC,MAAM,EACjC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,EACtB,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,GACzB,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,CAWrC;AAED,wBAAsB,gBAAgB,CAAC,CAAC,SAAS,kBAAkB,EAAE,OAAO,EAC1E,SAAS,EAAE,CAAC,EACZ,WAAW,GAAE,WAAW,CAAC,OAAO,CAAC,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,EAClE,GAAG,CAAC,EAAE,aAAa,GAAG;IACpB,YAAY,CAAC,EAAE,WAAW,CAAA;IAC1B,YAAY,CAAC,EAAE,WAAW,CAAA;CAC3B;;;;;;;;;;;;;;;;;;;;;;;GAuIF;AAED,wBAAsB,oBAAoB,CACxC,CAAC,SAAS,kBAAkB,EAC5B,OAAO,EAEP,SAAS,EAAE,CAAC,EACZ,WAAW,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,EAC9D,GAAG,CAAC,EAAE,aAAa,GAAG;IACpB,YAAY,CAAC,EAAE,WAAW,CAAA;IAC1B,YAAY,CAAC,EAAE,WAAW,CAAA;CAC3B;;;;;;;;;;GAmBF"}
|
|
@@ -3,9 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.pickByConfig = pickByConfig;
|
|
4
4
|
exports.prepareListQuery = prepareListQuery;
|
|
5
5
|
exports.prepareRetrieveQuery = prepareRetrieveQuery;
|
|
6
|
+
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
6
7
|
const utils_1 = require("@medusajs/utils");
|
|
8
|
+
const has_permission_1 = require("../../policies/has-permission");
|
|
7
9
|
const field_filtering_1 = require("./field-filtering");
|
|
8
10
|
const rbac_field_filter_1 = require("./policies/rbac-field-filter");
|
|
11
|
+
const resolve_roles_1 = require("./resolve-roles");
|
|
9
12
|
function pickByConfig(obj, config) {
|
|
10
13
|
const fields = [...(config.select ?? []), ...(config.relations ?? [])];
|
|
11
14
|
if (fields.length) {
|
|
@@ -23,12 +26,22 @@ async function prepareListQuery(validated, queryConfig = {}, req) {
|
|
|
23
26
|
const { order, fields, limit = defaultLimit, offset = 0, with_deleted, } = validated;
|
|
24
27
|
const parsedFields = field_filtering_1.FieldParser.parse(fields, defaults);
|
|
25
28
|
const { fields: allFields, starFields } = parsedFields;
|
|
26
|
-
const rbacFilterFieldsFeatureFlag = utils_1.FeatureFlag.isFeatureEnabled("rbac_filter_fields");
|
|
27
29
|
const filters = [];
|
|
28
|
-
if (req?.policies &&
|
|
30
|
+
if (req?.rbac_context?.policies?.length &&
|
|
31
|
+
req?.auth_context &&
|
|
32
|
+
entity &&
|
|
33
|
+
modules_sdk_1.MedusaModule.isInstalled(utils_1.Modules.RBAC)) {
|
|
29
34
|
filters.push(new rbac_field_filter_1.RBACFieldFilter({
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
getPermissions: async () => req.rbac_context?.permissions ??
|
|
36
|
+
(0, has_permission_1.listRolePermissions)({
|
|
37
|
+
roles: req.rbac_context?.role_ids ??
|
|
38
|
+
(await (0, resolve_roles_1.resolveRoles)({
|
|
39
|
+
authContext: req.auth_context,
|
|
40
|
+
container: req.scope,
|
|
41
|
+
scope: req.rbac_context?.scope,
|
|
42
|
+
})),
|
|
43
|
+
container: req.scope,
|
|
44
|
+
}),
|
|
32
45
|
container: req.scope,
|
|
33
46
|
}));
|
|
34
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-query-config.js","sourceRoot":"","sources":["../../../src/http/utils/get-query-config.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"get-query-config.js","sourceRoot":"","sources":["../../../src/http/utils/get-query-config.ts"],"names":[],"mappings":";;AA6BA,oCAcC;AAED,4CA6IC;AAED,oDA4BC;AAlND,uDAAoD;AACpD,2CASwB;AACxB,kEAAmE;AAEnE,uDAM0B;AAC1B,oEAA8D;AAC9D,mDAA8C;AAE9C,SAAgB,YAAY,CAC1B,GAAsB,EACtB,MAA0B;IAE1B,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,CAAA;IAEtE,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YACvB,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,gBAAQ,EAAC,CAAW,EAAE,MAAkB,CAAC,CAAC,CAAA;QAClE,CAAC;aAAM,CAAC;YACN,OAAO,IAAA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AAC;YACnC,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,KAAK;YACX,KAAK,EAAE,UAAU;YACjB,WAAW,EAAE,YAAY;SAC1B;QACD,iBAAiB,EAAE;YACjB,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC7B,qHAAqH;YACrH,MAAM,EAAE;gBACN,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;gBACxB,GAAG,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC;aAC/C;YACD,UAAU,EAAE,MAAM;gBAChB,CAAC,CAAC;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,KAAK;oBACX,KAAK,EAAE,UAAU;iBAClB;gBACH,CAAC,CAAC,EAAE;YACN,WAAW,EAAE,YAAY;SAC1B;KACF,CAAA;AACH,CAAC;AAEM,KAAK,UAAU,oBAAoB,CAIxC,SAAY,EACZ,WAA8D,EAC9D,GAGC;IAED,MAAM,EAAE,UAAU,EAAE,iBAAiB,EAAE,GAAG,MAAM,gBAAgB,CAC9D,SAAS,EACT,WAAW,EACX,GAAG,CACJ,CAAA;IAED,OAAO;QACL,cAAc,EAAE;YACd,MAAM,EAAE,UAAU,CAAC,MAAM;YACzB,SAAS,EAAE,UAAU,CAAC,SAAS;SAChC;QACD,iBAAiB,EAAE;YACjB,MAAM,EAAE,iBAAiB,CAAC,MAAM;YAChC,UAAU,EAAE,EAAE;YACd,WAAW,EAAE,iBAAiB,CAAC,WAAW;SAC3C;KACF,CAAA;AACH,CAAC"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { PolicyDefinition } from "@medusajs/framework/utils";
|
|
2
1
|
import type { MedusaContainer } from "@medusajs/types";
|
|
3
2
|
import { FieldFilterContext, IFieldFilter } from "../field-filtering/index";
|
|
4
3
|
/**
|
|
5
|
-
* RBAC Field Filter using the Strategy pattern
|
|
6
|
-
*
|
|
4
|
+
* RBAC Field Filter using the Strategy pattern. The actor's permissions are
|
|
5
|
+
* fetched once, then every governed relation path is checked against them.
|
|
7
6
|
*/
|
|
8
7
|
export declare class RBACFieldFilter implements IFieldFilter {
|
|
9
|
-
private
|
|
10
|
-
private userRoles;
|
|
8
|
+
private getPermissions;
|
|
11
9
|
private container;
|
|
12
|
-
constructor({
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
constructor({ getPermissions, container, }: {
|
|
11
|
+
/**
|
|
12
|
+
* The actor's `resource:operation` permissions, wildcards as stored.
|
|
13
|
+
*/
|
|
14
|
+
getPermissions: () => Promise<string[]>;
|
|
15
15
|
container: MedusaContainer;
|
|
16
16
|
});
|
|
17
17
|
getNotAllowedFields(context: FieldFilterContext): Promise<string[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rbac-field-filter.d.ts","sourceRoot":"","sources":["../../../../src/http/utils/policies/rbac-field-filter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rbac-field-filter.d.ts","sourceRoot":"","sources":["../../../../src/http/utils/policies/rbac-field-filter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAKtD,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAqY3E;;;GAGG;AACH,qBAAa,eAAgB,YAAW,YAAY;IAClD,OAAO,CAAC,cAAc,CAAyB;IAC/C,OAAO,CAAC,SAAS,CAAiB;gBAEtB,EACV,cAAc,EACd,SAAS,GACV,EAAE;QACD;;WAEG;QACH,cAAc,EAAE,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;QACvC,SAAS,EAAE,eAAe,CAAA;KAC3B;IAKK,mBAAmB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAkD1E"}
|
|
@@ -284,41 +284,30 @@ function collectUniqueEntityPaths(entity, fields) {
|
|
|
284
284
|
return uniquePaths;
|
|
285
285
|
}
|
|
286
286
|
/**
|
|
287
|
-
* RBAC Field Filter using the Strategy pattern
|
|
288
|
-
*
|
|
287
|
+
* RBAC Field Filter using the Strategy pattern. The actor's permissions are
|
|
288
|
+
* fetched once, then every governed relation path is checked against them.
|
|
289
289
|
*/
|
|
290
290
|
class RBACFieldFilter {
|
|
291
|
-
constructor({
|
|
292
|
-
this.
|
|
293
|
-
this.userRoles = userRoles;
|
|
291
|
+
constructor({ getPermissions, container, }) {
|
|
292
|
+
this.getPermissions = getPermissions;
|
|
294
293
|
this.container = container;
|
|
295
294
|
}
|
|
296
295
|
async getNotAllowedFields(context) {
|
|
297
296
|
const { entity, parsedFields } = context;
|
|
298
297
|
const { fields, starFields } = parsedFields;
|
|
299
298
|
const fieldsToCheck = [...fields, ...Array.from(starFields)];
|
|
300
|
-
if (!fieldsToCheck.length || !
|
|
299
|
+
if (!fieldsToCheck.length || !entity) {
|
|
301
300
|
return [];
|
|
302
301
|
}
|
|
302
|
+
const permissions = new Set(await this.getPermissions());
|
|
303
|
+
const policyResources = await (0, has_permission_1.fetchPolicyResources)(this.container);
|
|
303
304
|
const uniquePaths = collectUniqueEntityPaths(entity, fieldsToCheck);
|
|
304
|
-
const
|
|
305
|
+
const accessMap = new Map();
|
|
305
306
|
for (const [path, info] of uniquePaths) {
|
|
306
|
-
if (info.entityName &&
|
|
307
|
-
|
|
307
|
+
if (info.entityName && policyResources.has(info.entityName)) {
|
|
308
|
+
accessMap.set(path, (0, has_permission_1.isGranted)(permissions, info.entityName, "read"));
|
|
308
309
|
}
|
|
309
310
|
}
|
|
310
|
-
const permissionResults = await (0, utils_1.promiseAll)(pathsNeedingCheck.map(async ({ path, entityName }) => {
|
|
311
|
-
const hasAccess = await (0, has_permission_1.hasPermission)({
|
|
312
|
-
roles: this.userRoles,
|
|
313
|
-
actions: { resource: entityName, operation: "read" },
|
|
314
|
-
container: this.container,
|
|
315
|
-
});
|
|
316
|
-
return { path, hasAccess };
|
|
317
|
-
}));
|
|
318
|
-
const accessMap = new Map();
|
|
319
|
-
for (const result of permissionResults) {
|
|
320
|
-
accessMap.set(result.path, result.hasAccess);
|
|
321
|
-
}
|
|
322
311
|
const notAllowedFields = [];
|
|
323
312
|
for (const field of fieldsToCheck) {
|
|
324
313
|
const fullFieldPath = entity + "." + field;
|