@remit/calendar-service 0.0.18 → 0.0.20
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/dist/accept.d.ts +71 -0
- package/dist/accept.js +159 -0
- package/dist/build.d.ts +79 -0
- package/dist/build.js +196 -0
- package/dist/correct.d.ts +4 -0
- package/dist/correct.js +22 -0
- package/dist/errors.d.ts +56 -0
- package/dist/errors.js +1 -0
- package/dist/etag.d.ts +9 -0
- package/{src/etag.ts → dist/etag.js} +1 -3
- package/dist/expand.d.ts +73 -0
- package/dist/expand.js +188 -0
- package/dist/feed.d.ts +81 -0
- package/dist/feed.js +157 -0
- package/dist/fixtures.d.ts +19 -0
- package/dist/fixtures.js +37 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +15 -0
- package/dist/memory-store.d.ts +105 -0
- package/dist/memory-store.js +319 -0
- package/dist/parse.d.ts +39 -0
- package/dist/parse.js +87 -0
- package/dist/project.d.ts +30 -0
- package/dist/project.js +57 -0
- package/dist/put.d.ts +52 -0
- package/dist/put.js +78 -0
- package/dist/reopen.d.ts +14 -0
- package/dist/reopen.js +92 -0
- package/dist/scope.d.ts +70 -0
- package/dist/scope.js +687 -0
- package/dist/subscribe.d.ts +96 -0
- package/dist/subscribe.js +298 -0
- package/dist/suggest.d.ts +74 -0
- package/dist/suggest.js +138 -0
- package/dist/time.d.ts +76 -0
- package/dist/time.js +164 -0
- package/dist/window.d.ts +85 -0
- package/dist/window.js +161 -0
- package/package.json +40 -35
- package/src/accept.test.ts +0 -403
- package/src/accept.ts +0 -250
- package/src/build.test.ts +0 -113
- package/src/build.ts +0 -311
- package/src/correct.test.ts +0 -173
- package/src/correct.ts +0 -40
- package/src/errors.ts +0 -62
- package/src/etag.test.ts +0 -54
- package/src/expand.test.ts +0 -361
- package/src/expand.ts +0 -303
- package/src/feed.test.ts +0 -334
- package/src/feed.ts +0 -203
- package/src/feeds/google-secret-address.ics +0 -99
- package/src/fixtures.ts +0 -52
- package/src/index.ts +0 -128
- package/src/memory-store.ts +0 -485
- package/src/parse.test.ts +0 -264
- package/src/parse.ts +0 -138
- package/src/project.test.ts +0 -247
- package/src/project.ts +0 -122
- package/src/put.test.ts +0 -318
- package/src/put.ts +0 -133
- package/src/reopen.test.ts +0 -529
- package/src/reopen.ts +0 -199
- package/src/scope.test.ts +0 -1421
- package/src/scope.ts +0 -1003
- package/src/subscribe.test.ts +0 -582
- package/src/subscribe.ts +0 -433
- package/src/suggest.test.ts +0 -376
- package/src/suggest.ts +0 -244
- package/src/time.ts +0 -260
- package/src/window.test.ts +0 -648
- package/src/window.ts +0 -281
- package/tsconfig.json +0 -8
package/src/reopen.ts
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import type { CalendarAnswerOvertaken as CalendarAnswerOvertakenValue } from "@remit/api-openapi-types";
|
|
2
|
-
import type {
|
|
3
|
-
CalendarCollectionItem,
|
|
4
|
-
CalendarObjectItem,
|
|
5
|
-
CalendarRepositories,
|
|
6
|
-
CalendarSuggestionItem,
|
|
7
|
-
ICalendarStore,
|
|
8
|
-
ICalendarSuggestionRepository,
|
|
9
|
-
} from "@remit/data-ports";
|
|
10
|
-
import {
|
|
11
|
-
CalendarAnswerOvertaken,
|
|
12
|
-
CalendarInviteMethod,
|
|
13
|
-
CalendarSuggestionState,
|
|
14
|
-
} from "@remit/domain-enums";
|
|
15
|
-
import { type CalendarResult, calendarFailure } from "./errors.js";
|
|
16
|
-
import { deleteCalendarObjectWrite } from "./put.js";
|
|
17
|
-
import { followingUidPrefix } from "./scope.js";
|
|
18
|
-
|
|
19
|
-
export interface ReopenCalendarSuggestionInput {
|
|
20
|
-
accountConfigId: string;
|
|
21
|
-
suggestion: CalendarSuggestionItem;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const answeredStates: ReadonlySet<CalendarSuggestionItem["state"]> = new Set([
|
|
25
|
-
CalendarSuggestionState.Accepted,
|
|
26
|
-
CalendarSuggestionState.Tentative,
|
|
27
|
-
]);
|
|
28
|
-
|
|
29
|
-
type SuggestionHolders = Pick<
|
|
30
|
-
ICalendarSuggestionRepository,
|
|
31
|
-
"listByAcceptedCalendarObjects"
|
|
32
|
-
>;
|
|
33
|
-
|
|
34
|
-
const holdersByObject = async (
|
|
35
|
-
calendarSuggestion: SuggestionHolders,
|
|
36
|
-
accountConfigId: string,
|
|
37
|
-
suggestions: CalendarSuggestionItem[],
|
|
38
|
-
): Promise<Map<string, CalendarSuggestionItem[]>> => {
|
|
39
|
-
const objectIds = [
|
|
40
|
-
...new Set(
|
|
41
|
-
suggestions
|
|
42
|
-
.map((suggestion) => suggestion.acceptedCalendarObjectId)
|
|
43
|
-
.filter((objectId) => objectId !== ""),
|
|
44
|
-
),
|
|
45
|
-
];
|
|
46
|
-
const byObject = new Map<string, CalendarSuggestionItem[]>();
|
|
47
|
-
for (const holder of await calendarSuggestion.listByAcceptedCalendarObjects(
|
|
48
|
-
accountConfigId,
|
|
49
|
-
objectIds,
|
|
50
|
-
)) {
|
|
51
|
-
if (!answeredStates.has(holder.state)) continue;
|
|
52
|
-
const held = byObject.get(holder.acceptedCalendarObjectId) ?? [];
|
|
53
|
-
held.push(holder);
|
|
54
|
-
byObject.set(holder.acceptedCalendarObjectId, held);
|
|
55
|
-
}
|
|
56
|
-
return byObject;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const othersIn = (
|
|
60
|
-
byObject: Map<string, CalendarSuggestionItem[]>,
|
|
61
|
-
suggestion: CalendarSuggestionItem,
|
|
62
|
-
): CalendarSuggestionItem[] =>
|
|
63
|
-
(byObject.get(suggestion.acceptedCalendarObjectId) ?? []).filter(
|
|
64
|
-
(other) => other.suggestionId !== suggestion.suggestionId,
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
const overtakenOf = (
|
|
68
|
-
holders: CalendarSuggestionItem[],
|
|
69
|
-
): CalendarAnswerOvertakenValue =>
|
|
70
|
-
holders.some((other) => other.method === CalendarInviteMethod.Cancel)
|
|
71
|
-
? CalendarAnswerOvertaken.Cancellation
|
|
72
|
-
: CalendarAnswerOvertaken.None;
|
|
73
|
-
|
|
74
|
-
export const answersOvertakenBy = async (
|
|
75
|
-
calendarSuggestion: SuggestionHolders,
|
|
76
|
-
accountConfigId: string,
|
|
77
|
-
suggestions: CalendarSuggestionItem[],
|
|
78
|
-
): Promise<
|
|
79
|
-
{
|
|
80
|
-
suggestion: CalendarSuggestionItem;
|
|
81
|
-
answerOvertakenBy: CalendarAnswerOvertakenValue;
|
|
82
|
-
}[]
|
|
83
|
-
> => {
|
|
84
|
-
const byObject = await holdersByObject(
|
|
85
|
-
calendarSuggestion,
|
|
86
|
-
accountConfigId,
|
|
87
|
-
suggestions,
|
|
88
|
-
);
|
|
89
|
-
return suggestions.map((suggestion) => ({
|
|
90
|
-
suggestion,
|
|
91
|
-
answerOvertakenBy: overtakenOf(othersIn(byObject, suggestion)),
|
|
92
|
-
}));
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const locateAnswered = async (
|
|
96
|
-
repos: CalendarRepositories,
|
|
97
|
-
collections: CalendarCollectionItem[],
|
|
98
|
-
calendarObjectId: string,
|
|
99
|
-
): Promise<
|
|
100
|
-
{ collection: CalendarCollectionItem; object: CalendarObjectItem } | undefined
|
|
101
|
-
> => {
|
|
102
|
-
for (const collection of collections) {
|
|
103
|
-
const object = await repos.calendarObject.find(
|
|
104
|
-
collection.calendarId,
|
|
105
|
-
calendarObjectId,
|
|
106
|
-
);
|
|
107
|
-
if (object !== null) return { collection, object };
|
|
108
|
-
}
|
|
109
|
-
return undefined;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const partsOf = async (
|
|
113
|
-
repos: CalendarRepositories,
|
|
114
|
-
suggestion: CalendarSuggestionItem,
|
|
115
|
-
collection: CalendarCollectionItem,
|
|
116
|
-
answered: CalendarObjectItem,
|
|
117
|
-
): Promise<CalendarObjectItem[]> => [
|
|
118
|
-
answered,
|
|
119
|
-
...(await repos.calendarObject.listByUidPrefix(
|
|
120
|
-
collection.calendarId,
|
|
121
|
-
followingUidPrefix(suggestion.icalUid),
|
|
122
|
-
)),
|
|
123
|
-
];
|
|
124
|
-
|
|
125
|
-
export const reopenCalendarSuggestion = async (
|
|
126
|
-
store: ICalendarStore,
|
|
127
|
-
input: ReopenCalendarSuggestionInput,
|
|
128
|
-
): Promise<CalendarResult<CalendarSuggestionItem>> => {
|
|
129
|
-
const { accountConfigId, suggestion } = input;
|
|
130
|
-
if (suggestion.state === CalendarSuggestionState.Pending) {
|
|
131
|
-
return { ok: true, value: suggestion };
|
|
132
|
-
}
|
|
133
|
-
if (suggestion.state === CalendarSuggestionState.Superseded) {
|
|
134
|
-
return calendarFailure(
|
|
135
|
-
"NotReopenable",
|
|
136
|
-
"A later message replaced this invitation, so answer that one instead.",
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
if (suggestion.method === CalendarInviteMethod.Cancel) {
|
|
140
|
-
return calendarFailure(
|
|
141
|
-
"NotReopenable",
|
|
142
|
-
"This is a cancellation, so there is no answer to take back.",
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const { repos } = store;
|
|
147
|
-
const holders = othersIn(
|
|
148
|
-
await holdersByObject(repos.calendarSuggestion, accountConfigId, [
|
|
149
|
-
suggestion,
|
|
150
|
-
]),
|
|
151
|
-
suggestion,
|
|
152
|
-
);
|
|
153
|
-
if (overtakenOf(holders) === CalendarAnswerOvertaken.Cancellation) {
|
|
154
|
-
return calendarFailure<CalendarSuggestionItem>(
|
|
155
|
-
"AnswerOvertaken",
|
|
156
|
-
"The cancellation of this event was answered into the same event, so this answer can no longer be taken back.",
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const located =
|
|
161
|
-
suggestion.acceptedCalendarObjectId === "" || holders.length > 0
|
|
162
|
-
? undefined
|
|
163
|
-
: await locateAnswered(
|
|
164
|
-
repos,
|
|
165
|
-
await repos.calendarCollection.listByAccountConfig(accountConfigId),
|
|
166
|
-
suggestion.acceptedCalendarObjectId,
|
|
167
|
-
);
|
|
168
|
-
const removals = located
|
|
169
|
-
? (
|
|
170
|
-
await partsOf(repos, suggestion, located.collection, located.object)
|
|
171
|
-
).map((object) =>
|
|
172
|
-
deleteCalendarObjectWrite({
|
|
173
|
-
accountConfigId,
|
|
174
|
-
calendarId: located.collection.calendarId,
|
|
175
|
-
calendarObjectId: object.calendarObjectId,
|
|
176
|
-
}),
|
|
177
|
-
)
|
|
178
|
-
: [];
|
|
179
|
-
|
|
180
|
-
await store.commit([
|
|
181
|
-
...removals,
|
|
182
|
-
{
|
|
183
|
-
kind: "SettleSuggestion",
|
|
184
|
-
accountConfigId,
|
|
185
|
-
suggestionId: suggestion.suggestionId,
|
|
186
|
-
settle: {
|
|
187
|
-
state: CalendarSuggestionState.Pending,
|
|
188
|
-
acceptedCalendarObjectId: "",
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
]);
|
|
192
|
-
return {
|
|
193
|
-
ok: true,
|
|
194
|
-
value: await repos.calendarSuggestion.get(
|
|
195
|
-
accountConfigId,
|
|
196
|
-
suggestion.suggestionId,
|
|
197
|
-
),
|
|
198
|
-
};
|
|
199
|
-
};
|