@mohasinac/appkit 4.41.0 → 4.41.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.
Files changed (169) hide show
  1. package/dist/features/seller/schemas/coupon-form.d.ts +37 -37
  2. package/dist/features/seller/schemas/coupon-form.js +36 -8
  3. package/dist/features/shell/SectionForm.js +44 -5
  4. package/dist/schemas/registry.d.ts +10 -10
  5. package/package.json +2 -2
  6. package/dist/_internal/server/features/classified/actions.d.ts +0 -12
  7. package/dist/_internal/server/features/classified/actions.js +0 -33
  8. package/dist/_internal/server/features/digital-code/actions.d.ts +0 -12
  9. package/dist/_internal/server/features/digital-code/actions.js +0 -33
  10. package/dist/_internal/server/features/homepage/data.d.ts +0 -18
  11. package/dist/_internal/server/features/homepage/data.js +0 -70
  12. package/dist/_internal/server/features/live/actions.d.ts +0 -6
  13. package/dist/_internal/server/features/live/actions.js +0 -27
  14. package/dist/_internal/server/features/messages/actions.d.ts +0 -6
  15. package/dist/_internal/server/features/messages/actions.js +0 -6
  16. package/dist/_internal/server/features/messages/data.d.ts +0 -10
  17. package/dist/_internal/server/features/messages/data.js +0 -24
  18. package/dist/_internal/server/features/messages/index.d.ts +0 -2
  19. package/dist/_internal/server/features/messages/index.js +0 -2
  20. package/dist/_internal/server/jobs/core/testerSandboxRefresh.d.ts +0 -12
  21. package/dist/_internal/server/jobs/core/testerSandboxRefresh.js +0 -112
  22. package/dist/_internal/server/jobs/handlers/testerSandboxRefresh.d.ts +0 -2
  23. package/dist/_internal/server/jobs/handlers/testerSandboxRefresh.js +0 -2
  24. package/dist/_internal/shared/features/homepage/section-gate.d.ts +0 -14
  25. package/dist/_internal/shared/features/homepage/section-gate.js +0 -51
  26. package/dist/_internal/shared/features/lottery/config-form.d.ts +0 -58
  27. package/dist/_internal/shared/features/lottery/config-form.js +0 -71
  28. package/dist/client/api/useFeatureFlags.d.ts +0 -22
  29. package/dist/client/api/useFeatureFlags.js +0 -27
  30. package/dist/features/account/address-validation.d.ts +0 -20
  31. package/dist/features/account/address-validation.js +0 -35
  32. package/dist/features/account/components/ChatList.d.ts +0 -14
  33. package/dist/features/account/components/ChatList.js +0 -9
  34. package/dist/features/account/components/ChatWindow.d.ts +0 -17
  35. package/dist/features/account/components/ChatWindow.js +0 -6
  36. package/dist/features/account/components/MessagesView.d.ts +0 -16
  37. package/dist/features/account/components/MessagesView.js +0 -5
  38. package/dist/features/account/components/UserOffersView.d.ts +0 -10
  39. package/dist/features/account/components/UserOffersView.js +0 -5
  40. package/dist/features/account/constants/addresses.d.ts +0 -13
  41. package/dist/features/account/constants/addresses.js +0 -43
  42. package/dist/features/account/hooks/useAddressForm.d.ts +0 -24
  43. package/dist/features/account/hooks/useAddressForm.js +0 -58
  44. package/dist/features/admin/actions/chat-actions.d.ts +0 -29
  45. package/dist/features/admin/actions/chat-actions.js +0 -101
  46. package/dist/features/admin/components/AdminFeatureFlagsView.d.ts +0 -9
  47. package/dist/features/admin/components/AdminFeatureFlagsView.js +0 -109
  48. package/dist/features/admin/components/AdminSiteView.d.ts +0 -10
  49. package/dist/features/admin/components/AdminSiteView.js +0 -52
  50. package/dist/features/admin/hooks/useChat.d.ts +0 -24
  51. package/dist/features/admin/hooks/useChat.js +0 -100
  52. package/dist/features/admin/permission-map.d.ts +0 -3
  53. package/dist/features/admin/permission-map.js +0 -26
  54. package/dist/features/admin/repository/chat.repository.d.ts +0 -50
  55. package/dist/features/admin/repository/chat.repository.js +0 -223
  56. package/dist/features/auth/actions/password-change-otp-actions.d.ts +0 -18
  57. package/dist/features/auth/actions/password-change-otp-actions.js +0 -88
  58. package/dist/features/auth/actions/realtime-token-actions.d.ts +0 -11
  59. package/dist/features/auth/actions/realtime-token-actions.js +0 -38
  60. package/dist/features/auth/password-change-otp.d.ts +0 -34
  61. package/dist/features/auth/password-change-otp.js +0 -56
  62. package/dist/features/classified/components/ClassifiedContactSellerPanel.d.ts +0 -12
  63. package/dist/features/classified/components/ClassifiedContactSellerPanel.js +0 -49
  64. package/dist/features/events/api/route.d.ts +0 -12
  65. package/dist/features/events/api/route.js +0 -90
  66. package/dist/features/faq/api/route.d.ts +0 -11
  67. package/dist/features/faq/api/route.js +0 -52
  68. package/dist/features/faq/hooks/useFAQs.d.ts +0 -22
  69. package/dist/features/faq/hooks/useFAQs.js +0 -41
  70. package/dist/features/media/upload/video-poster.test.d.ts +0 -1
  71. package/dist/features/media/upload/video-poster.test.js +0 -42
  72. package/dist/features/messages/actions/index.d.ts +0 -2
  73. package/dist/features/messages/actions/index.js +0 -2
  74. package/dist/features/messages/actions/messages-actions.d.ts +0 -15
  75. package/dist/features/messages/actions/messages-actions.js +0 -33
  76. package/dist/features/messages/actions/ping-rtdb.d.ts +0 -2
  77. package/dist/features/messages/actions/ping-rtdb.js +0 -26
  78. package/dist/features/messages/hooks/useConversation.d.ts +0 -22
  79. package/dist/features/messages/hooks/useConversation.js +0 -155
  80. package/dist/features/messages/hooks/useConversations.d.ts +0 -15
  81. package/dist/features/messages/hooks/useConversations.js +0 -104
  82. package/dist/features/messages/index.d.ts +0 -6
  83. package/dist/features/messages/index.js +0 -4
  84. package/dist/features/messages/realtime.d.ts +0 -32
  85. package/dist/features/messages/realtime.js +0 -39
  86. package/dist/features/messages/repository/conversations.repository.d.ts +0 -71
  87. package/dist/features/messages/repository/conversations.repository.js +0 -284
  88. package/dist/features/messages/schemas/firestore.d.ts +0 -34
  89. package/dist/features/messages/schemas/firestore.js +0 -16
  90. package/dist/features/messages/schemas/index.d.ts +0 -177
  91. package/dist/features/messages/schemas/index.js +0 -35
  92. package/dist/features/messages/server.d.ts +0 -6
  93. package/dist/features/messages/server.js +0 -6
  94. package/dist/features/products/components/MakeOfferForm.d.ts +0 -20
  95. package/dist/features/products/components/MakeOfferForm.js +0 -9
  96. package/dist/features/reviews/api/route.d.ts +0 -21
  97. package/dist/features/reviews/api/route.js +0 -174
  98. package/dist/features/seller/api/offers/route.d.ts +0 -17
  99. package/dist/features/seller/api/offers/route.js +0 -63
  100. package/dist/features/seller/components/SellerAuctionsView.d.ts +0 -9
  101. package/dist/features/seller/components/SellerAuctionsView.js +0 -113
  102. package/dist/features/seller/components/SellerOffersPanel.d.ts +0 -21
  103. package/dist/features/seller/components/SellerOffersPanel.js +0 -160
  104. package/dist/features/seller/components/SellerPreOrdersView.d.ts +0 -6
  105. package/dist/features/seller/components/SellerPreOrdersView.js +0 -148
  106. package/dist/features/seller/components/SellerPrizeDrawsView.d.ts +0 -6
  107. package/dist/features/seller/components/SellerPrizeDrawsView.js +0 -152
  108. package/dist/features/seller/permission-map.d.ts +0 -5
  109. package/dist/features/seller/permission-map.js +0 -17
  110. package/dist/features/shell/StepForm.d.ts +0 -80
  111. package/dist/features/shell/StepForm.js +0 -136
  112. package/dist/features/stores/api/route.d.ts +0 -12
  113. package/dist/features/stores/api/route.js +0 -110
  114. package/dist/features/tester/seed-data/authored/account-auth__testing-program--admin.d.ts +0 -2
  115. package/dist/features/tester/seed-data/authored/account-auth__testing-program--admin.js +0 -33
  116. package/dist/features/tester/seed-data/authored/account-auth__testing-program.d.ts +0 -2
  117. package/dist/features/tester/seed-data/authored/account-auth__testing-program.js +0 -138
  118. package/dist/features/tester/seed-data/bids-tester-seed-data.d.ts +0 -2
  119. package/dist/features/tester/seed-data/bids-tester-seed-data.js +0 -37
  120. package/dist/features/tester/seed-data/blog-tester-seed-data.d.ts +0 -2
  121. package/dist/features/tester/seed-data/blog-tester-seed-data.js +0 -40
  122. package/dist/features/tester/seed-data/carts-tester-seed-data.d.ts +0 -3
  123. package/dist/features/tester/seed-data/carts-tester-seed-data.js +0 -70
  124. package/dist/features/tester/seed-data/categories-tester-seed-data.d.ts +0 -2
  125. package/dist/features/tester/seed-data/categories-tester-seed-data.js +0 -218
  126. package/dist/features/tester/seed-data/coupons-tester-seed-data.d.ts +0 -2
  127. package/dist/features/tester/seed-data/coupons-tester-seed-data.js +0 -76
  128. package/dist/features/tester/seed-data/events-tester-seed-data.d.ts +0 -2
  129. package/dist/features/tester/seed-data/events-tester-seed-data.js +0 -193
  130. package/dist/features/tester/seed-data/offers-tester-seed-data.d.ts +0 -2
  131. package/dist/features/tester/seed-data/offers-tester-seed-data.js +0 -191
  132. package/dist/features/tester/seed-data/orders-tester-seed-data.d.ts +0 -2
  133. package/dist/features/tester/seed-data/orders-tester-seed-data.js +0 -329
  134. package/dist/features/tester/seed-data/products-tester-seed-data.d.ts +0 -2
  135. package/dist/features/tester/seed-data/products-tester-seed-data.js +0 -815
  136. package/dist/features/tester/seed-data/stores-tester-seed-data.d.ts +0 -2
  137. package/dist/features/tester/seed-data/stores-tester-seed-data.js +0 -79
  138. package/dist/features/wishlist/components/WishlistToggleButton.d.ts +0 -12
  139. package/dist/features/wishlist/components/WishlistToggleButton.js +0 -36
  140. package/dist/monitoring/analytics.d.ts +0 -80
  141. package/dist/monitoring/analytics.js +0 -176
  142. package/dist/next/middleware/pii-redactor.d.ts +0 -32
  143. package/dist/next/middleware/pii-redactor.js +0 -84
  144. package/dist/providers/db-firebase/realtime.d.ts +0 -42
  145. package/dist/providers/db-firebase/realtime.js +0 -138
  146. package/dist/security/rbac/Can.d.ts +0 -31
  147. package/dist/security/rbac/Can.js +0 -22
  148. package/dist/security/rbac/default-roles.d.ts +0 -2
  149. package/dist/security/rbac/default-roles.js +0 -83
  150. package/dist/security/rbac/hook.d.ts +0 -20
  151. package/dist/security/rbac/hook.js +0 -30
  152. package/dist/security/rbac/index.d.ts +0 -8
  153. package/dist/security/rbac/index.js +0 -6
  154. package/dist/security/rbac/middleware.d.ts +0 -51
  155. package/dist/security/rbac/middleware.js +0 -51
  156. package/dist/security/rbac/resolver.d.ts +0 -5
  157. package/dist/security/rbac/resolver.js +0 -38
  158. package/dist/security/rbac/server.d.ts +0 -24
  159. package/dist/security/rbac/server.js +0 -42
  160. package/dist/security/rbac/types.d.ts +0 -22
  161. package/dist/security/rbac/types.js +0 -2
  162. package/dist/seed/conversations-seed-data.d.ts +0 -2
  163. package/dist/seed/conversations-seed-data.js +0 -292
  164. package/dist/utils/filter.helper.d.ts +0 -18
  165. package/dist/utils/filter.helper.js +0 -21
  166. package/dist/utils/pagination.helper.d.ts +0 -23
  167. package/dist/utils/pagination.helper.js +0 -24
  168. package/dist/utils/search-tokens.d.ts +0 -2
  169. package/dist/utils/search-tokens.js +0 -21
@@ -1,31 +0,0 @@
1
- import React from "react";
2
- import type { Permission } from "./types";
3
- import type { RbacHookReturn } from "./hook";
4
- interface CanProps {
5
- /** Single required permission */
6
- permission?: Permission;
7
- /** Multiple permissions to check */
8
- permissions?: Permission[];
9
- /** When multiple permissions are provided: "all" (default) or "any" */
10
- mode?: "all" | "any";
11
- /** Rendered when the check fails */
12
- fallback?: React.ReactNode;
13
- children: React.ReactNode;
14
- /** The resolved rbac hook return value — pass from useRBAC() */
15
- rbac: Pick<RbacHookReturn, "can" | "canAll" | "canAny">;
16
- }
17
- /**
18
- * Conditionally renders children based on RBAC permissions.
19
- *
20
- * The consumer's `useRBAC()` hook must be called in the parent component and
21
- * passed as the `rbac` prop; this avoids coupling `<Can>` to a specific context.
22
- *
23
- * @example
24
- * const rbac = useRBAC();
25
- * <Can rbac={rbac} permission="admin:payouts"><PayoutsTable /></Can>
26
- * <Can rbac={rbac} permissions={["seller:products:write", "seller:store"]} mode="any">
27
- * <SellerActions />
28
- * </Can>
29
- */
30
- export declare function Can({ permission, permissions, mode, fallback, children, rbac, }: CanProps): React.ReactElement | null;
31
- export {};
@@ -1,22 +0,0 @@
1
- import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
- /**
3
- * Conditionally renders children based on RBAC permissions.
4
- *
5
- * The consumer's `useRBAC()` hook must be called in the parent component and
6
- * passed as the `rbac` prop; this avoids coupling `<Can>` to a specific context.
7
- *
8
- * @example
9
- * const rbac = useRBAC();
10
- * <Can rbac={rbac} permission="admin:payouts"><PayoutsTable /></Can>
11
- * <Can rbac={rbac} permissions={["seller:products:write", "seller:store"]} mode="any">
12
- * <SellerActions />
13
- * </Can>
14
- */
15
- export function Can({ permission, permissions, mode = "all", fallback = null, children, rbac, }) {
16
- const allowed = permission
17
- ? rbac.can(permission)
18
- : mode === "all"
19
- ? rbac.canAll(permissions ?? [])
20
- : rbac.canAny(permissions ?? []);
21
- return allowed ? _jsx(_Fragment, { children: children }) : _jsx(_Fragment, { children: fallback });
22
- }
@@ -1,2 +0,0 @@
1
- import type { RoleDefinition } from "./types";
2
- export declare const DEFAULT_ROLES: Record<string, RoleDefinition>;
@@ -1,83 +0,0 @@
1
- export const DEFAULT_ROLES = {
2
- super_admin: {
3
- label: "Super Admin",
4
- permissions: ["*"],
5
- inherits: [],
6
- },
7
- admin: {
8
- label: "Admin",
9
- permissions: [
10
- "admin:access",
11
- "admin:settings",
12
- "admin:users",
13
- "admin:orders",
14
- "admin:orders:refund",
15
- "admin:products",
16
- "admin:reviews",
17
- "admin:analytics",
18
- "admin:activity",
19
- "admin:sessions",
20
- "admin:newsletter",
21
- "admin:search",
22
- "admin:feature-flags",
23
- "admin:cms",
24
- "admin:payouts",
25
- "admin:kyc",
26
- ],
27
- inherits: ["moderator"],
28
- },
29
- moderator: {
30
- label: "Moderator",
31
- permissions: [
32
- "admin:access",
33
- "admin:reviews",
34
- "admin:products",
35
- "content:reviews:moderate",
36
- "content:products:moderate",
37
- "content:orders:support",
38
- ],
39
- inherits: [],
40
- },
41
- seller: {
42
- label: "Seller",
43
- permissions: [
44
- "seller:access",
45
- "seller:products:read",
46
- "seller:products:write",
47
- "seller:products:delete",
48
- "seller:orders:read",
49
- "seller:orders:fulfill",
50
- "seller:analytics",
51
- "seller:coupons",
52
- "seller:store",
53
- "seller:payouts:read",
54
- "seller:shipping",
55
- ],
56
- inherits: ["user"],
57
- },
58
- user: {
59
- label: "User",
60
- permissions: [
61
- "user:profile",
62
- "user:orders",
63
- "user:orders:cancel",
64
- "user:reviews",
65
- "user:wishlist",
66
- "user:addresses",
67
- "user:chat",
68
- "user:offers",
69
- "user:auctions",
70
- ],
71
- inherits: [],
72
- },
73
- support_agent: {
74
- label: "Support Agent",
75
- permissions: [
76
- "admin:access",
77
- "admin:orders",
78
- "content:orders:support",
79
- "admin:users",
80
- ],
81
- inherits: [],
82
- },
83
- };
@@ -1,20 +0,0 @@
1
- import type { RbacConfig, Permission } from "./types";
2
- export interface RbacHookReturn {
3
- can: (permission: Permission) => boolean;
4
- canAll: (permissions: Permission[]) => boolean;
5
- canAny: (permissions: Permission[]) => boolean;
6
- roles: string[];
7
- permissions: Set<Permission>;
8
- isAdmin: boolean;
9
- isSeller: boolean;
10
- }
11
- /**
12
- * Factory that creates a typed `useRBAC` hook bound to the given config.
13
- *
14
- * @example
15
- * // src/hooks/useRBAC.ts
16
- * import { createRbacHook } from "@mohasinac/appkit/security";
17
- * import { RBAC_CONFIG } from "@/constants/rbac";
18
- * export const useRBAC = createRbacHook(RBAC_CONFIG);
19
- */
20
- export declare function createRbacHook(config: RbacConfig, getUserRoles: () => string[] | null | undefined): () => RbacHookReturn;
@@ -1,30 +0,0 @@
1
- "use client";
2
- // appkit/src/security/rbac/hook.ts
3
- import { useMemo } from "react";
4
- import { resolvePermissions, hasPermission, hasAllPermissions, hasAnyPermission, } from "./resolver";
5
- /**
6
- * Factory that creates a typed `useRBAC` hook bound to the given config.
7
- *
8
- * @example
9
- * // src/hooks/useRBAC.ts
10
- * import { createRbacHook } from "@mohasinac/appkit/security";
11
- * import { RBAC_CONFIG } from "@/constants/rbac";
12
- * export const useRBAC = createRbacHook(RBAC_CONFIG);
13
- */
14
- export function createRbacHook(config, getUserRoles) {
15
- return function useRBAC() {
16
- const userRoles = getUserRoles() ?? [];
17
- const permissions = useMemo(() => resolvePermissions(userRoles, config),
18
- // eslint-disable-next-line react-hooks/exhaustive-deps
19
- [userRoles.join(",")]);
20
- return {
21
- can: (permission) => hasPermission(permissions, permission),
22
- canAll: (perms) => hasAllPermissions(permissions, perms),
23
- canAny: (perms) => hasAnyPermission(permissions, perms),
24
- roles: userRoles,
25
- permissions,
26
- isAdmin: hasPermission(permissions, "admin:access"),
27
- isSeller: hasPermission(permissions, "seller:access"),
28
- };
29
- };
30
- }
@@ -1,8 +0,0 @@
1
- export type { Permission, RoleDefinition, RbacConfig, ResolvedUser } from "./types";
2
- export { DEFAULT_ROLES } from "./default-roles";
3
- export { resolvePermissions, hasPermission, hasAllPermissions, hasAnyPermission, } from "./resolver";
4
- export type { RbacHookReturn } from "./hook";
5
- export { createRbacHook } from "./hook";
6
- export { Can } from "./Can";
7
- export { createRequirePermission, createRequirePermissionSync } from "./server";
8
- export { createRbacMiddleware } from "./middleware";
@@ -1,6 +0,0 @@
1
- export { DEFAULT_ROLES } from "./default-roles";
2
- export { resolvePermissions, hasPermission, hasAllPermissions, hasAnyPermission, } from "./resolver";
3
- export { createRbacHook } from "./hook";
4
- export { Can } from "./Can";
5
- export { createRequirePermission, createRequirePermissionSync } from "./server";
6
- export { createRbacMiddleware } from "./middleware";
@@ -1,51 +0,0 @@
1
- import type { RbacConfig, Permission } from "./types";
2
- type NextRequest = {
3
- nextUrl: {
4
- pathname: string;
5
- };
6
- headers: {
7
- get: (name: string) => string | null;
8
- };
9
- cookies: {
10
- get: (name: string) => {
11
- value: string;
12
- } | undefined;
13
- };
14
- url: string;
15
- };
16
- type NextResponse = {
17
- redirect: (url: URL | string) => NextResponse;
18
- next: () => NextResponse;
19
- };
20
- type GetSessionUser = (request: NextRequest) => Promise<{
21
- uid: string;
22
- roles: string[];
23
- } | null>;
24
- /**
25
- * Factory that creates a Next.js middleware function for route-level RBAC.
26
- *
27
- * @example
28
- * // letitrip: middleware.ts
29
- * import { createRbacMiddleware } from "@mohasinac/appkit/security";
30
- * import { RBAC_CONFIG } from "@/constants/rbac";
31
- * import { ADMIN_PAGE_PERMISSIONS } from "@mohasinac/appkit/features/admin";
32
- * import { SELLER_PAGE_PERMISSIONS } from "@mohasinac/appkit/features/seller";
33
- * import { getSessionUser } from "@/lib/auth/session";
34
- *
35
- * export const middleware = createRbacMiddleware(
36
- * RBAC_CONFIG,
37
- * { ...ADMIN_PAGE_PERMISSIONS, ...SELLER_PAGE_PERMISSIONS },
38
- * getSessionUser,
39
- * { loginPath: "/auth/login", unauthorizedPath: "/unauthorized" }
40
- * );
41
- */
42
- export declare function createRbacMiddleware(config: RbacConfig, pageMap: Record<string, Permission>, getSessionUser: GetSessionUser, options?: {
43
- loginPath?: string;
44
- unauthorizedPath?: string;
45
- NextURL?: new (url: string, base: string) => URL;
46
- NextResponse?: NextResponse;
47
- }): (request: NextRequest, NextResponseLib: {
48
- redirect: (url: URL | string) => NextResponse;
49
- next: () => NextResponse;
50
- }) => Promise<NextResponse>;
51
- export {};
@@ -1,51 +0,0 @@
1
- import { resolvePermissions, hasPermission } from "./resolver";
2
- function matchesRoute(pathname, pattern) {
3
- // Convert route pattern like "/admin/:path*" to a testable form
4
- const escaped = pattern
5
- .replace(/\[.*?\]/g, "[^/]+")
6
- .replace(/:\w+\*/g, ".*")
7
- .replace(/:\w+/g, "[^/]+");
8
- return new RegExp(`^${escaped}(/|$)`).test(pathname);
9
- }
10
- /**
11
- * Factory that creates a Next.js middleware function for route-level RBAC.
12
- *
13
- * @example
14
- * // letitrip: middleware.ts
15
- * import { createRbacMiddleware } from "@mohasinac/appkit/security";
16
- * import { RBAC_CONFIG } from "@/constants/rbac";
17
- * import { ADMIN_PAGE_PERMISSIONS } from "@mohasinac/appkit/features/admin";
18
- * import { SELLER_PAGE_PERMISSIONS } from "@mohasinac/appkit/features/seller";
19
- * import { getSessionUser } from "@/lib/auth/session";
20
- *
21
- * export const middleware = createRbacMiddleware(
22
- * RBAC_CONFIG,
23
- * { ...ADMIN_PAGE_PERMISSIONS, ...SELLER_PAGE_PERMISSIONS },
24
- * getSessionUser,
25
- * { loginPath: "/auth/login", unauthorizedPath: "/unauthorized" }
26
- * );
27
- */
28
- export function createRbacMiddleware(config, pageMap, getSessionUser, options = {}) {
29
- const loginPath = options.loginPath ?? "/auth/login";
30
- const unauthorizedPath = options.unauthorizedPath ?? "/unauthorized";
31
- return async function rbacMiddleware(request, NextResponseLib) {
32
- const { pathname } = request.nextUrl;
33
- // Find the most specific matching route (longest match wins)
34
- const entry = Object.entries(pageMap)
35
- .filter(([route]) => matchesRoute(pathname, route))
36
- .sort((a, b) => b[0].length - a[0].length)[0];
37
- if (!entry)
38
- return NextResponseLib.next();
39
- const [, requiredPermission] = entry;
40
- const user = await getSessionUser(request);
41
- if (!user) {
42
- return NextResponseLib.redirect(new URL(loginPath + `?from=${encodeURIComponent(pathname)}`, request.url));
43
- }
44
- const perms = resolvePermissions(user.roles, config);
45
- if (!hasPermission(perms, requiredPermission)) {
46
- return NextResponseLib.redirect(new URL(unauthorizedPath +
47
- `?required=${encodeURIComponent(requiredPermission)}`, request.url));
48
- }
49
- return NextResponseLib.next();
50
- };
51
- }
@@ -1,5 +0,0 @@
1
- import type { Permission, RbacConfig } from "./types";
2
- export declare function resolvePermissions(userRoles: string[], config: RbacConfig): Set<Permission>;
3
- export declare function hasPermission(permissions: Set<Permission>, required: Permission): boolean;
4
- export declare function hasAllPermissions(permissions: Set<Permission>, required: Permission[]): boolean;
5
- export declare function hasAnyPermission(permissions: Set<Permission>, required: Permission[]): boolean;
@@ -1,38 +0,0 @@
1
- export function resolvePermissions(userRoles, config) {
2
- const { roles, multiRoleStrategy = "union" } = config;
3
- function getPermissionsForRole(roleKey, visited = new Set()) {
4
- if (visited.has(roleKey))
5
- return new Set();
6
- visited.add(roleKey);
7
- const def = roles[roleKey];
8
- if (!def)
9
- return new Set();
10
- const own = new Set(def.permissions);
11
- // Wildcard — super_admin gets everything
12
- if (own.has("*"))
13
- return new Set(["*"]);
14
- for (const inherited of def.inherits ?? []) {
15
- for (const p of getPermissionsForRole(inherited, visited)) {
16
- own.add(p);
17
- }
18
- }
19
- return own;
20
- }
21
- if (userRoles.length === 0)
22
- return new Set();
23
- const sets = userRoles.map((r) => getPermissionsForRole(r));
24
- if (multiRoleStrategy === "intersection") {
25
- return sets.reduce((acc, set) => new Set([...acc].filter((p) => set.has(p))));
26
- }
27
- // union (default)
28
- return sets.reduce((acc, set) => new Set([...acc, ...set]), new Set());
29
- }
30
- export function hasPermission(permissions, required) {
31
- return permissions.has("*") || permissions.has(required);
32
- }
33
- export function hasAllPermissions(permissions, required) {
34
- return required.every((p) => hasPermission(permissions, p));
35
- }
36
- export function hasAnyPermission(permissions, required) {
37
- return required.some((p) => hasPermission(permissions, p));
38
- }
@@ -1,24 +0,0 @@
1
- import type { RbacConfig, Permission } from "./types";
2
- /**
3
- * Factory creating a server-side permission guard for API routes + Server Actions.
4
- *
5
- * @example
6
- * // src/lib/auth/require-permission.ts
7
- * import { createRequirePermission } from "@mohasinac/appkit/security";
8
- * import { RBAC_CONFIG } from "@/constants/rbac";
9
- * export const requirePermission = createRequirePermission(RBAC_CONFIG);
10
- *
11
- * // In Server Action:
12
- * await requirePermission(authUser, "admin:payouts");
13
- */
14
- export declare function createRequirePermission(config: RbacConfig): (user: {
15
- uid: string;
16
- roles: string[];
17
- } | null | undefined, permission: Permission) => Promise<void>;
18
- /**
19
- * Synchronous variant — use when errors cannot be imported directly.
20
- */
21
- export declare function createRequirePermissionSync(config: RbacConfig): (user: {
22
- uid: string;
23
- roles: string[];
24
- } | null | undefined, permission: Permission) => void;
@@ -1,42 +0,0 @@
1
- import { resolvePermissions, hasPermission } from "./resolver";
2
- /**
3
- * Factory creating a server-side permission guard for API routes + Server Actions.
4
- *
5
- * @example
6
- * // src/lib/auth/require-permission.ts
7
- * import { createRequirePermission } from "@mohasinac/appkit/security";
8
- * import { RBAC_CONFIG } from "@/constants/rbac";
9
- * export const requirePermission = createRequirePermission(RBAC_CONFIG);
10
- *
11
- * // In Server Action:
12
- * await requirePermission(authUser, "admin:payouts");
13
- */
14
- export function createRequirePermission(config) {
15
- return async function requirePermission(user, permission) {
16
- if (!user) {
17
- const { AuthenticationError } = await import("../../errors");
18
- throw new AuthenticationError("Not authenticated");
19
- }
20
- const perms = resolvePermissions(user.roles, config);
21
- if (!hasPermission(perms, permission)) {
22
- const { AuthorizationError } = await import("../../errors");
23
- throw new AuthorizationError(`Missing permission: ${permission}`);
24
- }
25
- };
26
- }
27
- /**
28
- * Synchronous variant — use when errors cannot be imported directly.
29
- */
30
- export function createRequirePermissionSync(config) {
31
- return function requirePermission(user, permission) {
32
- if (!user) {
33
- throw Object.assign(new Error("Not authenticated"), { status: 401 });
34
- }
35
- const perms = resolvePermissions(user.roles, config);
36
- if (!hasPermission(perms, permission)) {
37
- throw Object.assign(new Error(`Missing permission: ${permission}`), {
38
- status: 403,
39
- });
40
- }
41
- };
42
- }
@@ -1,22 +0,0 @@
1
- export type Permission = string;
2
- export interface RoleDefinition {
3
- label: string;
4
- permissions: Permission[];
5
- /** Other role keys whose permissions are inherited */
6
- inherits?: string[];
7
- }
8
- export interface RbacConfig {
9
- /** App-defined roles — merges with or replaces DEFAULT_ROLES */
10
- roles: Record<string, RoleDefinition>;
11
- /**
12
- * How to resolve permissions when a user has multiple roles.
13
- * default: "union" — user gets the union of all roles' permissions
14
- */
15
- multiRoleStrategy?: "union" | "intersection";
16
- }
17
- export interface ResolvedUser {
18
- uid: string;
19
- roles: string[];
20
- /** Flat resolved permission set (after role inheritance + multi-role strategy) */
21
- permissions: Set<Permission>;
22
- }
@@ -1,2 +0,0 @@
1
- // appkit/src/security/rbac/types.ts
2
- export {};
@@ -1,2 +0,0 @@
1
- import type { ConversationDocument } from "../features/messages/schemas/firestore";
2
- export declare const conversationsSeedData: Partial<ConversationDocument>[];