@coopenomics/extension-kit 2026.10.11 → 2026.10.15
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 +12 -9
- package/dist/index.d.cts +14 -0
- package/dist/index.d.mts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.mjs +12 -9
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -573,8 +573,8 @@ async function checkRight(def, caller, roles, requirement, args) {
|
|
|
573
573
|
const { granted, missing } = await grantedActions(def, caller, roles, requirement.resource, actions);
|
|
574
574
|
if (granted.length === 0) {
|
|
575
575
|
if (missing === void 0)
|
|
576
|
-
return { allowed: false, reason: "right", denial: NO_RIGHT };
|
|
577
|
-
return { allowed: false, reason: "condition", denial: def.conditionDenials?.[missing] ?? NO_RIGHT };
|
|
576
|
+
return { allowed: false, reason: "right", denial: def.noRightDenial ?? NO_RIGHT };
|
|
577
|
+
return { allowed: false, reason: "condition", denial: def.conditionDenials?.[missing] ?? def.noRightDenial ?? NO_RIGHT };
|
|
578
578
|
}
|
|
579
579
|
const scope = await checkRightScope({
|
|
580
580
|
resource: requirement.resource,
|
|
@@ -632,26 +632,29 @@ exports.RightsGuard = class RightsGuard {
|
|
|
632
632
|
context.getHandler(),
|
|
633
633
|
context.getClass()
|
|
634
634
|
]);
|
|
635
|
-
if (!requirement)
|
|
636
|
-
return true;
|
|
637
635
|
const gql = graphql.GqlExecutionContext.create(context);
|
|
638
636
|
const request = gql.getContext()?.req;
|
|
637
|
+
const user = request?.user;
|
|
638
|
+
const signedIn = user?.username ? { username: user.username, role: user.role, status: user.status } : null;
|
|
639
|
+
if (this.def.onRequest)
|
|
640
|
+
await this.def.onRequest(signedIn, request);
|
|
641
|
+
if (!requirement)
|
|
642
|
+
return true;
|
|
639
643
|
if (hasServerSecret(request?.headers)) {
|
|
640
644
|
const everything = { scopes: ["all"], kus: null };
|
|
641
645
|
if (request)
|
|
642
646
|
request[GRANTED_SCOPE_KEY] = everything;
|
|
643
647
|
return true;
|
|
644
648
|
}
|
|
645
|
-
|
|
646
|
-
if (!user?.username)
|
|
649
|
+
if (!signedIn && !this.def.guestRoles)
|
|
647
650
|
throw DomainError.unauthorized("KIT_USER_NOT_AUTHORIZED");
|
|
648
|
-
const caller = { username:
|
|
649
|
-
const roles = await this.def.roles(caller, request);
|
|
651
|
+
const caller = signedIn ?? { username: "" };
|
|
652
|
+
const roles = signedIn ? await this.def.roles(caller, request) : [...this.def.guestRoles ?? []];
|
|
650
653
|
const outcome = await checkRight(this.def, caller, roles, requirement, gql.getArgs() ?? {});
|
|
651
654
|
if (!outcome.allowed) {
|
|
652
655
|
const actions = Array.isArray(requirement.action) ? requirement.action.join("|") : requirement.action;
|
|
653
656
|
this.logger.warn(
|
|
654
|
-
`forbidden-attempt: member=${caller.username} extension=${this.def.extensionName} operation=${context.getClass()?.name}.${context.getHandler()?.name} right=${requirement.resource}:${actions} reason=${outcome.reason} denial=${outcome.denial} roles=[${roles.join(", ")}]`
|
|
657
|
+
`forbidden-attempt: member=${caller.username || "guest"} extension=${this.def.extensionName} operation=${context.getClass()?.name}.${context.getHandler()?.name} right=${requirement.resource}:${actions} reason=${outcome.reason} denial=${outcome.denial} roles=[${roles.join(", ")}]`
|
|
655
658
|
);
|
|
656
659
|
throw DomainError.forbidden(outcome.denial);
|
|
657
660
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -340,6 +340,14 @@ interface AppRights<R extends string = string, C extends string = string> {
|
|
|
340
340
|
* когда без них право не складывается.
|
|
341
341
|
*/
|
|
342
342
|
readonly lazyConditions?: readonly C[];
|
|
343
|
+
/**
|
|
344
|
+
* Роли гостя — вызова без входа. Не названы — операция с требованием права
|
|
345
|
+
* без входа получает отказ входа. Названы — гость сверяется с таблицей как
|
|
346
|
+
* пайщик с этими ролями (охват «своё» ему закрыт: имени у гостя нет).
|
|
347
|
+
*/
|
|
348
|
+
readonly guestRoles?: readonly R[];
|
|
349
|
+
/** Код отказа «права нет»; по умолчанию `KIT_INSUFFICIENT_RIGHTS`. */
|
|
350
|
+
readonly noRightDenial?: string;
|
|
343
351
|
/**
|
|
344
352
|
* Роли таблицы, которые председатель назначает пайщикам на странице
|
|
345
353
|
* управления доступом. Приложение объявляет их ядру при запуске и
|
|
@@ -353,6 +361,12 @@ interface AppRights<R extends string = string, C extends string = string> {
|
|
|
353
361
|
readonly attachedRoles?: readonly AttachedRole<R>[];
|
|
354
362
|
/** Роли приложения у пайщика. `request` — запрос, если роли уже посчитал гард членства. */
|
|
355
363
|
roles(caller: RightsCaller, request?: unknown): Promise<R[]>;
|
|
364
|
+
/**
|
|
365
|
+
* Вызывается гардом на каждый запрос операции, стоящей под ним, до сверки
|
|
366
|
+
* права — и для операций без требования. Приложение кладёт в запрос то, что
|
|
367
|
+
* нужно его операциям о вошедшем (членство, роли); `caller` — null для гостя.
|
|
368
|
+
*/
|
|
369
|
+
onRequest?(caller: RightsCaller | null, request: unknown): Promise<void>;
|
|
356
370
|
/**
|
|
357
371
|
* Какие из условий `wanted` выполнены. `config` — настройки расширения,
|
|
358
372
|
* когда вызывающий их уже прочитал.
|
package/dist/index.d.mts
CHANGED
|
@@ -340,6 +340,14 @@ interface AppRights<R extends string = string, C extends string = string> {
|
|
|
340
340
|
* когда без них право не складывается.
|
|
341
341
|
*/
|
|
342
342
|
readonly lazyConditions?: readonly C[];
|
|
343
|
+
/**
|
|
344
|
+
* Роли гостя — вызова без входа. Не названы — операция с требованием права
|
|
345
|
+
* без входа получает отказ входа. Названы — гость сверяется с таблицей как
|
|
346
|
+
* пайщик с этими ролями (охват «своё» ему закрыт: имени у гостя нет).
|
|
347
|
+
*/
|
|
348
|
+
readonly guestRoles?: readonly R[];
|
|
349
|
+
/** Код отказа «права нет»; по умолчанию `KIT_INSUFFICIENT_RIGHTS`. */
|
|
350
|
+
readonly noRightDenial?: string;
|
|
343
351
|
/**
|
|
344
352
|
* Роли таблицы, которые председатель назначает пайщикам на странице
|
|
345
353
|
* управления доступом. Приложение объявляет их ядру при запуске и
|
|
@@ -353,6 +361,12 @@ interface AppRights<R extends string = string, C extends string = string> {
|
|
|
353
361
|
readonly attachedRoles?: readonly AttachedRole<R>[];
|
|
354
362
|
/** Роли приложения у пайщика. `request` — запрос, если роли уже посчитал гард членства. */
|
|
355
363
|
roles(caller: RightsCaller, request?: unknown): Promise<R[]>;
|
|
364
|
+
/**
|
|
365
|
+
* Вызывается гардом на каждый запрос операции, стоящей под ним, до сверки
|
|
366
|
+
* права — и для операций без требования. Приложение кладёт в запрос то, что
|
|
367
|
+
* нужно его операциям о вошедшем (членство, роли); `caller` — null для гостя.
|
|
368
|
+
*/
|
|
369
|
+
onRequest?(caller: RightsCaller | null, request: unknown): Promise<void>;
|
|
356
370
|
/**
|
|
357
371
|
* Какие из условий `wanted` выполнены. `config` — настройки расширения,
|
|
358
372
|
* когда вызывающий их уже прочитал.
|
package/dist/index.d.ts
CHANGED
|
@@ -340,6 +340,14 @@ interface AppRights<R extends string = string, C extends string = string> {
|
|
|
340
340
|
* когда без них право не складывается.
|
|
341
341
|
*/
|
|
342
342
|
readonly lazyConditions?: readonly C[];
|
|
343
|
+
/**
|
|
344
|
+
* Роли гостя — вызова без входа. Не названы — операция с требованием права
|
|
345
|
+
* без входа получает отказ входа. Названы — гость сверяется с таблицей как
|
|
346
|
+
* пайщик с этими ролями (охват «своё» ему закрыт: имени у гостя нет).
|
|
347
|
+
*/
|
|
348
|
+
readonly guestRoles?: readonly R[];
|
|
349
|
+
/** Код отказа «права нет»; по умолчанию `KIT_INSUFFICIENT_RIGHTS`. */
|
|
350
|
+
readonly noRightDenial?: string;
|
|
343
351
|
/**
|
|
344
352
|
* Роли таблицы, которые председатель назначает пайщикам на странице
|
|
345
353
|
* управления доступом. Приложение объявляет их ядру при запуске и
|
|
@@ -353,6 +361,12 @@ interface AppRights<R extends string = string, C extends string = string> {
|
|
|
353
361
|
readonly attachedRoles?: readonly AttachedRole<R>[];
|
|
354
362
|
/** Роли приложения у пайщика. `request` — запрос, если роли уже посчитал гард членства. */
|
|
355
363
|
roles(caller: RightsCaller, request?: unknown): Promise<R[]>;
|
|
364
|
+
/**
|
|
365
|
+
* Вызывается гардом на каждый запрос операции, стоящей под ним, до сверки
|
|
366
|
+
* права — и для операций без требования. Приложение кладёт в запрос то, что
|
|
367
|
+
* нужно его операциям о вошедшем (членство, роли); `caller` — null для гостя.
|
|
368
|
+
*/
|
|
369
|
+
onRequest?(caller: RightsCaller | null, request: unknown): Promise<void>;
|
|
356
370
|
/**
|
|
357
371
|
* Какие из условий `wanted` выполнены. `config` — настройки расширения,
|
|
358
372
|
* когда вызывающий их уже прочитал.
|
package/dist/index.mjs
CHANGED
|
@@ -565,8 +565,8 @@ async function checkRight(def, caller, roles, requirement, args) {
|
|
|
565
565
|
const { granted, missing } = await grantedActions(def, caller, roles, requirement.resource, actions);
|
|
566
566
|
if (granted.length === 0) {
|
|
567
567
|
if (missing === void 0)
|
|
568
|
-
return { allowed: false, reason: "right", denial: NO_RIGHT };
|
|
569
|
-
return { allowed: false, reason: "condition", denial: def.conditionDenials?.[missing] ?? NO_RIGHT };
|
|
568
|
+
return { allowed: false, reason: "right", denial: def.noRightDenial ?? NO_RIGHT };
|
|
569
|
+
return { allowed: false, reason: "condition", denial: def.conditionDenials?.[missing] ?? def.noRightDenial ?? NO_RIGHT };
|
|
570
570
|
}
|
|
571
571
|
const scope = await checkRightScope({
|
|
572
572
|
resource: requirement.resource,
|
|
@@ -624,26 +624,29 @@ let RightsGuard = class {
|
|
|
624
624
|
context.getHandler(),
|
|
625
625
|
context.getClass()
|
|
626
626
|
]);
|
|
627
|
-
if (!requirement)
|
|
628
|
-
return true;
|
|
629
627
|
const gql = GqlExecutionContext.create(context);
|
|
630
628
|
const request = gql.getContext()?.req;
|
|
629
|
+
const user = request?.user;
|
|
630
|
+
const signedIn = user?.username ? { username: user.username, role: user.role, status: user.status } : null;
|
|
631
|
+
if (this.def.onRequest)
|
|
632
|
+
await this.def.onRequest(signedIn, request);
|
|
633
|
+
if (!requirement)
|
|
634
|
+
return true;
|
|
631
635
|
if (hasServerSecret(request?.headers)) {
|
|
632
636
|
const everything = { scopes: ["all"], kus: null };
|
|
633
637
|
if (request)
|
|
634
638
|
request[GRANTED_SCOPE_KEY] = everything;
|
|
635
639
|
return true;
|
|
636
640
|
}
|
|
637
|
-
|
|
638
|
-
if (!user?.username)
|
|
641
|
+
if (!signedIn && !this.def.guestRoles)
|
|
639
642
|
throw DomainError.unauthorized("KIT_USER_NOT_AUTHORIZED");
|
|
640
|
-
const caller = { username:
|
|
641
|
-
const roles = await this.def.roles(caller, request);
|
|
643
|
+
const caller = signedIn ?? { username: "" };
|
|
644
|
+
const roles = signedIn ? await this.def.roles(caller, request) : [...this.def.guestRoles ?? []];
|
|
642
645
|
const outcome = await checkRight(this.def, caller, roles, requirement, gql.getArgs() ?? {});
|
|
643
646
|
if (!outcome.allowed) {
|
|
644
647
|
const actions = Array.isArray(requirement.action) ? requirement.action.join("|") : requirement.action;
|
|
645
648
|
this.logger.warn(
|
|
646
|
-
`forbidden-attempt: member=${caller.username} extension=${this.def.extensionName} operation=${context.getClass()?.name}.${context.getHandler()?.name} right=${requirement.resource}:${actions} reason=${outcome.reason} denial=${outcome.denial} roles=[${roles.join(", ")}]`
|
|
649
|
+
`forbidden-attempt: member=${caller.username || "guest"} extension=${this.def.extensionName} operation=${context.getClass()?.name}.${context.getHandler()?.name} right=${requirement.resource}:${actions} reason=${outcome.reason} denial=${outcome.denial} roles=[${roles.join(", ")}]`
|
|
647
650
|
);
|
|
648
651
|
throw DomainError.forbidden(outcome.denial);
|
|
649
652
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coopenomics/extension-kit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2026.10.
|
|
4
|
+
"version": "2026.10.15",
|
|
5
5
|
"description": "Служебный каркас расширения цифрового кооператива: базовый модуль, сущности и репозитории расширения, авторизация, каркас блокчейн-синхронизации, контракт миграций схемы, контракт реестра",
|
|
6
6
|
"author": "Alex Ant <dacom.dark.sun@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@casl/ability": "^7.0.0",
|
|
42
42
|
"@coopenomics/i18n": "workspace:*",
|
|
43
|
-
"@coopenomics/sdk": "2026.10.
|
|
43
|
+
"@coopenomics/sdk": "2026.10.15",
|
|
44
44
|
"@nestjs/common": "^10.0.0",
|
|
45
45
|
"@nestjs/core": "^10.0.0",
|
|
46
46
|
"@nestjs/graphql": "^12.2.1",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@casl/ability": "^7.0.0",
|
|
64
|
-
"@coopenomics/i18n": "2026.10.
|
|
64
|
+
"@coopenomics/i18n": "2026.10.15",
|
|
65
65
|
"@nestjs/common": "^10.0.0",
|
|
66
66
|
"@nestjs/core": "^10.0.0",
|
|
67
67
|
"@nestjs/graphql": "^12.2.1",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@wharfkit/session": "^1.4.0",
|
|
71
71
|
"class-transformer": "^0.5.1",
|
|
72
72
|
"class-validator": "^0.14.1",
|
|
73
|
-
"cooptypes": "2026.10.
|
|
73
|
+
"cooptypes": "2026.10.15",
|
|
74
74
|
"graphql": "^16.9.0",
|
|
75
75
|
"graphql-type-json": "^0.3.2",
|
|
76
76
|
"kysely": "0.28.17",
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"unbuild": "^2.0.0",
|
|
83
83
|
"zod": "^3.0.0"
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "8b81459760f93fc07335f02f7898310c6366e5c6"
|
|
86
86
|
}
|