@livetronics/wocul-domain 0.0.0-stage → 1.1.0
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 +91 -2
- package/dist/api/generated.d.ts +39302 -0
- package/dist/api/generated.js +2 -0
- package/dist/api/index.d.ts +37 -0
- package/dist/api/index.js +2 -0
- package/dist/channels.d.ts +31 -0
- package/dist/channels.js +34 -0
- package/dist/events/data.d.ts +427 -0
- package/dist/events/data.js +154 -0
- package/dist/events/message.d.ts +188 -0
- package/dist/events/message.js +99 -0
- package/dist/events/types.d.ts +27 -0
- package/dist/events/types.js +83 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +45 -0
- package/dist/intents.d.ts +305 -0
- package/dist/intents.js +149 -0
- package/package.json +40 -5
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.eventDataSchemas = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* The `data` each realtime event carries: ids, statuses and categories,
|
|
7
|
+
* never content. Clients re-read through the API.
|
|
8
|
+
*
|
|
9
|
+
* Two rules keep these schemas from breaking a client when a server moves on:
|
|
10
|
+
* - only ids are required. core-ts replaces an oversized payload with its
|
|
11
|
+
* id fields alone, so anything else may be missing;
|
|
12
|
+
* - unknown fields pass through. A newer server can add a field without a
|
|
13
|
+
* package release.
|
|
14
|
+
*
|
|
15
|
+
* Shapes were taken from the publishers (core-ts src/services/events, and
|
|
16
|
+
* notification-ts src/services/realtime/publish.ts) and checked against
|
|
17
|
+
* every row in the dev outbox on 15 Nov 2026.
|
|
18
|
+
*/
|
|
19
|
+
const id = zod_1.z.number().int().positive();
|
|
20
|
+
const stringId = zod_1.z.string().min(1);
|
|
21
|
+
const staff = zod_1.z.array(id);
|
|
22
|
+
const logged = {
|
|
23
|
+
/** The log category, e.g. ASSIGNEE_CHANGE, STATUS_CHANGE, WATCHERS. */
|
|
24
|
+
category: zod_1.z.string().optional(),
|
|
25
|
+
/** The log template, e.g. Task-Reassigned. */
|
|
26
|
+
templateId: zod_1.z.string().optional(),
|
|
27
|
+
/** People whose own lists change, told on staff:<id>. */
|
|
28
|
+
staff: staff.optional()
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* A sub-task's parent. A sub-task's task.* event is also published on
|
|
32
|
+
* task:<idTaskParent>, where the parent's panel lists its sub-tasks.
|
|
33
|
+
*/
|
|
34
|
+
const subTaskOf = { idTaskParent: id.optional() };
|
|
35
|
+
/**
|
|
36
|
+
* The board the task is on as the event goes out, or null when it is on
|
|
37
|
+
* none. Absent from producers before core 4.2: a board treats a missing
|
|
38
|
+
* value as possibly its own. A task that left a board (moved, removed,
|
|
39
|
+
* deleted) names its new board or null; the board it left knows it by the
|
|
40
|
+
* id among the tasks it shows.
|
|
41
|
+
*/
|
|
42
|
+
const onBoard = { idSprint: id.nullable().optional() };
|
|
43
|
+
exports.eventDataSchemas = {
|
|
44
|
+
'task.created': zod_1.z
|
|
45
|
+
.object({ idTask: id, ...logged, ...subTaskOf, ...onBoard })
|
|
46
|
+
.passthrough(),
|
|
47
|
+
'task.changed': zod_1.z
|
|
48
|
+
.object({
|
|
49
|
+
idTask: id,
|
|
50
|
+
...logged,
|
|
51
|
+
...subTaskOf,
|
|
52
|
+
...onBoard,
|
|
53
|
+
idAssignee: id.optional(),
|
|
54
|
+
idTaskComment: id.optional()
|
|
55
|
+
})
|
|
56
|
+
.passthrough(),
|
|
57
|
+
'task.removed': zod_1.z
|
|
58
|
+
.object({ idTask: id, ...logged, ...subTaskOf, ...onBoard })
|
|
59
|
+
.passthrough(),
|
|
60
|
+
'comment.changed': zod_1.z
|
|
61
|
+
.object({ idTask: id, idTaskComment: id, ...logged })
|
|
62
|
+
.passthrough(),
|
|
63
|
+
'approval.changed': zod_1.z
|
|
64
|
+
.object({ idTask: id, ...logged, idTaskComment: id.optional() })
|
|
65
|
+
.passthrough(),
|
|
66
|
+
'board.changed': zod_1.z.object({ idSprint: id, ...logged }).passthrough(),
|
|
67
|
+
'project.changed': zod_1.z.object({ idProject: id, ...logged }).passthrough(),
|
|
68
|
+
'membership.changed': zod_1.z.object({ idProject: id, ...logged }).passthrough(),
|
|
69
|
+
'okr.changed': zod_1.z
|
|
70
|
+
.object({
|
|
71
|
+
idObjective: id,
|
|
72
|
+
...logged,
|
|
73
|
+
/** Every project the objective is mapped to. */
|
|
74
|
+
projects: zod_1.z.array(id).optional()
|
|
75
|
+
})
|
|
76
|
+
.passthrough(),
|
|
77
|
+
'run.changed': zod_1.z
|
|
78
|
+
.object({
|
|
79
|
+
idAgentRun: id,
|
|
80
|
+
idTask: id,
|
|
81
|
+
status: zod_1.z.string().optional(),
|
|
82
|
+
stepType: zod_1.z.string().optional(),
|
|
83
|
+
stepStatus: zod_1.z.string().optional(),
|
|
84
|
+
needsInput: zod_1.z.boolean().optional(),
|
|
85
|
+
triggerType: zod_1.z.string().optional()
|
|
86
|
+
})
|
|
87
|
+
.passthrough(),
|
|
88
|
+
'draft.changed': zod_1.z
|
|
89
|
+
.object({
|
|
90
|
+
idDraft: stringId,
|
|
91
|
+
status: zod_1.z.string().optional(),
|
|
92
|
+
actionType: zod_1.z.string().optional(),
|
|
93
|
+
progress: zod_1.z.record(zod_1.z.unknown()).optional(),
|
|
94
|
+
staff: staff.optional()
|
|
95
|
+
})
|
|
96
|
+
.passthrough(),
|
|
97
|
+
'pulse.changed': zod_1.z
|
|
98
|
+
.object({
|
|
99
|
+
idFeedback: stringId,
|
|
100
|
+
idSprint: id,
|
|
101
|
+
status: zod_1.z.string().optional()
|
|
102
|
+
})
|
|
103
|
+
.passthrough(),
|
|
104
|
+
'kb.changed': zod_1.z
|
|
105
|
+
.object({ idDocument: stringId, status: zod_1.z.string().optional() })
|
|
106
|
+
.passthrough(),
|
|
107
|
+
'cycle.closed': zod_1.z
|
|
108
|
+
.object({
|
|
109
|
+
idSprintCycle: id,
|
|
110
|
+
idSprint: id,
|
|
111
|
+
onTime: zod_1.z.boolean().optional()
|
|
112
|
+
})
|
|
113
|
+
.passthrough(),
|
|
114
|
+
'dictionary.profiled': zod_1.z
|
|
115
|
+
.object({ idDataDictionary: id, idOrganisationDatabaseConnection: id })
|
|
116
|
+
.passthrough(),
|
|
117
|
+
'subscription.changed': zod_1.z
|
|
118
|
+
.object({
|
|
119
|
+
status: zod_1.z.string().optional(),
|
|
120
|
+
category: zod_1.z.string().optional()
|
|
121
|
+
})
|
|
122
|
+
.passthrough(),
|
|
123
|
+
'deepwork.changed': zod_1.z
|
|
124
|
+
.object({
|
|
125
|
+
idDeepWorkSession: id,
|
|
126
|
+
status: zod_1.z.string().optional(),
|
|
127
|
+
staff: staff.optional()
|
|
128
|
+
})
|
|
129
|
+
.passthrough(),
|
|
130
|
+
'plan.changed': zod_1.z
|
|
131
|
+
.object({
|
|
132
|
+
idPlanRun: stringId,
|
|
133
|
+
runType: zod_1.z.string().optional(),
|
|
134
|
+
status: zod_1.z.string().optional(),
|
|
135
|
+
staff: staff.optional()
|
|
136
|
+
})
|
|
137
|
+
.passthrough(),
|
|
138
|
+
'notification.created': zod_1.z
|
|
139
|
+
.object({
|
|
140
|
+
idStaff: id,
|
|
141
|
+
category: zod_1.z.string().optional(),
|
|
142
|
+
eventType: zod_1.z.string().optional(),
|
|
143
|
+
queueId: stringId.optional()
|
|
144
|
+
})
|
|
145
|
+
.passthrough(),
|
|
146
|
+
'notification.read': zod_1.z
|
|
147
|
+
.object({
|
|
148
|
+
idStaff: id,
|
|
149
|
+
scope: zod_1.z.string().optional(),
|
|
150
|
+
idNotifications: zod_1.z.array(stringId).optional(),
|
|
151
|
+
count: zod_1.z.number().int().nonnegative().optional()
|
|
152
|
+
})
|
|
153
|
+
.passthrough()
|
|
154
|
+
};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { RealtimeEventType } from './types';
|
|
3
|
+
import type { EventData } from './data';
|
|
4
|
+
/**
|
|
5
|
+
* The frame a realtime subscriber receives. core-ts's relay and
|
|
6
|
+
* notification-ts build it; the gateway adds `channel`, `seq` and
|
|
7
|
+
* `publishedAt` on the way out.
|
|
8
|
+
*/
|
|
9
|
+
export declare const frameSchema: z.ZodObject<{
|
|
10
|
+
type: z.ZodString;
|
|
11
|
+
eventId: z.ZodString;
|
|
12
|
+
entity: z.ZodObject<{
|
|
13
|
+
type: z.ZodString;
|
|
14
|
+
id: z.ZodString;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
type: string;
|
|
17
|
+
id: string;
|
|
18
|
+
}, {
|
|
19
|
+
type: string;
|
|
20
|
+
id: string;
|
|
21
|
+
}>;
|
|
22
|
+
idOrganisation: z.ZodNumber;
|
|
23
|
+
idProject: z.ZodNullable<z.ZodNumber>;
|
|
24
|
+
/** The entity's row version, when the writer knew it. */
|
|
25
|
+
version: z.ZodNullable<z.ZodNumber>;
|
|
26
|
+
actor: z.ZodNullable<z.ZodObject<{
|
|
27
|
+
type: z.ZodEnum<["STAFF", "SYSTEM", "AGENT"]>;
|
|
28
|
+
idStaff: z.ZodNullable<z.ZodNumber>;
|
|
29
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
|
+
type: "STAFF" | "SYSTEM" | "AGENT";
|
|
31
|
+
idStaff: number | null;
|
|
32
|
+
}, {
|
|
33
|
+
type: "STAFF" | "SYSTEM" | "AGENT";
|
|
34
|
+
idStaff: number | null;
|
|
35
|
+
}>>;
|
|
36
|
+
data: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
37
|
+
channel: z.ZodOptional<z.ZodString>;
|
|
38
|
+
seq: z.ZodOptional<z.ZodNumber>;
|
|
39
|
+
publishedAt: z.ZodOptional<z.ZodString>;
|
|
40
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
41
|
+
type: z.ZodString;
|
|
42
|
+
eventId: z.ZodString;
|
|
43
|
+
entity: z.ZodObject<{
|
|
44
|
+
type: z.ZodString;
|
|
45
|
+
id: z.ZodString;
|
|
46
|
+
}, "strip", z.ZodTypeAny, {
|
|
47
|
+
type: string;
|
|
48
|
+
id: string;
|
|
49
|
+
}, {
|
|
50
|
+
type: string;
|
|
51
|
+
id: string;
|
|
52
|
+
}>;
|
|
53
|
+
idOrganisation: z.ZodNumber;
|
|
54
|
+
idProject: z.ZodNullable<z.ZodNumber>;
|
|
55
|
+
/** The entity's row version, when the writer knew it. */
|
|
56
|
+
version: z.ZodNullable<z.ZodNumber>;
|
|
57
|
+
actor: z.ZodNullable<z.ZodObject<{
|
|
58
|
+
type: z.ZodEnum<["STAFF", "SYSTEM", "AGENT"]>;
|
|
59
|
+
idStaff: z.ZodNullable<z.ZodNumber>;
|
|
60
|
+
}, "strip", z.ZodTypeAny, {
|
|
61
|
+
type: "STAFF" | "SYSTEM" | "AGENT";
|
|
62
|
+
idStaff: number | null;
|
|
63
|
+
}, {
|
|
64
|
+
type: "STAFF" | "SYSTEM" | "AGENT";
|
|
65
|
+
idStaff: number | null;
|
|
66
|
+
}>>;
|
|
67
|
+
data: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
68
|
+
channel: z.ZodOptional<z.ZodString>;
|
|
69
|
+
seq: z.ZodOptional<z.ZodNumber>;
|
|
70
|
+
publishedAt: z.ZodOptional<z.ZodString>;
|
|
71
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
72
|
+
type: z.ZodString;
|
|
73
|
+
eventId: z.ZodString;
|
|
74
|
+
entity: z.ZodObject<{
|
|
75
|
+
type: z.ZodString;
|
|
76
|
+
id: z.ZodString;
|
|
77
|
+
}, "strip", z.ZodTypeAny, {
|
|
78
|
+
type: string;
|
|
79
|
+
id: string;
|
|
80
|
+
}, {
|
|
81
|
+
type: string;
|
|
82
|
+
id: string;
|
|
83
|
+
}>;
|
|
84
|
+
idOrganisation: z.ZodNumber;
|
|
85
|
+
idProject: z.ZodNullable<z.ZodNumber>;
|
|
86
|
+
/** The entity's row version, when the writer knew it. */
|
|
87
|
+
version: z.ZodNullable<z.ZodNumber>;
|
|
88
|
+
actor: z.ZodNullable<z.ZodObject<{
|
|
89
|
+
type: z.ZodEnum<["STAFF", "SYSTEM", "AGENT"]>;
|
|
90
|
+
idStaff: z.ZodNullable<z.ZodNumber>;
|
|
91
|
+
}, "strip", z.ZodTypeAny, {
|
|
92
|
+
type: "STAFF" | "SYSTEM" | "AGENT";
|
|
93
|
+
idStaff: number | null;
|
|
94
|
+
}, {
|
|
95
|
+
type: "STAFF" | "SYSTEM" | "AGENT";
|
|
96
|
+
idStaff: number | null;
|
|
97
|
+
}>>;
|
|
98
|
+
data: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
99
|
+
channel: z.ZodOptional<z.ZodString>;
|
|
100
|
+
seq: z.ZodOptional<z.ZodNumber>;
|
|
101
|
+
publishedAt: z.ZodOptional<z.ZodString>;
|
|
102
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
103
|
+
export type Frame = z.infer<typeof frameSchema>;
|
|
104
|
+
/** A frame whose type this package knows, with its `data` typed. */
|
|
105
|
+
export type RealtimeMessage = {
|
|
106
|
+
[T in RealtimeEventType]: Omit<Frame, 'type' | 'data'> & {
|
|
107
|
+
type: T;
|
|
108
|
+
data: EventData<T>;
|
|
109
|
+
};
|
|
110
|
+
}[RealtimeEventType];
|
|
111
|
+
export type MessageOf<T extends RealtimeEventType> = Extract<RealtimeMessage, {
|
|
112
|
+
type: T;
|
|
113
|
+
}>;
|
|
114
|
+
/**
|
|
115
|
+
* Frames the gateway sends about the connection itself, on the same socket
|
|
116
|
+
* as events: `ready` after auth and `renewed` after a renewed token (each
|
|
117
|
+
* with `expiresAt`), `subscribed` / `unsubscribed` / `resync` per channel
|
|
118
|
+
* (with `seq` where it has one, `reason` when the server dropped a
|
|
119
|
+
* subscription), and `error` with a `code`.
|
|
120
|
+
*/
|
|
121
|
+
export declare const CONTROL_FRAME_TYPES: readonly ["ready", "renewed", "subscribed", "unsubscribed", "resync", "error"];
|
|
122
|
+
export type ControlFrameType = (typeof CONTROL_FRAME_TYPES)[number];
|
|
123
|
+
export declare const controlFrameSchema: z.ZodObject<{
|
|
124
|
+
type: z.ZodEnum<["ready", "renewed", "subscribed", "unsubscribed", "resync", "error"]>;
|
|
125
|
+
channel: z.ZodOptional<z.ZodString>;
|
|
126
|
+
seq: z.ZodOptional<z.ZodNumber>;
|
|
127
|
+
code: z.ZodOptional<z.ZodString>;
|
|
128
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
129
|
+
/** When the socket's token expires (`ready`, `renewed`). */
|
|
130
|
+
expiresAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
131
|
+
/** Who the socket is (`ready`). */
|
|
132
|
+
idStaff: z.ZodOptional<z.ZodNumber>;
|
|
133
|
+
idOrganisation: z.ZodOptional<z.ZodNumber>;
|
|
134
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
135
|
+
type: z.ZodEnum<["ready", "renewed", "subscribed", "unsubscribed", "resync", "error"]>;
|
|
136
|
+
channel: z.ZodOptional<z.ZodString>;
|
|
137
|
+
seq: z.ZodOptional<z.ZodNumber>;
|
|
138
|
+
code: z.ZodOptional<z.ZodString>;
|
|
139
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
140
|
+
/** When the socket's token expires (`ready`, `renewed`). */
|
|
141
|
+
expiresAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
142
|
+
/** Who the socket is (`ready`). */
|
|
143
|
+
idStaff: z.ZodOptional<z.ZodNumber>;
|
|
144
|
+
idOrganisation: z.ZodOptional<z.ZodNumber>;
|
|
145
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
146
|
+
type: z.ZodEnum<["ready", "renewed", "subscribed", "unsubscribed", "resync", "error"]>;
|
|
147
|
+
channel: z.ZodOptional<z.ZodString>;
|
|
148
|
+
seq: z.ZodOptional<z.ZodNumber>;
|
|
149
|
+
code: z.ZodOptional<z.ZodString>;
|
|
150
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
151
|
+
/** When the socket's token expires (`ready`, `renewed`). */
|
|
152
|
+
expiresAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
153
|
+
/** Who the socket is (`ready`). */
|
|
154
|
+
idStaff: z.ZodOptional<z.ZodNumber>;
|
|
155
|
+
idOrganisation: z.ZodOptional<z.ZodNumber>;
|
|
156
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
157
|
+
export type ControlFrame = z.infer<typeof controlFrameSchema>;
|
|
158
|
+
export type ParseResult =
|
|
159
|
+
/** A gateway frame about the connection or a subscription, not an event. */
|
|
160
|
+
{
|
|
161
|
+
kind: 'control';
|
|
162
|
+
frame: ControlFrame;
|
|
163
|
+
}
|
|
164
|
+
/** A known type whose frame and data match. */
|
|
165
|
+
| {
|
|
166
|
+
kind: 'known';
|
|
167
|
+
message: RealtimeMessage;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* A well-formed frame of a type this version does not know (a newer
|
|
171
|
+
* server). Treat it as a hint without data.
|
|
172
|
+
*/
|
|
173
|
+
| {
|
|
174
|
+
kind: 'unknown';
|
|
175
|
+
message: Frame;
|
|
176
|
+
}
|
|
177
|
+
/** Not a frame, or a known type whose data does not match. */
|
|
178
|
+
| {
|
|
179
|
+
kind: 'invalid';
|
|
180
|
+
error: string;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Validates a raw frame. Never throws: a client should keep its socket and
|
|
184
|
+
* fall back to a plain re-read rather than fail on one odd message.
|
|
185
|
+
*/
|
|
186
|
+
export declare function parseMessage(raw: unknown): ParseResult;
|
|
187
|
+
/** Narrows a parsed message to one type. */
|
|
188
|
+
export declare const isMessageOf: <T extends RealtimeEventType>(message: RealtimeMessage, type: T) => message is MessageOf<T>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isMessageOf = exports.controlFrameSchema = exports.CONTROL_FRAME_TYPES = exports.frameSchema = void 0;
|
|
4
|
+
exports.parseMessage = parseMessage;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const types_1 = require("./types");
|
|
7
|
+
const data_1 = require("./data");
|
|
8
|
+
/**
|
|
9
|
+
* The frame a realtime subscriber receives. core-ts's relay and
|
|
10
|
+
* notification-ts build it; the gateway adds `channel`, `seq` and
|
|
11
|
+
* `publishedAt` on the way out.
|
|
12
|
+
*/
|
|
13
|
+
exports.frameSchema = zod_1.z
|
|
14
|
+
.object({
|
|
15
|
+
type: zod_1.z.string().min(1),
|
|
16
|
+
eventId: zod_1.z.string().min(1),
|
|
17
|
+
entity: zod_1.z.object({ type: zod_1.z.string(), id: zod_1.z.string() }),
|
|
18
|
+
idOrganisation: zod_1.z.number().int(),
|
|
19
|
+
idProject: zod_1.z.number().int().nullable(),
|
|
20
|
+
/** The entity's row version, when the writer knew it. */
|
|
21
|
+
version: zod_1.z.number().int().nullable(),
|
|
22
|
+
actor: zod_1.z
|
|
23
|
+
.object({
|
|
24
|
+
type: zod_1.z.enum(types_1.ACTOR_TYPES),
|
|
25
|
+
idStaff: zod_1.z.number().int().nullable()
|
|
26
|
+
})
|
|
27
|
+
.nullable(),
|
|
28
|
+
data: zod_1.z.record(zod_1.z.unknown()).nullable(),
|
|
29
|
+
channel: zod_1.z.string().optional(),
|
|
30
|
+
seq: zod_1.z.number().int().optional(),
|
|
31
|
+
publishedAt: zod_1.z.string().optional()
|
|
32
|
+
})
|
|
33
|
+
.passthrough();
|
|
34
|
+
/**
|
|
35
|
+
* Frames the gateway sends about the connection itself, on the same socket
|
|
36
|
+
* as events: `ready` after auth and `renewed` after a renewed token (each
|
|
37
|
+
* with `expiresAt`), `subscribed` / `unsubscribed` / `resync` per channel
|
|
38
|
+
* (with `seq` where it has one, `reason` when the server dropped a
|
|
39
|
+
* subscription), and `error` with a `code`.
|
|
40
|
+
*/
|
|
41
|
+
exports.CONTROL_FRAME_TYPES = [
|
|
42
|
+
'ready',
|
|
43
|
+
'renewed',
|
|
44
|
+
'subscribed',
|
|
45
|
+
'unsubscribed',
|
|
46
|
+
'resync',
|
|
47
|
+
'error'
|
|
48
|
+
];
|
|
49
|
+
exports.controlFrameSchema = zod_1.z
|
|
50
|
+
.object({
|
|
51
|
+
type: zod_1.z.enum(exports.CONTROL_FRAME_TYPES),
|
|
52
|
+
channel: zod_1.z.string().optional(),
|
|
53
|
+
seq: zod_1.z.number().int().optional(),
|
|
54
|
+
code: zod_1.z.string().optional(),
|
|
55
|
+
reason: zod_1.z.string().optional(),
|
|
56
|
+
/** When the socket's token expires (`ready`, `renewed`). */
|
|
57
|
+
expiresAt: zod_1.z.string().nullable().optional(),
|
|
58
|
+
/** Who the socket is (`ready`). */
|
|
59
|
+
idStaff: zod_1.z.number().int().optional(),
|
|
60
|
+
idOrganisation: zod_1.z.number().int().optional()
|
|
61
|
+
})
|
|
62
|
+
.passthrough();
|
|
63
|
+
/**
|
|
64
|
+
* Validates a raw frame. Never throws: a client should keep its socket and
|
|
65
|
+
* fall back to a plain re-read rather than fail on one odd message.
|
|
66
|
+
*/
|
|
67
|
+
function parseMessage(raw) {
|
|
68
|
+
const control = exports.controlFrameSchema.safeParse(raw);
|
|
69
|
+
if (control.success) {
|
|
70
|
+
return { kind: 'control', frame: control.data };
|
|
71
|
+
}
|
|
72
|
+
const frame = exports.frameSchema.safeParse(raw);
|
|
73
|
+
if (!frame.success) {
|
|
74
|
+
const issue = frame.error.issues[0];
|
|
75
|
+
return {
|
|
76
|
+
kind: 'invalid',
|
|
77
|
+
error: `${issue?.path.join('.') || 'frame'}: ${issue?.message ?? 'not a frame'}`
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const { type } = frame.data;
|
|
81
|
+
if (!(0, types_1.isRealtimeEventType)(type)) {
|
|
82
|
+
return { kind: 'unknown', message: frame.data };
|
|
83
|
+
}
|
|
84
|
+
const data = data_1.eventDataSchemas[type].safeParse(frame.data.data ?? {});
|
|
85
|
+
if (!data.success) {
|
|
86
|
+
const issue = data.error.issues[0];
|
|
87
|
+
return {
|
|
88
|
+
kind: 'invalid',
|
|
89
|
+
error: `${type}: data.${issue?.path.join('.') ?? ''} ${issue?.message ?? ''}`.trim()
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
kind: 'known',
|
|
94
|
+
message: { ...frame.data, type, data: data.data }
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** Narrows a parsed message to one type. */
|
|
98
|
+
const isMessageOf = (message, type) => message.type === type;
|
|
99
|
+
exports.isMessageOf = isMessageOf;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event names shared by every Wocul service. The server half is described in
|
|
3
|
+
* wocul-service-core-ts docs/realtime-events.md.
|
|
4
|
+
*
|
|
5
|
+
* Three kinds of name:
|
|
6
|
+
* - domain events: written to core-ts's DomainEvent outbox and published
|
|
7
|
+
* by its relay on realtime channels as hints ("task 42 changed");
|
|
8
|
+
* - notification events: published by notification-ts on staff:<id>;
|
|
9
|
+
* - intents: written to the same outbox but sent to a service's Redis
|
|
10
|
+
* stream instead of a channel. They wake the service; they are not hints.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DOMAIN_EVENT_TYPES: readonly ["task.created", "task.changed", "task.removed", "comment.changed", "approval.changed", "board.changed", "project.changed", "membership.changed", "okr.changed", "run.changed", "draft.changed", "pulse.changed", "kb.changed", "cycle.closed", "dictionary.profiled", "subscription.changed", "deepwork.changed", "plan.changed"];
|
|
13
|
+
export type DomainEventType = (typeof DOMAIN_EVENT_TYPES)[number];
|
|
14
|
+
export declare const NOTIFICATION_EVENT_TYPES: readonly ["notification.created", "notification.read"];
|
|
15
|
+
export type NotificationEventType = (typeof NOTIFICATION_EVENT_TYPES)[number];
|
|
16
|
+
/** Every type a realtime subscriber can receive. */
|
|
17
|
+
export declare const REALTIME_EVENT_TYPES: readonly ["task.created", "task.changed", "task.removed", "comment.changed", "approval.changed", "board.changed", "project.changed", "membership.changed", "okr.changed", "run.changed", "draft.changed", "pulse.changed", "kb.changed", "cycle.closed", "dictionary.profiled", "subscription.changed", "deepwork.changed", "plan.changed", "notification.created", "notification.read"];
|
|
18
|
+
export type RealtimeEventType = (typeof REALTIME_EVENT_TYPES)[number];
|
|
19
|
+
export declare const INTENT_TYPES: readonly ["notification.requested", "email.requested", "aicomment.requested", "kbproposal.requested", "run.requested"];
|
|
20
|
+
export type IntentType = (typeof INTENT_TYPES)[number];
|
|
21
|
+
export declare const ENTITY_TYPES: readonly ["task", "comment", "approval", "sprint", "kanbanColumn", "project", "member", "objective", "keyResult", "run", "draft", "pulse", "document", "cycle", "dictionary", "subscription", "deepwork", "plan", "notification", "email", "aicomment", "kbproposal", "staff"];
|
|
22
|
+
export type EntityType = (typeof ENTITY_TYPES)[number];
|
|
23
|
+
export declare const ACTOR_TYPES: readonly ["STAFF", "SYSTEM", "AGENT"];
|
|
24
|
+
export type ActorType = (typeof ACTOR_TYPES)[number];
|
|
25
|
+
export declare const isDomainEventType: (value: unknown) => value is DomainEventType;
|
|
26
|
+
export declare const isRealtimeEventType: (value: unknown) => value is RealtimeEventType;
|
|
27
|
+
export declare const isIntentType: (value: unknown) => value is IntentType;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Event names shared by every Wocul service. The server half is described in
|
|
4
|
+
* wocul-service-core-ts docs/realtime-events.md.
|
|
5
|
+
*
|
|
6
|
+
* Three kinds of name:
|
|
7
|
+
* - domain events: written to core-ts's DomainEvent outbox and published
|
|
8
|
+
* by its relay on realtime channels as hints ("task 42 changed");
|
|
9
|
+
* - notification events: published by notification-ts on staff:<id>;
|
|
10
|
+
* - intents: written to the same outbox but sent to a service's Redis
|
|
11
|
+
* stream instead of a channel. They wake the service; they are not hints.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.isIntentType = exports.isRealtimeEventType = exports.isDomainEventType = exports.ACTOR_TYPES = exports.ENTITY_TYPES = exports.INTENT_TYPES = exports.REALTIME_EVENT_TYPES = exports.NOTIFICATION_EVENT_TYPES = exports.DOMAIN_EVENT_TYPES = void 0;
|
|
15
|
+
exports.DOMAIN_EVENT_TYPES = [
|
|
16
|
+
'task.created',
|
|
17
|
+
'task.changed',
|
|
18
|
+
'task.removed',
|
|
19
|
+
'comment.changed',
|
|
20
|
+
'approval.changed',
|
|
21
|
+
'board.changed',
|
|
22
|
+
'project.changed',
|
|
23
|
+
'membership.changed',
|
|
24
|
+
'okr.changed',
|
|
25
|
+
'run.changed',
|
|
26
|
+
'draft.changed',
|
|
27
|
+
'pulse.changed',
|
|
28
|
+
'kb.changed',
|
|
29
|
+
'cycle.closed',
|
|
30
|
+
'dictionary.profiled',
|
|
31
|
+
'subscription.changed',
|
|
32
|
+
'deepwork.changed',
|
|
33
|
+
'plan.changed'
|
|
34
|
+
];
|
|
35
|
+
exports.NOTIFICATION_EVENT_TYPES = [
|
|
36
|
+
'notification.created',
|
|
37
|
+
'notification.read'
|
|
38
|
+
];
|
|
39
|
+
/** Every type a realtime subscriber can receive. */
|
|
40
|
+
exports.REALTIME_EVENT_TYPES = [
|
|
41
|
+
...exports.DOMAIN_EVENT_TYPES,
|
|
42
|
+
...exports.NOTIFICATION_EVENT_TYPES
|
|
43
|
+
];
|
|
44
|
+
exports.INTENT_TYPES = [
|
|
45
|
+
'notification.requested',
|
|
46
|
+
'email.requested',
|
|
47
|
+
'aicomment.requested',
|
|
48
|
+
'kbproposal.requested',
|
|
49
|
+
'run.requested'
|
|
50
|
+
];
|
|
51
|
+
exports.ENTITY_TYPES = [
|
|
52
|
+
'task',
|
|
53
|
+
'comment',
|
|
54
|
+
'approval',
|
|
55
|
+
'sprint',
|
|
56
|
+
'kanbanColumn',
|
|
57
|
+
'project',
|
|
58
|
+
'member',
|
|
59
|
+
'objective',
|
|
60
|
+
'keyResult',
|
|
61
|
+
'run',
|
|
62
|
+
'draft',
|
|
63
|
+
'pulse',
|
|
64
|
+
'document',
|
|
65
|
+
'cycle',
|
|
66
|
+
'dictionary',
|
|
67
|
+
'subscription',
|
|
68
|
+
'deepwork',
|
|
69
|
+
'plan',
|
|
70
|
+
'notification',
|
|
71
|
+
'email',
|
|
72
|
+
'aicomment',
|
|
73
|
+
'kbproposal',
|
|
74
|
+
'staff'
|
|
75
|
+
];
|
|
76
|
+
exports.ACTOR_TYPES = ['STAFF', 'SYSTEM', 'AGENT'];
|
|
77
|
+
const has = (list, value) => typeof value === 'string' && list.includes(value);
|
|
78
|
+
const isDomainEventType = (value) => has(exports.DOMAIN_EVENT_TYPES, value);
|
|
79
|
+
exports.isDomainEventType = isDomainEventType;
|
|
80
|
+
const isRealtimeEventType = (value) => has(exports.REALTIME_EVENT_TYPES, value);
|
|
81
|
+
exports.isRealtimeEventType = isRealtimeEventType;
|
|
82
|
+
const isIntentType = (value) => has(exports.INTENT_TYPES, value);
|
|
83
|
+
exports.isIntentType = isIntentType;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.api = void 0;
|
|
40
|
+
__exportStar(require("./events/types"), exports);
|
|
41
|
+
__exportStar(require("./events/data"), exports);
|
|
42
|
+
__exportStar(require("./events/message"), exports);
|
|
43
|
+
__exportStar(require("./channels"), exports);
|
|
44
|
+
__exportStar(require("./intents"), exports);
|
|
45
|
+
exports.api = __importStar(require("./api"));
|