@coopenomics/notifications 2026.9.22 → 2026.9.24-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.
- package/dist/index.cjs +1579 -2664
- package/dist/index.d.cts +238 -215
- package/dist/index.d.mts +238 -215
- package/dist/index.d.ts +238 -215
- package/dist/index.mjs +1576 -2665
- package/package.json +3 -2
- package/src/base/workflow-builder.ts +11 -0
- package/src/i18n/index.ts +52 -0
- package/src/i18n/ru.json +946 -0
- package/src/index.ts +1 -0
- package/src/types/index.ts +2 -0
- package/src/utils/slugify/builtinReplacements.ts +1 -0
- package/src/workflows/approval-request/index.ts +13 -10
- package/src/workflows/approval-response/index.ts +13 -16
- package/src/workflows/branch-meeting-reminder/index.ts +13 -10
- package/src/workflows/branch-trusted-requested/index.ts +13 -10
- package/src/workflows/branch-trusted-resolved/index.ts +13 -10
- package/src/workflows/branch-voting-started/index.ts +13 -10
- package/src/workflows/chatcoop-calendar-event-created/index.ts +13 -10
- package/src/workflows/chatcoop-calendar-event-updated/index.ts +13 -10
- package/src/workflows/decision-approved/index.ts +13 -10
- package/src/workflows/decision-expired/index.ts +13 -10
- package/src/workflows/document-approval-declined/index.ts +13 -10
- package/src/workflows/document-edition-available/index.ts +13 -10
- package/src/workflows/document-edition-reminder/index.ts +11 -8
- package/src/workflows/email-verification/index.ts +9 -10
- package/src/workflows/endorsement-expiring/index.ts +13 -10
- package/src/workflows/expense-advance-report-reminder/index.ts +11 -15
- package/src/workflows/incoming-transfer/index.ts +13 -10
- package/src/workflows/invite/index.ts +9 -7
- package/src/workflows/login-email-code/index.ts +9 -9
- package/src/workflows/marketplace-aid-council-decided/index.ts +13 -10
- package/src/workflows/marketplace-aid-payout-confirmed/index.ts +13 -10
- package/src/workflows/marketplace-apl-reception-cancelled-by-supplier/index.ts +11 -8
- package/src/workflows/marketplace-apl-supplier-sign-request/index.ts +13 -10
- package/src/workflows/marketplace-cashier-new-payment/index.ts +13 -10
- package/src/workflows/marketplace-issuance-decided/index.ts +13 -10
- package/src/workflows/marketplace-new-order-for-supplier/index.ts +11 -8
- package/src/workflows/marketplace-new-supplier-request/index.ts +13 -10
- package/src/workflows/marketplace-offer-approved/index.ts +13 -10
- package/src/workflows/marketplace-offer-on-moderation/index.ts +13 -10
- package/src/workflows/marketplace-offer-rejected/index.ts +13 -10
- package/src/workflows/marketplace-order-declined-by-supplier/index.ts +13 -10
- package/src/workflows/marketplace-order-ready/index.ts +13 -10
- package/src/workflows/marketplace-return-claim-decided/index.ts +13 -10
- package/src/workflows/marketplace-return-claim-finalized/index.ts +13 -10
- package/src/workflows/marketplace-return-claim-submitted/index.ts +13 -10
- package/src/workflows/marketplace-return-council-decided/index.ts +13 -10
- package/src/workflows/marketplace-supplier-approved/index.ts +13 -10
- package/src/workflows/marketplace-supplier-claim-issued/index.ts +13 -10
- package/src/workflows/marketplace-supplier-payment-confirmed/index.ts +13 -10
- package/src/workflows/marketplace-supplier-payment-declined/index.ts +13 -10
- package/src/workflows/marketplace-writeoff-authorized/index.ts +13 -10
- package/src/workflows/marketplace-writeoff-draft-built/index.ts +13 -10
- package/src/workflows/marketplace-writeoff-executed/index.ts +13 -10
- package/src/workflows/marketplace-writeoff-proposed/index.ts +13 -10
- package/src/workflows/marketplace-writeoff-rejected/index.ts +13 -10
- package/src/workflows/meet-ended/index.ts +13 -10
- package/src/workflows/meet-initial/index.ts +13 -10
- package/src/workflows/meet-reminder-end/index.ts +13 -10
- package/src/workflows/meet-reminder-start/index.ts +13 -10
- package/src/workflows/meet-restart/index.ts +13 -10
- package/src/workflows/meet-started/index.ts +13 -10
- package/src/workflows/membership-exit-confirmation/index.ts +9 -11
- package/src/workflows/new-agenda-item/index.ts +13 -10
- package/src/workflows/new-deposit-payment-request/index.ts +13 -10
- package/src/workflows/new-device-login/index.ts +11 -16
- package/src/workflows/new-initial-payment-request/index.ts +13 -10
- package/src/workflows/payment-cancelled/index.ts +13 -10
- package/src/workflows/payment-paid/index.ts +13 -10
- package/src/workflows/payment-refunded/index.ts +13 -10
- package/src/workflows/reset-key/index.ts +9 -9
- package/src/workflows/security-event/index.ts +11 -15
- package/src/workflows/server-provisioned/index.ts +13 -10
- package/src/workflows/welcome/index.ts +13 -10
- package/test/i18n.test.ts +103 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coopenomics/notifications",
|
|
3
|
-
"version": "2026.9.
|
|
3
|
+
"version": "2026.9.24-2",
|
|
4
4
|
"description": "Каталог типобезопасных типов уведомлений и шаблонов Центра уведомлений",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"test": "vitest run"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
+
"@coopenomics/i18n": "2026.9.24-2",
|
|
28
29
|
"transliteration": "^2.3.5",
|
|
29
30
|
"zod": "^3.22.4",
|
|
30
31
|
"zod-to-json-schema": "^3.22.5"
|
|
@@ -45,5 +46,5 @@
|
|
|
45
46
|
"require": "./dist/index.cjs"
|
|
46
47
|
}
|
|
47
48
|
},
|
|
48
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "08943be043e9451a6548b4934770d65ad37fa9e2"
|
|
49
50
|
}
|
|
@@ -18,6 +18,7 @@ export class WorkflowBuilder<T extends BaseWorkflowPayload> {
|
|
|
18
18
|
private _payloadZodSchema?: z.ZodSchema<T>;
|
|
19
19
|
private _origin?: NovuOrigin;
|
|
20
20
|
private _tags?: string[];
|
|
21
|
+
private _i18nKey?: string;
|
|
21
22
|
|
|
22
23
|
static create<T extends BaseWorkflowPayload>(): WorkflowBuilder<T> {
|
|
23
24
|
return new WorkflowBuilder<T>();
|
|
@@ -33,6 +34,12 @@ export class WorkflowBuilder<T extends BaseWorkflowPayload> {
|
|
|
33
34
|
return this;
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
/** Ключ сценария в словаре текстов (src/i18n) — для шаблона на языке получателя. */
|
|
38
|
+
i18nKey(key: string): this {
|
|
39
|
+
this._i18nKey = key;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
|
|
36
43
|
description(description: string): this {
|
|
37
44
|
this._description = description;
|
|
38
45
|
return this;
|
|
@@ -93,6 +100,10 @@ export class WorkflowBuilder<T extends BaseWorkflowPayload> {
|
|
|
93
100
|
workflow.origin = this._origin;
|
|
94
101
|
}
|
|
95
102
|
|
|
103
|
+
if (this._i18nKey) {
|
|
104
|
+
workflow.i18nKey = this._i18nKey;
|
|
105
|
+
}
|
|
106
|
+
|
|
96
107
|
// Добавляем tags только если они указаны
|
|
97
108
|
if (this._tags) {
|
|
98
109
|
workflow.tags = this._tags;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Тексты уведомлений по языкам.
|
|
3
|
+
*
|
|
4
|
+
* Словарь — `./<язык>.json`: по имени сценария (каталог в camelCase) лежат
|
|
5
|
+
* `name`, `description` и шаблоны каналов `email`/`inApp`/`push`/`sms` с полями
|
|
6
|
+
* `subject`/`body`. Шаблоны — Liquid (`{{ payload.x }}`, `{% if %}`), не формат
|
|
7
|
+
* vue-i18n: их отрисовывает контроллер при отправке.
|
|
8
|
+
*
|
|
9
|
+
* Сценарий берёт русский текст через `nt()` при описании — шаги несут текст
|
|
10
|
+
* языка по умолчанию, как и раньше. Текст на другом языке контроллер находит
|
|
11
|
+
* по `i18nKey` сценария (`templateFor`).
|
|
12
|
+
*/
|
|
13
|
+
import ru from './ru.json';
|
|
14
|
+
|
|
15
|
+
type Channel = 'email' | 'inApp' | 'push' | 'sms';
|
|
16
|
+
|
|
17
|
+
interface ChannelTemplate {
|
|
18
|
+
subject?: string;
|
|
19
|
+
body?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type WorkflowTexts = { name?: string; description?: string } & Partial<Record<Channel, ChannelTemplate>>;
|
|
23
|
+
|
|
24
|
+
export const DEFAULT_NOTIFICATION_LOCALE = 'ru';
|
|
25
|
+
|
|
26
|
+
export const notificationTemplates: Record<string, Record<string, WorkflowTexts>> = {
|
|
27
|
+
ru: ru as Record<string, WorkflowTexts>,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function lookup(tree: unknown, key: string): unknown {
|
|
31
|
+
return key.split('.').reduce<unknown>((node, part) => (node && typeof node === 'object' ? (node as Record<string, unknown>)[part] : undefined), tree);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Текст по ключу `<сценарий>.<поле>` на языке по умолчанию. */
|
|
35
|
+
export function nt(key: string): string {
|
|
36
|
+
const value = lookup(notificationTemplates[DEFAULT_NOTIFICATION_LOCALE], key);
|
|
37
|
+
// i18n-ignore: ошибка разработчика — ключ не заведён в словаре, падает при загрузке каталога
|
|
38
|
+
if (typeof value !== 'string') throw new Error(`notifications i18n: нет текста «${key}»`);
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const CHANNEL_KEY: Record<string, Channel> = { email: 'email', in_app: 'inApp', push: 'push', sms: 'sms' };
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Шаблон канала сценария на языке `locale`; нет перевода — undefined, и
|
|
46
|
+
* вызывающий берёт текст шага (язык по умолчанию).
|
|
47
|
+
*/
|
|
48
|
+
export function templateFor(i18nKey: string, channel: string, locale: string): ChannelTemplate | undefined {
|
|
49
|
+
const channelKey = CHANNEL_KEY[channel];
|
|
50
|
+
if (!channelKey) return undefined;
|
|
51
|
+
return notificationTemplates[locale]?.[i18nKey]?.[channelKey];
|
|
52
|
+
}
|