From 3ebe5824fef4c0900403b5d9b0c89a0174e12bba Mon Sep 17 00:00:00 2001 From: Lambdius Date: Sat, 7 Nov 2026 09:55:56 +0000 Subject: [PATCH] feat(notification): add HR in-app notification contracts --- catalog.json | 2 +- package.json | 2 +- src/enums.ts | 9 ++ src/kafka/notification.schema.json | 156 +++++++++++++++++++++++++++-- src/types.ts | 58 +++++++++-- 5 files changed, 209 insertions(+), 18 deletions(-) diff --git a/catalog.json b/catalog.json index c9aebad..971971c 100644 --- a/catalog.json +++ b/catalog.json @@ -61,7 +61,7 @@ "schemaType": "JSON", "protocol": "kafka", "path": "kafka/notification.schema.json", - "producers": ["identity-service", "access-control-service"], + "producers": ["hr-service", "identity-service", "access-control-service"], "consumers": ["notification-service"] }, { diff --git a/package.json b/package.json index 9b54e1e..e12add6 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "Shared Kafka/gRPC contracts and common enums between MonadIAM services", "author": "Daniil Egorov (https://github.com/Lambdius)", "license": "UNLICENSED", - "version": "3.6.0", + "version": "3.7.0", "types": "dist/index.d.ts", "main": "dist/index.js", "exports": { diff --git a/src/enums.ts b/src/enums.ts index 441f1ca..bb69b5d 100644 --- a/src/enums.ts +++ b/src/enums.ts @@ -264,6 +264,15 @@ export enum MessageTemplate { ASSIGNMENT_REVOKED = "ASSIGNMENT_REVOKED", REALM_EXCLUDED = "REALM_EXCLUDED", + // HR: approval and execution are separate lifecycle events + HR_APPROVAL_REQUIRED = "HR_APPROVAL_REQUIRED", + HR_APPROVAL_REASSIGNED = "HR_APPROVAL_REASSIGNED", + HR_REQUEST_RETURNED = "HR_REQUEST_RETURNED", + HR_REQUEST_REJECTED = "HR_REQUEST_REJECTED", + HR_REQUEST_APPROVED = "HR_REQUEST_APPROVED", + HR_REQUEST_APPLIED = "HR_REQUEST_APPLIED", + HR_REQUEST_FAILED = "HR_REQUEST_FAILED", + // identity: invites INVITE_CANCELLED = "INVITE_CANCELLED", INVITE_RECEIVED = "INVITE_RECEIVED", diff --git a/src/kafka/notification.schema.json b/src/kafka/notification.schema.json index 7bdd0ac..3247600 100644 --- a/src/kafka/notification.schema.json +++ b/src/kafka/notification.schema.json @@ -37,7 +37,8 @@ "organization-service", "certificate-service", "identity-service", - "template-service" + "template-service", + "hr-service" ] }, "dedupKey": { "type": "string" }, @@ -83,7 +84,8 @@ "organization-service", "certificate-service", "identity-service", - "template-service" + "template-service", + "hr-service" ] }, "dedupKey": { "type": "string" }, @@ -121,11 +123,61 @@ "ASSIGNMENT_REVOKED", "REALM_EXCLUDED", "INVITE_CANCELLED", - "INVITE_RECEIVED" + "INVITE_RECEIVED", + "HR_APPROVAL_REQUIRED", + "HR_APPROVAL_REASSIGNED", + "HR_REQUEST_RETURNED", + "HR_REQUEST_REJECTED", + "HR_REQUEST_APPROVED", + "HR_REQUEST_APPLIED", + "HR_REQUEST_FAILED" ] }, "language": { "type": "string" } - } + }, + "allOf": [ + { + "if": { + "properties": { + "template": { + "enum": [ + "HR_APPROVAL_REQUIRED", + "HR_APPROVAL_REASSIGNED", + "HR_REQUEST_RETURNED", + "HR_REQUEST_REJECTED", + "HR_REQUEST_APPROVED", + "HR_REQUEST_APPLIED", + "HR_REQUEST_FAILED" + ] + } + } + }, + "then": { + "required": ["dedupKey", "params"], + "properties": { + "sourceService": { "const": "hr-service" }, + "params": { + "type": "object", + "additionalProperties": false, + "required": ["requestId", "requestType"], + "properties": { + "requestId": { + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" + }, + "requestType": { + "enum": [ + "HIRE", "REHIRE", "TRANSFER", "CHANGE_TERMS", "TERMINATE", + "ABSENCE", "OVERTIME", "LEAVE_ADJUSTMENT", "CANCEL_REQUEST" + ] + } + } + } + }, + "not": { "required": ["delivery"] } + } + } + ] } } } @@ -180,7 +232,8 @@ "organization-service", "certificate-service", "identity-service", - "template-service" + "template-service", + "hr-service" ] }, "dedupKey": { "type": "string" }, @@ -226,7 +279,8 @@ "organization-service", "certificate-service", "identity-service", - "template-service" + "template-service", + "hr-service" ] }, "dedupKey": { "type": "string" }, @@ -259,16 +313,66 @@ "ACCOUNT_VERIFICATION_OTP", "RESET_PASSWORD_OTP", "LOGIN_OTP", - "REAUTHENTICATION_OTP", + "REAUTHENTICATION_OTP", "ASSIGNMENT_GRANTED", "ASSIGNMENT_REVOKED", "REALM_EXCLUDED", "INVITE_CANCELLED", - "INVITE_RECEIVED" + "INVITE_RECEIVED", + "HR_APPROVAL_REQUIRED", + "HR_APPROVAL_REASSIGNED", + "HR_REQUEST_RETURNED", + "HR_REQUEST_REJECTED", + "HR_REQUEST_APPROVED", + "HR_REQUEST_APPLIED", + "HR_REQUEST_FAILED" ] }, "language": { "type": "string" } - } + }, + "allOf": [ + { + "if": { + "properties": { + "template": { + "enum": [ + "HR_APPROVAL_REQUIRED", + "HR_APPROVAL_REASSIGNED", + "HR_REQUEST_RETURNED", + "HR_REQUEST_REJECTED", + "HR_REQUEST_APPROVED", + "HR_REQUEST_APPLIED", + "HR_REQUEST_FAILED" + ] + } + } + }, + "then": { + "required": ["dedupKey", "params"], + "properties": { + "sourceService": { "const": "hr-service" }, + "params": { + "type": "object", + "additionalProperties": false, + "required": ["requestId", "requestType"], + "properties": { + "requestId": { + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" + }, + "requestType": { + "enum": [ + "HIRE", "REHIRE", "TRANSFER", "CHANGE_TERMS", "TERMINATE", + "ABSENCE", "OVERTIME", "LEAVE_ADJUSTMENT", "CANCEL_REQUEST" + ] + } + } + } + }, + "not": { "required": ["delivery"] } + } + } + ] } } } @@ -279,6 +383,40 @@ } } } + }, + { + "type": "object", + "additionalProperties": false, + "required": ["actionType", "payload"], + "properties": { + "actionType": { "const": "CANCEL" }, + "payload": { + "type": "object", + "additionalProperties": false, + "required": ["realm", "input"], + "properties": { + "actor": { "type": "string" }, + "realm": { + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" + }, + "input": { + "type": "object", + "additionalProperties": false, + "required": ["invalidate", "recipient", "sourceService", "dedupKey"], + "properties": { + "invalidate": { "const": true }, + "recipient": { + "type": "string", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" + }, + "sourceService": { "const": "hr-service" }, + "dedupKey": { "type": "string", "minLength": 1 } + } + } + } + } + } } ] } diff --git a/src/types.ts b/src/types.ts index a0bd276..e83e7cc 100644 --- a/src/types.ts +++ b/src/types.ts @@ -622,10 +622,12 @@ declare global { payload: { actor?: string; realm?: string; - input: { - override: NotificationSpec; - dedupKey: string; - }; + input: + | { + override: NotificationSpec; + dedupKey: string; + } + | InvalidateInput; }; }; @@ -642,6 +644,29 @@ declare global { address: string; }; + type InvalidateInput = { + invalidate: true; + recipient: string; + sourceService: PlatformService.HR_SERVICE; + dedupKey: string; + }; + + type HRRequestType = + | "HIRE" + | "REHIRE" + | "TRANSFER" + | "CHANGE_TERMS" + | "TERMINATE" + | "ABSENCE" + | "OVERTIME" + | "LEAVE_ADJUSTMENT" + | "CANCEL_REQUEST"; + + type HRTemplateParams = { + requestId: string; + requestType: HRRequestType; + }; + type BaseInput = { delivery?: Delivery; category: NotificationCategory; @@ -657,12 +682,31 @@ declare global { text: string; }; + type HRTemplate = + | MessageTemplate.HR_APPROVAL_REASSIGNED + | MessageTemplate.HR_APPROVAL_REQUIRED + | MessageTemplate.HR_REQUEST_RETURNED + | MessageTemplate.HR_REQUEST_REJECTED + | MessageTemplate.HR_REQUEST_APPROVED + | MessageTemplate.HR_REQUEST_APPLIED + | MessageTemplate.HR_REQUEST_FAILED; + type TemplateInput = BaseInput & { kind: NotificationContentKind.TEMPLATE; - params?: Record; - template: MessageTemplate; language?: string; - }; + } & ( + | { + template: Exclude; + params?: Record; + } + | { + sourceService: PlatformService.HR_SERVICE; + params: HRTemplateParams; + template: HRTemplate; + dedupKey: string; + delivery?: never; + } + ); } namespace MessageDispatch {