@medusajs/rbac 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.
Files changed (71) hide show
  1. package/AGENTS.md +39 -19
  2. package/README.md +11 -16
  3. package/dist/index.d.ts +1 -58
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +2 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/loaders/core-policies.d.ts +14 -0
  8. package/dist/loaders/core-policies.d.ts.map +1 -0
  9. package/dist/loaders/core-policies.js +68 -0
  10. package/dist/loaders/core-policies.js.map +1 -0
  11. package/dist/loaders/core-policy-definitions.d.ts +8 -0
  12. package/dist/loaders/core-policy-definitions.d.ts.map +1 -0
  13. package/dist/loaders/core-policy-definitions.js +15 -0
  14. package/dist/loaders/core-policy-definitions.js.map +1 -0
  15. package/dist/loaders/initial-data.d.ts.map +1 -1
  16. package/dist/loaders/initial-data.js +3 -3
  17. package/dist/loaders/initial-data.js.map +1 -1
  18. package/dist/migrations/Migration20260612013735.d.ts +6 -0
  19. package/dist/migrations/Migration20260612013735.d.ts.map +1 -0
  20. package/dist/migrations/Migration20260612013735.js +24 -0
  21. package/dist/migrations/Migration20260612013735.js.map +1 -0
  22. package/dist/migrations/Migration20260729201429.d.ts +6 -0
  23. package/dist/migrations/Migration20260729201429.d.ts.map +1 -0
  24. package/dist/migrations/Migration20260729201429.js +22 -0
  25. package/dist/migrations/Migration20260729201429.js.map +1 -0
  26. package/dist/migrations/Migration20261022124403.d.ts +6 -0
  27. package/dist/migrations/Migration20261022124403.d.ts.map +1 -0
  28. package/dist/migrations/Migration20261022124403.js +14 -0
  29. package/dist/migrations/Migration20261022124403.js.map +1 -0
  30. package/dist/migrations/Migration20261029190116.d.ts +6 -0
  31. package/dist/migrations/Migration20261029190116.d.ts.map +1 -0
  32. package/dist/migrations/Migration20261029190116.js +20 -0
  33. package/dist/migrations/Migration20261029190116.js.map +1 -0
  34. package/dist/migrations/Migration20261030132556.d.ts +6 -0
  35. package/dist/migrations/Migration20261030132556.d.ts.map +1 -0
  36. package/dist/migrations/Migration20261030132556.js +20 -0
  37. package/dist/migrations/Migration20261030132556.js.map +1 -0
  38. package/dist/models/index.d.ts +1 -1
  39. package/dist/models/index.d.ts.map +1 -1
  40. package/dist/models/index.js +3 -3
  41. package/dist/models/index.js.map +1 -1
  42. package/dist/models/rbac-role-assignment.d.ts +31 -0
  43. package/dist/models/rbac-role-assignment.d.ts.map +1 -0
  44. package/dist/models/rbac-role-assignment.js +43 -0
  45. package/dist/models/rbac-role-assignment.js.map +1 -0
  46. package/dist/models/rbac-role-policy.d.ts +6 -3
  47. package/dist/models/rbac-role-policy.d.ts.map +1 -1
  48. package/dist/models/rbac-role-policy.js +1 -1
  49. package/dist/models/rbac-role-policy.js.map +1 -1
  50. package/dist/models/rbac-role.d.ts +6 -3
  51. package/dist/models/rbac-role.d.ts.map +1 -1
  52. package/dist/models/rbac-role.js +5 -2
  53. package/dist/models/rbac-role.js.map +1 -1
  54. package/dist/repositories/rbac.d.ts +0 -1
  55. package/dist/repositories/rbac.d.ts.map +1 -1
  56. package/dist/repositories/rbac.js +10 -52
  57. package/dist/repositories/rbac.js.map +1 -1
  58. package/dist/services/rbac-module-service.d.ts +29 -118
  59. package/dist/services/rbac-module-service.d.ts.map +1 -1
  60. package/dist/services/rbac-module-service.js +39 -141
  61. package/dist/services/rbac-module-service.js.map +1 -1
  62. package/dist/tsconfig.tsbuildinfo +1 -1
  63. package/package.json +6 -6
  64. package/dist/models/rbac-role-inheritance.d.ts +0 -58
  65. package/dist/models/rbac-role-inheritance.d.ts.map +0 -1
  66. package/dist/models/rbac-role-inheritance.js +0 -33
  67. package/dist/models/rbac-role-inheritance.js.map +0 -1
  68. package/dist/models/rbac-role-parent.d.ts +0 -48
  69. package/dist/models/rbac-role-parent.d.ts.map +0 -1
  70. package/dist/models/rbac-role-parent.js +0 -31
  71. package/dist/models/rbac-role-parent.js.map +0 -1
package/AGENTS.md CHANGED
@@ -1,12 +1,30 @@
1
1
  # @medusajs/rbac
2
2
 
3
- Role-based access control module: stores roles, policies (`resource:operation` permissions), role-to-policy assignments, and role inheritance. Registered as `Modules.RBAC` (`"rbac"`).
3
+ Role-based access control module: stores roles, policies (`resource:operation` permissions), role-to-policy assignments, and role assignments. Registered as `Modules.RBAC` (`"rbac"`).
4
4
 
5
5
  ## Using this package
6
6
 
7
- - Included in `defineConfig` (`@medusajs/medusa/rbac`) but disabled unless the `rbac` feature flag is on (`MEDUSA_FF_RBAC=true`, default `false`).
7
+ - Not registered by default: applications add `{ resolve: "@medusajs/medusa/rbac" }` to `modules` in `medusa-config.ts`. Everything RBAC (the `authorize` middleware, the `/rbac/*` routes, role assignment on users and invites, response field filtering) switches on when the module is installed and is a no-op otherwise.
8
8
  - It is a licensed module: the loader (`packages/core/modules-sdk/src/loaders/utils/load-internal.ts`, `LICENSED_MODULES`) only loads it when the license covers `LicenseFeature.RBAC`.
9
- - No module options and no providers.
9
+ - One module option, `actors`, says how each authenticated actor type reaches the entities that can hold role assignments for it (its grantees), and no providers. `user` always keeps `{ entity: "user", path: "id" }` as a grantee; configured grantees are added to it. Secret API keys authenticate as `api-key` and by default act with the roles of the user that created them. Set `actor_entity` when the actor type is not the name of a `query.graph` entity.
10
+
11
+ ```ts
12
+ // medusa-config.ts
13
+ {
14
+ resolve: "@medusajs/medusa/rbac",
15
+ options: {
16
+ actors: {
17
+ user: { grantees: [{ entity: "team", path: "teams.id" }] },
18
+ // Give each secret key its own role assignments (reference: "api_key")
19
+ // instead of inheriting its creator's roles:
20
+ "api-key": {
21
+ actor_entity: "api_key",
22
+ grantees: [{ entity: "api_key", path: "id" }],
23
+ },
24
+ },
25
+ },
26
+ }
27
+ ```
10
28
 
11
29
  ```ts
12
30
  import { Modules } from "@medusajs/framework/utils"
@@ -16,34 +34,35 @@ const rbacModuleService: IRbacModuleService = container.resolve(Modules.RBAC)
16
34
  const policies = await rbacModuleService.listPoliciesForRole("role_123")
17
35
  ```
18
36
 
19
- - Custom policies are declared with `definePolicies` from `@medusajs/framework/utils` (`{ name, resource, operation, description? }`); they land in the global `Policy` registry and this module syncs them to the DB on startup.
37
+ - Custom policies are created at runtime, for example with `createRbacPoliciesWorkflow` from `@medusajs/core-flows` and payloads from `buildPolicies({ resource, operation? })` (`@medusajs/framework/utils`), which expands each resource into one policy per operation (`read`, `create`, `update`, `delete` by default).
20
38
 
21
39
  ### Data models (`src/models`, all exported from `src/models/index.ts`)
22
40
 
23
- - `RbacRole` (`role_`): `name` (unique among non-deleted), `description`, `policies`, `parents`.
41
+ - `RbacRole` (`role_`): `name` (unique among non-deleted), `description`, `policies`, `assignments`. Deleting a role cascades to both.
24
42
  - `RbacPolicy` (`rpol_`): `key` (unique, `<resource>:<operation>`), `resource`, `operation`, `name`, `description`.
25
- - `RbacRolePolicy` (`rlpl_`): role-to-policy join.
26
- - `RbacRoleParent` (`rlin_`): `role` inherits from `parent`.
27
- - `src/models/rbac-role-inheritance.ts` is not exported from the models index and is not part of the service; do not build on it.
43
+ - `RbacRolePolicy` (`rlpl_`): role-to-policy join, unique per `(role_id, policy_id)`.
44
+ - `RbacRoleAssignment` (`rasgn_`): grants `role_id` to a grantee identified by `reference` (e.g. `"user"`) and `reference_id`, optionally narrowed by `scope` / `scope_id`. Unique partial indexes allow one assignment per `(role_id, scope, scope_id, reference, reference_id)` and one unscoped assignment per `(role_id, reference, reference_id)`, among non-deleted rows.
28
45
 
29
46
  ### Service methods (`src/services/rbac-module-service.ts`)
30
47
 
31
- Generated CRUD for `RbacRole`, `RbacPolicy`, `RbacRoleParent`, `RbacRolePolicy`, plus:
48
+ Generated CRUD for `RbacRole`, `RbacPolicy`, `RbacRolePolicy`, `RbacRoleAssignment`, plus:
32
49
 
33
- - `listPoliciesForRole(roleId)`: all policies of the role, including inherited ones (recursive CTE in `src/repositories/rbac.ts`); inherited rows carry `inherited_from_role_id`.
34
- - `listRbacRoles` / `listAndCountRbacRoles` (overridden): when `relations` or `select` include `"policies"`, `role.policies` is replaced with the resolved (inherited) policies, not the raw `RbacRolePolicy` rows.
35
- - `createRbacRoleParents` / `updateRbacRoleParents` (overridden): reject self-parenting and cycles (`checkForCycle`).
50
+ - `listPoliciesForRole(roleId)`: the policies assigned directly to the role (raw SQL join in `src/repositories/rbac.ts`), as `RbacPolicy` rows.
51
+ - `listRbacRoles` / `listAndCountRbacRoles` (overridden): when `relations` or `select` include `"policies"`, `role.policies` is replaced with the role's `RbacPolicy` rows, not the raw `RbacRolePolicy` join rows.
52
+ - `retrieveActorAuthzContextConfig(actorType)`: the resolved `actors` option entry for an actor type (`user` and `api-key` always have one).
53
+ - `listGranteeEntities()`: the grantee entities across all actor types, i.e. the valid `reference` values for a role assignment. `assignRolesWorkflow` rejects any other reference.
36
54
 
37
55
  ### Events and links
38
56
 
39
57
  - Emits internal CRUD events (`rbac.<model>.created|updated|deleted|restored`) through `MedusaService`.
40
- - Module links: `user-rbac-role` (`user_rbac_role`, User -> RbacRole) and `invite-rbac-role` (`invite_rbac_role`, Invite -> RbacRole) in `packages/modules/link-modules/src/definitions`.
58
+ - Read-only links in `packages/modules/link-modules/src/definitions` expose assignments on users (`user-rbac-role-assignment.ts`, `user_role_assignments`) and invites (`invite-rbac-role-assignment.ts`, `invite_role_assignments`), matching `reference_id` to the user or invite `id`. The legacy `user-rbac-role` / `invite-rbac-role` table links are kept only until a migration script copies their rows into `rbac_role_assignment`.
41
59
 
42
60
  ## Architecture
43
61
 
44
- - `src/loaders/initial-data.ts`: upserts the super admin role `role_super_admin`, policy `rpol_super_admin` (key `*:*`), and their join `rlpl_super_admin` on every load.
45
- - `__hooks.onApplicationStart` runs `syncRegisteredPolicies()`: creates policies newly registered via `definePolicies`, restores soft-deleted ones that are registered again, updates changed `name` / `description`, and soft-deletes DB policies no longer registered. The `*:*` super admin policy is always skipped.
46
- - `src/repositories/rbac.ts` (`RbacRepository`) uses raw SQL against `rbac_role`, `rbac_role_parent`, `rbac_role_policy`, `rbac_policy`; renaming those tables or columns requires updating these queries.
62
+ - Two loaders run on every module load, in this order (`src/index.ts`):
63
+ - `src/loaders/initial-data.ts` upserts the super admin role (`RBAC_SUPER_ADMIN_ROLE_ID`, `role_super_admin`), its `*:*` policy (`RBAC_SUPER_ADMIN_POLICY_ID`, `rpol_super_admin`), and their join `rlpl_super_admin`. Both constants come from `@medusajs/framework/utils`.
64
+ - `src/loaders/core-policies.ts` syncs `CORE_POLICY_DEFINITIONS` (`src/loaders/core-policy-definitions.ts`: `buildPolicies` over `CORE_POLICY_RESOURCES`, one policy per core resource and operation). Rows are matched by `key`: missing ones are created, soft-deleted ones restored, and drifted `name` / `description` updated. Policies it doesn't define are never touched, and it never deletes.
65
+ - `src/repositories/rbac.ts` (`RbacRepository`) uses raw SQL against `rbac_role`, `rbac_role_policy`, `rbac_policy`; renaming those tables or columns requires updating these queries.
47
66
 
48
67
  ## Development
49
68
 
@@ -59,6 +78,7 @@ yarn migration:create # after any change in src/models
59
78
 
60
79
  ## Gotchas
61
80
 
62
- - Policies created by hand that are not registered via `definePolicies` are soft-deleted on the next application start.
63
- - Role parent validation throws plain `Error`, not `MedusaError`.
64
- - Inheritance traversal skips soft-deleted roles and parent rows, and guards against cycles with a path array.
81
+ - A policy's `key`, `resource` and `operation` cannot be changed through `POST /rbac/policies/:id` (only `name`, `description` and `metadata` can). Every role holding the policy would silently gain the new permission, so an actor with `rbac_policy:update` could widen a policy they hold into `*:*`. Create a new policy, or change them from a migration script you control.
82
+ - The super admin role and policy can't be deleted (`deleteRbacRolesStep` / `deleteRbacPoliciesStep` in `@medusajs/core-flows` throw `NOT_ALLOWED`), and the last user holding the unscoped super admin role can't be unassigned from it or deleted (`ensureSuperAdminRemainsStep`). Calling the module service directly bypasses these checks.
83
+ - Deleting a core policy only lasts until the next boot: `core-policies.ts` restores it.
84
+ - The framework caches the resolved permissions of each set of roles an actor holds (`packages/core/framework/src/policies/has-permission.ts`) through the caching module, tagged with `RBAC_CACHE_TAGS` from `@medusajs/framework/utils`. The caching module invalidates those tags from this module's CRUD events, so writes that skip `MedusaService` (raw SQL, events not emitted) leave stale permissions until the entries expire.
package/README.md CHANGED
@@ -34,7 +34,7 @@
34
34
  </a>
35
35
  </p>
36
36
 
37
- RBAC (role-based access control) Module for Medusa: manages roles, policies, role-policy assignments, and role inheritance. Use it to control which admin users can perform which operations on which resources. It ships with `@medusajs/medusa` but is disabled unless the `rbac` feature flag is enabled.
37
+ RBAC (role-based access control) Module for Medusa: manages roles, policies, role-policy assignments, and role assignments. Use it to control which admin users can perform which operations on which resources. It ships with `@medusajs/medusa` and is registered by adding it to the `modules` of your `medusa-config.ts`.
38
38
 
39
39
  ## At a glance
40
40
 
@@ -43,44 +43,39 @@ RBAC (role-based access control) Module for Medusa: manages roles, policies, rol
43
43
  | Package | `@medusajs/rbac` |
44
44
  | Type | Commerce Module |
45
45
  | Module key | `Modules.RBAC` (`"rbac"`) |
46
- | Registered by default | No (only when the `rbac` feature flag is enabled) |
46
+ | Registered by default | No |
47
47
  | Import from | `@medusajs/medusa/rbac` |
48
48
 
49
49
  ## Features
50
50
 
51
51
  - Define policies as a resource and operation pair, such as `product:read`.
52
- - Group policies into roles, and let roles inherit from other roles.
52
+ - Group policies into roles, and assign roles to users and other references.
53
53
  - Seeds a Super Admin role with a wildcard policy that grants full access.
54
- - Powers the Admin API routes under `/admin/rbac`, which are also gated by the `rbac` feature flag.
54
+ - Powers the `/rbac/*` Admin API routes and the `authorize` route middleware, which are active only while the module is installed.
55
55
 
56
56
  ## Installation
57
57
 
58
- No installation needed. The module is included in `@medusajs/medusa`. Enable the `rbac` feature flag to register it.
58
+ No installation needed. The module is included in `@medusajs/medusa`. Register it in `medusa-config.ts`.
59
59
 
60
60
  ## Usage
61
61
 
62
- Enable the feature flag in `medusa-config.ts`:
62
+ Add the module to `medusa-config.ts`:
63
63
 
64
64
  ```ts
65
65
  import { defineConfig } from "@medusajs/framework/utils"
66
66
 
67
67
  module.exports = defineConfig({
68
68
  // ...
69
- featureFlags: {
70
- rbac: true,
71
- },
69
+ modules: [
70
+ {
71
+ resolve: "@medusajs/medusa/rbac",
72
+ },
73
+ ],
72
74
  })
73
75
  ```
74
76
 
75
- Or set the environment variable:
76
-
77
- ```bash
78
- MEDUSA_FF_RBAC=true
79
- ```
80
-
81
77
  Then run migrations with `npx medusa db:migrate`.
82
78
 
83
79
  ## Resources
84
80
 
85
- - [Feature flags](https://docs.medusajs.com/learn/debugging-and-testing/feature-flags)
86
81
  - [Modules](https://docs.medusajs.com/learn/fundamentals/modules)
package/dist/index.d.ts CHANGED
@@ -1,63 +1,6 @@
1
1
  import { RbacModuleService } from "./services/index.js";
2
2
  declare const _default: import("@medusajs/types").ModuleExports<typeof RbacModuleService> & {
3
- linkable: {
4
- readonly rbacRole: {
5
- id: {
6
- serviceName: "rbac";
7
- field: "rbacRole";
8
- linkable: "rbac_role_id";
9
- primaryKey: "id";
10
- };
11
- toJSON: () => {
12
- serviceName: "rbac";
13
- field: "rbacRole";
14
- linkable: "rbac_role_id";
15
- primaryKey: "id";
16
- };
17
- };
18
- readonly rbacPolicy: {
19
- id: {
20
- serviceName: "rbac";
21
- field: "rbacPolicy";
22
- linkable: "rbac_policy_id";
23
- primaryKey: "id";
24
- };
25
- toJSON: () => {
26
- serviceName: "rbac";
27
- field: "rbacPolicy";
28
- linkable: "rbac_policy_id";
29
- primaryKey: "id";
30
- };
31
- };
32
- readonly rbacRoleParent: {
33
- id: {
34
- serviceName: "rbac";
35
- field: "rbacRoleParent";
36
- linkable: "rbac_role_parent_id";
37
- primaryKey: "id";
38
- };
39
- toJSON: () => {
40
- serviceName: "rbac";
41
- field: "rbacRoleParent";
42
- linkable: "rbac_role_parent_id";
43
- primaryKey: "id";
44
- };
45
- };
46
- readonly rbacRolePolicy: {
47
- id: {
48
- serviceName: "rbac";
49
- field: "rbacRolePolicy";
50
- linkable: "rbac_role_policy_id";
51
- primaryKey: "id";
52
- };
53
- toJSON: () => {
54
- serviceName: "rbac";
55
- field: "rbacRolePolicy";
56
- linkable: "rbac_role_policy_id";
57
- primaryKey: "id";
58
- };
59
- };
60
- };
3
+ linkable: Record<string, any>;
61
4
  };
62
5
  export default _default;
63
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG7C,wBAGE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;;;;AAI7C,wBAGE"}
package/dist/index.js CHANGED
@@ -5,9 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const utils_1 = require("@medusajs/framework/utils");
7
7
  const _services_1 = require("./services/index.js");
8
+ const core_policies_1 = __importDefault(require("./loaders/core-policies"));
8
9
  const initial_data_1 = __importDefault(require("./loaders/initial-data"));
9
10
  exports.default = (0, utils_1.Module)(utils_1.Modules.RBAC, {
10
11
  service: _services_1.RbacModuleService,
11
- loaders: [initial_data_1.default],
12
+ loaders: [initial_data_1.default, core_policies_1.default],
12
13
  });
13
14
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,qDAA2D;AAC3D,yCAA6C;AAC7C,0EAAsD;AAEtD,kBAAe,IAAA,cAAM,EAAC,eAAO,CAAC,IAAI,EAAE;IAClC,OAAO,EAAE,6BAAiB;IAC1B,OAAO,EAAE,CAAC,sBAAiB,CAAC;CAC7B,CAAC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,qDAA2D;AAC3D,yCAA6C;AAC7C,4EAAwD;AACxD,0EAAsD;AAEtD,kBAAe,IAAA,cAAM,EAAC,eAAO,CAAC,IAAI,EAAE;IAClC,OAAO,EAAE,6BAAiB;IAC1B,OAAO,EAAE,CAAC,sBAAiB,EAAE,uBAAkB,CAAC;CACjD,CAAC,CAAA"}
@@ -0,0 +1,14 @@
1
+ import { LoaderOptions, ModulesSdkTypes } from "@medusajs/framework/types";
2
+ /**
3
+ * Syncs Medusa's predefined core policies on every boot, so that an
4
+ * accidentally removed core policy self-heals on restart: missing rows are
5
+ * created, soft-deleted rows are restored and drifted names/descriptions are
6
+ * updated.
7
+ *
8
+ * Rows are matched by `key`, never by id, so databases seeded by an earlier
9
+ * Medusa version are reused as-is. Policies created at runtime are never
10
+ * touched, and nothing is ever deleted.
11
+ */
12
+ declare const _default: ({ container, }: LoaderOptions<ModulesSdkTypes.ModuleServiceInitializeOptions | ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions>) => Promise<void>;
13
+ export default _default;
14
+ //# sourceMappingURL=core-policies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-policies.d.ts","sourceRoot":"","sources":["../../src/loaders/core-policies.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EACb,eAAe,EAChB,MAAM,2BAA2B,CAAA;AAIlC;;;;;;;;;GASG;yBACmB,gBAEnB,aAAa,CACZ,eAAe,CAAC,8BAA8B,GAC9C,eAAe,CAAC,6CAA6C,CAChE,KAAG,OAAO,CAAC,IAAI,CAAC;AALjB,wBAmFC"}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_policy_definitions_1 = require("./core-policy-definitions");
4
+ /**
5
+ * Syncs Medusa's predefined core policies on every boot, so that an
6
+ * accidentally removed core policy self-heals on restart: missing rows are
7
+ * created, soft-deleted rows are restored and drifted names/descriptions are
8
+ * updated.
9
+ *
10
+ * Rows are matched by `key`, never by id, so databases seeded by an earlier
11
+ * Medusa version are reused as-is. Policies created at runtime are never
12
+ * touched, and nothing is ever deleted.
13
+ */
14
+ exports.default = async ({ container, }) => {
15
+ const rbacPolicyService = container.resolve("rbacPolicyService");
16
+ const existingPolicies = await rbacPolicyService.list({}, { withDeleted: true });
17
+ const existingPoliciesByKey = existingPolicies.reduce((byKey, policy) => {
18
+ const current = byKey.get(policy.key);
19
+ if (!current || (current.deleted_at && !policy.deleted_at)) {
20
+ byKey.set(policy.key, policy);
21
+ }
22
+ return byKey;
23
+ }, new Map());
24
+ const policiesToCreate = [];
25
+ const policiesToUpdate = [];
26
+ const policiesToRestore = [];
27
+ for (const definition of core_policy_definitions_1.CORE_POLICY_DEFINITIONS) {
28
+ const existing = existingPoliciesByKey.get(definition.key);
29
+ if (!existing) {
30
+ policiesToCreate.push(definition);
31
+ continue;
32
+ }
33
+ if (existing.deleted_at) {
34
+ policiesToRestore.push(existing.id);
35
+ }
36
+ const hasChanges = existing.name !== definition.name ||
37
+ existing.description !== definition.description;
38
+ if (hasChanges) {
39
+ policiesToUpdate.push({
40
+ id: existing.id,
41
+ name: definition.name,
42
+ description: definition.description,
43
+ });
44
+ }
45
+ }
46
+ if (policiesToRestore.length > 0) {
47
+ await rbacPolicyService.restore(policiesToRestore);
48
+ }
49
+ if (policiesToCreate.length > 0) {
50
+ try {
51
+ await rbacPolicyService.create(policiesToCreate);
52
+ }
53
+ catch (error) {
54
+ const livePolicies = await rbacPolicyService.list({
55
+ key: policiesToCreate.map((definition) => definition.key),
56
+ });
57
+ const liveKeys = new Set(livePolicies.map((policy) => policy.key));
58
+ const stillMissing = policiesToCreate.some((definition) => !liveKeys.has(definition.key));
59
+ if (stillMissing) {
60
+ throw error;
61
+ }
62
+ }
63
+ }
64
+ if (policiesToUpdate.length > 0) {
65
+ await rbacPolicyService.upsert(policiesToUpdate);
66
+ }
67
+ };
68
+ //# sourceMappingURL=core-policies.js.map
@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BAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,MAAM,iBAAiB,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAA;IAClD,CAAC;AACH,CAAC,CAAA"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The fully expanded core policy list, one policy per
3
+ * `(core resource, core operation)` pair. Keys, names and descriptions are
4
+ * derived deterministically so that re-running the sync against a database
5
+ * seeded by an earlier Medusa version is a no-op.
6
+ */
7
+ export declare const CORE_POLICY_DEFINITIONS: import("@medusajs/framework/utils").BuiltPolicy[];
8
+ //# sourceMappingURL=core-policy-definitions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-policy-definitions.d.ts","sourceRoot":"","sources":["../../src/loaders/core-policy-definitions.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,mDAElC,CAAA"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CORE_POLICY_DEFINITIONS = void 0;
4
+ const types_1 = require("@medusajs/framework/types");
5
+ const utils_1 = require("@medusajs/framework/utils");
6
+ /**
7
+ * The fully expanded core policy list, one policy per
8
+ * `(core resource, core operation)` pair. Keys, names and descriptions are
9
+ * derived deterministically so that re-running the sync against a database
10
+ * seeded by an earlier Medusa version is a no-op.
11
+ */
12
+ exports.CORE_POLICY_DEFINITIONS = (0, utils_1.buildPolicies)({
13
+ resource: types_1.CORE_POLICY_RESOURCES,
14
+ });
15
+ //# sourceMappingURL=core-policy-definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-policy-definitions.js","sourceRoot":"","sources":["../../src/loaders/core-policy-definitions.ts"],"names":[],"mappings":";;;AAAA,qDAAiE;AACjE,qDAAyD;AAEzD;;;;;GAKG;AACU,QAAA,uBAAuB,GAAG,IAAA,qBAAa,EAAC;IACnD,QAAQ,EAAE,6BAAqB;CAChC,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"initial-data.d.ts","sourceRoot":"","sources":["../../src/loaders/initial-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EACb,eAAe,EAChB,MAAM,2BAA2B,CAAA;yBAIZ,yBAGnB,aAAa,CACZ,eAAe,CAAC,8BAA8B,GAC9C,eAAe,CAAC,6CAA6C,CAChE,KAAG,OAAO,CAAC,IAAI,CAAC;AANjB,wBA8CC"}
1
+ {"version":3,"file":"initial-data.d.ts","sourceRoot":"","sources":["../../src/loaders/initial-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EACb,eAAe,EAChB,MAAM,2BAA2B,CAAA;yBASZ,yBAGnB,aAAa,CACZ,eAAe,CAAC,8BAA8B,GAC9C,eAAe,CAAC,6CAA6C,CAChE,KAAG,OAAO,CAAC,IAAI,CAAC;AANjB,wBA8CC"}
@@ -7,13 +7,13 @@ exports.default = async ({ container, options, }) => {
7
7
  const rbacRolePolicyService = container.resolve("rbacRolePolicyService");
8
8
  // Create super admin role
9
9
  const role = await rbacRoleService.upsert({
10
- id: "role_super_admin",
10
+ id: utils_1.RBAC_SUPER_ADMIN_ROLE_ID,
11
11
  name: "Super Admin",
12
12
  description: "Super admin role with full access to all resources and operations",
13
13
  });
14
14
  const policy = await rbacPolicyService.upsert({
15
- id: "rpol_super_admin",
16
- key: `${utils_1.WILDCARD}:${utils_1.WILDCARD}`,
15
+ id: utils_1.RBAC_SUPER_ADMIN_POLICY_ID,
16
+ key: (0, utils_1.permissionKey)(utils_1.WILDCARD, utils_1.WILDCARD),
17
17
  resource: utils_1.WILDCARD,
18
18
  operation: utils_1.WILDCARD,
19
19
  name: "Super Admin",
@@ -1 +1 @@
1
- {"version":3,"file":"initial-data.js","sourceRoot":"","sources":["../../src/loaders/initial-data.ts"],"names":[],"mappings":";;AAKA,qDAAoD;AAGpD,kBAAe,KAAK,EAAE,EACpB,SAAS,EACT,OAAO,GAIR,EAAiB,EAAE;IAClB,MAAM,eAAe,GAAG,S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ACxC,EAAE,EAAE,gCAAwB;QAC5B,IAAI,EAAE,aAAa;QACnB,WAAW,EACT,mEAAmE;KACtE,CAAC,CAAA;IAEF,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,MAAM,CAAC;QAC5C,EAAE,EAAE,kCAA0B;QAC9B,GAAG,EAAE,IAAA,qBAAa,EAAC,gBAAQ,EAAE,gBAAQ,CAAC;QACtC,QAAQ,EAAE,gBAAQ;QAClB,SAAS,EAAE,gBAAQ;QACnB,IAAI,EAAE,aAAa;QACnB,WAAW,EACT,qEAAqE;KACxE,CAAC,CAAA;IAEF,MAAM,qBAAqB,CAAC,MAAM,CAAC;QACjC,EAAE,EAAE,kBAAkB;QACtB,OAAO,EAAE,IAAI,CAAC,EAAE;QAChB,SAAS,EAAE,MAAM,CAAC,EAAE;KACrB,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { Migration } from "@medusajs/framework/mikro-orm/migrations";
2
+ export declare class Migration20260612013735 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
6
+ //# sourceMappingURL=Migration20260612013735.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration20260612013735.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20260612013735.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAErE,qBAAa,uBAAwB,SAAQ,SAAS;IAErC,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAYnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAYrC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20260612013735 = void 0;
4
+ const migrations_1 = require("@medusajs/framework/mikro-orm/migrations");
5
+ class Migration20260612013735 extends migrations_1.Migration {
6
+ async up() {
7
+ this.addSql(`alter table if exists "rbac_role_parent" drop constraint if exists "rbac_role_parent_role_id_foreign";`);
8
+ this.addSql(`alter table if exists "rbac_role_parent" drop constraint if exists "rbac_role_parent_parent_id_foreign";`);
9
+ this.addSql(`alter table if exists "rbac_role_policy" drop constraint if exists "rbac_role_policy_role_id_foreign";`);
10
+ this.addSql(`alter table if exists "rbac_role_parent" add constraint "rbac_role_parent_role_id_foreign" foreign key ("role_id") references "rbac_role" ("id") on update cascade on delete cascade;`);
11
+ this.addSql(`alter table if exists "rbac_role_parent" add constraint "rbac_role_parent_parent_id_foreign" foreign key ("parent_id") references "rbac_role" ("id") on update cascade on delete cascade;`);
12
+ this.addSql(`alter table if exists "rbac_role_policy" add constraint "rbac_role_policy_role_id_foreign" foreign key ("role_id") references "rbac_role" ("id") on update cascade on delete cascade;`);
13
+ }
14
+ async down() {
15
+ this.addSql(`alter table if exists "rbac_role_parent" drop constraint if exists "rbac_role_parent_role_id_foreign";`);
16
+ this.addSql(`alter table if exists "rbac_role_parent" drop constraint if exists "rbac_role_parent_parent_id_foreign";`);
17
+ this.addSql(`alter table if exists "rbac_role_policy" drop constraint if exists "rbac_role_policy_role_id_foreign";`);
18
+ this.addSql(`alter table if exists "rbac_role_parent" add constraint "rbac_role_parent_role_id_foreign" foreign key ("role_id") references "rbac_role" ("id") on update cascade;`);
19
+ this.addSql(`alter table if exists "rbac_role_parent" add constraint "rbac_role_parent_parent_id_foreign" foreign key ("parent_id") references "rbac_role" ("id") on update cascade;`);
20
+ this.addSql(`alter table if exists "rbac_role_policy" add constraint "rbac_role_policy_role_id_foreign" foreign key ("role_id") references "rbac_role" ("id") on update cascade;`);
21
+ }
22
+ }
23
+ exports.Migration20260612013735 = Migration20260612013735;
24
+ //# sourceMappingURL=Migration20260612013735.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration20260612013735.js","sourceRoot":"","sources":["../../src/migrations/Migration20260612013735.ts"],"names":[],"mappings":";;;AAAA,yEAAqE;AAErE,MAAa,uBAAwB,SAAQ,sBAAS;IAE3C,KAAK,CAAC,EAAE;QACf,IAAI,CAAC,MAAM,CAAC,wGAAwG,CAAC,CAAC;QACtH,IAAI,CAAC,MAAM,CAAC,0GAA0G,CAAC,CAAC;QAExH,IAAI,CAAC,MAAM,CAAC,wGAAwG,CAAC,CAAC;QAEtH,IAAI,CAAC,MAAM,CAAC,uLAAuL,CAAC,CAAC;QACrM,IAAI,CAAC,MAAM,CAAC,2LAA2L,CAAC,CAAC;QAEzM,IAAI,CAAC,MAAM,CAAC,uLAAuL,CAAC,CAAC;IACvM,CAAC;IAEQ,KAAK,CAAC,IAAI;QACjB,IAAI,CAAC,MAAM,CAAC,wGAAwG,CAAC,CAAC;QACtH,IAAI,CAAC,MAAM,CAAC,0GAA0G,CAAC,CAAC;QAExH,IAAI,CAAC,MAAM,CAAC,wGAAwG,CAAC,CAAC;QAEtH,IAAI,CAAC,MAAM,CAAC,qKAAqK,CAAC,CAAC;QACnL,IAAI,CAAC,MAAM,CAAC,yKAAyK,CAAC,CAAC;QAEvL,IAAI,CAAC,MAAM,CAAC,qKAAqK,CAAC,CAAC;IACrL,CAAC;CAEF;AA1BD,0DA0BC"}
@@ -0,0 +1,6 @@
1
+ import { Migration } from "@medusajs/framework/mikro-orm/migrations";
2
+ export declare class Migration20260729201429 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
6
+ //# sourceMappingURL=Migration20260729201429.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration20260729201429.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20260729201429.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAErE,qBAAa,uBAAwB,SAAQ,SAAS;IAErC,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAanB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAIrC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20260729201429 = void 0;
4
+ const migrations_1 = require("@medusajs/framework/mikro-orm/migrations");
5
+ class Migration20260729201429 extends migrations_1.Migration {
6
+ async up() {
7
+ this.addSql(`alter table if exists "rbac_role_assignment" drop constraint if exists "rbac_role_assignment_role_id_scope_scope_id_reference_reference_id_unique";`);
8
+ this.addSql(`create table if not exists "rbac_role_assignment" ("id" text not null, "role_id" text not null, "reference" text not null, "reference_id" text not null, "scope" text null, "scope_id" text null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "rbac_role_assignment_pkey" primary key ("id"));`);
9
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_rbac_role_assignment_role_id" ON "rbac_role_assignment" ("role_id") WHERE deleted_at IS NULL;`);
10
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_rbac_role_assignment_deleted_at" ON "rbac_role_assignment" ("deleted_at") WHERE deleted_at IS NULL;`);
11
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_rbac_role_assignment_role_id_scope_scope_id" ON "rbac_role_assignment" ("role_id", "scope", "scope_id") WHERE deleted_at IS NULL;`);
12
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_rbac_role_assignment_scope_scope_id_reference_reference_id" ON "rbac_role_assignment" ("scope", "scope_id", "reference", "reference_id") WHERE deleted_at IS NULL;`);
13
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_rbac_role_assignment_reference_reference_id" ON "rbac_role_assignment" ("reference", "reference_id") WHERE deleted_at IS NULL;`);
14
+ this.addSql(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_rbac_role_assignment_role_id_scope_scope_id_reference_reference_id_unique" ON "rbac_role_assignment" ("role_id", "scope", "scope_id", "reference", "reference_id") WHERE deleted_at IS NULL;`);
15
+ this.addSql(`alter table if exists "rbac_role_assignment" add constraint "rbac_role_assignment_role_id_foreign" foreign key ("role_id") references "rbac_role" ("id") on update cascade on delete cascade;`);
16
+ }
17
+ async down() {
18
+ this.addSql(`drop table if exists "rbac_role_assignment" cascade;`);
19
+ }
20
+ }
21
+ exports.Migration20260729201429 = Migration20260729201429;
22
+ //# sourceMappingURL=Migration20260729201429.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration20260729201429.js","sourceRoot":"","sources":["../../src/migrations/Migration20260729201429.ts"],"names":[],"mappings":";;;AAAA,yEAAqE;AAErE,MAAa,uBAAwB,SAAQ,sBAAS;IAE3C,KAAK,CAAC,EAAE;QACf,IAAI,CAAC,MAAM,CAAC,qJAAqJ,CAAC,CAAC;QACnK,IAAI,CAAC,MAAM,CAAC,uZAAuZ,CAAC,CAAC;QACra,IAAI,CAAC,MAAM,CAAC,+HAA+H,CAAC,CAAC;QAC7I,IAAI,CAAC,MAAM,CAAC,qIAAqI,CAAC,CAAC;QACnJ,IAAI,CAAC,MAAM,CAAC,mKAAmK,CAAC,CAAC;QACjL,IAAI,CAAC,MAAM,CAAC,oMAAoM,CAAC,CAAC;QAClN,IAAI,CAAC,MAAM,CAAC,gKAAgK,CAAC,CAAC;QAC9K,IAAI,CAAC,MAAM,CAAC,qOAAqO,CAAC,CAAC;QAEnP,IAAI,CAAC,MAAM,CAAC,+LAA+L,CAAC,CAAC;IAC/M,CAAC;IAEQ,KAAK,CAAC,IAAI;QACjB,IAAI,CAAC,MAAM,CAAC,sDAAsD,CAAC,CAAC;IACtE,CAAC;CAEF;AAnBD,0DAmBC"}
@@ -0,0 +1,6 @@
1
+ import { Migration } from "@medusajs/framework/mikro-orm/migrations";
2
+ export declare class Migration20261022124403 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
6
+ //# sourceMappingURL=Migration20261022124403.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration20261022124403.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20261022124403.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAA;AAEpE,qBAAa,uBAAwB,SAAQ,SAAS;IACrC,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAMnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAKrC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20261022124403 = void 0;
4
+ const migrations_1 = require("@medusajs/framework/mikro-orm/migrations");
5
+ class Migration20261022124403 extends migrations_1.Migration {
6
+ async up() {
7
+ this.addSql(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_rbac_role_assignment_role_id_reference_reference_id_unique" ON "rbac_role_assignment" ("role_id", "reference", "reference_id") WHERE scope IS NULL AND scope_id IS NULL AND deleted_at IS NULL;`);
8
+ }
9
+ async down() {
10
+ this.addSql(`drop index if exists "IDX_rbac_role_assignment_role_id_reference_reference_id_unique";`);
11
+ }
12
+ }
13
+ exports.Migration20261022124403 = Migration20261022124403;
14
+ //# sourceMappingURL=Migration20261022124403.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration20261022124403.js","sourceRoot":"","sources":["../../src/migrations/Migration20261022124403.ts"],"names":[],"mappings":";;;AAAA,yEAAoE;AAEpE,MAAa,uBAAwB,SAAQ,sBAAS;IAC3C,KAAK,CAAC,EAAE;QACf,IAAI,CAAC,MAAM,CACT,wOAAwO,CACzO,CAAA;IACH,CAAC;IAEQ,KAAK,CAAC,IAAI;QACjB,IAAI,CAAC,MAAM,CACT,wFAAwF,CACzF,CAAA;IACH,CAAC;CACF;AAZD,0DAYC"}
@@ -0,0 +1,6 @@
1
+ import { Migration } from "@medusajs/framework/mikro-orm/migrations";
2
+ export declare class Migration20261029190116 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
6
+ //# sourceMappingURL=Migration20261029190116.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration20261029190116.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20261029190116.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAErE,qBAAa,uBAAwB,SAAQ,SAAS;IAErC,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAInB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAWrC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20261029190116 = void 0;
4
+ const migrations_1 = require("@medusajs/framework/mikro-orm/migrations");
5
+ class Migration20261029190116 extends migrations_1.Migration {
6
+ async up() {
7
+ this.addSql(`drop table if exists "rbac_role_parent" cascade;`);
8
+ }
9
+ async down() {
10
+ this.addSql(`create table if not exists "rbac_role_parent" ("id" text not null, "role_id" text not null, "parent_id" text not null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "rbac_role_parent_pkey" primary key ("id"));`);
11
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_rbac_role_parent_role_id" ON "rbac_role_parent" ("role_id") WHERE deleted_at IS NULL;`);
12
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_rbac_role_parent_parent_id" ON "rbac_role_parent" ("parent_id") WHERE deleted_at IS NULL;`);
13
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_rbac_role_parent_deleted_at" ON "rbac_role_parent" ("deleted_at") WHERE deleted_at IS NULL;`);
14
+ this.addSql(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_rbac_role_parent_role_id_parent_id_unique" ON "rbac_role_parent" ("role_id", "parent_id") WHERE deleted_at IS NULL;`);
15
+ this.addSql(`alter table if exists "rbac_role_parent" add constraint "rbac_role_parent_role_id_foreign" foreign key ("role_id") references "rbac_role" ("id") on update cascade on delete cascade;`);
16
+ this.addSql(`alter table if exists "rbac_role_parent" add constraint "rbac_role_parent_parent_id_foreign" foreign key ("parent_id") references "rbac_role" ("id") on update cascade on delete cascade;`);
17
+ }
18
+ }
19
+ exports.Migration20261029190116 = Migration20261029190116;
20
+ //# sourceMappingURL=Migration20261029190116.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration20261029190116.js","sourceRoot":"","sources":["../../src/migrations/Migration20261029190116.ts"],"names":[],"mappings":";;;AAAA,yEAAqE;AAErE,MAAa,uBAAwB,SAAQ,sBAAS;IAE3C,KAAK,CAAC,EAAE;QACf,IAAI,CAAC,MAAM,CAAC,kDAAkD,CAAC,CAAC;IAClE,CAAC;IAEQ,KAAK,CAAC,IAAI;QACjB,IAAI,CAAC,MAAM,CAAC,wUAAwU,CAAC,CAAC;QACtV,IAAI,CAAC,MAAM,CAAC,uHAAuH,CAAC,CAAC;QACrI,IAAI,CAAC,MAAM,CAAC,2HAA2H,CAAC,CAAC;QACzI,IAAI,CAAC,MAAM,CAAC,6HAA6H,CAAC,CAAC;QAC3I,IAAI,CAAC,MAAM,CAAC,4JAA4J,CAAC,CAAC;QAE1K,IAAI,CAAC,MAAM,CAAC,uLAAuL,CAAC,CAAC;QACrM,IAAI,CAAC,MAAM,CAAC,2LAA2L,CAAC,CAAC;IAC3M,CAAC;CAEF;AAjBD,0DAiBC"}
@@ -0,0 +1,6 @@
1
+ import { Migration } from "@medusajs/framework/mikro-orm/migrations";
2
+ export declare class Migration20261030132556 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
6
+ //# sourceMappingURL=Migration20261030132556.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration20261030132556.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20261030132556.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAErE,qBAAa,uBAAwB,SAAQ,SAAS;IAErC,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAInB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAWrC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20261030132556 = void 0;
4
+ const migrations_1 = require("@medusajs/framework/mikro-orm/migrations");
5
+ class Migration20261030132556 extends migrations_1.Migration {
6
+ async up() {
7
+ this.addSql(`drop table if exists "rbac_role_inheritance" cascade;`);
8
+ }
9
+ async down() {
10
+ this.addSql(`create table if not exists "rbac_role_inheritance" ("id" text not null, "role_id" text not null, "inherited_role_id" text not null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "rbac_role_inheritance_pkey" primary key ("id"));`);
11
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_rbac_role_inheritance_role_id" ON "rbac_role_inheritance" ("role_id") WHERE deleted_at IS NULL;`);
12
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_rbac_role_inheritance_inherited_role_id" ON "rbac_role_inheritance" ("inherited_role_id") WHERE deleted_at IS NULL;`);
13
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_rbac_role_inheritance_deleted_at" ON "rbac_role_inheritance" ("deleted_at") WHERE deleted_at IS NULL;`);
14
+ this.addSql(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_rbac_role_inheritance_role_id_inherited_role_id_unique" ON "rbac_role_inheritance" ("role_id", "inherited_role_id") WHERE deleted_at IS NULL;`);
15
+ this.addSql(`alter table if exists "rbac_role_inheritance" add constraint "rbac_role_inheritance_role_id_foreign" foreign key ("role_id") references "rbac_role" ("id") on update cascade;`);
16
+ this.addSql(`alter table if exists "rbac_role_inheritance" add constraint "rbac_role_inheritance_inherited_role_id_foreign" foreign key ("inherited_role_id") references "rbac_role" ("id") on update cascade;`);
17
+ }
18
+ }
19
+ exports.Migration20261030132556 = Migration20261030132556;
20
+ //# sourceMappingURL=Migration20261030132556.js.map