@skillstew/common 1.0.12 → 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.
- package/build/events/AppEvent.d.ts +12 -0
- package/build/events/AppEvent.js +2 -0
- package/build/events/EventMap.d.ts +12 -0
- package/build/events/EventMap.js +6 -0
- package/build/events/schemas/userEventsSchema.d.ts +17 -0
- package/build/events/schemas/userEventsSchema.js +18 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +3 -0
- package/package.json +3 -2
- package/src/events/AppEvent.ts +15 -0
- package/src/events/EventMap.ts +16 -0
- package/src/events/schemas/userEventsSchema.ts +15 -0
- package/src/index.ts +4 -0
|
@@ -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,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
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.
|
|
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;
|