@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.
Files changed (73) hide show
  1. package/dist/accept.d.ts +71 -0
  2. package/dist/accept.js +159 -0
  3. package/dist/build.d.ts +79 -0
  4. package/dist/build.js +196 -0
  5. package/dist/correct.d.ts +4 -0
  6. package/dist/correct.js +22 -0
  7. package/dist/errors.d.ts +56 -0
  8. package/dist/errors.js +1 -0
  9. package/dist/etag.d.ts +9 -0
  10. package/{src/etag.ts → dist/etag.js} +1 -3
  11. package/dist/expand.d.ts +73 -0
  12. package/dist/expand.js +188 -0
  13. package/dist/feed.d.ts +81 -0
  14. package/dist/feed.js +157 -0
  15. package/dist/fixtures.d.ts +19 -0
  16. package/dist/fixtures.js +37 -0
  17. package/dist/index.d.ts +16 -0
  18. package/dist/index.js +15 -0
  19. package/dist/memory-store.d.ts +105 -0
  20. package/dist/memory-store.js +319 -0
  21. package/dist/parse.d.ts +39 -0
  22. package/dist/parse.js +87 -0
  23. package/dist/project.d.ts +30 -0
  24. package/dist/project.js +57 -0
  25. package/dist/put.d.ts +52 -0
  26. package/dist/put.js +78 -0
  27. package/dist/reopen.d.ts +14 -0
  28. package/dist/reopen.js +92 -0
  29. package/dist/scope.d.ts +70 -0
  30. package/dist/scope.js +687 -0
  31. package/dist/subscribe.d.ts +96 -0
  32. package/dist/subscribe.js +298 -0
  33. package/dist/suggest.d.ts +74 -0
  34. package/dist/suggest.js +138 -0
  35. package/dist/time.d.ts +76 -0
  36. package/dist/time.js +164 -0
  37. package/dist/window.d.ts +85 -0
  38. package/dist/window.js +161 -0
  39. package/package.json +40 -35
  40. package/src/accept.test.ts +0 -403
  41. package/src/accept.ts +0 -250
  42. package/src/build.test.ts +0 -113
  43. package/src/build.ts +0 -311
  44. package/src/correct.test.ts +0 -173
  45. package/src/correct.ts +0 -40
  46. package/src/errors.ts +0 -62
  47. package/src/etag.test.ts +0 -54
  48. package/src/expand.test.ts +0 -361
  49. package/src/expand.ts +0 -303
  50. package/src/feed.test.ts +0 -334
  51. package/src/feed.ts +0 -203
  52. package/src/feeds/google-secret-address.ics +0 -99
  53. package/src/fixtures.ts +0 -52
  54. package/src/index.ts +0 -128
  55. package/src/memory-store.ts +0 -485
  56. package/src/parse.test.ts +0 -264
  57. package/src/parse.ts +0 -138
  58. package/src/project.test.ts +0 -247
  59. package/src/project.ts +0 -122
  60. package/src/put.test.ts +0 -318
  61. package/src/put.ts +0 -133
  62. package/src/reopen.test.ts +0 -529
  63. package/src/reopen.ts +0 -199
  64. package/src/scope.test.ts +0 -1421
  65. package/src/scope.ts +0 -1003
  66. package/src/subscribe.test.ts +0 -582
  67. package/src/subscribe.ts +0 -433
  68. package/src/suggest.test.ts +0 -376
  69. package/src/suggest.ts +0 -244
  70. package/src/time.ts +0 -260
  71. package/src/window.test.ts +0 -648
  72. package/src/window.ts +0 -281
  73. 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
- };