@skillstew/common 1.0.11 → 1.0.13

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,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
@@ -3,8 +3,11 @@ export * from "./errors/JwtErrors";
3
3
  export * from "./errors/UnauthenticatedError";
4
4
  export * from "./errors/UnauthorizedError";
5
5
  export * from "./errors/codes/JwtErrorCodes";
6
+ export * from "./errors/ForbiddenError";
6
7
  export * from "./jwt-utils/JwtHelper";
7
8
  export * from "./middlewares/authMiddleware";
8
9
  export * from "./middlewares/requireRole";
9
10
  export * from "./types/UserRoles";
10
11
  export * from "./constants/HttpStatus";
12
+ export * from "./events/AppEvent";
13
+ export * from "./events/schemas/userEventsSchema";
package/build/index.js CHANGED
@@ -20,6 +20,7 @@ __exportStar(require("./errors/JwtErrors"), exports);
20
20
  __exportStar(require("./errors/UnauthenticatedError"), exports);
21
21
  __exportStar(require("./errors/UnauthorizedError"), exports);
22
22
  __exportStar(require("./errors/codes/JwtErrorCodes"), exports);
23
+ __exportStar(require("./errors/ForbiddenError"), exports);
23
24
  // Helpers
24
25
  __exportStar(require("./jwt-utils/JwtHelper"), exports);
25
26
  // Middlewares
@@ -29,3 +30,6 @@ __exportStar(require("./middlewares/requireRole"), exports);
29
30
  __exportStar(require("./types/UserRoles"), exports);
30
31
  // Constants
31
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.11",
3
+ "version": "1.0.13",
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
  }
@@ -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,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
@@ -4,6 +4,7 @@ export * from "./errors/JwtErrors";
4
4
  export * from "./errors/UnauthenticatedError";
5
5
  export * from "./errors/UnauthorizedError";
6
6
  export * from "./errors/codes/JwtErrorCodes";
7
+ export * from "./errors/ForbiddenError";
7
8
 
8
9
  // Helpers
9
10
  export * from "./jwt-utils/JwtHelper";
@@ -17,3 +18,7 @@ export * from "./types/UserRoles";
17
18
 
18
19
  // Constants
19
20
  export * from "./constants/HttpStatus";
21
+
22
+ // Events
23
+ export * from "./events/AppEvent";
24
+ export * from "./events/schemas/userEventsSchema";