@medusajs/framework 2.22.2-snapshot-20261026132527 → 2.22.2
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/config/config.d.ts.map +1 -1
- package/dist/config/config.js.map +1 -1
- package/dist/http/index.d.ts +0 -2
- package/dist/http/index.d.ts.map +1 -1
- package/dist/http/index.js +0 -2
- 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 +15 -6
- package/dist/http/middleware-file-loader.js.map +1 -1
- package/dist/http/middlewares/authenticate-middleware.d.ts.map +1 -1
- package/dist/http/middlewares/authenticate-middleware.js.map +1 -1
- package/dist/http/middlewares/check-permissions.d.ts +15 -0
- package/dist/http/middlewares/check-permissions.d.ts.map +1 -0
- package/dist/http/middlewares/check-permissions.js +54 -0
- package/dist/http/middlewares/check-permissions.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 +15 -20
- package/dist/http/router.js.map +1 -1
- package/dist/http/routes-loader.d.ts.map +1 -1
- package/dist/http/routes-loader.js +1 -9
- package/dist/http/routes-loader.js.map +1 -1
- package/dist/http/types.d.ts +159 -7
- package/dist/http/types.d.ts.map +1 -1
- package/dist/http/types.js.map +1 -1
- package/dist/http/utils/get-query-config.d.ts +4 -3
- package/dist/http/utils/get-query-config.d.ts.map +1 -1
- package/dist/http/utils/get-query-config.js +4 -11
- package/dist/http/utils/get-query-config.js.map +1 -1
- package/dist/http/utils/maybe-apply-link-filter.d.ts.map +1 -1
- package/dist/http/utils/maybe-apply-link-filter.js.map +1 -1
- package/dist/http/utils/policies/rbac-field-filter.d.ts +6 -3
- package/dist/http/utils/policies/rbac-field-filter.d.ts.map +1 -1
- package/dist/http/utils/policies/rbac-field-filter.js +6 -7
- package/dist/http/utils/policies/rbac-field-filter.js.map +1 -1
- package/dist/medusa-app-loader.d.ts.map +1 -1
- package/dist/medusa-app-loader.js.map +1 -1
- package/dist/migrations/run-migration-scripts.js.map +1 -1
- package/dist/policies/has-permission.d.ts +0 -26
- package/dist/policies/has-permission.d.ts.map +1 -1
- package/dist/policies/has-permission.js +9 -69
- package/dist/policies/has-permission.js.map +1 -1
- package/dist/policies/index.d.ts +1 -0
- package/dist/policies/index.d.ts.map +1 -1
- package/dist/policies/index.js +1 -0
- package/dist/policies/index.js.map +1 -1
- package/dist/policies/policy-loader.d.ts +6 -0
- package/dist/policies/policy-loader.d.ts.map +1 -0
- package/dist/policies/policy-loader.js +17 -0
- package/dist/policies/policy-loader.js.map +1 -0
- package/dist/telemetry/index.d.ts.map +1 -1
- package/dist/telemetry/index.js.map +1 -1
- package/package.json +13 -13
- package/dist/http/middlewares/authorize.d.ts +0 -43
- package/dist/http/middlewares/authorize.d.ts.map +0 -1
- package/dist/http/middlewares/authorize.js +0 -89
- package/dist/http/middlewares/authorize.js.map +0 -1
- package/dist/http/utils/build-authz-context.d.ts +0 -16
- package/dist/http/utils/build-authz-context.d.ts.map +0 -1
- package/dist/http/utils/build-authz-context.js +0 -44
- package/dist/http/utils/build-authz-context.js.map +0 -1
- package/dist/http/utils/resolve-roles.d.ts +0 -13
- package/dist/http/utils/resolve-roles.d.ts.map +0 -1
- package/dist/http/utils/resolve-roles.js +0 -42
- package/dist/http/utils/resolve-roles.js.map +0 -1
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hasPermission = hasPermission;
|
|
4
4
|
exports.resolvePermissions = resolvePermissions;
|
|
5
|
-
exports.listRolePermissions = listRolePermissions;
|
|
6
|
-
exports.fetchPolicyResources = fetchPolicyResources;
|
|
7
|
-
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
8
5
|
const utils_1 = require("@medusajs/utils");
|
|
9
6
|
/**
|
|
10
7
|
* Applies wildcard-aware matching to decide whether any of the
|
|
@@ -49,7 +46,8 @@ async function hasPermission(input) {
|
|
|
49
46
|
const { roles, actions, container } = input;
|
|
50
47
|
const roleIds = Array.isArray(roles) ? roles : [roles];
|
|
51
48
|
const actionList = Array.isArray(actions) ? actions : [actions];
|
|
52
|
-
const
|
|
49
|
+
const ffRouter = container.resolve(utils_1.ContainerRegistrationKeys.FEATURE_FLAG_ROUTER);
|
|
50
|
+
const isDisabled = !ffRouter.isFeatureEnabled("rbac");
|
|
53
51
|
if (isDisabled || !roleIds?.length || !actionList?.length) {
|
|
54
52
|
return true;
|
|
55
53
|
}
|
|
@@ -90,7 +88,8 @@ async function hasPermission(input) {
|
|
|
90
88
|
async function resolvePermissions(input) {
|
|
91
89
|
const { roles, universe, container } = input;
|
|
92
90
|
const roleIds = Array.isArray(roles) ? roles : [roles];
|
|
93
|
-
|
|
91
|
+
const ffRouter = container.resolve(utils_1.ContainerRegistrationKeys.FEATURE_FLAG_ROUTER);
|
|
92
|
+
if (!ffRouter.isFeatureEnabled("rbac")) {
|
|
94
93
|
return new Set(universe.map(({ resource, operation }) => `${resource}:${operation}`));
|
|
95
94
|
}
|
|
96
95
|
if (!roleIds.length) {
|
|
@@ -105,49 +104,12 @@ async function resolvePermissions(input) {
|
|
|
105
104
|
}
|
|
106
105
|
return granted;
|
|
107
106
|
}
|
|
108
|
-
/**
|
|
109
|
-
* Lists the permissions the given roles grant, as `resource:operation` strings.
|
|
110
|
-
*
|
|
111
|
-
* Wildcards are listed as they are stored (e.g. `product:*`, `*:*`), because
|
|
112
|
-
* expanding them requires the universe of persisted policies. Use
|
|
113
|
-
* {@link resolvePermissions} when the expanded set is needed.
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* ```ts
|
|
117
|
-
* const permissions = await listRolePermissions({
|
|
118
|
-
* roles: ["role_123"],
|
|
119
|
-
* container,
|
|
120
|
-
* })
|
|
121
|
-
* // permissions = ["product:delete", "product:read"]
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
async function listRolePermissions(input) {
|
|
125
|
-
const { roles, container } = input;
|
|
126
|
-
const roleIds = Array.isArray(roles) ? roles : [roles];
|
|
127
|
-
if (!roleIds.length) {
|
|
128
|
-
return [];
|
|
129
|
-
}
|
|
130
|
-
const rolePoliciesMap = await fetchRolePolicies(roleIds, container);
|
|
131
|
-
const permissions = new Set();
|
|
132
|
-
for (const resourceMap of rolePoliciesMap.values()) {
|
|
133
|
-
for (const [resource, operations] of resourceMap) {
|
|
134
|
-
for (const operation of operations) {
|
|
135
|
-
permissions.add(`${resource}:${operation}`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return Array.from(permissions).sort();
|
|
140
|
-
}
|
|
141
107
|
/**
|
|
142
108
|
* Fetches a single role's policies from cache or database.
|
|
143
109
|
*/
|
|
144
110
|
async function fetchSingleRolePolicies(roleId, container) {
|
|
145
111
|
const query = container.resolve(utils_1.ContainerRegistrationKeys.QUERY);
|
|
146
|
-
const tags = [
|
|
147
|
-
`RbacRole:${roleId}`,
|
|
148
|
-
"RbacRoleParent:list:*",
|
|
149
|
-
"RbacRolePolicy:list:*",
|
|
150
|
-
];
|
|
112
|
+
const tags = [];
|
|
151
113
|
return await (0, utils_1.useCache)(async () => {
|
|
152
114
|
const { data: roles } = await query.graph({
|
|
153
115
|
entity: "rbac_role",
|
|
@@ -156,13 +118,16 @@ async function fetchSingleRolePolicies(roleId, container) {
|
|
|
156
118
|
});
|
|
157
119
|
const role = roles[0];
|
|
158
120
|
const resourceMap = new Map();
|
|
121
|
+
tags.push(`rbac_role:${roleId}`);
|
|
159
122
|
if (role?.policies && Array.isArray(role.policies)) {
|
|
123
|
+
const policyIds = [];
|
|
160
124
|
for (const policy of role.policies) {
|
|
125
|
+
policyIds.push(policy.id);
|
|
161
126
|
if (!resourceMap.has(policy.resource)) {
|
|
162
127
|
resourceMap.set(policy.resource, new Set());
|
|
163
128
|
}
|
|
164
129
|
resourceMap.get(policy.resource).add(policy.operation);
|
|
165
|
-
tags.push(`
|
|
130
|
+
tags.push(`rbac_policy:${policy.id}`);
|
|
166
131
|
}
|
|
167
132
|
}
|
|
168
133
|
return resourceMap;
|
|
@@ -170,31 +135,6 @@ async function fetchSingleRolePolicies(roleId, container) {
|
|
|
170
135
|
container,
|
|
171
136
|
key: roleId,
|
|
172
137
|
tags,
|
|
173
|
-
enable: true,
|
|
174
|
-
ttl: 60 * 60 * 24 * 7,
|
|
175
|
-
providers: ["cache-memory"],
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Fetches the set of governed resources: every distinct `rbac_policy.resource`
|
|
180
|
-
* from cache or database.
|
|
181
|
-
*/
|
|
182
|
-
async function fetchPolicyResources(container) {
|
|
183
|
-
if (!modules_sdk_1.MedusaModule.isInstalled(utils_1.Modules.RBAC)) {
|
|
184
|
-
return new Set();
|
|
185
|
-
}
|
|
186
|
-
const query = container.resolve(utils_1.ContainerRegistrationKeys.QUERY);
|
|
187
|
-
return await (0, utils_1.useCache)(async () => {
|
|
188
|
-
const { data: policies } = await query.graph({
|
|
189
|
-
entity: "rbac_policy",
|
|
190
|
-
fields: ["resource"],
|
|
191
|
-
});
|
|
192
|
-
return new Set((policies ?? []).map((policy) => policy.resource));
|
|
193
|
-
}, {
|
|
194
|
-
container,
|
|
195
|
-
key: "rbac-policy-resources",
|
|
196
|
-
tags: ["RbacPolicy:list:*"],
|
|
197
|
-
enable: true,
|
|
198
138
|
ttl: 60 * 60 * 24 * 7,
|
|
199
139
|
providers: ["cache-memory"],
|
|
200
140
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"has-permission.js","sourceRoot":"","sources":["../../src/policies/has-permission.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"has-permission.js","sourceRoot":"","sources":["../../src/policies/has-permission.ts"],"names":[],"mappings":";;AAmFA,sCA+BC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S,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;gBAEzB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;oBACtC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,GAAG,EAAE,CAAC,CAAA;gBAC7C,CAAC;gBACD,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAE,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;gBAEvD,IAAI,CAAC,IAAI,CAAC,eAAe,MAAM,CAAC,EAAE,EAAE,CAAC,CAAA;YACvC,CAAC;QACH,CAAC;QAED,OAAO,WAAW,CAAA;IACpB,CAAC,EACD;QACE,SAAS;QACT,GAAG,EAAE,MAAM;QACX,IAAI;QACJ,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;QACrB,SAAS,EAAE,CAAC,cAAc,CAAC;KAC5B,CACF,CAAA;AACH,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,iBAAiB,CAC9B,OAAiB,EACjB,SAA0B;IAE1B,MAAM,eAAe,GAAsB,IAAI,GAAG,EAAE,CAAA;IAEpD,MAAM,OAAO,CAAC,GAAG,CACf,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC3B,MAAM,WAAW,GAAG,MAAM,uBAAuB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;QACpE,eAAe,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;IAC1C,CAAC,CAAC,CACH,CAAA;IAED,OAAO,eAAe,CAAA;AACxB,CAAC"}
|
package/dist/policies/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/policies/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/policies/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA"}
|
package/dist/policies/index.js
CHANGED
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./has-permission"), exports);
|
|
18
|
+
__exportStar(require("./policy-loader"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/policies/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/policies/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC;AAChC,kDAA+B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-loader.d.ts","sourceRoot":"","sources":["../../src/policies/policy-loader.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAsB,cAAc,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQvE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.policiesLoader = policiesLoader;
|
|
4
|
+
const utils_1 = require("@medusajs/utils");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
/**
|
|
7
|
+
* Load RBAC policies from a directory
|
|
8
|
+
* @param sourcePath - Path to scan for policies directories
|
|
9
|
+
*/
|
|
10
|
+
async function policiesLoader(sourcePath) {
|
|
11
|
+
if (!sourcePath) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const policyDir = (0, path_1.normalize)(sourcePath);
|
|
15
|
+
await (0, utils_1.discoverPoliciesFromDir)(policyDir);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=policy-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-loader.js","sourceRoot":"","sources":["../../src/policies/policy-loader.ts"],"names":[],"mappings":";;AAOA,wCAQC;AAfD,2CAAyD;AACzD,+BAAgC;AAEhC;;;GAGG;AACI,KAAK,UAAU,cAAc,CAAC,UAAmB;IACtD,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAM;IACR,CAAC;IAED,MAAM,SAAS,GAAG,IAAA,gBAAS,EAAC,UAAU,CAAC,CAAA;IAEvC,MAAM,IAAA,+BAAuB,EAAC,SAAS,CAAC,CAAA;AAC1C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/telemetry/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,IAAI,QAAQ,EAClB,IAAI,EAIL,MAAM,2BAA2B,CAAA;AAElC;;;;;;;;GAQG;AACH,qBAAa,MAAM;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/telemetry/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,IAAI,QAAQ,EAClB,IAAI,EAIL,MAAM,2BAA2B,CAAA;AAElC;;;;;;;;GAQG;AACH,qBAAa,MAAM;;IAMR,IAAI,EAAE,MAAM;IACZ,OAAO,CAAC,EAAE,MAAM;gBADhB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,YAAA;IAKzB;;;OAGG;IACH,WAAW;IAIX;;;OAGG;IACH,KAAK,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,EACrC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,GACV,UAAU,CAAC,CAAC,CAAC;IAIhB;;OAEG;IACH,gBAAgB;IAIhB;;;OAGG;IACH,mBAAmB,IAGA;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE;IAG/D;;;;OAIG;IACH,oBAAoB,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE;gBAE5D,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,QACjC,MAAM,YACF,CAAC,KACV,UAAU,CAAC,CAAC,CAAC;;CAMrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/telemetry/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iEAMkC;AAElC;;;;;;;;GAQG;AACH,MAAa,MAAM;IAKjB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/telemetry/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iEAMkC;AAElC;;;;;;;;GAQG;AACH,MAAa,MAAM;IAKjB,YACS,IAAY,EACZ,OAAgB;QADhB,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAS;QANzB;;WAEG;QACH,mCAAmB;QAKjB,uBAAA,IAAI,oBAAa,yBAAK,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,MAAA,CAAA;IACjD,CAAC;IAED;;;OAGG;IACH,WAAW;QACT,OAAO,uBAAA,IAAI,wBAAU,CAAA;IACvB,CAAC;IAED;;;OAGG;IACH,KAAK,CACH,IAAY,EACZ,QAAW;QAEX,OAAO,uBAAA,IAAI,wBAAU,CAAC,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;IACvD,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,OAAO,2BAAO,CAAC,MAAM,EAAE,CAAA;IACzB,CAAC;IAED;;;OAGG;IACH,mBAAmB;QACjB,IAAI,MAAM,GAAG,EAAE,CAAA;QACf,+BAAW,CAAC,MAAM,CAAC,2BAAO,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,CAAA;QAC5C,OAAO,MAAsD,CAAA;IAC/D,CAAC;IAED;;;;OAIG;IACH,oBAAoB,CAAC,KAAmD;QACtE,OAAO;YACL,KAAK,EAAE,CACL,IAAY,EACZ,QAAW,EACI,EAAE;gBACjB,MAAM,aAAa,GAAG,+BAAW,CAAC,OAAO,CAAC,2BAAO,CAAC,MAAM,EAAE,EAAE,KAAK,CAAC,CAAA;gBAClE,OAAO,uBAAA,IAAI,wBAAU,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAA;YAC1E,CAAC;SACF,CAAA;IACH,CAAC;CACF;AAhED,wBAgEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medusajs/framework",
|
|
3
|
-
"version": "2.22.2
|
|
3
|
+
"version": "2.22.2",
|
|
4
4
|
"description": "Framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -79,18 +79,18 @@
|
|
|
79
79
|
"test": "../../../node_modules/.bin/jest --bail --forceExit --testPathPattern=src"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
|
-
"@medusajs/cli": "2.22.2
|
|
82
|
+
"@medusajs/cli": "2.22.2"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@aws-sdk/client-dynamodb": "^3.
|
|
85
|
+
"@aws-sdk/client-dynamodb": "^3.1156.0",
|
|
86
86
|
"@jercle/yargonaut": "^1.1.5",
|
|
87
|
-
"@medusajs/deps": "2.22.2
|
|
88
|
-
"@medusajs/modules-sdk": "2.22.2
|
|
89
|
-
"@medusajs/orchestration": "2.22.2
|
|
90
|
-
"@medusajs/telemetry": "2.22.2
|
|
91
|
-
"@medusajs/types": "2.22.2
|
|
92
|
-
"@medusajs/utils": "2.22.2
|
|
93
|
-
"@medusajs/workflows-sdk": "2.22.2
|
|
87
|
+
"@medusajs/deps": "2.22.2",
|
|
88
|
+
"@medusajs/modules-sdk": "2.22.2",
|
|
89
|
+
"@medusajs/orchestration": "2.22.2",
|
|
90
|
+
"@medusajs/telemetry": "2.22.2",
|
|
91
|
+
"@medusajs/types": "2.22.2",
|
|
92
|
+
"@medusajs/utils": "2.22.2",
|
|
93
|
+
"@medusajs/workflows-sdk": "2.22.2",
|
|
94
94
|
"@types/express": "^4.17.21",
|
|
95
95
|
"chokidar": "^4.0.3",
|
|
96
96
|
"compression": "^1.8.2",
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"cookie-parser": "^1.4.6",
|
|
100
100
|
"cors": "^2.8.5",
|
|
101
101
|
"express": "^4.21.0",
|
|
102
|
-
"express-session": "^1.
|
|
102
|
+
"express-session": "^1.19.0",
|
|
103
103
|
"glob": "13.0.6",
|
|
104
104
|
"http-errors": "2.0.0",
|
|
105
105
|
"jsonwebtoken": "^9.0.2",
|
|
@@ -110,8 +110,8 @@
|
|
|
110
110
|
"zod-validation-error": "5.0.0"
|
|
111
111
|
},
|
|
112
112
|
"peerDependencies": {
|
|
113
|
-
"@medusajs/cli": "2.22.2
|
|
114
|
-
"ioredis": "^5.
|
|
113
|
+
"@medusajs/cli": "2.22.2",
|
|
114
|
+
"ioredis": "^5.11.1"
|
|
115
115
|
},
|
|
116
116
|
"peerDependenciesMeta": {
|
|
117
117
|
"ioredis": {
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { PolicyAction } from "@medusajs/types";
|
|
2
|
-
import type { AuthenticatedMedusaRequest, MedusaNextFunction, MedusaResponse } from "../types";
|
|
3
|
-
/**
|
|
4
|
-
* A middleware guarding a route with RBAC policies. The policies it checks are
|
|
5
|
-
* exposed on the middleware itself, so a route's guards can be inspected
|
|
6
|
-
* without running it.
|
|
7
|
-
*/
|
|
8
|
-
export type AuthorizeMiddleware = ((req: AuthenticatedMedusaRequest, res: MedusaResponse, next: MedusaNextFunction) => Promise<void>) & {
|
|
9
|
-
policies: PolicyAction[];
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Creates a middleware guarding a route with the given RBAC policies.
|
|
13
|
-
*
|
|
14
|
-
* The actor's roles are resolved for the scope the request acts within, which
|
|
15
|
-
* the application sets on `req.rbac_context.scope` from a middleware of its
|
|
16
|
-
* own. That middleware must run before this one: register it on a less
|
|
17
|
-
* specific matcher. Without a scope, only unscoped role assignments are
|
|
18
|
-
* considered.
|
|
19
|
-
*
|
|
20
|
-
* On success, the resolved permissions are exposed on
|
|
21
|
-
* `req.rbac_context.permissions` for the route handler and the middlewares
|
|
22
|
-
* downstream. It is a no-op when RBAC is disabled.
|
|
23
|
-
*
|
|
24
|
-
* @param policies - Single policy or array of policies guarding the route
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* export default defineMiddlewares({
|
|
29
|
-
* routes: [
|
|
30
|
-
* {
|
|
31
|
-
* matcher: "/admin/products",
|
|
32
|
-
* methods: ["POST"],
|
|
33
|
-
* middlewares: [
|
|
34
|
-
* authorize({ resource: "product", operation: "create" }),
|
|
35
|
-
* validateAndTransformBody(AdminCreateProduct),
|
|
36
|
-
* ],
|
|
37
|
-
* },
|
|
38
|
-
* ],
|
|
39
|
-
* })
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export declare function authorize(policies: PolicyAction | PolicyAction[]): AuthorizeMiddleware;
|
|
43
|
-
//# sourceMappingURL=authorize.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../../../src/http/middlewares/authorize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAOnD,OAAO,KAAK,EACV,0BAA0B,EAC1B,kBAAkB,EAClB,cAAc,EACf,MAAM,UAAU,CAAA;AAGjB;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CACjC,GAAG,EAAE,0BAA0B,EAC/B,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE,kBAAkB,KACrB,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG;IAAE,QAAQ,EAAE,YAAY,EAAE,CAAA;CAAE,CAAA;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,SAAS,CACvB,QAAQ,EAAE,YAAY,GAAG,YAAY,EAAE,GACtC,mBAAmB,CAqErB"}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.authorize = authorize;
|
|
4
|
-
const modules_sdk_1 = require("@medusajs/modules-sdk");
|
|
5
|
-
const utils_1 = require("@medusajs/utils");
|
|
6
|
-
const has_permission_1 = require("../../policies/has-permission");
|
|
7
|
-
const resolve_roles_1 = require("../utils/resolve-roles");
|
|
8
|
-
/**
|
|
9
|
-
* Creates a middleware guarding a route with the given RBAC policies.
|
|
10
|
-
*
|
|
11
|
-
* The actor's roles are resolved for the scope the request acts within, which
|
|
12
|
-
* the application sets on `req.rbac_context.scope` from a middleware of its
|
|
13
|
-
* own. That middleware must run before this one: register it on a less
|
|
14
|
-
* specific matcher. Without a scope, only unscoped role assignments are
|
|
15
|
-
* considered.
|
|
16
|
-
*
|
|
17
|
-
* On success, the resolved permissions are exposed on
|
|
18
|
-
* `req.rbac_context.permissions` for the route handler and the middlewares
|
|
19
|
-
* downstream. It is a no-op when RBAC is disabled.
|
|
20
|
-
*
|
|
21
|
-
* @param policies - Single policy or array of policies guarding the route
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* export default defineMiddlewares({
|
|
26
|
-
* routes: [
|
|
27
|
-
* {
|
|
28
|
-
* matcher: "/admin/products",
|
|
29
|
-
* methods: ["POST"],
|
|
30
|
-
* middlewares: [
|
|
31
|
-
* authorize({ resource: "product", operation: "create" }),
|
|
32
|
-
* validateAndTransformBody(AdminCreateProduct),
|
|
33
|
-
* ],
|
|
34
|
-
* },
|
|
35
|
-
* ],
|
|
36
|
-
* })
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
function authorize(policies) {
|
|
40
|
-
const policyList = Array.isArray(policies) ? policies : [policies];
|
|
41
|
-
const authorizeMiddleware = async (req, _, next) => {
|
|
42
|
-
if (!modules_sdk_1.MedusaModule.isInstalled(utils_1.Modules.RBAC) || !policyList.length) {
|
|
43
|
-
return next();
|
|
44
|
-
}
|
|
45
|
-
req.rbac_context ??= {};
|
|
46
|
-
/**
|
|
47
|
-
* The policies are recorded on the request before they are checked,
|
|
48
|
-
* because the query config middlewares read them to filter the requested
|
|
49
|
-
* fields. Those middlewares must therefore be registered after this one.
|
|
50
|
-
*/
|
|
51
|
-
req.rbac_context = {
|
|
52
|
-
...req.rbac_context,
|
|
53
|
-
policies: [...(req.rbac_context.policies ?? []), ...policyList],
|
|
54
|
-
};
|
|
55
|
-
if (!req.auth_context?.actor_id) {
|
|
56
|
-
throw new utils_1.MedusaError(utils_1.MedusaError.Types.FORBIDDEN, "Forbidden");
|
|
57
|
-
}
|
|
58
|
-
const roleIds = await (0, resolve_roles_1.resolveRoles)({
|
|
59
|
-
authContext: req.auth_context,
|
|
60
|
-
container: req.scope,
|
|
61
|
-
scope: req.rbac_context?.scope,
|
|
62
|
-
});
|
|
63
|
-
if (!roleIds.length) {
|
|
64
|
-
throw new utils_1.MedusaError(utils_1.MedusaError.Types.FORBIDDEN, "Forbidden");
|
|
65
|
-
}
|
|
66
|
-
const hasAccess = await (0, has_permission_1.hasPermission)({
|
|
67
|
-
roles: roleIds,
|
|
68
|
-
actions: policyList,
|
|
69
|
-
container: req.scope,
|
|
70
|
-
});
|
|
71
|
-
if (!hasAccess) {
|
|
72
|
-
const policyKeys = policyList
|
|
73
|
-
.map((p) => `${p.resource}:${p.operation}`)
|
|
74
|
-
.join(", ");
|
|
75
|
-
throw new utils_1.MedusaError(utils_1.MedusaError.Types.FORBIDDEN, `Insufficient permissions. Required policies: ${policyKeys}`);
|
|
76
|
-
}
|
|
77
|
-
req.rbac_context = {
|
|
78
|
-
...req.rbac_context,
|
|
79
|
-
permissions: await (0, has_permission_1.listRolePermissions)({
|
|
80
|
-
roles: roleIds,
|
|
81
|
-
container: req.scope,
|
|
82
|
-
}),
|
|
83
|
-
};
|
|
84
|
-
return next();
|
|
85
|
-
};
|
|
86
|
-
authorizeMiddleware.policies = policyList;
|
|
87
|
-
return authorizeMiddleware;
|
|
88
|
-
}
|
|
89
|
-
//# sourceMappingURL=authorize.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../../src/http/middlewares/authorize.ts"],"names":[],"mappings":";;AAwDA,8BAuEC;AA9HD,uDAAoD;AACpD,2CAAsD;AACtD,kEAGsC;AAMtC,0DAAqD;AAarD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,SAAgB,SAAS,CACvB,QAAuC;IAEvC,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;IAElE,MAAM,mBAAmB,GAAG,KAAK,EAC/B,GAA+B,EAC/B,CAAiB,EACjB,IAAwB,EACxB,EAAE;QACF,IAAI,CAAC,0BAAY,CAAC,WAAW,CAAC,eAAO,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;YAClE,OAAO,IAAI,EAAE,CAAA;QACf,CAAC;QAED,GAAG,CAAC,YAAY,KAAK,EAAE,CAAA;QAEvB;;;;WAIG;QACH,GAAG,CAAC,YAAY,GAAG;YACjB,GAAG,GAAG,CAAC,YAAY;YACnB,QAAQ,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,YAA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AED,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;IAED,mBAAmB,CAAC,QAAQ,GAAG,UAAU,CAAA;IAEzC,OAAO,mBAAmB,CAAA;AAC5B,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,44 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version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AI,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"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { AuthContext, MedusaContainer, RbacScope } from "@medusajs/types";
|
|
2
|
-
export declare const resolveRoles: ({ authContext, container, scope, }: {
|
|
3
|
-
authContext: Pick<AuthContext, "actor_type" | "actor_id">;
|
|
4
|
-
container: MedusaContainer;
|
|
5
|
-
/**
|
|
6
|
-
* The scope the request acts within, resolved by the application. Role
|
|
7
|
-
* assignments scoped to it, as well as unscoped assignments, are considered.
|
|
8
|
-
*
|
|
9
|
-
* When it is not provided, only unscoped assignments are considered.
|
|
10
|
-
*/
|
|
11
|
-
scope?: RbacScope;
|
|
12
|
-
}) => Promise<string[]>;
|
|
13
|
-
//# sourceMappingURL=resolve-roles.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-roles.d.ts","sourceRoot":"","sources":["../../../src/http/utils/resolve-roles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAIzE,eAAO,MAAM,YAAY,GAAU,oCAIhC;IACD,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,YAAY,GAAG,UAAU,CAAC,CAAA;IACzD,SAAS,EAAE,eAAe,CAAA;IAC1B;;;;;OAKG;IACH,KAAK,CAAC,EAAE,SAAS,CAAA;CAClB,sBA2CA,CAAA"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveRoles = void 0;
|
|
4
|
-
const utils_1 = require("@medusajs/utils");
|
|
5
|
-
const build_authz_context_1 = require("./build-authz-context");
|
|
6
|
-
const resolveRoles = async ({ authContext, container, scope, }) => {
|
|
7
|
-
const rbacModule = container.resolve(utils_1.Modules.RBAC);
|
|
8
|
-
const { actor_type, actor_id } = authContext;
|
|
9
|
-
const authzConfig = await rbacModule.retrieveActorAutzContextConfig(actor_type);
|
|
10
|
-
if (!authzConfig) {
|
|
11
|
-
return [];
|
|
12
|
-
}
|
|
13
|
-
const authzContext = await (0, build_authz_context_1.buildAuthzContext)({
|
|
14
|
-
actor_type,
|
|
15
|
-
actor_id,
|
|
16
|
-
config: authzConfig,
|
|
17
|
-
container,
|
|
18
|
-
});
|
|
19
|
-
if (!authzContext.grantees.length) {
|
|
20
|
-
return [];
|
|
21
|
-
}
|
|
22
|
-
const assignments = await rbacModule.listRbacRoleAssignments({
|
|
23
|
-
$and: [
|
|
24
|
-
{
|
|
25
|
-
$or: authzContext.grantees.map((g) => ({
|
|
26
|
-
reference: g.type,
|
|
27
|
-
reference_id: g.id,
|
|
28
|
-
})),
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
$or: [
|
|
32
|
-
// Unscoped role assignments allow exercising privileges across all scopes.
|
|
33
|
-
{ scope: null, scope_id: null },
|
|
34
|
-
...(scope ? [{ scope: scope.type, scope_id: scope.id }] : []),
|
|
35
|
-
],
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
});
|
|
39
|
-
return (0, utils_1.deduplicate)(assignments.map((assignment) => assignment.role_id));
|
|
40
|
-
};
|
|
41
|
-
exports.resolveRoles = resolveRoles;
|
|
42
|
-
//# sourceMappingURL=resolve-roles.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-roles.js","sourceRoot":"","sources":["../../../src/http/utils/resolve-roles.ts"],"names":[],"mappings":";;;AACA,2CAAsD;AACtD,+DAAyD;AAElD,MAAM,YAAY,GAAG,KAAK,EAAE,EACjC,WAAW,EACX,SAAS,EACT,KAAK,GAWN,EAAE,EAAE;IACH,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,CAAC,eAAO,CAAC,IAAI,CAAC,CAAA;IAElD,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAA;IAE5C,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,8BAA8B,CACjE,UAAU,CACX,CAAA;IAED,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,YAAY,GAAG,MAAM,IAAA,uCAAiB,EAAC;QAC3C,UAAU;QACV,QAAQ;QACR,MAAM,EAAE,WAAW;QACnB,SAAS;KACV,CAAC,CAAA;IAEF,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QAClC,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,uBAAuB,CAAC;QAC3D,IAAI,EAAE;YACJ;gBACE,GAAG,EAAE,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;oBACrC,SAAS,EAAE,CAAC,CAAC,IAAI;oBACjB,YAAY,EAAE,CAAC,CAAC,EAAE;iBACnB,CAAC,CAAC;aACJ;YACD;gBACE,GAAG,EAAE;oBACH,2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