@skillstew/common 1.0.37 → 1.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.
- package/README.md +85 -0
- package/build/events/EventMap.d.ts +15 -0
- package/build/events/EventMap.js +2 -1
- package/build/events/schemas/expertEventsSchema.d.ts +33 -0
- package/build/events/schemas/expertEventsSchema.js +26 -0
- package/package.json +1 -1
- package/src/events/EventMap.ts +2 -0
- package/src/events/schemas/expertEventsSchema.ts +23 -0
- package/publish.sh +0 -27
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Common Package (`@skillstew/common`)
|
|
2
|
+
|
|
3
|
+
A shared npm package containing event definitions used across all services. It defines the canonical event names, Zod payload schemas, and the `AppEvent` envelope type.
|
|
4
|
+
|
|
5
|
+
**Published to:** npm (`@skillstew/common`)
|
|
6
|
+
**Package Manager:** npm
|
|
7
|
+
**Version:** patch-bumped on each publish via `npm run pub`
|
|
8
|
+
|
|
9
|
+
## What It Exports
|
|
10
|
+
|
|
11
|
+
### `AppEvent<T>`
|
|
12
|
+
|
|
13
|
+
The envelope type for all inter-service events:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
interface AppEvent<T extends EventName> {
|
|
17
|
+
eventId: string;
|
|
18
|
+
eventName: T;
|
|
19
|
+
timestamp: string; // ISO format
|
|
20
|
+
producer: string; // service that emitted the event
|
|
21
|
+
data: EventPayload<T>; // Zod-validated payload
|
|
22
|
+
traceId?: string;
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### `CreateEvent(eventName, data, producer, traceId?)`
|
|
27
|
+
|
|
28
|
+
Factory function that builds an `AppEvent` with a random UUID and ISO timestamp.
|
|
29
|
+
|
|
30
|
+
### `EventSchemas`
|
|
31
|
+
|
|
32
|
+
A single object mapping every event name to its Zod schema. Used by outbox workers to validate payloads before publishing, and by consumers to parse incoming events.
|
|
33
|
+
|
|
34
|
+
### `EventName` / `EventPayload<T>`
|
|
35
|
+
|
|
36
|
+
Derived types — `EventName` is the union of all event name strings, and `EventPayload<T>` infers the payload type from the corresponding Zod schema.
|
|
37
|
+
|
|
38
|
+
## Event Catalog
|
|
39
|
+
|
|
40
|
+
### User Events
|
|
41
|
+
|
|
42
|
+
| Event Name | Payload Fields |
|
|
43
|
+
| --------------------- | ------------------------------------------------------------------- |
|
|
44
|
+
| `user.registered` | `id`, `email` |
|
|
45
|
+
| `user.verified` | `id` |
|
|
46
|
+
| `user.profileUpdated` | `id`, `name?`, `username?`, `location?`, `languages?`, `avatarKey?` |
|
|
47
|
+
|
|
48
|
+
### Skill Events
|
|
49
|
+
|
|
50
|
+
| Event Name | Payload Fields |
|
|
51
|
+
| ---------------------- | ---------------------------------------------------------- |
|
|
52
|
+
| `skill.created` | `id`, `name`, `normalizedName`, `alternateNames`, `status` |
|
|
53
|
+
| `skill.updated` | Same as `skill.created` |
|
|
54
|
+
| `skill.deleted` | `id` |
|
|
55
|
+
| `skill.profileUpdated` | `userId`, `offered[{id, name}]`, `wanted[{id, name}]` |
|
|
56
|
+
|
|
57
|
+
### Connection Events
|
|
58
|
+
|
|
59
|
+
| Event Name | Payload Fields |
|
|
60
|
+
| ---------------------- | ----------------------------------------------------------------------------------------------------- |
|
|
61
|
+
| `connection.requested` | `connectionId`, `requesterId`, `requesterUsername?`, `recipientId`, `recipientUsername?`, `timestamp` |
|
|
62
|
+
| `connection.accepted` | `connectionId`, `accepterId`, `accepterUsername?`, `requesterId`, `requesterUsername?`, `timestamp` |
|
|
63
|
+
| `connection.rejected` | `connectionId`, `rejecterId`, `rejecterUsername?`, `requesterId`, `requesterUsername?`, `timestamp` |
|
|
64
|
+
|
|
65
|
+
## Adding a New Event
|
|
66
|
+
|
|
67
|
+
1. Create or update a Zod schema in `src/events/schemas/`
|
|
68
|
+
2. Add the event name → schema mapping to the schema group object (e.g., `UserEventSchemas`)
|
|
69
|
+
3. The event name is automatically available in `EventName`, and the payload type is inferred from the schema
|
|
70
|
+
4. Run `npm run pub` to patch-bump, build, and publish
|
|
71
|
+
|
|
72
|
+
## Directory Structure
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
common/src/
|
|
76
|
+
├── index.ts # Re-exports everything
|
|
77
|
+
└── events/
|
|
78
|
+
├── AppEvent.ts # AppEvent<T> interface
|
|
79
|
+
├── CreateEvent.ts # Factory function
|
|
80
|
+
├── EventMap.ts # EventSchemas, EventName, EventPayload<T>
|
|
81
|
+
└── schemas/
|
|
82
|
+
├── userEventsSchema.ts # user.registered, user.verified, user.profileUpdated
|
|
83
|
+
├── skillsEventSchemas.ts # skill.created, skill.updated, skill.deleted, skill.profileUpdated
|
|
84
|
+
└── userConnectionEventSchemas.ts # connection.requested, connection.accepted, connection.rejected
|
|
85
|
+
```
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
2
|
export declare const EventSchemas: {
|
|
3
|
+
readonly "expert.registered": z.ZodObject<{
|
|
4
|
+
id: z.ZodUUID;
|
|
5
|
+
email: z.ZodEmail;
|
|
6
|
+
token: z.ZodString;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
readonly "expert.onboarded": z.ZodObject<{
|
|
9
|
+
expertId: z.ZodUUID;
|
|
10
|
+
fullName: z.ZodString;
|
|
11
|
+
bio: z.ZodString;
|
|
12
|
+
socialLinks: z.ZodArray<z.ZodString>;
|
|
13
|
+
username: z.ZodString;
|
|
14
|
+
yearsExperience: z.ZodNumber;
|
|
15
|
+
hasTeachingExperience: z.ZodBoolean;
|
|
16
|
+
teachingExperienceDesc: z.ZodString;
|
|
17
|
+
}, z.core.$strip>;
|
|
3
18
|
readonly "connection.requested": z.ZodObject<{
|
|
4
19
|
connectionId: z.ZodString;
|
|
5
20
|
requesterId: z.ZodString;
|
package/build/events/EventMap.js
CHANGED
|
@@ -4,7 +4,8 @@ exports.EventName = exports.EventSchemas = void 0;
|
|
|
4
4
|
const userEventsSchema_1 = require("./schemas/userEventsSchema");
|
|
5
5
|
const skillsEventSchemas_1 = require("./schemas/skillsEventSchemas");
|
|
6
6
|
const userConnectionEventSchemas_1 = require("./schemas/userConnectionEventSchemas");
|
|
7
|
+
const expertEventsSchema_1 = require("./schemas/expertEventsSchema");
|
|
7
8
|
// Union of all app event schemas
|
|
8
|
-
exports.EventSchemas = Object.assign(Object.assign(Object.assign({}, userEventsSchema_1.UserEventSchemas), skillsEventSchemas_1.SkillsEventSchemas), userConnectionEventSchemas_1.ConnectionEventSchemas);
|
|
9
|
+
exports.EventSchemas = Object.assign(Object.assign(Object.assign(Object.assign({}, userEventsSchema_1.UserEventSchemas), skillsEventSchemas_1.SkillsEventSchemas), userConnectionEventSchemas_1.ConnectionEventSchemas), expertEventsSchema_1.ExpertEventSchemas);
|
|
9
10
|
// Array of all event names
|
|
10
11
|
exports.EventName = Object.keys(exports.EventSchemas);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
export declare const expertRegisteredSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodUUID;
|
|
4
|
+
email: z.ZodEmail;
|
|
5
|
+
token: z.ZodString;
|
|
6
|
+
}, z.core.$strip>;
|
|
7
|
+
export declare const newExpertOnboardedSchema: z.ZodObject<{
|
|
8
|
+
expertId: z.ZodUUID;
|
|
9
|
+
fullName: z.ZodString;
|
|
10
|
+
bio: z.ZodString;
|
|
11
|
+
socialLinks: z.ZodArray<z.ZodString>;
|
|
12
|
+
username: z.ZodString;
|
|
13
|
+
yearsExperience: z.ZodNumber;
|
|
14
|
+
hasTeachingExperience: z.ZodBoolean;
|
|
15
|
+
teachingExperienceDesc: z.ZodString;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
export declare const ExpertEventSchemas: {
|
|
18
|
+
readonly "expert.registered": z.ZodObject<{
|
|
19
|
+
id: z.ZodUUID;
|
|
20
|
+
email: z.ZodEmail;
|
|
21
|
+
token: z.ZodString;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
readonly "expert.onboarded": z.ZodObject<{
|
|
24
|
+
expertId: z.ZodUUID;
|
|
25
|
+
fullName: z.ZodString;
|
|
26
|
+
bio: z.ZodString;
|
|
27
|
+
socialLinks: z.ZodArray<z.ZodString>;
|
|
28
|
+
username: z.ZodString;
|
|
29
|
+
yearsExperience: z.ZodNumber;
|
|
30
|
+
hasTeachingExperience: z.ZodBoolean;
|
|
31
|
+
teachingExperienceDesc: z.ZodString;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
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.ExpertEventSchemas = exports.newExpertOnboardedSchema = exports.expertRegisteredSchema = void 0;
|
|
7
|
+
const zod_1 = __importDefault(require("zod"));
|
|
8
|
+
exports.expertRegisteredSchema = zod_1.default.object({
|
|
9
|
+
id: zod_1.default.uuid(),
|
|
10
|
+
email: zod_1.default.email(),
|
|
11
|
+
token: zod_1.default.string(),
|
|
12
|
+
});
|
|
13
|
+
exports.newExpertOnboardedSchema = zod_1.default.object({
|
|
14
|
+
expertId: zod_1.default.uuid(),
|
|
15
|
+
fullName: zod_1.default.string(),
|
|
16
|
+
bio: zod_1.default.string(),
|
|
17
|
+
socialLinks: zod_1.default.array(zod_1.default.string()),
|
|
18
|
+
username: zod_1.default.string(),
|
|
19
|
+
yearsExperience: zod_1.default.number(),
|
|
20
|
+
hasTeachingExperience: zod_1.default.boolean(),
|
|
21
|
+
teachingExperienceDesc: zod_1.default.string(),
|
|
22
|
+
});
|
|
23
|
+
exports.ExpertEventSchemas = {
|
|
24
|
+
"expert.registered": exports.expertRegisteredSchema,
|
|
25
|
+
"expert.onboarded": exports.newExpertOnboardedSchema,
|
|
26
|
+
};
|
package/package.json
CHANGED
package/src/events/EventMap.ts
CHANGED
|
@@ -2,6 +2,7 @@ import z from "zod";
|
|
|
2
2
|
import { UserEventSchemas } from "./schemas/userEventsSchema";
|
|
3
3
|
import { SkillsEventSchemas } from "./schemas/skillsEventSchemas";
|
|
4
4
|
import { ConnectionEventSchemas } from "./schemas/userConnectionEventSchemas";
|
|
5
|
+
import { ExpertEventSchemas } from "./schemas/expertEventsSchema";
|
|
5
6
|
|
|
6
7
|
// Union of all app event schemas
|
|
7
8
|
|
|
@@ -9,6 +10,7 @@ export const EventSchemas = {
|
|
|
9
10
|
...UserEventSchemas,
|
|
10
11
|
...SkillsEventSchemas,
|
|
11
12
|
...ConnectionEventSchemas,
|
|
13
|
+
...ExpertEventSchemas,
|
|
12
14
|
} as const;
|
|
13
15
|
|
|
14
16
|
// Array of all event names
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
|
|
3
|
+
export const expertRegisteredSchema = z.object({
|
|
4
|
+
id: z.uuid(),
|
|
5
|
+
email: z.email(),
|
|
6
|
+
token: z.string(),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export const newExpertOnboardedSchema = z.object({
|
|
10
|
+
expertId: z.uuid(),
|
|
11
|
+
fullName: z.string(),
|
|
12
|
+
bio: z.string(),
|
|
13
|
+
socialLinks: z.array(z.string()),
|
|
14
|
+
username: z.string(),
|
|
15
|
+
yearsExperience: z.number(),
|
|
16
|
+
hasTeachingExperience: z.boolean(),
|
|
17
|
+
teachingExperienceDesc: z.string(),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const ExpertEventSchemas = {
|
|
21
|
+
"expert.registered": expertRegisteredSchema,
|
|
22
|
+
"expert.onboarded": newExpertOnboardedSchema,
|
|
23
|
+
} as const;
|
package/publish.sh
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Exit immediately on error
|
|
4
|
-
set -e
|
|
5
|
-
|
|
6
|
-
# Change to correct dir
|
|
7
|
-
cd "/home/faheem/Work/dev/brototype/skillStew/skill-stew-api/common/"
|
|
8
|
-
|
|
9
|
-
# Step 1: Bump patch version
|
|
10
|
-
npm version patch
|
|
11
|
-
|
|
12
|
-
# Step 2: Build the package
|
|
13
|
-
npm run build
|
|
14
|
-
|
|
15
|
-
# Step 3: Stage all changes
|
|
16
|
-
git add .
|
|
17
|
-
|
|
18
|
-
# Step 4: Prompt for a commit message
|
|
19
|
-
echo "Enter commit message:"
|
|
20
|
-
read COMMIT_MESSAGE
|
|
21
|
-
git commit -m "$COMMIT_MESSAGE"
|
|
22
|
-
|
|
23
|
-
# Step 5: Push to GitHub
|
|
24
|
-
git push
|
|
25
|
-
|
|
26
|
-
# Step 6: Publish to npm
|
|
27
|
-
npm publish
|