@mereb/shared-packages 0.0.38 → 0.0.39

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.
@@ -0,0 +1,25 @@
1
+ export interface IntegrationEventEnvelope<TData = unknown> {
2
+ event_id: string;
3
+ event_type: string;
4
+ occurred_at: string;
5
+ producer: string;
6
+ version: number;
7
+ correlation_id?: string;
8
+ causation_id?: string;
9
+ tenant_id?: string;
10
+ data: TData;
11
+ }
12
+ export interface CreateIntegrationEventEnvelopeInput<TData> {
13
+ eventType: string;
14
+ producer: string;
15
+ data: TData;
16
+ version?: number;
17
+ eventId?: string;
18
+ occurredAt?: Date | string;
19
+ correlationId?: string;
20
+ causationId?: string;
21
+ tenantId?: string;
22
+ }
23
+ export declare function createIntegrationEventEnvelope<TData>(input: CreateIntegrationEventEnvelopeInput<TData>): IntegrationEventEnvelope<TData>;
24
+ export declare function serializeIntegrationEventEnvelope<TData>(envelope: IntegrationEventEnvelope<TData>): string;
25
+ //# sourceMappingURL=envelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/events/envelope.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,wBAAwB,CAAC,KAAK,GAAG,OAAO;IACvD,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,KAAK,CAAC;CACb;AAED,MAAM,WAAW,mCAAmC,CAAC,KAAK;IACxD,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,KAAK,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAcD,wBAAgB,8BAA8B,CAAC,KAAK,EAClD,KAAK,EAAE,mCAAmC,CAAC,KAAK,CAAC,GAChD,wBAAwB,CAAC,KAAK,CAAC,CAYjC;AAED,wBAAgB,iCAAiC,CAAC,KAAK,EACrD,QAAQ,EAAE,wBAAwB,CAAC,KAAK,CAAC,GACxC,MAAM,CAER"}
@@ -0,0 +1,26 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ function toIsoString(value) {
3
+ if (!value) {
4
+ return new Date().toISOString();
5
+ }
6
+ if (typeof value === 'string') {
7
+ return value;
8
+ }
9
+ return value.toISOString();
10
+ }
11
+ export function createIntegrationEventEnvelope(input) {
12
+ return {
13
+ event_id: input.eventId ?? randomUUID(),
14
+ event_type: input.eventType,
15
+ occurred_at: toIsoString(input.occurredAt),
16
+ producer: input.producer,
17
+ version: input.version ?? 1,
18
+ ...(input.correlationId ? { correlation_id: input.correlationId } : {}),
19
+ ...(input.causationId ? { causation_id: input.causationId } : {}),
20
+ ...(input.tenantId ? { tenant_id: input.tenantId } : {}),
21
+ data: input.data
22
+ };
23
+ }
24
+ export function serializeIntegrationEventEnvelope(envelope) {
25
+ return JSON.stringify(envelope);
26
+ }
@@ -0,0 +1,11 @@
1
+ import type { KafkaConfig } from 'kafkajs';
2
+ import type { IntegrationEventEnvelope } from './envelope.js';
3
+ export interface PublishIntegrationEventOptions {
4
+ key?: string;
5
+ }
6
+ export interface IntegrationEventPublisher {
7
+ publish<TData>(topic: string, envelope: IntegrationEventEnvelope<TData>, options?: PublishIntegrationEventOptions): Promise<void>;
8
+ }
9
+ export declare function createNoopIntegrationEventPublisher(): IntegrationEventPublisher;
10
+ export declare function createKafkaIntegrationEventPublisher(config: KafkaConfig): IntegrationEventPublisher;
11
+ //# sourceMappingURL=publisher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publisher.d.ts","sourceRoot":"","sources":["../../src/events/publisher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAI9D,MAAM,WAAW,8BAA8B;IAC7C,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,yBAAyB;IACxC,OAAO,CAAC,KAAK,EACX,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,wBAAwB,CAAC,KAAK,CAAC,EACzC,OAAO,CAAC,EAAE,8BAA8B,GACvC,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB;AAED,wBAAgB,mCAAmC,IAAI,yBAAyB,CAM/E;AAED,wBAAgB,oCAAoC,CAClD,MAAM,EAAE,WAAW,GAClB,yBAAyB,CAmB3B"}
@@ -0,0 +1,25 @@
1
+ import { serializeIntegrationEventEnvelope } from './envelope.js';
2
+ import { getProducer } from '../messaging/kafka.js';
3
+ export function createNoopIntegrationEventPublisher() {
4
+ return {
5
+ async publish() {
6
+ return;
7
+ }
8
+ };
9
+ }
10
+ export function createKafkaIntegrationEventPublisher(config) {
11
+ return {
12
+ async publish(topic, envelope, options) {
13
+ const producer = await getProducer(config);
14
+ await producer.send({
15
+ topic,
16
+ messages: [
17
+ {
18
+ key: options?.key,
19
+ value: serializeIntegrationEventEnvelope(envelope)
20
+ }
21
+ ]
22
+ });
23
+ }
24
+ };
25
+ }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from './auth/jwks.js';
2
2
  export * from './cache/redis.js';
3
3
  export * from './config/env.js';
4
+ export * from './events/envelope.js';
5
+ export * from './events/publisher.js';
4
6
  export * from './logger.js';
5
7
  export { createFastifyLoggerOptions } from './logger.js';
6
8
  export type { Logger } from 'pino';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,YAAY,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,YAAY,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from './auth/jwks.js';
2
2
  export * from './cache/redis.js';
3
3
  export * from './config/env.js';
4
+ export * from './events/envelope.js';
5
+ export * from './events/publisher.js';
4
6
  export * from './logger.js';
5
7
  export { createFastifyLoggerOptions } from './logger.js';
6
8
  export * from './messaging/kafka.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mereb/shared-packages",
3
- "version": "0.0.38",
3
+ "version": "0.0.39",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",