@skillstew/common 1.0.12 → 1.0.14

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,12 @@
1
+ import { EventName, EventPayload } from "./EventMap";
2
+ export interface AppEvent<T extends EventName> {
3
+ eventId: string;
4
+ eventName: T;
5
+ timestamp: string;
6
+ producer: string;
7
+ data: EventPayload<T>;
8
+ traceId?: string;
9
+ }
10
+ export type UserRegisteredEvent = AppEvent<"user.registered">;
11
+ export type UserVerifiedEvent = AppEvent<"user.verified">;
12
+ export type AnyAppEvent = AppEvent<EventName>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ import { AppEvent } from "./AppEvent";
2
+ import { EventName, EventPayload } from "./EventMap";
3
+ export declare function CreateEvent<T extends EventName>(eventName: T, data: EventPayload<T>, producer: string, traceId?: string): AppEvent<T>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreateEvent = CreateEvent;
4
+ const crypto_1 = require("crypto");
5
+ function CreateEvent(eventName, data, producer, traceId) {
6
+ return {
7
+ eventName,
8
+ eventId: (0, crypto_1.randomUUID)(),
9
+ data,
10
+ producer,
11
+ timestamp: new Date().toISOString(),
12
+ traceId,
13
+ };
14
+ }
@@ -0,0 +1,12 @@
1
+ import z from "zod";
2
+ export declare const EventSchemas: {
3
+ readonly "user.registered": z.ZodObject<{
4
+ id: z.ZodUUID;
5
+ email: z.ZodEmail;
6
+ }, z.core.$strip>;
7
+ readonly "user.verified": z.ZodObject<{
8
+ id: z.ZodUUID;
9
+ }, z.core.$strip>;
10
+ };
11
+ export type EventName = keyof typeof EventSchemas;
12
+ export type EventPayload<T extends EventName> = z.infer<(typeof EventSchemas)[T]>;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventSchemas = void 0;
4
+ const userEventsSchema_1 = require("./schemas/userEventsSchema");
5
+ // Union of all app event schemas
6
+ exports.EventSchemas = Object.assign({}, userEventsSchema_1.UserEventSchemas);
@@ -0,0 +1,17 @@
1
+ import z from "zod";
2
+ export declare const userRegisteredSchema: z.ZodObject<{
3
+ id: z.ZodUUID;
4
+ email: z.ZodEmail;
5
+ }, z.core.$strip>;
6
+ export declare const userVerifiedSchema: z.ZodObject<{
7
+ id: z.ZodUUID;
8
+ }, z.core.$strip>;
9
+ export declare const UserEventSchemas: {
10
+ readonly "user.registered": z.ZodObject<{
11
+ id: z.ZodUUID;
12
+ email: z.ZodEmail;
13
+ }, z.core.$strip>;
14
+ readonly "user.verified": z.ZodObject<{
15
+ id: z.ZodUUID;
16
+ }, z.core.$strip>;
17
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.UserEventSchemas = exports.userVerifiedSchema = exports.userRegisteredSchema = void 0;
7
+ const zod_1 = __importDefault(require("zod"));
8
+ exports.userRegisteredSchema = zod_1.default.object({
9
+ id: zod_1.default.uuid(),
10
+ email: zod_1.default.email(),
11
+ });
12
+ exports.userVerifiedSchema = zod_1.default.object({
13
+ id: zod_1.default.uuid(),
14
+ });
15
+ exports.UserEventSchemas = {
16
+ "user.registered": exports.userRegisteredSchema,
17
+ "user.verified": exports.userVerifiedSchema,
18
+ };
package/build/index.d.ts CHANGED
@@ -9,3 +9,5 @@ export * from "./middlewares/authMiddleware";
9
9
  export * from "./middlewares/requireRole";
10
10
  export * from "./types/UserRoles";
11
11
  export * from "./constants/HttpStatus";
12
+ export * from "./events/AppEvent";
13
+ export * from "./events/schemas/userEventsSchema";
package/build/index.js CHANGED
@@ -30,3 +30,6 @@ __exportStar(require("./middlewares/requireRole"), exports);
30
30
  __exportStar(require("./types/UserRoles"), exports);
31
31
  // Constants
32
32
  __exportStar(require("./constants/HttpStatus"), exports);
33
+ // Events
34
+ __exportStar(require("./events/AppEvent"), exports);
35
+ __exportStar(require("./events/schemas/userEventsSchema"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skillstew/common",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "main": "./build/index.js",
5
5
  "types": "./build/index.d.ts",
6
6
  "scripts": {
@@ -17,6 +17,7 @@
17
17
  "@types/jsonwebtoken": "^9.0.10",
18
18
  "del-cli": "^6.0.0",
19
19
  "express": "^5.1.0",
20
- "jsonwebtoken": "^9.0.2"
20
+ "jsonwebtoken": "^9.0.2",
21
+ "zod": "^4.0.10"
21
22
  }
22
23
  }
package/publish.sh ADDED
@@ -0,0 +1,26 @@
1
+ #!/bin/bash
2
+
3
+ # Exit immediately on error
4
+ set -e
5
+
6
+ # Step 1: Bump patch version
7
+ npm version patch
8
+
9
+ # Step 2: Build the package
10
+ npm run build
11
+
12
+ # Step 3: Stage all changes
13
+ git add .
14
+
15
+ # Step 4: Prompt for a commit message
16
+ echo "Enter commit message:"
17
+ read COMMIT_MESSAGE
18
+ git commit -m "$COMMIT_MESSAGE"
19
+
20
+ # Step 5: Push to GitHub
21
+ echo "Enter remote branch to push to:"
22
+ read REMOTE_BRANCH
23
+ git push -u origin "$REMOTE_BRANCH"
24
+
25
+ # Step 6: Publish to npm
26
+ npm publish
@@ -0,0 +1,15 @@
1
+ import { EventName, EventPayload } from "./EventMap";
2
+
3
+ export interface AppEvent<T extends EventName> {
4
+ eventId: string;
5
+ eventName: T;
6
+ timestamp: string; // ISO format
7
+ producer: string; // the service that emitted this event
8
+ data: EventPayload<T>;
9
+ traceId?: string;
10
+ }
11
+
12
+ export type UserRegisteredEvent = AppEvent<"user.registered">;
13
+ export type UserVerifiedEvent = AppEvent<"user.verified">;
14
+
15
+ export type AnyAppEvent = AppEvent<EventName>;
@@ -0,0 +1,19 @@
1
+ import { AppEvent } from "./AppEvent";
2
+ import { EventName, EventPayload } from "./EventMap";
3
+ import { randomUUID } from "crypto";
4
+
5
+ export function CreateEvent<T extends EventName>(
6
+ eventName: T,
7
+ data: EventPayload<T>,
8
+ producer: string,
9
+ traceId?: string,
10
+ ): AppEvent<T> {
11
+ return {
12
+ eventName,
13
+ eventId: randomUUID(),
14
+ data,
15
+ producer,
16
+ timestamp: new Date().toISOString(),
17
+ traceId,
18
+ };
19
+ }
@@ -0,0 +1,16 @@
1
+ import z from "zod";
2
+ import { UserEventSchemas } from "./schemas/userEventsSchema";
3
+
4
+ // Union of all app event schemas
5
+
6
+ export const EventSchemas = {
7
+ ...UserEventSchemas,
8
+ } as const;
9
+
10
+ // Union of all app event names
11
+ export type EventName = keyof typeof EventSchemas;
12
+
13
+ // Union of all app event payloads
14
+ export type EventPayload<T extends EventName> = z.infer<
15
+ (typeof EventSchemas)[T]
16
+ >;
@@ -0,0 +1,15 @@
1
+ import z from "zod";
2
+
3
+ export const userRegisteredSchema = z.object({
4
+ id: z.uuid(),
5
+ email: z.email(),
6
+ });
7
+
8
+ export const userVerifiedSchema = z.object({
9
+ id: z.uuid(),
10
+ });
11
+
12
+ export const UserEventSchemas = {
13
+ "user.registered": userRegisteredSchema,
14
+ "user.verified": userVerifiedSchema,
15
+ } as const;
package/src/index.ts CHANGED
@@ -18,3 +18,7 @@ export * from "./types/UserRoles";
18
18
 
19
19
  // Constants
20
20
  export * from "./constants/HttpStatus";
21
+
22
+ // Events
23
+ export * from "./events/AppEvent";
24
+ export * from "./events/schemas/userEventsSchema";