@remit/data-ports 0.0.75 → 0.0.77

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/data-ports",
3
- "version": "0.0.75",
3
+ "version": "0.0.77",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -231,6 +231,98 @@ export function calendarCollectionRepositoryConformance(
231
231
  );
232
232
  });
233
233
 
234
+ test("a collection starts with no subscription and empty fetch bookkeeping", async () => {
235
+ const calendar = await repo.create({
236
+ accountConfigId: harness.makeId(),
237
+ urlSegment: "plain",
238
+ displayName: "Plain",
239
+ });
240
+
241
+ assert.equal(calendar.subscriptionUrl, "");
242
+ assert.equal(calendar.subscriptionEnabled, false);
243
+ assert.equal(calendar.subscriptionCheckedAt, 0);
244
+ assert.equal(calendar.subscriptionFetchedAt, 0);
245
+ assert.equal(calendar.subscriptionError, "");
246
+ });
247
+
248
+ test("listEnabledSubscriptions returns enabled subscriptions across account configs and nothing else", async () => {
249
+ const first = harness.makeId();
250
+ const second = harness.makeId();
251
+ const subscribed = await repo.create({
252
+ accountConfigId: first,
253
+ urlSegment: "feed",
254
+ displayName: "Feed",
255
+ source: CalendarSource.Subscribed,
256
+ subscriptionUrl: "https://calendar.example/feed.ics",
257
+ subscriptionEnabled: true,
258
+ });
259
+ const elsewhere = await repo.create({
260
+ accountConfigId: second,
261
+ urlSegment: "feed",
262
+ displayName: "Feed",
263
+ source: CalendarSource.Subscribed,
264
+ subscriptionUrl: "https://calendar.example/other.ics",
265
+ subscriptionEnabled: true,
266
+ });
267
+ const paused = await repo.create({
268
+ accountConfigId: first,
269
+ urlSegment: "paused",
270
+ displayName: "Paused",
271
+ source: CalendarSource.Subscribed,
272
+ subscriptionUrl: "https://calendar.example/paused.ics",
273
+ subscriptionEnabled: true,
274
+ });
275
+ await repo.update(first, paused.calendarId, {
276
+ subscriptionEnabled: false,
277
+ });
278
+ await repo.create({
279
+ accountConfigId: first,
280
+ urlSegment: "own",
281
+ displayName: "Own",
282
+ });
283
+
284
+ const ids = (await repo.listEnabledSubscriptions())
285
+ .filter(
286
+ (calendar) =>
287
+ calendar.accountConfigId === first ||
288
+ calendar.accountConfigId === second,
289
+ )
290
+ .map((calendar) => calendar.calendarId)
291
+ .sort();
292
+
293
+ assert.deepEqual(
294
+ ids,
295
+ [subscribed.calendarId, elsewhere.calendarId].sort(),
296
+ );
297
+ });
298
+
299
+ test("update records a fetch outcome on the collection", async () => {
300
+ const accountConfigId = harness.makeId();
301
+ const calendar = await repo.create({
302
+ accountConfigId,
303
+ urlSegment: "fetched",
304
+ displayName: "Fetched",
305
+ source: CalendarSource.Subscribed,
306
+ subscriptionUrl: "https://calendar.example/feed.ics",
307
+ subscriptionEnabled: true,
308
+ });
309
+
310
+ const updated = await repo.update(accountConfigId, calendar.calendarId, {
311
+ subscriptionCheckedAt: 2_000,
312
+ subscriptionFetchedAt: 1_000,
313
+ subscriptionError: "the feed answered 404",
314
+ });
315
+
316
+ assert.equal(updated.subscriptionCheckedAt, 2_000);
317
+ assert.equal(updated.subscriptionFetchedAt, 1_000);
318
+ assert.equal(updated.subscriptionError, "the feed answered 404");
319
+ assert.equal(
320
+ updated.subscriptionUrl,
321
+ "https://calendar.example/feed.ics",
322
+ );
323
+ assert.equal(updated.subscriptionEnabled, true);
324
+ });
325
+
234
326
  test("delete removes the row", async () => {
235
327
  const accountConfigId = harness.makeId();
236
328
  const calendar = await repo.create({
@@ -37,6 +37,12 @@ export interface ICalendarCollectionRepository {
37
37
  listByAccountConfig(
38
38
  accountConfigId: string,
39
39
  ): Promise<CalendarCollectionItem[]>;
40
+ /**
41
+ * Every `Subscribed` collection whose refresh is on, across all account
42
+ * configs. The scheduled refresh walks this; a disabled subscription is
43
+ * absent, which is what stops its refresh.
44
+ */
45
+ listEnabledSubscriptions(): Promise<CalendarCollectionItem[]>;
40
46
  findByUrlSegment(
41
47
  accountConfigId: string,
42
48
  urlSegment: string,
package/src/types.ts CHANGED
@@ -661,6 +661,7 @@ export type CreateFilterInput = Omit<
661
661
  | "createdAt"
662
662
  | "updatedAt"
663
663
  | "state"
664
+ | "disabledReason"
664
665
  | "hasAnchor"
665
666
  | "ruleChangedAt"
666
667
  | "actionChangedAt"
@@ -670,6 +671,7 @@ export type CreateFilterInput = Omit<
670
671
  | "actionMailboxId"
671
672
  > & {
672
673
  state?: FilterItem["state"];
674
+ disabledReason?: FilterItem["disabledReason"];
673
675
  hasAnchor?: FilterItem["hasAnchor"];
674
676
  matchOperator?: FilterItem["matchOperator"];
675
677
  literalClauses?: FilterItem["literalClauses"];
@@ -701,7 +703,8 @@ export type CalendarEventIndexItem = z.infer<typeof CalendarEventIndexSchema>;
701
703
 
702
704
  // `calendarId` is derived from accountConfigId + urlSegment, and syncSequence
703
705
  // starts at zero and only ever moves through the collection's own bump — so
704
- // neither is ever supplied here.
706
+ // neither is ever supplied here. The fetch bookkeeping starts empty and only
707
+ // moves through an update after a fetch.
705
708
  export type CreateCalendarCollectionInput = Omit<
706
709
  CalendarCollectionItem,
707
710
  | "calendarId"
@@ -712,15 +715,31 @@ export type CreateCalendarCollectionInput = Omit<
712
715
  | "componentSet"
713
716
  | "source"
714
717
  | "timezone"
718
+ | "subscriptionUrl"
719
+ | "subscriptionEnabled"
720
+ | "subscriptionCheckedAt"
721
+ | "subscriptionFetchedAt"
722
+ | "subscriptionError"
715
723
  > & {
716
724
  color?: CalendarCollectionItem["color"];
717
725
  componentSet?: CalendarCollectionItem["componentSet"];
718
726
  source?: CalendarCollectionItem["source"];
719
727
  timezone?: CalendarCollectionItem["timezone"];
728
+ subscriptionUrl?: CalendarCollectionItem["subscriptionUrl"];
729
+ subscriptionEnabled?: CalendarCollectionItem["subscriptionEnabled"];
720
730
  };
721
731
 
722
732
  export type UpdateCalendarCollectionInput = Partial<
723
- Pick<CalendarCollectionItem, "displayName" | "color" | "timezone">
733
+ Pick<
734
+ CalendarCollectionItem,
735
+ | "displayName"
736
+ | "color"
737
+ | "timezone"
738
+ | "subscriptionEnabled"
739
+ | "subscriptionCheckedAt"
740
+ | "subscriptionFetchedAt"
741
+ | "subscriptionError"
742
+ >
724
743
  >;
725
744
 
726
745
  export type CalendarFeedTokenItem = z.infer<typeof CalendarFeedTokenSchema>;