@mercurjs/dashboard-sdk 2.3.6-canary.2 → 2.3.6-canary.3
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/index.cjs +24 -17
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +21 -15
- package/dist/types-CEb2yQNN.d.cts +126 -0
- package/dist/types-CEb2yQNN.d.ts +126 -0
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/package.json +3 -3
- package/dist/types-CTuDKgPc.d.cts +0 -142
- package/dist/types-CTuDKgPc.d.ts +0 -142
package/dist/index.cjs
CHANGED
|
@@ -20,12 +20,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
|
|
23
|
+
PERMISSION_RIGHT_RANK: () => PERMISSION_RIGHT_RANK,
|
|
24
24
|
buildPermission: () => buildPermission,
|
|
25
25
|
defineCustomFieldsConfig: () => defineCustomFieldsConfig,
|
|
26
26
|
defineNavigationConfig: () => defineNavigationConfig,
|
|
27
27
|
defineWidgetConfig: () => defineWidgetConfig,
|
|
28
|
-
parsePermission: () => parsePermission
|
|
28
|
+
parsePermission: () => parsePermission,
|
|
29
|
+
satisfiesPermission: () => satisfiesPermission
|
|
29
30
|
});
|
|
30
31
|
module.exports = __toCommonJS(index_exports);
|
|
31
32
|
|
|
@@ -47,33 +48,39 @@ function defineCustomFieldsConfig(config) {
|
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
// src/permissions.ts
|
|
50
|
-
var
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
delete: ["delete"],
|
|
55
|
-
"*": ["read", "create", "update", "delete", "*"]
|
|
51
|
+
var PERMISSION_RIGHT_RANK = {
|
|
52
|
+
view: 1,
|
|
53
|
+
edit: 2,
|
|
54
|
+
manage: 3
|
|
56
55
|
};
|
|
57
56
|
function parsePermission(permission) {
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
57
|
+
const index = permission.lastIndexOf(":");
|
|
58
|
+
if (index <= 0) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const right = permission.slice(index + 1);
|
|
62
|
+
if (!(right in PERMISSION_RIGHT_RANK)) {
|
|
60
63
|
return null;
|
|
61
64
|
}
|
|
62
|
-
const [resource, operation] = parts;
|
|
63
65
|
return {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
key: permission.slice(0, index),
|
|
67
|
+
right
|
|
66
68
|
};
|
|
67
69
|
}
|
|
68
|
-
function buildPermission(
|
|
69
|
-
return `${
|
|
70
|
+
function buildPermission(key, right) {
|
|
71
|
+
return `${key}:${right}`;
|
|
72
|
+
}
|
|
73
|
+
function satisfiesPermission(permissions, key, right) {
|
|
74
|
+
const granted = permissions[key];
|
|
75
|
+
return !!granted && PERMISSION_RIGHT_RANK[granted] >= PERMISSION_RIGHT_RANK[right];
|
|
70
76
|
}
|
|
71
77
|
// Annotate the CommonJS export names for ESM import in node:
|
|
72
78
|
0 && (module.exports = {
|
|
73
|
-
|
|
79
|
+
PERMISSION_RIGHT_RANK,
|
|
74
80
|
buildPermission,
|
|
75
81
|
defineCustomFieldsConfig,
|
|
76
82
|
defineNavigationConfig,
|
|
77
83
|
defineWidgetConfig,
|
|
78
|
-
parsePermission
|
|
84
|
+
parsePermission,
|
|
85
|
+
satisfiesPermission
|
|
79
86
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { B as BuiltMercurConfig, M as MercurConfig,
|
|
1
|
+
export { B as BuiltMercurConfig, M as MercurConfig, P as PERMISSION_RIGHT_RANK, a as Permission, b as PermissionKey, c as PermissionMap, d as PermissionRight, e as PermissionsContextValue, R as RouteConfig, f as RouteHandle, g as buildPermission, p as parsePermission, s as satisfiesPermission } from './types-CEb2yQNN.cjs';
|
|
2
2
|
import { ComponentType, ReactNode } from 'react';
|
|
3
3
|
|
|
4
4
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { B as BuiltMercurConfig, M as MercurConfig,
|
|
1
|
+
export { B as BuiltMercurConfig, M as MercurConfig, P as PERMISSION_RIGHT_RANK, a as Permission, b as PermissionKey, c as PermissionMap, d as PermissionRight, e as PermissionsContextValue, R as RouteConfig, f as RouteHandle, g as buildPermission, p as parsePermission, s as satisfiesPermission } from './types-CEb2yQNN.js';
|
|
2
2
|
import { ComponentType, ReactNode } from 'react';
|
|
3
3
|
|
|
4
4
|
/**
|
package/dist/index.js
CHANGED
|
@@ -18,32 +18,38 @@ function defineCustomFieldsConfig(config) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// src/permissions.ts
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
delete: ["delete"],
|
|
26
|
-
"*": ["read", "create", "update", "delete", "*"]
|
|
21
|
+
var PERMISSION_RIGHT_RANK = {
|
|
22
|
+
view: 1,
|
|
23
|
+
edit: 2,
|
|
24
|
+
manage: 3
|
|
27
25
|
};
|
|
28
26
|
function parsePermission(permission) {
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
27
|
+
const index = permission.lastIndexOf(":");
|
|
28
|
+
if (index <= 0) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const right = permission.slice(index + 1);
|
|
32
|
+
if (!(right in PERMISSION_RIGHT_RANK)) {
|
|
31
33
|
return null;
|
|
32
34
|
}
|
|
33
|
-
const [resource, operation] = parts;
|
|
34
35
|
return {
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
key: permission.slice(0, index),
|
|
37
|
+
right
|
|
37
38
|
};
|
|
38
39
|
}
|
|
39
|
-
function buildPermission(
|
|
40
|
-
return `${
|
|
40
|
+
function buildPermission(key, right) {
|
|
41
|
+
return `${key}:${right}`;
|
|
42
|
+
}
|
|
43
|
+
function satisfiesPermission(permissions, key, right) {
|
|
44
|
+
const granted = permissions[key];
|
|
45
|
+
return !!granted && PERMISSION_RIGHT_RANK[granted] >= PERMISSION_RIGHT_RANK[right];
|
|
41
46
|
}
|
|
42
47
|
export {
|
|
43
|
-
|
|
48
|
+
PERMISSION_RIGHT_RANK,
|
|
44
49
|
buildPermission,
|
|
45
50
|
defineCustomFieldsConfig,
|
|
46
51
|
defineNavigationConfig,
|
|
47
52
|
defineWidgetConfig,
|
|
48
|
-
parsePermission
|
|
53
|
+
parsePermission,
|
|
54
|
+
satisfiesPermission
|
|
49
55
|
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { ComponentType, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Permission strings follow `{key}:{right}`, e.g. `orders:view`,
|
|
5
|
+
* `products:edit`, `sellers.approval:edit`.
|
|
6
|
+
*
|
|
7
|
+
* Keys mirror the catalog declared server-side with `defineMercurPermissions`
|
|
8
|
+
* (`packages/core/src/permissions/definitions`). Rights nest:
|
|
9
|
+
* `manage` implies `edit`, `edit` implies `view`.
|
|
10
|
+
*/
|
|
11
|
+
type PermissionKey = "sellers" | "sellers.approval" | "sellers.premium" | "members" | "members.invites" | "roles" | "roles.owner" | "orders" | "orders.refunds" | "orders.returns" | "orders.edits" | "order_groups" | "payments" | "customers" | "customer_groups" | "products" | "products.review" | "product_changes" | "product_categories" | "product_collections" | "product_types" | "product_tags" | "product_attributes" | "offers" | "inventory_items" | "reservations" | "stock_locations" | "price_lists" | "price_preferences" | "promotions" | "campaigns" | "commission_rates" | "commission_lines" | "payouts" | "payout_accounts" | "shipping_profiles" | "shipping_options" | "fulfillment_sets" | "regions" | "tax_regions" | "store" | "sales_channels" | "return_reasons" | "refund_reasons" | "users" | "api_keys" | "translations" | "notifications" | "workflow_executions" | "reviews";
|
|
12
|
+
type PermissionRight = "view" | "edit" | "manage";
|
|
13
|
+
type Permission = `${PermissionKey}:${PermissionRight}`;
|
|
14
|
+
/** Effective rights of the acting user, as returned by `fields=+permissions`. */
|
|
15
|
+
type PermissionMap = Partial<Record<string, PermissionRight>>;
|
|
16
|
+
declare const PERMISSION_RIGHT_RANK: Record<PermissionRight, number>;
|
|
17
|
+
interface PermissionsContextValue {
|
|
18
|
+
/** `null` while no access-control module is enforcing permissions. */
|
|
19
|
+
permissions: PermissionMap | null;
|
|
20
|
+
isLoading: boolean;
|
|
21
|
+
/** When `false`, every check resolves to `true`. */
|
|
22
|
+
isEnforced: boolean;
|
|
23
|
+
hasPermission: (permission: Permission) => boolean;
|
|
24
|
+
hasAnyPermission: (permissions: Permission[]) => boolean;
|
|
25
|
+
hasAllPermissions: (permissions: Permission[]) => boolean;
|
|
26
|
+
can: (key: PermissionKey, right?: PermissionRight) => boolean;
|
|
27
|
+
}
|
|
28
|
+
declare function parsePermission(permission: string): {
|
|
29
|
+
key: PermissionKey;
|
|
30
|
+
right: PermissionRight;
|
|
31
|
+
} | null;
|
|
32
|
+
declare function buildPermission(key: PermissionKey, right: PermissionRight): Permission;
|
|
33
|
+
declare function satisfiesPermission(permissions: PermissionMap, key: string, right: PermissionRight): boolean;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Configuration for the Mercur dashboard plugin.
|
|
37
|
+
*
|
|
38
|
+
* Passed to `mercurDashboardPlugin()` in `vite.config.ts` to configure
|
|
39
|
+
* the vendor or admin dashboard at build time.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* mercurDashboardPlugin({
|
|
44
|
+
* medusaConfigPath: '../../packages/api/medusa-config.ts',
|
|
45
|
+
* enableSellerRegistration: true,
|
|
46
|
+
* })
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
interface MercurConfig {
|
|
50
|
+
/** Path to the MedusaJS config file, resolved relative to the project root. */
|
|
51
|
+
medusaConfigPath: string;
|
|
52
|
+
/**
|
|
53
|
+
* Backend URL for API requests.
|
|
54
|
+
* @default "http://localhost:9000"
|
|
55
|
+
*/
|
|
56
|
+
backendUrl?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Absolute base URL for the vendor dashboard, including any path prefix
|
|
59
|
+
* (for example `https://vendors.example.com/seller`).
|
|
60
|
+
*
|
|
61
|
+
* The plugin does not read `.env` files on its own. Load env in your
|
|
62
|
+
* app's `vite.config.ts` and pass the value here when you need
|
|
63
|
+
* cross-origin links such as seller invite URLs.
|
|
64
|
+
*
|
|
65
|
+
* If omitted, the plugin falls back to vendor module dev server
|
|
66
|
+
* detection in development and to the configured vendor path in
|
|
67
|
+
* production.
|
|
68
|
+
*/
|
|
69
|
+
vendorUrl?: string;
|
|
70
|
+
/** Dashboard display name. */
|
|
71
|
+
name?: string;
|
|
72
|
+
/** Path to a logo asset for the dashboard. */
|
|
73
|
+
logo?: string;
|
|
74
|
+
/** Internationalization settings. */
|
|
75
|
+
i18n?: {
|
|
76
|
+
/** The default language code (e.g. `"en"`). */
|
|
77
|
+
defaultLanguage: string;
|
|
78
|
+
};
|
|
79
|
+
/** Whether to allow new sellers to register from the login screen. */
|
|
80
|
+
enableSellerRegistration?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Maximum allowed size for image uploads, in bytes.
|
|
83
|
+
* Used by dashboard upload components to reject oversized files
|
|
84
|
+
* before they are sent to the backend.
|
|
85
|
+
* @default 2_097_152 // 2 MB
|
|
86
|
+
*/
|
|
87
|
+
imageLimit?: number;
|
|
88
|
+
}
|
|
89
|
+
interface BuiltMercurConfig extends MercurConfig {
|
|
90
|
+
backendUrl: string;
|
|
91
|
+
base?: string;
|
|
92
|
+
root: string;
|
|
93
|
+
srcDir: string;
|
|
94
|
+
pluginExtensions: string[];
|
|
95
|
+
imageLimit: number;
|
|
96
|
+
}
|
|
97
|
+
type RouteConfig = {
|
|
98
|
+
label: string;
|
|
99
|
+
icon?: ComponentType;
|
|
100
|
+
rank?: number;
|
|
101
|
+
nested?: string;
|
|
102
|
+
translationNs?: string;
|
|
103
|
+
public?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Permissions the actor must hold for this route's sidebar entry to be
|
|
106
|
+
* shown. Enforcement of the route itself comes from `handle.permissions`
|
|
107
|
+
* — this only controls navigation visibility.
|
|
108
|
+
*/
|
|
109
|
+
permissions?: Permission[];
|
|
110
|
+
/** If true, ALL `permissions` are required. Defaults to ANY. */
|
|
111
|
+
requireAll?: boolean;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* The value of a route module's `export const handle`. Read by react-router's
|
|
115
|
+
* `useMatches()`; `permissions` is enforced by `RoutePermissionGuard`.
|
|
116
|
+
*/
|
|
117
|
+
type RouteHandle = {
|
|
118
|
+
permissions?: Permission | Permission[];
|
|
119
|
+
/** If true (default at the route level), ALL permissions are required. */
|
|
120
|
+
requireAll?: boolean;
|
|
121
|
+
/** Where to send the actor on denial. Renders Access Denied when unset. */
|
|
122
|
+
redirectTo?: string;
|
|
123
|
+
breadcrumb?: (match: never) => ReactNode;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export { type BuiltMercurConfig as B, type MercurConfig as M, PERMISSION_RIGHT_RANK as P, type RouteConfig as R, type Permission as a, type PermissionKey as b, type PermissionMap as c, type PermissionRight as d, type PermissionsContextValue as e, type RouteHandle as f, buildPermission as g, parsePermission as p, satisfiesPermission as s };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { ComponentType, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Permission strings follow `{key}:{right}`, e.g. `orders:view`,
|
|
5
|
+
* `products:edit`, `sellers.approval:edit`.
|
|
6
|
+
*
|
|
7
|
+
* Keys mirror the catalog declared server-side with `defineMercurPermissions`
|
|
8
|
+
* (`packages/core/src/permissions/definitions`). Rights nest:
|
|
9
|
+
* `manage` implies `edit`, `edit` implies `view`.
|
|
10
|
+
*/
|
|
11
|
+
type PermissionKey = "sellers" | "sellers.approval" | "sellers.premium" | "members" | "members.invites" | "roles" | "roles.owner" | "orders" | "orders.refunds" | "orders.returns" | "orders.edits" | "order_groups" | "payments" | "customers" | "customer_groups" | "products" | "products.review" | "product_changes" | "product_categories" | "product_collections" | "product_types" | "product_tags" | "product_attributes" | "offers" | "inventory_items" | "reservations" | "stock_locations" | "price_lists" | "price_preferences" | "promotions" | "campaigns" | "commission_rates" | "commission_lines" | "payouts" | "payout_accounts" | "shipping_profiles" | "shipping_options" | "fulfillment_sets" | "regions" | "tax_regions" | "store" | "sales_channels" | "return_reasons" | "refund_reasons" | "users" | "api_keys" | "translations" | "notifications" | "workflow_executions" | "reviews";
|
|
12
|
+
type PermissionRight = "view" | "edit" | "manage";
|
|
13
|
+
type Permission = `${PermissionKey}:${PermissionRight}`;
|
|
14
|
+
/** Effective rights of the acting user, as returned by `fields=+permissions`. */
|
|
15
|
+
type PermissionMap = Partial<Record<string, PermissionRight>>;
|
|
16
|
+
declare const PERMISSION_RIGHT_RANK: Record<PermissionRight, number>;
|
|
17
|
+
interface PermissionsContextValue {
|
|
18
|
+
/** `null` while no access-control module is enforcing permissions. */
|
|
19
|
+
permissions: PermissionMap | null;
|
|
20
|
+
isLoading: boolean;
|
|
21
|
+
/** When `false`, every check resolves to `true`. */
|
|
22
|
+
isEnforced: boolean;
|
|
23
|
+
hasPermission: (permission: Permission) => boolean;
|
|
24
|
+
hasAnyPermission: (permissions: Permission[]) => boolean;
|
|
25
|
+
hasAllPermissions: (permissions: Permission[]) => boolean;
|
|
26
|
+
can: (key: PermissionKey, right?: PermissionRight) => boolean;
|
|
27
|
+
}
|
|
28
|
+
declare function parsePermission(permission: string): {
|
|
29
|
+
key: PermissionKey;
|
|
30
|
+
right: PermissionRight;
|
|
31
|
+
} | null;
|
|
32
|
+
declare function buildPermission(key: PermissionKey, right: PermissionRight): Permission;
|
|
33
|
+
declare function satisfiesPermission(permissions: PermissionMap, key: string, right: PermissionRight): boolean;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Configuration for the Mercur dashboard plugin.
|
|
37
|
+
*
|
|
38
|
+
* Passed to `mercurDashboardPlugin()` in `vite.config.ts` to configure
|
|
39
|
+
* the vendor or admin dashboard at build time.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* mercurDashboardPlugin({
|
|
44
|
+
* medusaConfigPath: '../../packages/api/medusa-config.ts',
|
|
45
|
+
* enableSellerRegistration: true,
|
|
46
|
+
* })
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
interface MercurConfig {
|
|
50
|
+
/** Path to the MedusaJS config file, resolved relative to the project root. */
|
|
51
|
+
medusaConfigPath: string;
|
|
52
|
+
/**
|
|
53
|
+
* Backend URL for API requests.
|
|
54
|
+
* @default "http://localhost:9000"
|
|
55
|
+
*/
|
|
56
|
+
backendUrl?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Absolute base URL for the vendor dashboard, including any path prefix
|
|
59
|
+
* (for example `https://vendors.example.com/seller`).
|
|
60
|
+
*
|
|
61
|
+
* The plugin does not read `.env` files on its own. Load env in your
|
|
62
|
+
* app's `vite.config.ts` and pass the value here when you need
|
|
63
|
+
* cross-origin links such as seller invite URLs.
|
|
64
|
+
*
|
|
65
|
+
* If omitted, the plugin falls back to vendor module dev server
|
|
66
|
+
* detection in development and to the configured vendor path in
|
|
67
|
+
* production.
|
|
68
|
+
*/
|
|
69
|
+
vendorUrl?: string;
|
|
70
|
+
/** Dashboard display name. */
|
|
71
|
+
name?: string;
|
|
72
|
+
/** Path to a logo asset for the dashboard. */
|
|
73
|
+
logo?: string;
|
|
74
|
+
/** Internationalization settings. */
|
|
75
|
+
i18n?: {
|
|
76
|
+
/** The default language code (e.g. `"en"`). */
|
|
77
|
+
defaultLanguage: string;
|
|
78
|
+
};
|
|
79
|
+
/** Whether to allow new sellers to register from the login screen. */
|
|
80
|
+
enableSellerRegistration?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Maximum allowed size for image uploads, in bytes.
|
|
83
|
+
* Used by dashboard upload components to reject oversized files
|
|
84
|
+
* before they are sent to the backend.
|
|
85
|
+
* @default 2_097_152 // 2 MB
|
|
86
|
+
*/
|
|
87
|
+
imageLimit?: number;
|
|
88
|
+
}
|
|
89
|
+
interface BuiltMercurConfig extends MercurConfig {
|
|
90
|
+
backendUrl: string;
|
|
91
|
+
base?: string;
|
|
92
|
+
root: string;
|
|
93
|
+
srcDir: string;
|
|
94
|
+
pluginExtensions: string[];
|
|
95
|
+
imageLimit: number;
|
|
96
|
+
}
|
|
97
|
+
type RouteConfig = {
|
|
98
|
+
label: string;
|
|
99
|
+
icon?: ComponentType;
|
|
100
|
+
rank?: number;
|
|
101
|
+
nested?: string;
|
|
102
|
+
translationNs?: string;
|
|
103
|
+
public?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Permissions the actor must hold for this route's sidebar entry to be
|
|
106
|
+
* shown. Enforcement of the route itself comes from `handle.permissions`
|
|
107
|
+
* — this only controls navigation visibility.
|
|
108
|
+
*/
|
|
109
|
+
permissions?: Permission[];
|
|
110
|
+
/** If true, ALL `permissions` are required. Defaults to ANY. */
|
|
111
|
+
requireAll?: boolean;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* The value of a route module's `export const handle`. Read by react-router's
|
|
115
|
+
* `useMatches()`; `permissions` is enforced by `RoutePermissionGuard`.
|
|
116
|
+
*/
|
|
117
|
+
type RouteHandle = {
|
|
118
|
+
permissions?: Permission | Permission[];
|
|
119
|
+
/** If true (default at the route level), ALL permissions are required. */
|
|
120
|
+
requireAll?: boolean;
|
|
121
|
+
/** Where to send the actor on denial. Renders Access Denied when unset. */
|
|
122
|
+
redirectTo?: string;
|
|
123
|
+
breadcrumb?: (match: never) => ReactNode;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export { type BuiltMercurConfig as B, type MercurConfig as M, PERMISSION_RIGHT_RANK as P, type RouteConfig as R, type Permission as a, type PermissionKey as b, type PermissionMap as c, type PermissionRight as d, type PermissionsContextValue as e, type RouteHandle as f, buildPermission as g, parsePermission as p, satisfiesPermission as s };
|
package/dist/vite.d.cts
CHANGED
package/dist/vite.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mercurjs/dashboard-sdk",
|
|
3
|
-
"version": "2.3.6-canary.
|
|
3
|
+
"version": "2.3.6-canary.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/mercurjs/mercur",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@babel/parser": "8.0.5",
|
|
38
|
-
"@babel/traverse": "
|
|
39
|
-
"@babel/types": "8.0.
|
|
38
|
+
"@babel/traverse": "8.0.6",
|
|
39
|
+
"@babel/types": "8.0.6",
|
|
40
40
|
"esbuild-register": "^3.6.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { ComponentType, ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Permission strings follow the pattern `{resource}:{operation}`, e.g.
|
|
5
|
-
* `customer:read`, `product:create`, `order:*`.
|
|
6
|
-
*
|
|
7
|
-
* The resource list mirrors the policies registered server-side — Medusa's own
|
|
8
|
-
* catalog plus Mercur's (`packages/core/src/policies`). A name that is not
|
|
9
|
-
* registered there is not a type error, it simply never matches a granted
|
|
10
|
-
* policy, so the two are kept in sync by a test in `packages/admin`.
|
|
11
|
-
*/
|
|
12
|
-
type PermissionResource = "api_key" | "campaign" | "commission_line" | "commission_rate" | "commission_rule" | "currency" | "customer" | "customer_address" | "customer_group" | "file" | "fulfillment" | "fulfillment_provider" | "fulfillment_set" | "inventory_item" | "inventory_level" | "invite" | "member_invite" | "notification" | "offer" | "order" | "order_change" | "order_claim" | "order_claim_item" | "order_exchange" | "order_group" | "order_item" | "payment" | "payment_collection" | "payment_method" | "payment_session" | "payout" | "payout_account" | "price" | "price_list" | "price_preference" | "product" | "product_attribute" | "product_attribute_value" | "product_category" | "product_change" | "product_collection" | "product_option" | "product_option_value" | "product_tag" | "product_type" | "product_variant" | "promotion" | "rbac_policy" | "rbac_role" | "refund_reason" | "region" | "reservation_item" | "return" | "return_reason" | "review" | "sales_channel" | "seller" | "seller_member" | "service_zone" | "shipping_option" | "shipping_option_type" | "shipping_profile" | "stock_location" | "store" | "store_locale" | "tax_provider" | "tax_rate" | "tax_region" | "translation" | "translation_setting" | "user" | "workflow_execution";
|
|
13
|
-
type PermissionOperation = "read" | "create" | "update" | "delete" | "*";
|
|
14
|
-
type Permission = `${PermissionResource}:${PermissionOperation}`;
|
|
15
|
-
interface UserPolicy {
|
|
16
|
-
permissions: Permission[];
|
|
17
|
-
}
|
|
18
|
-
interface PermissionRequirement {
|
|
19
|
-
permissions: Permission[];
|
|
20
|
-
/** If true, ALL permissions are required. Defaults to ANY. */
|
|
21
|
-
requireAll?: boolean;
|
|
22
|
-
/** Optional label describing where the requirement came from. */
|
|
23
|
-
source?: string;
|
|
24
|
-
}
|
|
25
|
-
interface PermissionsContextValue {
|
|
26
|
-
policy: UserPolicy | null;
|
|
27
|
-
isLoading: boolean;
|
|
28
|
-
/** Whether RBAC is active. When `false`, every check resolves to `true`. */
|
|
29
|
-
isRbacEnabled: boolean;
|
|
30
|
-
hasPermission: (permission: Permission) => boolean;
|
|
31
|
-
hasAnyPermission: (permissions: Permission[]) => boolean;
|
|
32
|
-
hasAllPermissions: (permissions: Permission[]) => boolean;
|
|
33
|
-
can: (resource: PermissionResource, operation: PermissionOperation) => boolean;
|
|
34
|
-
}
|
|
35
|
-
interface PermissionsRequirementsContextValue {
|
|
36
|
-
requiredPermissions: PermissionRequirement[];
|
|
37
|
-
registerRequiredPermissions: (id: string, requirement: PermissionRequirement) => void;
|
|
38
|
-
unregisterRequiredPermissions: (id: string) => void;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Operations implied by a granted operation. Only the wildcard fans out.
|
|
42
|
-
* Note that `update` does not imply `read` — grants must be explicit.
|
|
43
|
-
*/
|
|
44
|
-
declare const OPERATION_IMPLICATIONS: Record<PermissionOperation, PermissionOperation[]>;
|
|
45
|
-
declare function parsePermission(permission: string): {
|
|
46
|
-
resource: PermissionResource;
|
|
47
|
-
operation: PermissionOperation;
|
|
48
|
-
} | null;
|
|
49
|
-
declare function buildPermission(resource: PermissionResource, operation: PermissionOperation): Permission;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Configuration for the Mercur dashboard plugin.
|
|
53
|
-
*
|
|
54
|
-
* Passed to `mercurDashboardPlugin()` in `vite.config.ts` to configure
|
|
55
|
-
* the vendor or admin dashboard at build time.
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```ts
|
|
59
|
-
* mercurDashboardPlugin({
|
|
60
|
-
* medusaConfigPath: '../../packages/api/medusa-config.ts',
|
|
61
|
-
* enableSellerRegistration: true,
|
|
62
|
-
* })
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
interface MercurConfig {
|
|
66
|
-
/** Path to the MedusaJS config file, resolved relative to the project root. */
|
|
67
|
-
medusaConfigPath: string;
|
|
68
|
-
/**
|
|
69
|
-
* Backend URL for API requests.
|
|
70
|
-
* @default "http://localhost:9000"
|
|
71
|
-
*/
|
|
72
|
-
backendUrl?: string;
|
|
73
|
-
/**
|
|
74
|
-
* Absolute base URL for the vendor dashboard, including any path prefix
|
|
75
|
-
* (for example `https://vendors.example.com/seller`).
|
|
76
|
-
*
|
|
77
|
-
* The plugin does not read `.env` files on its own. Load env in your
|
|
78
|
-
* app's `vite.config.ts` and pass the value here when you need
|
|
79
|
-
* cross-origin links such as seller invite URLs.
|
|
80
|
-
*
|
|
81
|
-
* If omitted, the plugin falls back to vendor module dev server
|
|
82
|
-
* detection in development and to the configured vendor path in
|
|
83
|
-
* production.
|
|
84
|
-
*/
|
|
85
|
-
vendorUrl?: string;
|
|
86
|
-
/** Dashboard display name. */
|
|
87
|
-
name?: string;
|
|
88
|
-
/** Path to a logo asset for the dashboard. */
|
|
89
|
-
logo?: string;
|
|
90
|
-
/** Internationalization settings. */
|
|
91
|
-
i18n?: {
|
|
92
|
-
/** The default language code (e.g. `"en"`). */
|
|
93
|
-
defaultLanguage: string;
|
|
94
|
-
};
|
|
95
|
-
/** Whether to allow new sellers to register from the login screen. */
|
|
96
|
-
enableSellerRegistration?: boolean;
|
|
97
|
-
/**
|
|
98
|
-
* Maximum allowed size for image uploads, in bytes.
|
|
99
|
-
* Used by dashboard upload components to reject oversized files
|
|
100
|
-
* before they are sent to the backend.
|
|
101
|
-
* @default 2_097_152 // 2 MB
|
|
102
|
-
*/
|
|
103
|
-
imageLimit?: number;
|
|
104
|
-
}
|
|
105
|
-
interface BuiltMercurConfig extends MercurConfig {
|
|
106
|
-
backendUrl: string;
|
|
107
|
-
base?: string;
|
|
108
|
-
root: string;
|
|
109
|
-
srcDir: string;
|
|
110
|
-
pluginExtensions: string[];
|
|
111
|
-
imageLimit: number;
|
|
112
|
-
}
|
|
113
|
-
type RouteConfig = {
|
|
114
|
-
label: string;
|
|
115
|
-
icon?: ComponentType;
|
|
116
|
-
rank?: number;
|
|
117
|
-
nested?: string;
|
|
118
|
-
translationNs?: string;
|
|
119
|
-
public?: boolean;
|
|
120
|
-
/**
|
|
121
|
-
* Permissions the actor must hold for this route's sidebar entry to be
|
|
122
|
-
* shown. Enforcement of the route itself comes from `handle.permissions`
|
|
123
|
-
* — this only controls navigation visibility.
|
|
124
|
-
*/
|
|
125
|
-
permissions?: Permission[];
|
|
126
|
-
/** If true, ALL `permissions` are required. Defaults to ANY. */
|
|
127
|
-
requireAll?: boolean;
|
|
128
|
-
};
|
|
129
|
-
/**
|
|
130
|
-
* The value of a route module's `export const handle`. Read by react-router's
|
|
131
|
-
* `useMatches()`; `permissions` is enforced by `RoutePermissionGuard`.
|
|
132
|
-
*/
|
|
133
|
-
type RouteHandle = {
|
|
134
|
-
permissions?: Permission | Permission[];
|
|
135
|
-
/** If true (default at the route level), ALL permissions are required. */
|
|
136
|
-
requireAll?: boolean;
|
|
137
|
-
/** Where to send the actor on denial. Renders Access Denied when unset. */
|
|
138
|
-
redirectTo?: string;
|
|
139
|
-
breadcrumb?: (match: never) => ReactNode;
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
export { type BuiltMercurConfig as B, type MercurConfig as M, OPERATION_IMPLICATIONS as O, type Permission as P, type RouteConfig as R, type UserPolicy as U, type PermissionOperation as a, type PermissionRequirement as b, type PermissionResource as c, type PermissionsContextValue as d, type PermissionsRequirementsContextValue as e, type RouteHandle as f, buildPermission as g, parsePermission as p };
|
package/dist/types-CTuDKgPc.d.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { ComponentType, ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Permission strings follow the pattern `{resource}:{operation}`, e.g.
|
|
5
|
-
* `customer:read`, `product:create`, `order:*`.
|
|
6
|
-
*
|
|
7
|
-
* The resource list mirrors the policies registered server-side — Medusa's own
|
|
8
|
-
* catalog plus Mercur's (`packages/core/src/policies`). A name that is not
|
|
9
|
-
* registered there is not a type error, it simply never matches a granted
|
|
10
|
-
* policy, so the two are kept in sync by a test in `packages/admin`.
|
|
11
|
-
*/
|
|
12
|
-
type PermissionResource = "api_key" | "campaign" | "commission_line" | "commission_rate" | "commission_rule" | "currency" | "customer" | "customer_address" | "customer_group" | "file" | "fulfillment" | "fulfillment_provider" | "fulfillment_set" | "inventory_item" | "inventory_level" | "invite" | "member_invite" | "notification" | "offer" | "order" | "order_change" | "order_claim" | "order_claim_item" | "order_exchange" | "order_group" | "order_item" | "payment" | "payment_collection" | "payment_method" | "payment_session" | "payout" | "payout_account" | "price" | "price_list" | "price_preference" | "product" | "product_attribute" | "product_attribute_value" | "product_category" | "product_change" | "product_collection" | "product_option" | "product_option_value" | "product_tag" | "product_type" | "product_variant" | "promotion" | "rbac_policy" | "rbac_role" | "refund_reason" | "region" | "reservation_item" | "return" | "return_reason" | "review" | "sales_channel" | "seller" | "seller_member" | "service_zone" | "shipping_option" | "shipping_option_type" | "shipping_profile" | "stock_location" | "store" | "store_locale" | "tax_provider" | "tax_rate" | "tax_region" | "translation" | "translation_setting" | "user" | "workflow_execution";
|
|
13
|
-
type PermissionOperation = "read" | "create" | "update" | "delete" | "*";
|
|
14
|
-
type Permission = `${PermissionResource}:${PermissionOperation}`;
|
|
15
|
-
interface UserPolicy {
|
|
16
|
-
permissions: Permission[];
|
|
17
|
-
}
|
|
18
|
-
interface PermissionRequirement {
|
|
19
|
-
permissions: Permission[];
|
|
20
|
-
/** If true, ALL permissions are required. Defaults to ANY. */
|
|
21
|
-
requireAll?: boolean;
|
|
22
|
-
/** Optional label describing where the requirement came from. */
|
|
23
|
-
source?: string;
|
|
24
|
-
}
|
|
25
|
-
interface PermissionsContextValue {
|
|
26
|
-
policy: UserPolicy | null;
|
|
27
|
-
isLoading: boolean;
|
|
28
|
-
/** Whether RBAC is active. When `false`, every check resolves to `true`. */
|
|
29
|
-
isRbacEnabled: boolean;
|
|
30
|
-
hasPermission: (permission: Permission) => boolean;
|
|
31
|
-
hasAnyPermission: (permissions: Permission[]) => boolean;
|
|
32
|
-
hasAllPermissions: (permissions: Permission[]) => boolean;
|
|
33
|
-
can: (resource: PermissionResource, operation: PermissionOperation) => boolean;
|
|
34
|
-
}
|
|
35
|
-
interface PermissionsRequirementsContextValue {
|
|
36
|
-
requiredPermissions: PermissionRequirement[];
|
|
37
|
-
registerRequiredPermissions: (id: string, requirement: PermissionRequirement) => void;
|
|
38
|
-
unregisterRequiredPermissions: (id: string) => void;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Operations implied by a granted operation. Only the wildcard fans out.
|
|
42
|
-
* Note that `update` does not imply `read` — grants must be explicit.
|
|
43
|
-
*/
|
|
44
|
-
declare const OPERATION_IMPLICATIONS: Record<PermissionOperation, PermissionOperation[]>;
|
|
45
|
-
declare function parsePermission(permission: string): {
|
|
46
|
-
resource: PermissionResource;
|
|
47
|
-
operation: PermissionOperation;
|
|
48
|
-
} | null;
|
|
49
|
-
declare function buildPermission(resource: PermissionResource, operation: PermissionOperation): Permission;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Configuration for the Mercur dashboard plugin.
|
|
53
|
-
*
|
|
54
|
-
* Passed to `mercurDashboardPlugin()` in `vite.config.ts` to configure
|
|
55
|
-
* the vendor or admin dashboard at build time.
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```ts
|
|
59
|
-
* mercurDashboardPlugin({
|
|
60
|
-
* medusaConfigPath: '../../packages/api/medusa-config.ts',
|
|
61
|
-
* enableSellerRegistration: true,
|
|
62
|
-
* })
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
interface MercurConfig {
|
|
66
|
-
/** Path to the MedusaJS config file, resolved relative to the project root. */
|
|
67
|
-
medusaConfigPath: string;
|
|
68
|
-
/**
|
|
69
|
-
* Backend URL for API requests.
|
|
70
|
-
* @default "http://localhost:9000"
|
|
71
|
-
*/
|
|
72
|
-
backendUrl?: string;
|
|
73
|
-
/**
|
|
74
|
-
* Absolute base URL for the vendor dashboard, including any path prefix
|
|
75
|
-
* (for example `https://vendors.example.com/seller`).
|
|
76
|
-
*
|
|
77
|
-
* The plugin does not read `.env` files on its own. Load env in your
|
|
78
|
-
* app's `vite.config.ts` and pass the value here when you need
|
|
79
|
-
* cross-origin links such as seller invite URLs.
|
|
80
|
-
*
|
|
81
|
-
* If omitted, the plugin falls back to vendor module dev server
|
|
82
|
-
* detection in development and to the configured vendor path in
|
|
83
|
-
* production.
|
|
84
|
-
*/
|
|
85
|
-
vendorUrl?: string;
|
|
86
|
-
/** Dashboard display name. */
|
|
87
|
-
name?: string;
|
|
88
|
-
/** Path to a logo asset for the dashboard. */
|
|
89
|
-
logo?: string;
|
|
90
|
-
/** Internationalization settings. */
|
|
91
|
-
i18n?: {
|
|
92
|
-
/** The default language code (e.g. `"en"`). */
|
|
93
|
-
defaultLanguage: string;
|
|
94
|
-
};
|
|
95
|
-
/** Whether to allow new sellers to register from the login screen. */
|
|
96
|
-
enableSellerRegistration?: boolean;
|
|
97
|
-
/**
|
|
98
|
-
* Maximum allowed size for image uploads, in bytes.
|
|
99
|
-
* Used by dashboard upload components to reject oversized files
|
|
100
|
-
* before they are sent to the backend.
|
|
101
|
-
* @default 2_097_152 // 2 MB
|
|
102
|
-
*/
|
|
103
|
-
imageLimit?: number;
|
|
104
|
-
}
|
|
105
|
-
interface BuiltMercurConfig extends MercurConfig {
|
|
106
|
-
backendUrl: string;
|
|
107
|
-
base?: string;
|
|
108
|
-
root: string;
|
|
109
|
-
srcDir: string;
|
|
110
|
-
pluginExtensions: string[];
|
|
111
|
-
imageLimit: number;
|
|
112
|
-
}
|
|
113
|
-
type RouteConfig = {
|
|
114
|
-
label: string;
|
|
115
|
-
icon?: ComponentType;
|
|
116
|
-
rank?: number;
|
|
117
|
-
nested?: string;
|
|
118
|
-
translationNs?: string;
|
|
119
|
-
public?: boolean;
|
|
120
|
-
/**
|
|
121
|
-
* Permissions the actor must hold for this route's sidebar entry to be
|
|
122
|
-
* shown. Enforcement of the route itself comes from `handle.permissions`
|
|
123
|
-
* — this only controls navigation visibility.
|
|
124
|
-
*/
|
|
125
|
-
permissions?: Permission[];
|
|
126
|
-
/** If true, ALL `permissions` are required. Defaults to ANY. */
|
|
127
|
-
requireAll?: boolean;
|
|
128
|
-
};
|
|
129
|
-
/**
|
|
130
|
-
* The value of a route module's `export const handle`. Read by react-router's
|
|
131
|
-
* `useMatches()`; `permissions` is enforced by `RoutePermissionGuard`.
|
|
132
|
-
*/
|
|
133
|
-
type RouteHandle = {
|
|
134
|
-
permissions?: Permission | Permission[];
|
|
135
|
-
/** If true (default at the route level), ALL permissions are required. */
|
|
136
|
-
requireAll?: boolean;
|
|
137
|
-
/** Where to send the actor on denial. Renders Access Denied when unset. */
|
|
138
|
-
redirectTo?: string;
|
|
139
|
-
breadcrumb?: (match: never) => ReactNode;
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
export { type BuiltMercurConfig as B, type MercurConfig as M, OPERATION_IMPLICATIONS as O, type Permission as P, type RouteConfig as R, type UserPolicy as U, type PermissionOperation as a, type PermissionRequirement as b, type PermissionResource as c, type PermissionsContextValue as d, type PermissionsRequirementsContextValue as e, type RouteHandle as f, buildPermission as g, parsePermission as p };
|