@veridid/calendar 0.0.0-stage → 1.0.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/LICENSE +202 -0
- package/README.md +39 -2
- package/build/CalendarEvents.d.mts +59 -0
- package/build/CalendarEvents.d.mts.map +1 -0
- package/build/CalendarEvents.mjs +13 -0
- package/build/CalendarEvents.mjs.map +1 -0
- package/build/CalendarModule.d.mts +17 -0
- package/build/CalendarModule.d.mts.map +1 -0
- package/build/CalendarModule.mjs +98 -0
- package/build/CalendarModule.mjs.map +1 -0
- package/build/CalendarModuleConfig.d.mts +15 -0
- package/build/CalendarModuleConfig.d.mts.map +1 -0
- package/build/CalendarModuleConfig.mjs +12 -0
- package/build/CalendarModuleConfig.mjs.map +1 -0
- package/build/_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs +10 -0
- package/build/_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateMetadata.mjs +7 -0
- package/build/_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateParam.mjs +9 -0
- package/build/api/CalendarApi.d.mts +132 -0
- package/build/api/CalendarApi.d.mts.map +1 -0
- package/build/api/CalendarApi.mjs +289 -0
- package/build/api/CalendarApi.mjs.map +1 -0
- package/build/index.d.mts +44 -0
- package/build/index.mjs +44 -0
- package/build/model/types.d.mts +133 -0
- package/build/model/types.d.mts.map +1 -0
- package/build/protocol/CalendarMessageTypes.d.mts +23 -0
- package/build/protocol/CalendarMessageTypes.d.mts.map +1 -0
- package/build/protocol/CalendarMessageTypes.mjs +24 -0
- package/build/protocol/CalendarMessageTypes.mjs.map +1 -0
- package/build/protocol/handlers/AcceptHandler.d.mts +14 -0
- package/build/protocol/handlers/AcceptHandler.d.mts.map +1 -0
- package/build/protocol/handlers/AcceptHandler.mjs +57 -0
- package/build/protocol/handlers/AcceptHandler.mjs.map +1 -0
- package/build/protocol/handlers/AvailabilityHandler.d.mts +14 -0
- package/build/protocol/handlers/AvailabilityHandler.d.mts.map +1 -0
- package/build/protocol/handlers/AvailabilityHandler.mjs +24 -0
- package/build/protocol/handlers/AvailabilityHandler.mjs.map +1 -0
- package/build/protocol/handlers/CancelHandler.d.mts +14 -0
- package/build/protocol/handlers/CancelHandler.d.mts.map +1 -0
- package/build/protocol/handlers/CancelHandler.mjs +60 -0
- package/build/protocol/handlers/CancelHandler.mjs.map +1 -0
- package/build/protocol/handlers/DeclineHandler.d.mts +14 -0
- package/build/protocol/handlers/DeclineHandler.d.mts.map +1 -0
- package/build/protocol/handlers/DeclineHandler.mjs +57 -0
- package/build/protocol/handlers/DeclineHandler.mjs.map +1 -0
- package/build/protocol/handlers/DelegateAcceptHandler.d.mts +14 -0
- package/build/protocol/handlers/DelegateAcceptHandler.d.mts.map +1 -0
- package/build/protocol/handlers/DelegateAcceptHandler.mjs +37 -0
- package/build/protocol/handlers/DelegateAcceptHandler.mjs.map +1 -0
- package/build/protocol/handlers/DelegateDeclineHandler.d.mts +14 -0
- package/build/protocol/handlers/DelegateDeclineHandler.d.mts.map +1 -0
- package/build/protocol/handlers/DelegateDeclineHandler.mjs +45 -0
- package/build/protocol/handlers/DelegateDeclineHandler.mjs.map +1 -0
- package/build/protocol/handlers/DelegateHandler.d.mts +14 -0
- package/build/protocol/handlers/DelegateHandler.d.mts.map +1 -0
- package/build/protocol/handlers/DelegateHandler.mjs +90 -0
- package/build/protocol/handlers/DelegateHandler.mjs.map +1 -0
- package/build/protocol/handlers/InviteHandler.d.mts +14 -0
- package/build/protocol/handlers/InviteHandler.d.mts.map +1 -0
- package/build/protocol/handlers/InviteHandler.mjs +69 -0
- package/build/protocol/handlers/InviteHandler.mjs.map +1 -0
- package/build/protocol/handlers/PollResultHandler.d.mts +14 -0
- package/build/protocol/handlers/PollResultHandler.d.mts.map +1 -0
- package/build/protocol/handlers/PollResultHandler.mjs +34 -0
- package/build/protocol/handlers/PollResultHandler.mjs.map +1 -0
- package/build/protocol/handlers/PollVoteHandler.d.mts +14 -0
- package/build/protocol/handlers/PollVoteHandler.d.mts.map +1 -0
- package/build/protocol/handlers/PollVoteHandler.mjs +54 -0
- package/build/protocol/handlers/PollVoteHandler.mjs.map +1 -0
- package/build/protocol/handlers/ProblemReportHandler.d.mts +14 -0
- package/build/protocol/handlers/ProblemReportHandler.d.mts.map +1 -0
- package/build/protocol/handlers/ProblemReportHandler.mjs +29 -0
- package/build/protocol/handlers/ProblemReportHandler.mjs.map +1 -0
- package/build/protocol/handlers/ProposeHandler.d.mts +14 -0
- package/build/protocol/handlers/ProposeHandler.d.mts.map +1 -0
- package/build/protocol/handlers/ProposeHandler.mjs +64 -0
- package/build/protocol/handlers/ProposeHandler.mjs.map +1 -0
- package/build/protocol/handlers/QueryAvailabilityHandler.d.mts +15 -0
- package/build/protocol/handlers/QueryAvailabilityHandler.d.mts.map +1 -0
- package/build/protocol/handlers/QueryAvailabilityHandler.mjs +75 -0
- package/build/protocol/handlers/QueryAvailabilityHandler.mjs.map +1 -0
- package/build/protocol/handlers/RecurrenceExceptionHandler.d.mts +14 -0
- package/build/protocol/handlers/RecurrenceExceptionHandler.d.mts.map +1 -0
- package/build/protocol/handlers/RecurrenceExceptionHandler.mjs +57 -0
- package/build/protocol/handlers/RecurrenceExceptionHandler.mjs.map +1 -0
- package/build/protocol/handlers/ReminderHandler.d.mts +14 -0
- package/build/protocol/handlers/ReminderHandler.d.mts.map +1 -0
- package/build/protocol/handlers/ReminderHandler.mjs +35 -0
- package/build/protocol/handlers/ReminderHandler.mjs.map +1 -0
- package/build/protocol/handlers/TentativeHandler.d.mts +14 -0
- package/build/protocol/handlers/TentativeHandler.d.mts.map +1 -0
- package/build/protocol/handlers/TentativeHandler.mjs +57 -0
- package/build/protocol/handlers/TentativeHandler.mjs.map +1 -0
- package/build/protocol/handlers/UpdateHandler.d.mts +14 -0
- package/build/protocol/handlers/UpdateHandler.d.mts.map +1 -0
- package/build/protocol/handlers/UpdateHandler.mjs +57 -0
- package/build/protocol/handlers/UpdateHandler.mjs.map +1 -0
- package/build/protocol/messages/AcceptMessage.d.mts +22 -0
- package/build/protocol/messages/AcceptMessage.d.mts.map +1 -0
- package/build/protocol/messages/AcceptMessage.mjs +23 -0
- package/build/protocol/messages/AcceptMessage.mjs.map +1 -0
- package/build/protocol/messages/AvailabilityMessage.d.mts +23 -0
- package/build/protocol/messages/AvailabilityMessage.d.mts.map +1 -0
- package/build/protocol/messages/AvailabilityMessage.mjs +23 -0
- package/build/protocol/messages/AvailabilityMessage.mjs.map +1 -0
- package/build/protocol/messages/CancelMessage.d.mts +24 -0
- package/build/protocol/messages/CancelMessage.d.mts.map +1 -0
- package/build/protocol/messages/CancelMessage.mjs +23 -0
- package/build/protocol/messages/CancelMessage.mjs.map +1 -0
- package/build/protocol/messages/DeclineMessage.d.mts +23 -0
- package/build/protocol/messages/DeclineMessage.d.mts.map +1 -0
- package/build/protocol/messages/DeclineMessage.mjs +23 -0
- package/build/protocol/messages/DeclineMessage.mjs.map +1 -0
- package/build/protocol/messages/DelegateAcceptMessage.d.mts +22 -0
- package/build/protocol/messages/DelegateAcceptMessage.d.mts.map +1 -0
- package/build/protocol/messages/DelegateAcceptMessage.mjs +23 -0
- package/build/protocol/messages/DelegateAcceptMessage.mjs.map +1 -0
- package/build/protocol/messages/DelegateDeclineMessage.d.mts +22 -0
- package/build/protocol/messages/DelegateDeclineMessage.d.mts.map +1 -0
- package/build/protocol/messages/DelegateDeclineMessage.mjs +23 -0
- package/build/protocol/messages/DelegateDeclineMessage.mjs.map +1 -0
- package/build/protocol/messages/DelegateMessage.d.mts +25 -0
- package/build/protocol/messages/DelegateMessage.d.mts.map +1 -0
- package/build/protocol/messages/DelegateMessage.mjs +23 -0
- package/build/protocol/messages/DelegateMessage.mjs.map +1 -0
- package/build/protocol/messages/InviteMessage.d.mts +38 -0
- package/build/protocol/messages/InviteMessage.d.mts.map +1 -0
- package/build/protocol/messages/InviteMessage.mjs +23 -0
- package/build/protocol/messages/InviteMessage.mjs.map +1 -0
- package/build/protocol/messages/PollResultMessage.d.mts +24 -0
- package/build/protocol/messages/PollResultMessage.d.mts.map +1 -0
- package/build/protocol/messages/PollResultMessage.mjs +23 -0
- package/build/protocol/messages/PollResultMessage.mjs.map +1 -0
- package/build/protocol/messages/PollVoteMessage.d.mts +21 -0
- package/build/protocol/messages/PollVoteMessage.d.mts.map +1 -0
- package/build/protocol/messages/PollVoteMessage.mjs +23 -0
- package/build/protocol/messages/PollVoteMessage.mjs.map +1 -0
- package/build/protocol/messages/ProblemReportMessage.d.mts +21 -0
- package/build/protocol/messages/ProblemReportMessage.d.mts.map +1 -0
- package/build/protocol/messages/ProblemReportMessage.mjs +23 -0
- package/build/protocol/messages/ProblemReportMessage.mjs.map +1 -0
- package/build/protocol/messages/ProposeMessage.d.mts +31 -0
- package/build/protocol/messages/ProposeMessage.d.mts.map +1 -0
- package/build/protocol/messages/ProposeMessage.mjs +23 -0
- package/build/protocol/messages/ProposeMessage.mjs.map +1 -0
- package/build/protocol/messages/QueryAvailabilityMessage.d.mts +25 -0
- package/build/protocol/messages/QueryAvailabilityMessage.d.mts.map +1 -0
- package/build/protocol/messages/QueryAvailabilityMessage.mjs +23 -0
- package/build/protocol/messages/QueryAvailabilityMessage.mjs.map +1 -0
- package/build/protocol/messages/RecurrenceExceptionMessage.d.mts +24 -0
- package/build/protocol/messages/RecurrenceExceptionMessage.d.mts.map +1 -0
- package/build/protocol/messages/RecurrenceExceptionMessage.mjs +23 -0
- package/build/protocol/messages/RecurrenceExceptionMessage.mjs.map +1 -0
- package/build/protocol/messages/ReminderMessage.d.mts +26 -0
- package/build/protocol/messages/ReminderMessage.d.mts.map +1 -0
- package/build/protocol/messages/ReminderMessage.mjs +23 -0
- package/build/protocol/messages/ReminderMessage.mjs.map +1 -0
- package/build/protocol/messages/TentativeMessage.d.mts +22 -0
- package/build/protocol/messages/TentativeMessage.d.mts.map +1 -0
- package/build/protocol/messages/TentativeMessage.mjs +23 -0
- package/build/protocol/messages/TentativeMessage.mjs.map +1 -0
- package/build/protocol/messages/UpdateMessage.d.mts +23 -0
- package/build/protocol/messages/UpdateMessage.d.mts.map +1 -0
- package/build/protocol/messages/UpdateMessage.mjs +23 -0
- package/build/protocol/messages/UpdateMessage.mjs.map +1 -0
- package/build/repository/CalendarEventRecord.d.mts +49 -0
- package/build/repository/CalendarEventRecord.d.mts.map +1 -0
- package/build/repository/CalendarEventRecord.mjs +42 -0
- package/build/repository/CalendarEventRecord.mjs.map +1 -0
- package/build/repository/CalendarEventRepository.d.mts +18 -0
- package/build/repository/CalendarEventRepository.d.mts.map +1 -0
- package/build/repository/CalendarEventRepository.mjs +63 -0
- package/build/repository/CalendarEventRepository.mjs.map +1 -0
- package/build/services/CalendarService.d.mts +222 -0
- package/build/services/CalendarService.d.mts.map +1 -0
- package/build/services/CalendarService.mjs +587 -0
- package/build/services/CalendarService.mjs.map +1 -0
- package/package.json +43 -3
|
@@ -0,0 +1,587 @@
|
|
|
1
|
+
import { CalendarEventRecord } from "../repository/CalendarEventRecord.mjs";
|
|
2
|
+
import { CalendarEventTypes } from "../CalendarEvents.mjs";
|
|
3
|
+
import { CalendarModuleConfig } from "../CalendarModuleConfig.mjs";
|
|
4
|
+
import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateMetadata.mjs";
|
|
5
|
+
import { __decorate } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs";
|
|
6
|
+
import { CalendarEventRepository } from "../repository/CalendarEventRepository.mjs";
|
|
7
|
+
import { AgentConfig, AgentContext, EventEmitter, injectable } from "@credo-ts/core";
|
|
8
|
+
|
|
9
|
+
//#region src/services/CalendarService.ts
|
|
10
|
+
var _ref, _ref2, _ref3, _ref4;
|
|
11
|
+
let CalendarService = class CalendarService {
|
|
12
|
+
constructor(eventRepo, config, agentConfig, eventEmitter) {
|
|
13
|
+
this.eventRepo = eventRepo;
|
|
14
|
+
this.config = config;
|
|
15
|
+
this.agentConfig = agentConfig;
|
|
16
|
+
this.eventEmitter = eventEmitter;
|
|
17
|
+
}
|
|
18
|
+
async createProposal(agentContext, opts) {
|
|
19
|
+
const eventId = opts.event_id || this.uuid();
|
|
20
|
+
const participants = [{
|
|
21
|
+
did: opts.organizer_did,
|
|
22
|
+
role: "organizer",
|
|
23
|
+
status: "accepted"
|
|
24
|
+
}, ...opts.participant_dids.map((did) => ({
|
|
25
|
+
did,
|
|
26
|
+
role: "invitee",
|
|
27
|
+
status: "pending"
|
|
28
|
+
}))];
|
|
29
|
+
const event = {
|
|
30
|
+
event_id: eventId,
|
|
31
|
+
title: opts.title,
|
|
32
|
+
type: opts.type,
|
|
33
|
+
organizer: opts.organizer_did,
|
|
34
|
+
participants,
|
|
35
|
+
sequence: 0,
|
|
36
|
+
sensitivity: opts.sensitivity ?? "private",
|
|
37
|
+
allow_delegation: false,
|
|
38
|
+
require_signed_rsvp: false,
|
|
39
|
+
description: opts.description,
|
|
40
|
+
location: opts.location,
|
|
41
|
+
reminders: opts.reminders,
|
|
42
|
+
recurrence: opts.recurrence,
|
|
43
|
+
call_config: opts.call_config,
|
|
44
|
+
quorum: opts.quorum,
|
|
45
|
+
tags: opts.tags,
|
|
46
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
47
|
+
};
|
|
48
|
+
const record = new CalendarEventRecord({
|
|
49
|
+
eventId,
|
|
50
|
+
connectionId: opts.connection_id,
|
|
51
|
+
role: "organizer",
|
|
52
|
+
event,
|
|
53
|
+
organizerState: "proposing",
|
|
54
|
+
timeOptions: opts.time_options,
|
|
55
|
+
pollVotes: {},
|
|
56
|
+
pollClosed: false
|
|
57
|
+
});
|
|
58
|
+
await this.eventRepo.save(agentContext, record);
|
|
59
|
+
this.emitStateChanged(agentContext, record, null, "proposing", "propose");
|
|
60
|
+
return record;
|
|
61
|
+
}
|
|
62
|
+
async createInvite(agentContext, opts) {
|
|
63
|
+
const eventId = opts.event_id || this.uuid();
|
|
64
|
+
const participants = [{
|
|
65
|
+
did: opts.organizer_did,
|
|
66
|
+
role: "organizer",
|
|
67
|
+
status: "accepted"
|
|
68
|
+
}, ...opts.participant_dids.map((did) => ({
|
|
69
|
+
did,
|
|
70
|
+
role: "invitee",
|
|
71
|
+
status: "pending"
|
|
72
|
+
}))];
|
|
73
|
+
const event = {
|
|
74
|
+
event_id: eventId,
|
|
75
|
+
title: opts.title,
|
|
76
|
+
type: opts.type,
|
|
77
|
+
start: opts.start,
|
|
78
|
+
end: opts.end,
|
|
79
|
+
timezone: opts.timezone,
|
|
80
|
+
organizer: opts.organizer_did,
|
|
81
|
+
participants,
|
|
82
|
+
sequence: 0,
|
|
83
|
+
sensitivity: opts.sensitivity ?? "private",
|
|
84
|
+
allow_delegation: opts.allow_delegation ?? false,
|
|
85
|
+
require_signed_rsvp: opts.require_signed_rsvp ?? false,
|
|
86
|
+
description: opts.description,
|
|
87
|
+
location: opts.location,
|
|
88
|
+
reminders: opts.reminders,
|
|
89
|
+
recurrence: opts.recurrence,
|
|
90
|
+
call_config: opts.call_config,
|
|
91
|
+
quorum: opts.quorum,
|
|
92
|
+
vault_ref: opts.vault_ref,
|
|
93
|
+
tags: opts.tags,
|
|
94
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
95
|
+
};
|
|
96
|
+
const record = new CalendarEventRecord({
|
|
97
|
+
eventId,
|
|
98
|
+
connectionId: opts.connection_id,
|
|
99
|
+
role: "organizer",
|
|
100
|
+
event,
|
|
101
|
+
organizerState: "invited"
|
|
102
|
+
});
|
|
103
|
+
await this.eventRepo.save(agentContext, record);
|
|
104
|
+
this.emitStateChanged(agentContext, record, null, "invited", "invite");
|
|
105
|
+
return record;
|
|
106
|
+
}
|
|
107
|
+
async receiveProposal(agentContext, opts, connectionId) {
|
|
108
|
+
try {
|
|
109
|
+
const existing = await this.eventRepo.findByEventId(agentContext, opts.event_id);
|
|
110
|
+
if (existing) return existing;
|
|
111
|
+
} catch {}
|
|
112
|
+
const event = {
|
|
113
|
+
event_id: opts.event_id,
|
|
114
|
+
title: opts.title,
|
|
115
|
+
type: opts.type,
|
|
116
|
+
organizer: opts.organizer_did,
|
|
117
|
+
participants: [],
|
|
118
|
+
sequence: 0,
|
|
119
|
+
sensitivity: opts.sensitivity ?? "private",
|
|
120
|
+
allow_delegation: false,
|
|
121
|
+
require_signed_rsvp: false,
|
|
122
|
+
description: opts.description,
|
|
123
|
+
location: opts.location,
|
|
124
|
+
reminders: opts.reminders,
|
|
125
|
+
recurrence: opts.recurrence,
|
|
126
|
+
call_config: opts.call_config,
|
|
127
|
+
tags: opts.tags
|
|
128
|
+
};
|
|
129
|
+
const record = new CalendarEventRecord({
|
|
130
|
+
eventId: opts.event_id,
|
|
131
|
+
connectionId,
|
|
132
|
+
role: "invitee",
|
|
133
|
+
event,
|
|
134
|
+
inviteeState: "polling",
|
|
135
|
+
timeOptions: opts.time_options
|
|
136
|
+
});
|
|
137
|
+
await this.eventRepo.save(agentContext, record);
|
|
138
|
+
this.emitStateChanged(agentContext, record, null, "polling", "propose_received");
|
|
139
|
+
return record;
|
|
140
|
+
}
|
|
141
|
+
async receiveInvite(agentContext, event, connectionId) {
|
|
142
|
+
try {
|
|
143
|
+
const existing = await this.eventRepo.findByEventId(agentContext, event.event_id);
|
|
144
|
+
if (existing) {
|
|
145
|
+
existing.event = event;
|
|
146
|
+
existing.inviteeState = "pending";
|
|
147
|
+
existing.history.push({
|
|
148
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
149
|
+
action: "invite_received",
|
|
150
|
+
from_state: existing.inviteeState || "idle",
|
|
151
|
+
to_state: "pending"
|
|
152
|
+
});
|
|
153
|
+
await this.eventRepo.update(agentContext, existing);
|
|
154
|
+
return existing;
|
|
155
|
+
}
|
|
156
|
+
} catch {}
|
|
157
|
+
const record = new CalendarEventRecord({
|
|
158
|
+
eventId: event.event_id,
|
|
159
|
+
connectionId,
|
|
160
|
+
role: "invitee",
|
|
161
|
+
event,
|
|
162
|
+
inviteeState: "pending"
|
|
163
|
+
});
|
|
164
|
+
await this.eventRepo.save(agentContext, record);
|
|
165
|
+
this.emitStateChanged(agentContext, record, null, "pending", "invite_received");
|
|
166
|
+
return record;
|
|
167
|
+
}
|
|
168
|
+
async respond(agentContext, opts) {
|
|
169
|
+
const record = await this.getEventRecord(agentContext, opts.event_id);
|
|
170
|
+
if (record.role !== "invitee") throw this.problem("forbidden", "only invitees can respond");
|
|
171
|
+
const prevState = record.inviteeState;
|
|
172
|
+
record.inviteeState = {
|
|
173
|
+
accept: "accepted",
|
|
174
|
+
decline: "declined",
|
|
175
|
+
tentative: "tentative"
|
|
176
|
+
}[opts.response];
|
|
177
|
+
record.history.push({
|
|
178
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
179
|
+
action: opts.response,
|
|
180
|
+
from_state: prevState || "pending",
|
|
181
|
+
to_state: record.inviteeState
|
|
182
|
+
});
|
|
183
|
+
await this.eventRepo.update(agentContext, record);
|
|
184
|
+
this.emitStateChanged(agentContext, record, prevState || null, record.inviteeState, opts.response);
|
|
185
|
+
return record;
|
|
186
|
+
}
|
|
187
|
+
async receiveResponse(agentContext, opts) {
|
|
188
|
+
const record = await this.getEventRecord(agentContext, opts.event_id);
|
|
189
|
+
if (record.role !== "organizer") throw this.problem("forbidden", "only organizer receives responses");
|
|
190
|
+
if (opts.sequence < record.event.sequence) throw this.problem("sequence_stale", `expected sequence >= ${record.event.sequence}, got ${opts.sequence}`);
|
|
191
|
+
const participant = record.event.participants.find((p) => p.did === opts.from_did);
|
|
192
|
+
if (participant) {
|
|
193
|
+
const prevStatus = participant.status;
|
|
194
|
+
participant.status = opts.response === "accept" ? "accepted" : opts.response === "decline" ? "declined" : "tentative";
|
|
195
|
+
record.event.updated_at = (/* @__PURE__ */ new Date()).toISOString();
|
|
196
|
+
record.history.push({
|
|
197
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
198
|
+
action: `${opts.response}_received`,
|
|
199
|
+
from_state: prevStatus,
|
|
200
|
+
to_state: participant.status,
|
|
201
|
+
actor_did: opts.from_did
|
|
202
|
+
});
|
|
203
|
+
const acceptedCount = record.event.participants.filter((p) => p.status === "accepted").length;
|
|
204
|
+
const minAccept = record.event.quorum?.min_accept ?? 2;
|
|
205
|
+
if (record.organizerState === "invited" && acceptedCount >= minAccept) record.organizerState = "confirmed";
|
|
206
|
+
if (record.event.quorum?.deadline && record.organizerState === "invited") {
|
|
207
|
+
if (new Date(record.event.quorum.deadline) < /* @__PURE__ */ new Date() && acceptedCount < minAccept) record.organizerState = "failed";
|
|
208
|
+
}
|
|
209
|
+
await this.eventRepo.update(agentContext, record);
|
|
210
|
+
try {
|
|
211
|
+
this.eventEmitter?.emit(agentContext, {
|
|
212
|
+
type: CalendarEventTypes.CalendarInviteeStatusChanged,
|
|
213
|
+
payload: {
|
|
214
|
+
eventRecord: record,
|
|
215
|
+
participantDid: opts.from_did,
|
|
216
|
+
previousStatus: prevStatus,
|
|
217
|
+
newStatus: participant.status
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
} catch {}
|
|
221
|
+
}
|
|
222
|
+
return record;
|
|
223
|
+
}
|
|
224
|
+
async updateEvent(agentContext, opts) {
|
|
225
|
+
const record = await this.getEventRecord(agentContext, opts.event_id);
|
|
226
|
+
if (record.role !== "organizer") throw this.problem("forbidden", "only organizer can update");
|
|
227
|
+
const prevState = record.organizerState;
|
|
228
|
+
record.event.sequence += 1;
|
|
229
|
+
record.event.updated_at = (/* @__PURE__ */ new Date()).toISOString();
|
|
230
|
+
for (const [key, value] of Object.entries(opts.changes)) record.event[key] = value;
|
|
231
|
+
if (opts.require_re_rsvp) {
|
|
232
|
+
for (const p of record.event.participants) if (p.role !== "organizer") p.status = "pending";
|
|
233
|
+
}
|
|
234
|
+
record.history.push({
|
|
235
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
236
|
+
action: "update",
|
|
237
|
+
from_state: prevState || "confirmed",
|
|
238
|
+
to_state: record.organizerState || "confirmed"
|
|
239
|
+
});
|
|
240
|
+
await this.eventRepo.update(agentContext, record);
|
|
241
|
+
return record;
|
|
242
|
+
}
|
|
243
|
+
async receiveUpdate(agentContext, opts) {
|
|
244
|
+
const record = await this.getEventRecord(agentContext, opts.event_id);
|
|
245
|
+
if (opts.sequence <= record.event.sequence) throw this.problem("sequence_stale", `expected sequence > ${record.event.sequence}, got ${opts.sequence}`);
|
|
246
|
+
record.event.sequence = opts.sequence;
|
|
247
|
+
record.event.updated_at = (/* @__PURE__ */ new Date()).toISOString();
|
|
248
|
+
for (const [key, value] of Object.entries(opts.changes)) record.event[key] = value;
|
|
249
|
+
if (opts.require_re_rsvp) {
|
|
250
|
+
const prevState = record.inviteeState;
|
|
251
|
+
record.inviteeState = "pending";
|
|
252
|
+
record.history.push({
|
|
253
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
254
|
+
action: "update_received_re_rsvp",
|
|
255
|
+
from_state: prevState || "accepted",
|
|
256
|
+
to_state: "pending"
|
|
257
|
+
});
|
|
258
|
+
} else record.history.push({
|
|
259
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
260
|
+
action: "update_received",
|
|
261
|
+
from_state: record.inviteeState || "accepted",
|
|
262
|
+
to_state: record.inviteeState || "accepted"
|
|
263
|
+
});
|
|
264
|
+
await this.eventRepo.update(agentContext, record);
|
|
265
|
+
return record;
|
|
266
|
+
}
|
|
267
|
+
async cancelEvent(agentContext, opts) {
|
|
268
|
+
const record = await this.getEventRecord(agentContext, opts.event_id);
|
|
269
|
+
if (record.role !== "organizer") throw this.problem("forbidden", "only organizer can cancel");
|
|
270
|
+
const prevState = record.organizerState;
|
|
271
|
+
record.organizerState = "cancelled";
|
|
272
|
+
record.event.sequence += 1;
|
|
273
|
+
record.event.updated_at = (/* @__PURE__ */ new Date()).toISOString();
|
|
274
|
+
record.history.push({
|
|
275
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
276
|
+
action: "cancel",
|
|
277
|
+
from_state: prevState || "confirmed",
|
|
278
|
+
to_state: "cancelled"
|
|
279
|
+
});
|
|
280
|
+
await this.eventRepo.update(agentContext, record);
|
|
281
|
+
try {
|
|
282
|
+
this.eventEmitter?.emit(agentContext, {
|
|
283
|
+
type: CalendarEventTypes.CalendarEventCancelled,
|
|
284
|
+
payload: {
|
|
285
|
+
eventRecord: record,
|
|
286
|
+
reason: opts.reason
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
} catch {}
|
|
290
|
+
return record;
|
|
291
|
+
}
|
|
292
|
+
async receiveCancellation(agentContext, opts) {
|
|
293
|
+
const record = await this.getEventRecord(agentContext, opts.event_id);
|
|
294
|
+
const prevState = record.inviteeState;
|
|
295
|
+
record.inviteeState = "cancelled";
|
|
296
|
+
record.event.sequence = opts.sequence;
|
|
297
|
+
record.event.updated_at = (/* @__PURE__ */ new Date()).toISOString();
|
|
298
|
+
record.history.push({
|
|
299
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
300
|
+
action: "cancel_received",
|
|
301
|
+
from_state: prevState || "accepted",
|
|
302
|
+
to_state: "cancelled"
|
|
303
|
+
});
|
|
304
|
+
await this.eventRepo.update(agentContext, record);
|
|
305
|
+
try {
|
|
306
|
+
this.eventEmitter?.emit(agentContext, {
|
|
307
|
+
type: CalendarEventTypes.CalendarEventCancelled,
|
|
308
|
+
payload: {
|
|
309
|
+
eventRecord: record,
|
|
310
|
+
reason: opts.reason
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
} catch {}
|
|
314
|
+
return record;
|
|
315
|
+
}
|
|
316
|
+
async respondAvailability(agentContext, opts) {
|
|
317
|
+
return {
|
|
318
|
+
timezone: opts.timezone,
|
|
319
|
+
slots: opts.slots,
|
|
320
|
+
expires: new Date(Date.now() + 1440 * 60 * 1e3).toISOString(),
|
|
321
|
+
privacy_level: opts.privacy_level || "free_busy_only"
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
async delegate(agentContext, opts) {
|
|
325
|
+
const record = await this.getEventRecord(agentContext, opts.event_id);
|
|
326
|
+
if (record.role !== "invitee") throw this.problem("forbidden", "only invitees can delegate");
|
|
327
|
+
if (!record.event.allow_delegation) throw this.problem("delegation_not_allowed", "event does not permit delegation");
|
|
328
|
+
const myParticipant = record.event.participants.find((p) => p.role === "invitee" && (p.status === "accepted" || p.status === "tentative"));
|
|
329
|
+
if (!myParticipant) throw this.problem("forbidden", "invitee has not accepted this event");
|
|
330
|
+
const token = {
|
|
331
|
+
event_id: opts.event_id,
|
|
332
|
+
delegator: myParticipant.did,
|
|
333
|
+
delegate: opts.delegate_to,
|
|
334
|
+
scope: opts.scope,
|
|
335
|
+
issued_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
336
|
+
expires_at: record.event.end || new Date(Date.now() + 10080 * 60 * 1e3).toISOString(),
|
|
337
|
+
jws: opts.jws
|
|
338
|
+
};
|
|
339
|
+
const prevState = record.inviteeState;
|
|
340
|
+
record.inviteeState = "delegated";
|
|
341
|
+
record.delegationTokens = [...record.delegationTokens || [], token];
|
|
342
|
+
record.history.push({
|
|
343
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
344
|
+
action: "delegate",
|
|
345
|
+
from_state: prevState || "accepted",
|
|
346
|
+
to_state: "delegated"
|
|
347
|
+
});
|
|
348
|
+
await this.eventRepo.update(agentContext, record);
|
|
349
|
+
return {
|
|
350
|
+
record,
|
|
351
|
+
token
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
async receiveDelegation(agentContext, opts) {
|
|
355
|
+
const record = await this.getEventRecord(agentContext, opts.event_id);
|
|
356
|
+
if (record.role !== "organizer") throw this.problem("forbidden", "only organizer receives delegation requests");
|
|
357
|
+
if (!record.event.allow_delegation) throw this.problem("delegation_not_allowed", "event does not permit delegation");
|
|
358
|
+
if (opts.delegation_token.expires_at && new Date(opts.delegation_token.expires_at) < /* @__PURE__ */ new Date()) throw this.problem("delegation_expired", "delegation token has expired");
|
|
359
|
+
record.delegationTokens = [...record.delegationTokens || [], opts.delegation_token];
|
|
360
|
+
const delegator = record.event.participants.find((p) => p.did === opts.delegator);
|
|
361
|
+
if (delegator && opts.scope === "full") delegator.status = "delegated";
|
|
362
|
+
record.event.participants.push({
|
|
363
|
+
did: opts.delegate_to,
|
|
364
|
+
role: "delegate",
|
|
365
|
+
status: "pending"
|
|
366
|
+
});
|
|
367
|
+
record.event.updated_at = (/* @__PURE__ */ new Date()).toISOString();
|
|
368
|
+
await this.eventRepo.update(agentContext, record);
|
|
369
|
+
return record;
|
|
370
|
+
}
|
|
371
|
+
async approveDelegation(agentContext, opts) {
|
|
372
|
+
const record = await this.getEventRecord(agentContext, opts.event_id);
|
|
373
|
+
const delegateParticipant = record.event.participants.find((p) => p.did === opts.delegate && p.role === "delegate");
|
|
374
|
+
if (delegateParticipant) delegateParticipant.status = "accepted";
|
|
375
|
+
record.event.updated_at = (/* @__PURE__ */ new Date()).toISOString();
|
|
376
|
+
await this.eventRepo.update(agentContext, record);
|
|
377
|
+
return record;
|
|
378
|
+
}
|
|
379
|
+
async declineDelegation(agentContext, opts) {
|
|
380
|
+
const record = await this.getEventRecord(agentContext, opts.event_id);
|
|
381
|
+
record.event.participants = record.event.participants.filter((p) => !(p.did === opts.delegate && p.role === "delegate"));
|
|
382
|
+
const delegator = record.event.participants.find((p) => p.did === opts.delegator);
|
|
383
|
+
if (delegator && delegator.status === "delegated") delegator.status = "accepted";
|
|
384
|
+
record.event.updated_at = (/* @__PURE__ */ new Date()).toISOString();
|
|
385
|
+
await this.eventRepo.update(agentContext, record);
|
|
386
|
+
return record;
|
|
387
|
+
}
|
|
388
|
+
async handleRecurrenceException(agentContext, opts) {
|
|
389
|
+
const record = await this.getEventRecord(agentContext, opts.event_id);
|
|
390
|
+
if (!record.event.recurrence) throw this.problem("rrule_invalid", "event has no recurrence rule");
|
|
391
|
+
const exception = {
|
|
392
|
+
recurrence_id: opts.recurrence_id,
|
|
393
|
+
action: opts.action,
|
|
394
|
+
changes: opts.changes
|
|
395
|
+
};
|
|
396
|
+
if (!record.event.recurrence.exceptions) record.event.recurrence.exceptions = [];
|
|
397
|
+
record.event.recurrence.exceptions.push(exception);
|
|
398
|
+
if (opts.action === "cancel") {
|
|
399
|
+
if (!record.event.recurrence.exdates) record.event.recurrence.exdates = [];
|
|
400
|
+
record.event.recurrence.exdates.push(opts.recurrence_id);
|
|
401
|
+
}
|
|
402
|
+
record.event.sequence = opts.sequence;
|
|
403
|
+
record.event.updated_at = (/* @__PURE__ */ new Date()).toISOString();
|
|
404
|
+
record.history.push({
|
|
405
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
406
|
+
action: `recurrence_exception_${opts.action}`,
|
|
407
|
+
from_state: record.organizerState || record.inviteeState || "confirmed",
|
|
408
|
+
to_state: record.organizerState || record.inviteeState || "confirmed"
|
|
409
|
+
});
|
|
410
|
+
await this.eventRepo.update(agentContext, record);
|
|
411
|
+
return record;
|
|
412
|
+
}
|
|
413
|
+
async receiveRecurrenceException(agentContext, opts) {
|
|
414
|
+
const record = await this.getEventRecord(agentContext, opts.event_id);
|
|
415
|
+
if (opts.sequence <= record.event.sequence) throw this.problem("sequence_stale", `expected sequence > ${record.event.sequence}`);
|
|
416
|
+
return this.handleRecurrenceException(agentContext, {
|
|
417
|
+
...opts,
|
|
418
|
+
event_id: opts.event_id
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
async castPollVote(agentContext, opts) {
|
|
422
|
+
const record = await this.getEventRecord(agentContext, opts.event_id);
|
|
423
|
+
if (record.inviteeState !== "polling") throw this.problem("forbidden", "not in polling state");
|
|
424
|
+
record.inviteeState = "voted";
|
|
425
|
+
record.history.push({
|
|
426
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
427
|
+
action: "poll_vote",
|
|
428
|
+
from_state: "polling",
|
|
429
|
+
to_state: "voted"
|
|
430
|
+
});
|
|
431
|
+
await this.eventRepo.update(agentContext, record);
|
|
432
|
+
return record;
|
|
433
|
+
}
|
|
434
|
+
async receivePollVote(agentContext, opts) {
|
|
435
|
+
const record = await this.getEventRecord(agentContext, opts.event_id);
|
|
436
|
+
if (record.role !== "organizer") throw this.problem("forbidden", "only organizer receives votes");
|
|
437
|
+
if (record.pollClosed) throw this.problem("forbidden", "poll is closed");
|
|
438
|
+
if (!record.pollVotes) record.pollVotes = {};
|
|
439
|
+
record.pollVotes[opts.voter_did] = opts.votes;
|
|
440
|
+
record.history.push({
|
|
441
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
442
|
+
action: "poll_vote_received",
|
|
443
|
+
from_state: record.organizerState || "proposing",
|
|
444
|
+
to_state: record.organizerState || "proposing",
|
|
445
|
+
actor_did: opts.voter_did
|
|
446
|
+
});
|
|
447
|
+
await this.eventRepo.update(agentContext, record);
|
|
448
|
+
return record;
|
|
449
|
+
}
|
|
450
|
+
async closePoll(agentContext, opts) {
|
|
451
|
+
const record = await this.getEventRecord(agentContext, opts.event_id);
|
|
452
|
+
if (record.role !== "organizer") throw this.problem("forbidden", "only organizer can close poll");
|
|
453
|
+
const tallies = this.computeTallies(record.timeOptions || [], record.pollVotes || {});
|
|
454
|
+
const selectedOption = record.timeOptions?.find((o) => o.option_id === opts.selected_option_id);
|
|
455
|
+
if (!selectedOption) throw this.problem("event_not_found", "selected option not found");
|
|
456
|
+
record.event.start = selectedOption.start;
|
|
457
|
+
record.event.end = selectedOption.end;
|
|
458
|
+
record.event.timezone = selectedOption.timezone;
|
|
459
|
+
record.event.updated_at = (/* @__PURE__ */ new Date()).toISOString();
|
|
460
|
+
record.pollClosed = true;
|
|
461
|
+
record.organizerState = "proposed";
|
|
462
|
+
record.history.push({
|
|
463
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
464
|
+
action: "poll_closed",
|
|
465
|
+
from_state: "proposing",
|
|
466
|
+
to_state: "proposed"
|
|
467
|
+
});
|
|
468
|
+
await this.eventRepo.update(agentContext, record);
|
|
469
|
+
try {
|
|
470
|
+
this.eventEmitter?.emit(agentContext, {
|
|
471
|
+
type: CalendarEventTypes.CalendarPollCompleted,
|
|
472
|
+
payload: {
|
|
473
|
+
eventRecord: record,
|
|
474
|
+
selectedOptionId: opts.selected_option_id
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
} catch {}
|
|
478
|
+
return {
|
|
479
|
+
record,
|
|
480
|
+
tallies
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
async receivePollResult(agentContext, opts) {
|
|
484
|
+
const record = await this.getEventRecord(agentContext, opts.event_id);
|
|
485
|
+
record.pollClosed = true;
|
|
486
|
+
if (opts.proceed) record.history.push({
|
|
487
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
488
|
+
action: "poll_result_received",
|
|
489
|
+
from_state: record.inviteeState || "voted",
|
|
490
|
+
to_state: record.inviteeState || "voted"
|
|
491
|
+
});
|
|
492
|
+
await this.eventRepo.update(agentContext, record);
|
|
493
|
+
return record;
|
|
494
|
+
}
|
|
495
|
+
async receiveReminder(agentContext, opts) {
|
|
496
|
+
let record;
|
|
497
|
+
try {
|
|
498
|
+
record = await this.getEventRecord(agentContext, opts.event_id);
|
|
499
|
+
} catch {
|
|
500
|
+
return null;
|
|
501
|
+
}
|
|
502
|
+
try {
|
|
503
|
+
this.eventEmitter?.emit(agentContext, {
|
|
504
|
+
type: CalendarEventTypes.CalendarReminderTriggered,
|
|
505
|
+
payload: {
|
|
506
|
+
eventRecord: record,
|
|
507
|
+
offsetMinutes: opts.offset_minutes,
|
|
508
|
+
action: opts.action,
|
|
509
|
+
callTrigger: opts.call_trigger
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
} catch {}
|
|
513
|
+
return record;
|
|
514
|
+
}
|
|
515
|
+
async getEvent(agentContext, eventId) {
|
|
516
|
+
return this.getEventRecord(agentContext, eventId);
|
|
517
|
+
}
|
|
518
|
+
async listEvents(agentContext, filters) {
|
|
519
|
+
if (filters?.connectionId && filters?.role) return this.eventRepo.findByConnectionAndRole(agentContext, filters.connectionId, filters.role);
|
|
520
|
+
if (filters?.connectionId) return this.eventRepo.findByConnection(agentContext, filters.connectionId);
|
|
521
|
+
if (filters?.role) return this.eventRepo.findByRole(agentContext, filters.role);
|
|
522
|
+
return this.eventRepo.getAll(agentContext);
|
|
523
|
+
}
|
|
524
|
+
async getUpcomingEvents(agentContext) {
|
|
525
|
+
return this.eventRepo.findUpcoming(agentContext);
|
|
526
|
+
}
|
|
527
|
+
async getEventRecord(agentContext, eventId) {
|
|
528
|
+
try {
|
|
529
|
+
const record = await this.eventRepo.findByEventId(agentContext, eventId);
|
|
530
|
+
if (!record) throw this.problem("event_not_found", `event not found: ${eventId}`);
|
|
531
|
+
return record;
|
|
532
|
+
} catch (e) {
|
|
533
|
+
if (e?.code === "event_not_found") throw e;
|
|
534
|
+
throw this.problem("event_not_found", `event not found: ${eventId}`);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
computeTallies(timeOptions, pollVotes) {
|
|
538
|
+
return timeOptions.map((opt) => {
|
|
539
|
+
let yes = 0;
|
|
540
|
+
let if_needed = 0;
|
|
541
|
+
let no = 0;
|
|
542
|
+
for (const votes of Object.values(pollVotes)) {
|
|
543
|
+
const vote = votes.find((v) => v.option_id === opt.option_id);
|
|
544
|
+
if (vote?.preference === "yes") yes++;
|
|
545
|
+
else if (vote?.preference === "if_needed") if_needed++;
|
|
546
|
+
else if (vote?.preference === "no") no++;
|
|
547
|
+
}
|
|
548
|
+
return {
|
|
549
|
+
option_id: opt.option_id,
|
|
550
|
+
yes,
|
|
551
|
+
if_needed,
|
|
552
|
+
no
|
|
553
|
+
};
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
emitStateChanged(agentContext, record, previousState, newState, action) {
|
|
557
|
+
try {
|
|
558
|
+
this.eventEmitter?.emit(agentContext, {
|
|
559
|
+
type: CalendarEventTypes.CalendarEventStateChanged,
|
|
560
|
+
payload: {
|
|
561
|
+
eventRecord: record,
|
|
562
|
+
previousState,
|
|
563
|
+
newState,
|
|
564
|
+
action
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
} catch {}
|
|
568
|
+
}
|
|
569
|
+
problem(code, comment) {
|
|
570
|
+
const err = new Error(comment);
|
|
571
|
+
err.code = code;
|
|
572
|
+
return err;
|
|
573
|
+
}
|
|
574
|
+
uuid() {
|
|
575
|
+
return `evt-${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
CalendarService = __decorate([injectable(), __decorateMetadata("design:paramtypes", [
|
|
579
|
+
CalendarEventRepository,
|
|
580
|
+
CalendarModuleConfig,
|
|
581
|
+
AgentConfig,
|
|
582
|
+
EventEmitter
|
|
583
|
+
])], CalendarService);
|
|
584
|
+
|
|
585
|
+
//#endregion
|
|
586
|
+
export { CalendarService };
|
|
587
|
+
//# sourceMappingURL=CalendarService.mjs.map
|