@mamindom/common 1.0.94 → 1.0.98

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.
@@ -9,6 +9,16 @@ export declare const GRPC_CLIENTS: {
9
9
  readonly protoPath: string;
10
10
  readonly env: "AUTH_GRPC_URL";
11
11
  };
12
+ readonly RBAC_PACKAGE: {
13
+ readonly package: "rbac.v1";
14
+ readonly protoPath: string;
15
+ readonly env: "AUTH_GRPC_URL";
16
+ };
17
+ readonly AUDIT_PACKAGE: {
18
+ readonly package: "audit.v1";
19
+ readonly protoPath: string;
20
+ readonly env: "AUTH_GRPC_URL";
21
+ };
12
22
  readonly USERS_PACKAGE: {
13
23
  readonly package: "users.v1";
14
24
  readonly protoPath: string;
@@ -26,7 +36,7 @@ export declare const GRPC_CLIENTS: {
26
36
  };
27
37
  readonly PROMO_PACKAGE: {
28
38
  readonly package: "promo.v1";
29
- readonly protoPath: readonly [string, string, string, string];
39
+ readonly protoPath: readonly [string, string, string, string, string];
30
40
  readonly env: "PROMO_GRPC_URL";
31
41
  };
32
42
  readonly CONTENT_PACKAGE: {
@@ -44,6 +54,11 @@ export declare const GRPC_CLIENTS: {
44
54
  readonly protoPath: readonly [string];
45
55
  readonly env: "ORDER_GRPC_URL";
46
56
  };
57
+ readonly MANAGER_PACKAGE: {
58
+ readonly package: "manager.v1";
59
+ readonly protoPath: readonly [string];
60
+ readonly env: "ORDER_GRPC_URL";
61
+ };
47
62
  readonly PAYMENT_PACKAGE: {
48
63
  readonly package: "payment.v1";
49
64
  readonly protoPath: readonly [string];
@@ -51,7 +66,12 @@ export declare const GRPC_CLIENTS: {
51
66
  };
52
67
  readonly DELIVERY_PACKAGE: {
53
68
  readonly package: "delivery.v1";
54
- readonly protoPath: readonly [string];
69
+ readonly protoPath: readonly [string, string];
55
70
  readonly env: "DELIVERY_GRPC_URL";
56
71
  };
72
+ readonly NOTIFICATION_PACKAGE: {
73
+ readonly package: "notification.v1";
74
+ readonly protoPath: readonly [string];
75
+ readonly env: "NOTIFICATION_GRPC_URL";
76
+ };
57
77
  };
@@ -13,6 +13,16 @@ exports.GRPC_CLIENTS = {
13
13
  protoPath: contracts_1.PROTO_PATHS.ACCOUNT,
14
14
  env: 'AUTH_GRPC_URL'
15
15
  },
16
+ RBAC_PACKAGE: {
17
+ package: 'rbac.v1',
18
+ protoPath: contracts_1.PROTO_PATHS.RBAC,
19
+ env: 'AUTH_GRPC_URL'
20
+ },
21
+ AUDIT_PACKAGE: {
22
+ package: 'audit.v1',
23
+ protoPath: contracts_1.PROTO_PATHS.AUDIT,
24
+ env: 'AUTH_GRPC_URL'
25
+ },
16
26
  USERS_PACKAGE: {
17
27
  package: 'users.v1',
18
28
  protoPath: contracts_1.PROTO_PATHS.USERS,
@@ -47,7 +57,8 @@ exports.GRPC_CLIENTS = {
47
57
  contracts_1.PROTO_PATHS.COMMON_PROMO,
48
58
  contracts_1.PROTO_PATHS.CALCULATION,
49
59
  contracts_1.PROTO_PATHS.PROMOTION,
50
- contracts_1.PROTO_PATHS.COUPON
60
+ contracts_1.PROTO_PATHS.COUPON,
61
+ contracts_1.PROTO_PATHS.BONUS_SETTINGS
51
62
  ],
52
63
  env: 'PROMO_GRPC_URL'
53
64
  },
@@ -77,6 +88,11 @@ exports.GRPC_CLIENTS = {
77
88
  protoPath: [contracts_1.PROTO_PATHS.ORDER],
78
89
  env: 'ORDER_GRPC_URL'
79
90
  },
91
+ MANAGER_PACKAGE: {
92
+ package: 'manager.v1',
93
+ protoPath: [contracts_1.PROTO_PATHS.MANAGER],
94
+ env: 'ORDER_GRPC_URL'
95
+ },
80
96
  PAYMENT_PACKAGE: {
81
97
  package: 'payment.v1',
82
98
  protoPath: [contracts_1.PROTO_PATHS.PAYMENT],
@@ -84,7 +100,12 @@ exports.GRPC_CLIENTS = {
84
100
  },
85
101
  DELIVERY_PACKAGE: {
86
102
  package: 'delivery.v1',
87
- protoPath: [contracts_1.PROTO_PATHS.DELIVERY],
103
+ protoPath: [contracts_1.PROTO_PATHS.DELIVERY, contracts_1.PROTO_PATHS.DELIVERY_SETTINGS],
88
104
  env: 'DELIVERY_GRPC_URL'
105
+ },
106
+ NOTIFICATION_PACKAGE: {
107
+ package: 'notification.v1',
108
+ protoPath: [contracts_1.PROTO_PATHS.NOTIFICATION],
109
+ env: 'NOTIFICATION_GRPC_URL'
89
110
  }
90
111
  };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './enum';
2
2
  export * from './grpc';
3
+ export * from './rbac';
3
4
  export * from './utils';
package/dist/index.js CHANGED
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./enum"), exports);
18
18
  __exportStar(require("./grpc"), exports);
19
+ __exportStar(require("./rbac"), exports);
19
20
  __exportStar(require("./utils"), exports);
@@ -0,0 +1 @@
1
+ export * from './permissions';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./permissions"), exports);
@@ -0,0 +1,23 @@
1
+ export interface PermissionDefinition {
2
+ key: string;
3
+ groupKey: string;
4
+ label: string;
5
+ description?: string;
6
+ }
7
+ export interface PermissionGroup {
8
+ key: string;
9
+ label: string;
10
+ permissions: PermissionDefinition[];
11
+ }
12
+ export declare const PERMISSION_GROUPS: PermissionGroup[];
13
+ export declare const ALL_PERMISSIONS: PermissionDefinition[];
14
+ export declare const ALL_PERMISSION_KEYS: string[];
15
+ export declare const WILDCARD_PERMISSION = "*";
16
+ export declare const SYSTEM_ROLE_DEFAULTS: Record<'admin' | 'manager' | 'copywriter' | 'seo' | 'user', {
17
+ name: string;
18
+ color: string;
19
+ isProtected: boolean;
20
+ permissions: string[];
21
+ }>;
22
+ export declare function hasPermission(granted: string[], required: string): boolean;
23
+ export declare function hasPermissions(granted: string[], required: string[], mode?: 'all' | 'any'): boolean;
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ // Каталог усіх можливих дозволів. Single source of truth — імпортується
3
+ // auth-service для seed-у, gateway-service для guard'у, frontend-ом для UI.
4
+ // Зміни тут вимагають re-seed + sync-local-packages.sh.
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SYSTEM_ROLE_DEFAULTS = exports.WILDCARD_PERMISSION = exports.ALL_PERMISSION_KEYS = exports.ALL_PERMISSIONS = exports.PERMISSION_GROUPS = void 0;
7
+ exports.hasPermission = hasPermission;
8
+ exports.hasPermissions = hasPermissions;
9
+ exports.PERMISSION_GROUPS = [
10
+ {
11
+ key: 'products',
12
+ label: 'Товари',
13
+ permissions: [
14
+ { key: 'products.view', groupKey: 'products', label: 'Перегляд товарів' },
15
+ { key: 'products.create', groupKey: 'products', label: 'Створення товарів' },
16
+ {
17
+ key: 'products.edit_content',
18
+ groupKey: 'products',
19
+ label: 'Редагування описів та фото'
20
+ },
21
+ { key: 'products.edit_seo', groupKey: 'products', label: 'Редагування SEO полів' },
22
+ { key: 'products.edit_price', groupKey: 'products', label: 'Зміна цін' },
23
+ { key: 'products.delete', groupKey: 'products', label: 'Видалення товарів' },
24
+ { key: 'products.bulk', groupKey: 'products', label: 'Масові операції' }
25
+ ]
26
+ },
27
+ {
28
+ key: 'orders',
29
+ label: 'Замовлення',
30
+ permissions: [
31
+ { key: 'orders.view', groupKey: 'orders', label: 'Перегляд замовлень' },
32
+ { key: 'orders.create', groupKey: 'orders', label: 'Створення замовлень' },
33
+ { key: 'orders.edit', groupKey: 'orders', label: 'Редагування замовлень' },
34
+ { key: 'orders.cancel', groupKey: 'orders', label: 'Скасування замовлень' },
35
+ { key: 'orders.refund', groupKey: 'orders', label: 'Повернення коштів' },
36
+ { key: 'orders.assign', groupKey: 'orders', label: 'Призначення менеджера' }
37
+ ]
38
+ },
39
+ {
40
+ key: 'customers',
41
+ label: 'Клієнти',
42
+ permissions: [
43
+ { key: 'customers.view', groupKey: 'customers', label: 'Перегляд клієнтів' },
44
+ { key: 'customers.edit', groupKey: 'customers', label: 'Редагування клієнтів' },
45
+ { key: 'customers.export', groupKey: 'customers', label: 'Експорт бази' }
46
+ ]
47
+ },
48
+ {
49
+ key: 'content',
50
+ label: 'Контент',
51
+ permissions: [
52
+ { key: 'content.blog.view', groupKey: 'content', label: 'Перегляд блогу' },
53
+ { key: 'content.blog.create', groupKey: 'content', label: 'Створення постів' },
54
+ { key: 'content.blog.publish', groupKey: 'content', label: 'Публікація постів' },
55
+ { key: 'content.pages.edit', groupKey: 'content', label: 'Редагування сторінок' },
56
+ { key: 'content.banners.edit', groupKey: 'content', label: 'Керування банерами' },
57
+ { key: 'content.faq.edit', groupKey: 'content', label: 'FAQ' }
58
+ ]
59
+ },
60
+ {
61
+ key: 'seo',
62
+ label: 'SEO',
63
+ permissions: [
64
+ { key: 'seo.meta', groupKey: 'seo', label: 'Meta-теги' },
65
+ { key: 'seo.redirects', groupKey: 'seo', label: 'Редиректи' },
66
+ { key: 'seo.sitemap', groupKey: 'seo', label: 'Sitemap' },
67
+ { key: 'seo.robots', groupKey: 'seo', label: 'Robots.txt' }
68
+ ]
69
+ },
70
+ {
71
+ key: 'promotions',
72
+ label: 'Акції та бонуси',
73
+ permissions: [
74
+ { key: 'promotions.view', groupKey: 'promotions', label: 'Перегляд акцій' },
75
+ { key: 'promotions.edit', groupKey: 'promotions', label: 'Створення/редагування акцій' },
76
+ { key: 'promotions.coupons', groupKey: 'promotions', label: 'Керування купонами' },
77
+ { key: 'promotions.bonuses', groupKey: 'promotions', label: 'Бонусні налаштування' }
78
+ ]
79
+ },
80
+ {
81
+ key: 'reviews',
82
+ label: 'Відгуки',
83
+ permissions: [
84
+ { key: 'reviews.view', groupKey: 'reviews', label: 'Перегляд відгуків' },
85
+ { key: 'reviews.moderate', groupKey: 'reviews', label: 'Модерація відгуків' }
86
+ ]
87
+ },
88
+ {
89
+ key: 'system',
90
+ label: 'Система',
91
+ permissions: [
92
+ { key: 'settings.general', groupKey: 'system', label: 'Загальні налаштування' },
93
+ { key: 'settings.payment', groupKey: 'system', label: 'Модулі оплати' },
94
+ { key: 'settings.delivery', groupKey: 'system', label: 'Модулі доставки' },
95
+ { key: 'settings.api', groupKey: 'system', label: 'API ключі' },
96
+ { key: 'settings.notifications', groupKey: 'system', label: 'Email та push шаблони' },
97
+ { key: 'users.manage', groupKey: 'system', label: 'Керування користувачами' },
98
+ { key: 'roles.manage', groupKey: 'system', label: 'Керування ролями' },
99
+ { key: 'managers.view', groupKey: 'system', label: 'Перегляд менеджерів' },
100
+ { key: 'managers.manage', groupKey: 'system', label: 'Керування менеджерами' },
101
+ { key: 'audit.view', groupKey: 'system', label: 'Перегляд audit log' },
102
+ { key: 'reports.view', groupKey: 'system', label: 'Перегляд звітів' }
103
+ ]
104
+ }
105
+ ];
106
+ exports.ALL_PERMISSIONS = exports.PERMISSION_GROUPS.flatMap(g => g.permissions);
107
+ exports.ALL_PERMISSION_KEYS = exports.ALL_PERMISSIONS.map(p => p.key);
108
+ // Маркер "повний доступ" — ADMIN. Не зберігається в БД як окремий permission.
109
+ exports.WILDCARD_PERMISSION = '*';
110
+ // Дефолтні пермішени для системних ролей (seed values).
111
+ // Можна редагувати в адмінці після seed-у, крім ADMIN.
112
+ exports.SYSTEM_ROLE_DEFAULTS = {
113
+ admin: {
114
+ name: 'Адміністратор',
115
+ color: '#dc2626',
116
+ isProtected: true,
117
+ permissions: [exports.WILDCARD_PERMISSION]
118
+ },
119
+ manager: {
120
+ name: 'Менеджер магазину',
121
+ color: '#2563eb',
122
+ isProtected: false,
123
+ permissions: [
124
+ 'orders.view',
125
+ 'orders.create',
126
+ 'orders.edit',
127
+ 'orders.cancel',
128
+ 'orders.refund',
129
+ 'orders.assign',
130
+ 'customers.view',
131
+ 'customers.edit',
132
+ 'reviews.view',
133
+ 'reviews.moderate',
134
+ 'products.view',
135
+ 'reports.view'
136
+ ]
137
+ },
138
+ copywriter: {
139
+ name: 'Копірайтер',
140
+ color: '#7c3aed',
141
+ isProtected: false,
142
+ permissions: [
143
+ 'products.view',
144
+ 'products.edit_content',
145
+ 'content.blog.view',
146
+ 'content.blog.create',
147
+ 'content.blog.publish',
148
+ 'content.pages.edit',
149
+ 'content.faq.edit'
150
+ ]
151
+ },
152
+ seo: {
153
+ name: 'SEO-фахівець',
154
+ color: '#059669',
155
+ isProtected: false,
156
+ permissions: [
157
+ 'products.view',
158
+ 'products.edit_seo',
159
+ 'products.edit_content',
160
+ 'content.pages.edit',
161
+ 'content.blog.view',
162
+ 'seo.meta',
163
+ 'seo.redirects',
164
+ 'seo.sitemap',
165
+ 'seo.robots'
166
+ ]
167
+ },
168
+ user: {
169
+ name: 'Користувач',
170
+ color: '#6b7280',
171
+ isProtected: true,
172
+ permissions: []
173
+ }
174
+ };
175
+ // Перевірка чи має набір permissions конкретний дозвіл.
176
+ // Підтримує wildcard "*" (повний доступ).
177
+ function hasPermission(granted, required) {
178
+ if (granted.includes(exports.WILDCARD_PERMISSION))
179
+ return true;
180
+ return granted.includes(required);
181
+ }
182
+ // Перевірка набору required permissions проти granted.
183
+ // Режим "all" — потрібні всі; режим "any" — достатньо одного.
184
+ function hasPermissions(granted, required, mode = 'all') {
185
+ if (granted.includes(exports.WILDCARD_PERMISSION))
186
+ return true;
187
+ if (required.length === 0)
188
+ return true;
189
+ return mode === 'all'
190
+ ? required.every(p => granted.includes(p))
191
+ : required.some(p => granted.includes(p));
192
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mamindom/common",
3
- "version": "1.0.94",
3
+ "version": "1.0.98",
4
4
  "type": "commonjs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -21,7 +21,7 @@
21
21
  "typescript": "^5.9.3"
22
22
  },
23
23
  "dependencies": {
24
- "@mamindom/contracts": "^1.0.123",
24
+ "@mamindom/contracts": "^1.0.127",
25
25
  "@nestjs/common": "^11.1.16",
26
26
  "@nestjs/config": "^4.0.3",
27
27
  "@nestjs/microservices": "^11.1.16"