@platform-modules/civil-aviation-authority 2.3.279 → 2.3.281

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.
@@ -1,56 +1,5 @@
1
- export type BilingualText = {
2
- en: string;
3
- ar: string;
4
- };
5
- type WorkflowChatI18nCatalog = {
6
- workflowTemplates: Record<string, BilingualText>;
7
- chatTemplates: Record<string, BilingualText>;
8
- workflowStatusLabels: Record<string, string>;
9
- chatStatusLabels: Record<string, string>;
10
- };
11
- /** Read-only view of the shared workflow/chat translation catalog. */
12
- export declare function getWorkflowChatI18nCatalog(): WorkflowChatI18nCatalog;
13
- export declare function buildBilingualFromTemplate(templateCatalog: Record<string, BilingualText>, key: string, params?: Record<string, string>, arParams?: Record<string, string>): BilingualText;
14
- export declare function workflowTemplate(key: string, params?: Record<string, string>, arParams?: Record<string, string>): BilingualText;
15
- export declare function chatTemplate(key: string, params?: Record<string, string>, arParams?: Record<string, string>): BilingualText;
16
- export declare function resolveWorkflowStatusAr(status: string | null | undefined): string | null;
17
- export declare function resolveChatStatusAr(status: string | null | undefined): string | null;
18
- /** Arabic DB value when present; otherwise English so AR text stays structurally complete. */
19
- export declare function resolveBilingualName(englishName?: string | null, arabicName?: string | null): string;
20
- export declare function pickArabicName(arabicName?: string | null, fallback?: string): string;
21
- export declare function pickLocalizedName(englishName?: string | null, arabicName?: string | null, fallback?: string): string;
22
- /** Parallel EN/AR dept-section labels (Arabic columns preferred; English fallback per field). */
23
- export declare function joinDeptSectionBilingualLabels(deptEn?: string | null, deptAr?: string | null, sectEn?: string | null, sectAr?: string | null): {
24
- en: string;
25
- ar: string;
26
- };
27
- /** @deprecated Use joinDeptSectionBilingualLabels */
28
- export declare function joinDeptSectionArabicLabels(deptArabic?: string | null, sectionArabic?: string | null): string;
29
- export declare function buildApprovalWorkflowContent(params: {
30
- status: 'Approved' | 'Rejected' | 'Returned for Modification' | 'Pending' | string;
31
- roleName?: string | null;
32
- roleArabicName?: string | null;
33
- comment?: string | null;
34
- }): BilingualText;
35
- export declare function buildHumanApprovalWorkflowContent(params: {
36
- isFirst: boolean;
37
- roleName?: string | null;
38
- roleArabicName?: string | null;
39
- deptName?: string | null;
40
- deptArabicName?: string | null;
41
- sectionName?: string | null;
42
- sectionArabicName?: string | null;
43
- }): BilingualText;
44
- export declare function buildApprovalChatMessage(params: {
45
- status: 'Approved' | 'Rejected' | 'Returned for Modification' | string;
46
- roleName?: string | null;
47
- roleArabicName?: string | null;
48
- comment?: string | null;
49
- }): BilingualText;
50
- /** Resolve Arabic workflow content from a stored English content string (legacy rows). */
51
- export declare function resolveWorkflowContentAr(content: string | null | undefined): string | null;
52
- /** Resolve Arabic chat message from a stored English message string (legacy rows). */
53
- export declare function resolveChatMessageAr(message: string | null | undefined): string | null;
54
- export declare function enrichCancellationWorkflowLog(log: Record<string, unknown>): Record<string, unknown>;
55
- export declare function enrichCancellationChatMessage(chat: Record<string, unknown>): Record<string, unknown>;
56
- export {};
1
+ /**
2
+ * Re-exports the CAA standard bilingual message builder.
3
+ * Import from '@platform-modules/civil-aviation-authority' in all services.
4
+ */
5
+ export * from './workflow-chat-message.builder';
@@ -1,229 +1,21 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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);
4
15
  };
5
16
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getWorkflowChatI18nCatalog = getWorkflowChatI18nCatalog;
7
- exports.buildBilingualFromTemplate = buildBilingualFromTemplate;
8
- exports.workflowTemplate = workflowTemplate;
9
- exports.chatTemplate = chatTemplate;
10
- exports.resolveWorkflowStatusAr = resolveWorkflowStatusAr;
11
- exports.resolveChatStatusAr = resolveChatStatusAr;
12
- exports.resolveBilingualName = resolveBilingualName;
13
- exports.pickArabicName = pickArabicName;
14
- exports.pickLocalizedName = pickLocalizedName;
15
- exports.joinDeptSectionBilingualLabels = joinDeptSectionBilingualLabels;
16
- exports.joinDeptSectionArabicLabels = joinDeptSectionArabicLabels;
17
- exports.buildApprovalWorkflowContent = buildApprovalWorkflowContent;
18
- exports.buildHumanApprovalWorkflowContent = buildHumanApprovalWorkflowContent;
19
- exports.buildApprovalChatMessage = buildApprovalChatMessage;
20
- exports.resolveWorkflowContentAr = resolveWorkflowContentAr;
21
- exports.resolveChatMessageAr = resolveChatMessageAr;
22
- exports.enrichCancellationWorkflowLog = enrichCancellationWorkflowLog;
23
- exports.enrichCancellationChatMessage = enrichCancellationChatMessage;
24
- const workflow_chat_i18n_json_1 = __importDefault(require("./workflow-chat-i18n.json"));
25
- const WORKFLOW_TEMPLATES = workflow_chat_i18n_json_1.default.workflowTemplates;
26
- const CHAT_TEMPLATES = workflow_chat_i18n_json_1.default.chatTemplates;
27
- const WORKFLOW_STATUS_LABELS = workflow_chat_i18n_json_1.default.workflowStatusLabels;
28
- const CHAT_STATUS_LABELS = workflow_chat_i18n_json_1.default.chatStatusLabels;
29
- /** Read-only view of the shared workflow/chat translation catalog. */
30
- function getWorkflowChatI18nCatalog() {
31
- return workflow_chat_i18n_json_1.default;
32
- }
33
- function interpolate(template, params = {}) {
34
- return template.replace(/\{\{(\w+)\}\}/g, (_, key) => params[key] ?? '');
35
- }
36
- function buildBilingualFromTemplate(templateCatalog, key, params = {}, arParams) {
37
- const tpl = templateCatalog[key];
38
- if (!tpl) {
39
- return { en: key, ar: key };
40
- }
41
- const arabicParams = arParams ?? params;
42
- return {
43
- en: interpolate(tpl.en, params),
44
- ar: interpolate(tpl.ar, arabicParams),
45
- };
46
- }
47
- function workflowTemplate(key, params = {}, arParams) {
48
- return buildBilingualFromTemplate(WORKFLOW_TEMPLATES, key, params, arParams);
49
- }
50
- function chatTemplate(key, params = {}, arParams) {
51
- return buildBilingualFromTemplate(CHAT_TEMPLATES, key, params, arParams);
52
- }
53
- function resolveWorkflowStatusAr(status) {
54
- if (status == null || status === '')
55
- return null;
56
- return WORKFLOW_STATUS_LABELS[status] ?? status;
57
- }
58
- function resolveChatStatusAr(status) {
59
- if (status == null || status === '')
60
- return null;
61
- return CHAT_STATUS_LABELS[status] ?? status;
62
- }
63
- /** Arabic DB value when present; otherwise English so AR text stays structurally complete. */
64
- function resolveBilingualName(englishName, arabicName) {
65
- const ar = arabicName?.trim();
66
- if (ar)
67
- return ar;
68
- return englishName?.trim() || '';
69
- }
70
- function pickArabicName(arabicName, fallback = '') {
71
- return arabicName?.trim() || fallback;
72
- }
73
- function pickLocalizedName(englishName, arabicName, fallback = '') {
74
- const ar = arabicName?.trim();
75
- if (ar)
76
- return ar;
77
- const en = englishName?.trim();
78
- if (en)
79
- return en;
80
- return fallback;
81
- }
82
- function joinDeptSectionLabels(dept, section) {
83
- return [dept, section].map((s) => s?.trim()).filter(Boolean).join(' - ');
84
- }
85
- /** Parallel EN/AR dept-section labels (Arabic columns preferred; English fallback per field). */
86
- function joinDeptSectionBilingualLabels(deptEn, deptAr, sectEn, sectAr) {
87
- const en = joinDeptSectionLabels(deptEn, sectEn);
88
- const ar = joinDeptSectionLabels(resolveBilingualName(deptEn, deptAr), resolveBilingualName(sectEn, sectAr));
89
- return { en, ar };
90
- }
91
- /** @deprecated Use joinDeptSectionBilingualLabels */
92
- function joinDeptSectionArabicLabels(deptArabic, sectionArabic) {
93
- return joinDeptSectionLabels(deptArabic, sectionArabic);
94
- }
95
- function formatWorkflowCommentSuffix(comment) {
96
- const text = comment?.trim();
97
- return text ? `: ${text}` : '';
98
- }
99
- function formatChatCommentSuffix(comment) {
100
- const text = comment?.trim();
101
- return text ? ` - ${text}` : '';
102
- }
103
- function buildWorkflowApprovalByName(templateKey, nameEn, nameAr, comment) {
104
- const commentSuffix = formatWorkflowCommentSuffix(comment);
105
- return workflowTemplate(templateKey, { name: nameEn, comment: commentSuffix }, { name: nameAr, comment: commentSuffix });
106
- }
107
- function buildWorkflowApprovalWithoutName(templateKey, comment) {
108
- const commentSuffix = formatWorkflowCommentSuffix(comment);
109
- return workflowTemplate(templateKey, { comment: commentSuffix }, { comment: commentSuffix });
110
- }
111
- function buildApprovalWorkflowContent(params) {
112
- const nameEn = params.roleName?.trim() || '';
113
- const nameAr = resolveBilingualName(nameEn, params.roleArabicName);
114
- if (params.status === 'Approved') {
115
- return nameEn
116
- ? buildWorkflowApprovalByName('request_approved_by', nameEn, nameAr, params.comment)
117
- : buildWorkflowApprovalWithoutName('request_approved', params.comment);
118
- }
119
- if (params.status === 'Rejected') {
120
- return nameEn
121
- ? buildWorkflowApprovalByName('request_rejected_by', nameEn, nameAr, params.comment)
122
- : buildWorkflowApprovalWithoutName('request_rejected', params.comment);
123
- }
124
- if (params.status === 'Returned for Modification') {
125
- return nameEn
126
- ? buildWorkflowApprovalByName('request_returned_for_modification_by', nameEn, nameAr, params.comment)
127
- : buildWorkflowApprovalWithoutName('request_returned_for_modification', params.comment);
128
- }
129
- const commentSuffix = formatWorkflowCommentSuffix(params.comment);
130
- if (nameEn) {
131
- return workflowTemplate('request_approval_pending_from', { name: nameEn, comment: commentSuffix }, { name: nameAr, comment: commentSuffix });
132
- }
133
- return workflowTemplate('request_approval_pending', { comment: commentSuffix }, { comment: commentSuffix });
134
- }
135
- function buildHumanApprovalWorkflowContent(params) {
136
- const key = params.isFirst ? 'request_approval_in_progress_from' : 'request_approval_pending_from';
137
- if (params.roleName?.trim()) {
138
- const nameEn = params.roleName.trim();
139
- const nameAr = resolveBilingualName(nameEn, params.roleArabicName);
140
- return workflowTemplate(key, { name: nameEn }, { name: nameAr });
141
- }
142
- const { en, ar } = joinDeptSectionBilingualLabels(params.deptName, params.deptArabicName, params.sectionName, params.sectionArabicName);
143
- if (en) {
144
- return workflowTemplate(key, { name: en }, { name: ar });
145
- }
146
- return params.isFirst
147
- ? workflowTemplate('request_approval_in_progress')
148
- : workflowTemplate('request_approval_pending');
149
- }
150
- function buildApprovalChatMessage(params) {
151
- const roleEn = params.roleName?.trim() || 'Unknown Role';
152
- const roleAr = resolveBilingualName(roleEn, params.roleArabicName);
153
- const commentSuffix = formatChatCommentSuffix(params.comment);
154
- let key;
155
- if (params.status === 'Approved') {
156
- key = 'request_approved_by_role';
157
- }
158
- else if (params.status === 'Rejected') {
159
- key = 'request_rejected_by_role';
160
- }
161
- else if (params.status === 'Returned for Modification') {
162
- key = 'request_returned_for_modification_by_role';
163
- }
164
- else {
165
- key = 'request_approved_by_role';
166
- }
167
- return chatTemplate(key, { roleName: roleEn, comment: commentSuffix }, { roleName: roleAr, comment: commentSuffix });
168
- }
169
- /** Resolve Arabic workflow content from a stored English content string (legacy rows). */
170
- function resolveWorkflowContentAr(content) {
171
- if (content == null || content.trim() === '')
172
- return null;
173
- const normalized = content.trim();
174
- for (const tpl of Object.values(WORKFLOW_TEMPLATES)) {
175
- if (tpl.en === normalized)
176
- return tpl.ar;
177
- }
178
- const commentIdx = normalized.indexOf(': ');
179
- if (commentIdx > 0) {
180
- const baseEn = normalized.slice(0, commentIdx).trim();
181
- const commentText = normalized.slice(commentIdx + 2).trim();
182
- const commentSuffix = formatWorkflowCommentSuffix(commentText);
183
- for (const tpl of Object.values(WORKFLOW_TEMPLATES)) {
184
- if (!tpl.en.includes('{{comment}}'))
185
- continue;
186
- const withoutComment = tpl.en.replace('{{comment}}', '');
187
- if (withoutComment.includes('{{name}}')) {
188
- const staticPrefix = withoutComment.replace('{{name}}', '').trim();
189
- if (baseEn.startsWith(staticPrefix)) {
190
- const namePart = baseEn.slice(staticPrefix.length).trim();
191
- return interpolate(tpl.ar, { name: namePart, comment: commentSuffix });
192
- }
193
- }
194
- else if (withoutComment.trim() === baseEn) {
195
- return interpolate(tpl.ar, { comment: commentSuffix });
196
- }
197
- }
198
- }
199
- return null;
200
- }
201
- /** Resolve Arabic chat message from a stored English message string (legacy rows). */
202
- function resolveChatMessageAr(message) {
203
- if (message == null || message.trim() === '')
204
- return null;
205
- const normalized = message.trim();
206
- for (const tpl of Object.values(CHAT_TEMPLATES)) {
207
- if (tpl.en === normalized)
208
- return tpl.ar;
209
- }
210
- return null;
211
- }
212
- function enrichCancellationWorkflowLog(log) {
213
- const status = log.status != null ? String(log.status) : null;
214
- const content = log.content != null ? String(log.content) : null;
215
- return {
216
- ...log,
217
- content_ar: log.content_ar ?? resolveWorkflowContentAr(content),
218
- status_ar: log.status_ar ?? resolveWorkflowStatusAr(status),
219
- };
220
- }
221
- function enrichCancellationChatMessage(chat) {
222
- const status = chat.status != null ? String(chat.status) : null;
223
- const message = chat.message != null ? String(chat.message) : null;
224
- return {
225
- ...chat,
226
- message_ar: chat.message_ar ?? resolveChatMessageAr(message),
227
- status_ar: chat.status_ar ?? resolveChatStatusAr(status),
228
- };
229
- }
17
+ /**
18
+ * Re-exports the CAA standard bilingual message builder.
19
+ * Import from '@platform-modules/civil-aviation-authority' in all services.
20
+ */
21
+ __exportStar(require("./workflow-chat-message.builder"), exports);
@@ -58,6 +58,10 @@
58
58
  "en": "Cancellation request submitted by {{userName}} ({{employeeId}})",
59
59
  "ar": "تم تقديم طلب الإلغاء بواسطة {{userName}} ({{employeeId}})"
60
60
  },
61
+ "cancellation_submitted": {
62
+ "en": "Cancellation request submitted",
63
+ "ar": "تم تقديم طلب الإلغاء"
64
+ },
61
65
  "request_received": {
62
66
  "en": "Request Received",
63
67
  "ar": "تم استلام الطلب"
@@ -73,6 +77,18 @@
73
77
  "request_returned_for_modification_by_role": {
74
78
  "en": "Request Returned for Modification by: {{roleName}}{{comment}}",
75
79
  "ar": "تم إرجاع الطلب للتعديل من قبل: {{roleName}}{{comment}}"
80
+ },
81
+ "request_approved": {
82
+ "en": "Request Approved{{comment}}",
83
+ "ar": "تمت الموافقة على الطلب{{comment}}"
84
+ },
85
+ "request_rejected": {
86
+ "en": "Request Rejected{{comment}}",
87
+ "ar": "تم رفض الطلب{{comment}}"
88
+ },
89
+ "request_returned_for_modification": {
90
+ "en": "Request Returned for Modification{{comment}}",
91
+ "ar": "تم إرجاع الطلب للتعديل{{comment}}"
76
92
  }
77
93
  },
78
94
  "workflowStatusLabels": {
@@ -0,0 +1,103 @@
1
+ export type BilingualText = {
2
+ en: string;
3
+ ar: string;
4
+ };
5
+ export type WorkflowChatI18nCatalog = {
6
+ workflowTemplates: Record<string, BilingualText>;
7
+ chatTemplates: Record<string, BilingualText>;
8
+ workflowStatusLabels: Record<string, string>;
9
+ chatStatusLabels: Record<string, string>;
10
+ };
11
+ /** Master-data fields with English + Arabic columns (roles, departments, sections, users). */
12
+ export type BilingualActorNames = {
13
+ roleName?: string | null;
14
+ roleArabicName?: string | null;
15
+ deptName?: string | null;
16
+ deptArabicName?: string | null;
17
+ sectionName?: string | null;
18
+ sectionArabicName?: string | null;
19
+ userName?: string | null;
20
+ userArabicName?: string | null;
21
+ employeeId?: string | number | null;
22
+ };
23
+ export type WorkflowMessageAction = 'request_submitted' | 'notification_sent_pending' | 'notification_sent_successfully' | 'approval_in_progress' | 'approval_pending' | 'approved' | 'rejected' | 'returned_for_modification' | 'approval_pending_update';
24
+ export type ChatMessageAction = 'cancellation_submitted' | 'request_received' | 'approved' | 'rejected' | 'returned_for_modification';
25
+ export type WorkflowMessageContext = BilingualActorNames & {
26
+ action: WorkflowMessageAction;
27
+ /** First human approval step → "in progress"; later steps → "pending". */
28
+ isFirstApprovalStep?: boolean;
29
+ comment?: string | null;
30
+ };
31
+ export type ChatMessageContext = BilingualActorNames & {
32
+ action: ChatMessageAction;
33
+ comment?: string | null;
34
+ };
35
+ export declare function getWorkflowChatI18nCatalog(): WorkflowChatI18nCatalog;
36
+ /** Arabic DB column preferred; English fallback so AR keeps identical structure to EN. */
37
+ export declare function resolveBilingualName(englishName?: string | null, arabicName?: string | null): string;
38
+ export declare function pickLocalizedName(englishName?: string | null, arabicName?: string | null, fallback?: string): string;
39
+ /** @deprecated Use resolveBilingualName */
40
+ export declare function pickArabicName(arabicName?: string | null): string;
41
+ /** Build parallel EN / AR actor label from role OR dept+section. */
42
+ export declare function resolveActorDisplayNames(actors: BilingualActorNames): {
43
+ en: string;
44
+ ar: string;
45
+ };
46
+ /** @deprecated Use resolveActorDisplayNames */
47
+ export declare function joinDeptSectionBilingualLabels(deptEn?: string | null, deptAr?: string | null, sectEn?: string | null, sectAr?: string | null): {
48
+ en: string;
49
+ ar: string;
50
+ };
51
+ /** @deprecated Use resolveActorDisplayNames */
52
+ export declare function joinDeptSectionArabicLabels(deptArabic?: string | null, sectionArabic?: string | null): string;
53
+ export declare function formatWorkflowCommentSuffix(comment?: string | null): string;
54
+ export declare function formatChatCommentSuffix(comment?: string | null): string;
55
+ /** Core renderer — always pass explicit EN and AR param objects with the same keys. */
56
+ export declare function renderSynchronizedWorkflowMessage(templateKey: string, enParams: Record<string, string>, arParams: Record<string, string>): BilingualText;
57
+ export declare function renderSynchronizedChatMessage(templateKey: string, enParams: Record<string, string>, arParams: Record<string, string>): BilingualText;
58
+ export declare function buildBilingualFromTemplate(templateCatalog: Record<string, BilingualText>, key: string, params?: Record<string, string>, arParams?: Record<string, string>): BilingualText;
59
+ export declare function workflowTemplate(key: string, params?: Record<string, string>, arParams?: Record<string, string>): BilingualText;
60
+ export declare function chatTemplate(key: string, params?: Record<string, string>, arParams?: Record<string, string>): BilingualText;
61
+ /**
62
+ * Standard entry point for workflow `content` + `content_ar`.
63
+ * Use for every workflow log insert/update across all CAA modules.
64
+ */
65
+ export declare function buildSynchronizedWorkflowMessage(ctx: WorkflowMessageContext): BilingualText;
66
+ /**
67
+ * Standard entry point for chat `message` + `message_ar`.
68
+ * Use for every chat insert/update across all CAA modules.
69
+ */
70
+ export declare function buildSynchronizedChatMessage(ctx: ChatMessageContext): BilingualText;
71
+ export declare function buildApprovalWorkflowContent(params: {
72
+ status: 'Approved' | 'Rejected' | 'Returned for Modification' | 'Pending' | string;
73
+ roleName?: string | null;
74
+ roleArabicName?: string | null;
75
+ comment?: string | null;
76
+ }): BilingualText;
77
+ export declare function buildHumanApprovalWorkflowContent(params: {
78
+ isFirst: boolean;
79
+ roleName?: string | null;
80
+ roleArabicName?: string | null;
81
+ deptName?: string | null;
82
+ deptArabicName?: string | null;
83
+ sectionName?: string | null;
84
+ sectionArabicName?: string | null;
85
+ }): BilingualText;
86
+ export declare function buildApprovalChatMessage(params: {
87
+ status: 'Approved' | 'Rejected' | 'Returned for Modification' | string;
88
+ roleName?: string | null;
89
+ roleArabicName?: string | null;
90
+ comment?: string | null;
91
+ }): BilingualText;
92
+ export declare function resolveWorkflowStatusAr(status: string | null | undefined): string | null;
93
+ export declare function resolveChatStatusAr(status: string | null | undefined): string | null;
94
+ export declare function resolveWorkflowContentAr(content: string | null | undefined): string | null;
95
+ export declare function resolveChatMessageAr(message: string | null | undefined): string | null;
96
+ /** Generic workflow log enricher — use in all module repositories. */
97
+ export declare function enrichWorkflowLog(log: Record<string, unknown>): Record<string, unknown>;
98
+ /** Generic chat enricher — use in all module repositories. */
99
+ export declare function enrichChatMessage(chat: Record<string, unknown>): Record<string, unknown>;
100
+ /** @deprecated Use enrichWorkflowLog */
101
+ export declare const enrichCancellationWorkflowLog: typeof enrichWorkflowLog;
102
+ /** @deprecated Use enrichChatMessage */
103
+ export declare const enrichCancellationChatMessage: typeof enrichChatMessage;