@things-factory/calendar 10.1.262 → 10.1.264

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.
@@ -21,6 +21,10 @@ export interface ImportedEvent {
21
21
  }[] | null;
22
22
  location?: string | null;
23
23
  cancelled?: boolean | null;
24
+ /** Whose calendar it was read from. */
25
+ mailbox?: string | null;
26
+ /** Every calendar it was read from - mergedReadings gathers them. */
27
+ mailboxes?: string[];
24
28
  }
25
29
  /** One event read from several people's calendars is one event: the first reading, with every measured attendance. */
26
30
  export declare function mergedReadings(events: readonly ImportedEvent[]): ImportedEvent[];
@@ -20,10 +20,13 @@ function mergedReadings(events) {
20
20
  if (!one?.id)
21
21
  continue;
22
22
  const held = merged.get(one.id);
23
+ const mailbox = String(one.mailbox ?? '').trim().toLowerCase();
23
24
  if (!held) {
24
- merged.set(one.id, { ...one, attendance: one.attendance ? [...one.attendance] : null });
25
+ merged.set(one.id, { ...one, attendance: one.attendance ? [...one.attendance] : null, mailboxes: mailbox ? [mailbox] : [] });
25
26
  continue;
26
27
  }
28
+ if (mailbox && !held.mailboxes.includes(mailbox))
29
+ held.mailboxes.push(mailbox);
27
30
  if (one.attendance?.length) {
28
31
  const seen = new Map((held.attendance ?? []).map(row => [row.email.toLowerCase(), row]));
29
32
  for (const row of one.attendance)
@@ -95,6 +98,15 @@ async function importEvents(tx, domain, user, input) {
95
98
  const people = peopleOf(one);
96
99
  const organizer = users.get(String(one.organizer ?? '').toLowerCase()) ?? null;
97
100
  const held = await repository.findOne({ where: { domain: { id: domain.id }, source, externalId: one.id } });
101
+ /*
102
+ * A cancellation is handed on so a meeting brought in before is cancelled here too. One never brought in is
103
+ * left: a series' cancelled occurrences came in as rows of their own - 20 「Canceled: 쉐프 스크럼」 on the first
104
+ * reading (Office, 2026-11-09).
105
+ */
106
+ if (one.cancelled && !held) {
107
+ left += 1;
108
+ continue;
109
+ }
98
110
  const status = one.cancelled ? event_rules_1.EventStatus.CANCELLED : held?.status === event_rules_1.EventStatus.HELD ? event_rules_1.EventStatus.HELD : event_rules_1.EventStatus.SCHEDULED;
99
111
  const facts = {
100
112
  calendar,
@@ -104,6 +116,7 @@ async function importEvents(tx, domain, user, input) {
104
116
  name: String(one.subject ?? '').trim().slice(0, 300) || NO_TITLE,
105
117
  location: one.location?.trim() || null,
106
118
  organizer,
119
+ sourceMailboxes: one.mailboxes?.length ? [...one.mailboxes].sort() : null,
107
120
  updater: user
108
121
  };
109
122
  const saved = held
@@ -1 +1 @@
1
- {"version":3,"file":"event-import.js","sourceRoot":"","sources":["../../../server/service/event/event-import.ts"],"names":[],"mappings":";;AA8CA,wCAgBC;AAGD,4BAWC;AA0BD,oCAyEC;AA/KD,qCAAoD;AAEpD,yDAAoF;AACpF,iDAAuD;AAEvD,mDAA+C;AAC/C,mEAA6G;AAC7G,mDAA6D;AAC7D,mCAA+B;AAC/B,+CAA2C;AAiC3C,MAAM,KAAK,GAAG,4BAA4B,CAAA;AAC1C,MAAM,QAAQ,GAAG,YAAY,CAAA;AAE7B,sHAAsH;AACtH,SAAgB,cAAc,CAAC,MAAgC;IAC7D,MAAM,MAAM,GAAG,IAAI,GAAG,EAAyB,CAAA;IAC/C,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QACzB,IAAI,CAAC,GAAG,EAAE,EAAE;YAAE,SAAQ;QACtB,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QAC/B,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,GAAG,GAAG,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;YACvF,SAAQ;QACV,CAAC;QACD,IAAI,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,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AAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAA;QACxI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAAE,SAAQ;QACnD,MAAM,EAAE,CAAC,aAAa,CAAC,aAAK,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,yBAAW,CAAC,SAAS,EAAE,YAAY,EAAE,kDAAkD,EAAE,OAAO,EAAE,IAAI,EAAS,CAAC,CAAA;QACjL,SAAS,IAAI,CAAC,CAAA;IAChB,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC","sourcesContent":["import { Between, EntityManager, In } from 'typeorm'\n\nimport { entersDomainAsAssignee, User, UserStatus } from '@things-factory/auth-base'\nimport { Domain, Refusal } from '@things-factory/shell'\n\nimport { Attendee } from '../attendee/attendee'\nimport { attendeeKey, attendeesOf, replaceAttendees, type AttendeeEntry } from '../attendee/attendee-service'\nimport { Calendar, CalendarKind } from '../calendar/calendar'\nimport { Event } from './event'\nimport { EventStatus } from './event-rules'\n\n/*\n * Events brought in from another calendar - a Teams or Outlook calendar read through Microsoft Graph (Office ADR-0191).\n * Each lands on one calendar of the domain, named by its id there: bringing it in again changes the row - its name,\n * time, place, people and their answers - and never adds a second. What this domain decided of it stays: an event\n * recorded as held is still held.\n *\n * A person is the domain's user when their address is an activated user who enters the domain; anyone else is named by\n * the address alone. How long each was in it is kept when the other calendar measured it, and is not wiped by a later\n * reading that did not.\n */\n\nexport interface ImportedAttendee {\n email: string\n name?: string | null\n response?: string | null\n}\n\nexport interface ImportedEvent {\n /** The event's id in the other calendar. */\n id: string\n subject?: string | null\n start: string\n end: string\n organizer?: string | null\n attendees?: ImportedAttendee[] | null\n /** Seconds each person was in it, when the other calendar measured it. */\n attendance?: { email: string; seconds: number }[] | null\n location?: string | null\n cancelled?: boolean | null\n}\n\nconst EMAIL = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\nconst NO_TITLE = '(no title)'\n\n/** One event read from several people's calendars is one event: the first reading, with every measured attendance. */\nexport function mergedReadings(events: readonly ImportedEvent[]): ImportedEvent[] {\n const merged = new Map<string, ImportedEvent>()\n for (const one of events) {\n if (!one?.id) continue\n const held = merged.get(one.id)\n if (!held) {\n merged.set(one.id, { ...one, attendance: one.attendance ? [...one.attendance] : null })\n continue\n }\n if (one.attendance?.length) {\n const seen = new Map((held.attendance ?? []).map(row => [row.email.toLowerCase(), row]))\n for (const row of one.attendance) if (!seen.has(row.email.toLowerCase())) seen.set(row.email.toLowerCase(), row)\n held.attendance = [...seen.values()]\n }\n }\n return [...merged.values()]\n}\n\n/** The people of an event by address - its organizer first, each once - with their answer and measured seconds. */\nexport function peopleOf(event: ImportedEvent): { email: string; name: string; response: string | null; seconds: number | null }[] {\n const seconds = new Map((event.attendance ?? []).map(row => [String(row.email).toLowerCase(), Math.max(0, Math.round(Number(row.seconds) || 0))]))\n const people = new Map<string, { email: string; name: string; response: string | null; seconds: number | null }>()\n const add = (email: string | null | undefined, name: string | null | undefined, response: string | null | undefined) => {\n const address = String(email ?? '').trim().toLowerCase()\n if (!EMAIL.test(address) || people.has(address)) return\n people.set(address, { email: address, name: String(name ?? '').trim() || address, response: response ?? null, seconds: seconds.has(address) ? seconds.get(address)! : null })\n }\n add(event.organizer, null, 'organizer')\n for (const one of event.attendees ?? []) add(one.email, one.name, one.response)\n return [...people.values()]\n}\n\n/** The domain calendar events are brought in on - made, as a calendar of meetings, when the domain has none by that name. */\nasync function calendarNamed(tx: EntityManager, domain: Domain, user: User, name: string): Promise<Calendar> {\n const repository = tx.getRepository(Calendar)\n const found = await repository.findOne({ where: { domain: { id: domain.id }, name } as any })\n if (found) {\n if (found.kind !== CalendarKind.GENERAL) throw new Refusal('event-import-calendar-not-general', { name }, `'${name}' is not a calendar of meetings`)\n return found\n }\n return repository.save(repository.create({ domain, name, kind: CalendarKind.GENERAL, active: true, creator: user, updater: user } as any) as any) as any\n}\n\n/** What one reading of the other calendar covered: its window and the mailboxes it could read. */\nexport interface ImportReading {\n from: string\n to: string\n mailboxes: string[]\n failed?: { mailbox: string; reason?: string | null }[] | null\n}\n\n/**\n * Brings `events` from the calendar `source` onto the domain calendar `calendarName`. Answers how many were added,\n * changed, left and cancelled. Given the `reading` they came from, an event of that source in its window that a mailbox\n * it read holds and the reading no longer has was removed there: it is cancelled here - unless it was held.\n */\nexport async function importEvents(tx: EntityManager, domain: Domain, user: User, input: { calendarName: string; source: string; events: ImportedEvent[]; reading?: ImportReading | null }) {\n const calendarName = String(input.calendarName ?? '').trim()\n const source = String(input.source ?? '').trim().toUpperCase()\n if (!calendarName) throw new Refusal('event-import-calendar-required', {}, 'Name the calendar to bring the events onto')\n if (!source) throw new Refusal('event-import-source-required', {}, 'Name the calendar the events come from')\n const calendar = await calendarNamed(tx, domain, user, calendarName)\n const events = mergedReadings(input.events ?? [])\n\n /* The domain's users among the addresses, read once. */\n const addresses = [...new Set(events.flatMap(one => peopleOf(one).map(person => person.email)))]\n const found = addresses.length ? await tx.getRepository(User).find({ where: { email: In(addresses) } as any }) : []\n const users = new Map<string, User>()\n for (const one of found)\n if (one.status === UserStatus.ACTIVATED && (await entersDomainAsAssignee(domain, one, tx))) users.set(String(one.email).toLowerCase(), one)\n\n const repository = tx.getRepository(Event)\n let created = 0\n let updated = 0\n let left = 0\n for (const one of events) {\n const startAt = new Date(one.start)\n const endAt = new Date(one.end)\n if (isNaN(startAt.getTime()) || isNaN(endAt.getTime()) || !(endAt > startAt)) {\n left += 1\n continue\n }\n const people = peopleOf(one)\n const organizer = users.get(String(one.organizer ?? '').toLowerCase()) ?? null\n const held = await repository.findOne({ where: { domain: { id: domain.id }, source, externalId: one.id } as any })\n const status = one.cancelled ? EventStatus.CANCELLED : held?.status === EventStatus.HELD ? EventStatus.HELD : EventStatus.SCHEDULED\n const facts = {\n calendar,\n startAt,\n endAt,\n status,\n name: String(one.subject ?? '').trim().slice(0, 300) || NO_TITLE,\n location: one.location?.trim() || null,\n organizer,\n updater: user\n }\n const saved = held\n ? (await repository.save({ ...held, ...facts }), held)\n : await repository.save(repository.create({ domain, series: null, scheduledAt: startAt, source, externalId: one.id, creator: user, ...facts } as any) as any)\n held ? (updated += 1) : (created += 1)\n\n const entries: AttendeeEntry[] = people.map(person => {\n const known = users.get(person.email)\n return known ? { key: attendeeKey({ userId: known.id }), userId: known.id, name: known.name || person.name } : { key: attendeeKey({ email: person.email }), email: person.email, name: person.name }\n })\n await replaceAttendees(tx, domain, user, { event: { id: (saved as any).id } }, entries)\n const rows = await attendeesOf(tx, domain, { event: { id: (saved as any).id } })\n const byKey = new Map(people.map((person, index) => [entries[index].key, person]))\n for (const row of rows) {\n const person = byKey.get(attendeeKey(row))\n if (!person) continue\n const change: Partial<Attendee> = {}\n if ((row.response ?? null) !== person.response) change.response = person.response\n if (person.seconds !== null && row.attendedSeconds !== person.seconds) change.attendedSeconds = person.seconds\n if (Object.keys(change).length) await tx.getRepository(Attendee).update({ id: row.id }, { ...change, updater: user } as any)\n }\n }\n const cancelled = input.reading ? await cancelRemoved(tx, domain, user, source, input.reading, new Set(events.map(one => one.id))) : 0\n if (input.reading) {\n const lastImport = {\n at: new Date().toISOString(),\n source,\n read: (input.reading.mailboxes ?? []).length,\n mailboxes: (input.reading.mailboxes ?? []).map(one => String(one).toLowerCase()),\n failed: (input.reading.failed ?? []).map(one => ({ mailbox: String(one.mailbox).toLowerCase(), reason: one.reason ?? null }))\n }\n await tx.getRepository(Calendar).update({ id: calendar.id }, { lastImport, updater: user } as any)\n }\n return { created, updated, left, cancelled }\n}\n\n/** The events of `source` in the reading's window, held by a mailbox it read, that it did not find - removed there. */\nasync function cancelRemoved(tx: EntityManager, domain: Domain, user: User, source: string, reading: ImportReading, found: Set<string>): Promise<number> {\n const from = new Date(reading.from)\n const to = new Date(reading.to)\n const read = new Set((reading.mailboxes ?? []).map(one => String(one).trim().toLowerCase()).filter(Boolean))\n if (isNaN(from.getTime()) || isNaN(to.getTime()) || !read.size) return 0\n const standing = await tx.getRepository(Event).find({\n where: { domain: { id: domain.id }, source, startAt: Between(from, to), status: In([EventStatus.SCHEDULED, EventStatus.POSTPONED]) } as any,\n relations: ['organizer']\n })\n const gone = standing.filter(one => one.externalId && !found.has(one.externalId))\n let cancelled = 0\n for (const event of gone) {\n const rows = await tx.getRepository(Attendee).find({ where: { domain: { id: domain.id }, event: { id: event.id } } as any, relations: ['user'] })\n const addresses = [event.organizer?.email, ...rows.map(row => row.email ?? row.user?.email)].map(one => String(one ?? '').toLowerCase())\n if (!addresses.some(one => read.has(one))) continue\n await tx.getRepository(Event).update({ id: event.id }, { status: EventStatus.CANCELLED, statusReason: 'removed from the calendar it was brought in from', updater: user } as any)\n cancelled += 1\n }\n return cancelled\n}\n"]}
1
+ {"version":3,"file":"event-import.js","sourceRoot":"","sources":["../../../server/service/event/event-import.ts"],"names":[],"mappings":";;AAkDA,wCAkBC;AAGD,4BAWC;AA0BD,oCAmFC;AA/LD,qCAAoD;AAEpD,yDAAoF;AACpF,iDAAuD;AAEvD,mDAA+C;AAC/C,mEAA6G;AAC7G,mDAA6D;AAC7D,mCAA+B;AAC/B,+CAA2C;AAqC3C,MAAM,KAAK,GAAG,4BAA4B,CAAA;AAC1C,MAAM,QAAQ,GAAG,YAAY,CAAA;AAE7B,sHAAsH;AACtH,SAAgB,cAAc,CAAC,MAAgC;IAC7D,MAAM,MAAM,GAAG,IAAI,GAAG,EAAyB,CAAA;IAC/C,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QACzB,IAAI,CAAC,GAAG,EAAE,EAAE;YAAE,SAAQ;QACtB,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QAC/B,MAAM,OAAO,GAAG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AAC,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,yBAAW,CAAC,SAAS,EAAE,YAAY,EAAE,kDAAkD,EAAE,OAAO,EAAE,IAAI,EAAS,CAAC,CAAA;QACjL,SAAS,IAAI,CAAC,CAAA;IAChB,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC","sourcesContent":["import { Between, EntityManager, In } from 'typeorm'\n\nimport { entersDomainAsAssignee, User, UserStatus } from '@things-factory/auth-base'\nimport { Domain, Refusal } from '@things-factory/shell'\n\nimport { Attendee } from '../attendee/attendee'\nimport { attendeeKey, attendeesOf, replaceAttendees, type AttendeeEntry } from '../attendee/attendee-service'\nimport { Calendar, CalendarKind } from '../calendar/calendar'\nimport { Event } from './event'\nimport { EventStatus } from './event-rules'\n\n/*\n * Events brought in from another calendar - a Teams or Outlook calendar read through Microsoft Graph (Office ADR-0191).\n * Each lands on one calendar of the domain, named by its id there: bringing it in again changes the row - its name,\n * time, place, people and their answers - and never adds a second. What this domain decided of it stays: an event\n * recorded as held is still held.\n *\n * A person is the domain's user when their address is an activated user who enters the domain; anyone else is named by\n * the address alone. How long each was in it is kept when the other calendar measured it, and is not wiped by a later\n * reading that did not.\n */\n\nexport interface ImportedAttendee {\n email: string\n name?: string | null\n response?: string | null\n}\n\nexport interface ImportedEvent {\n /** The event's id in the other calendar. */\n id: string\n subject?: string | null\n start: string\n end: string\n organizer?: string | null\n attendees?: ImportedAttendee[] | null\n /** Seconds each person was in it, when the other calendar measured it. */\n attendance?: { email: string; seconds: number }[] | null\n location?: string | null\n cancelled?: boolean | null\n /** Whose calendar it was read from. */\n mailbox?: string | null\n /** Every calendar it was read from - mergedReadings gathers them. */\n mailboxes?: string[]\n}\n\nconst EMAIL = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\nconst NO_TITLE = '(no title)'\n\n/** One event read from several people's calendars is one event: the first reading, with every measured attendance. */\nexport function mergedReadings(events: readonly ImportedEvent[]): ImportedEvent[] {\n const merged = new Map<string, ImportedEvent>()\n for (const one of events) {\n if (!one?.id) continue\n const held = merged.get(one.id)\n const mailbox = String(one.mailbox ?? '').trim().toLowerCase()\n if (!held) {\n merged.set(one.id, { ...one, attendance: one.attendance ? [...one.attendance] : null, mailboxes: mailbox ? [mailbox] : [] })\n continue\n }\n if (mailbox && !held.mailboxes!.includes(mailbox)) held.mailboxes!.push(mailbox)\n if (one.attendance?.length) {\n const seen = new Map((held.attendance ?? []).map(row => [row.email.toLowerCase(), row]))\n for (const row of one.attendance) if (!seen.has(row.email.toLowerCase())) seen.set(row.email.toLowerCase(), row)\n held.attendance = [...seen.values()]\n }\n }\n return [...merged.values()]\n}\n\n/** The people of an event by address - its organizer first, each once - with their answer and measured seconds. */\nexport function peopleOf(event: ImportedEvent): { email: string; name: string; response: string | null; seconds: number | null }[] {\n const seconds = new Map((event.attendance ?? []).map(row => [String(row.email).toLowerCase(), Math.max(0, Math.round(Number(row.seconds) || 0))]))\n const people = new Map<string, { email: string; name: string; response: string | null; seconds: number | null }>()\n const add = (email: string | null | undefined, name: string | null | undefined, response: string | null | undefined) => {\n const address = String(email ?? '').trim().toLowerCase()\n if (!EMAIL.test(address) || people.has(address)) return\n people.set(address, { email: address, name: String(name ?? '').trim() || address, response: response ?? null, seconds: seconds.has(address) ? seconds.get(address)! : null })\n }\n add(event.organizer, null, 'organizer')\n for (const one of event.attendees ?? []) add(one.email, one.name, one.response)\n return [...people.values()]\n}\n\n/** The domain calendar events are brought in on - made, as a calendar of meetings, when the domain has none by that name. */\nasync function calendarNamed(tx: EntityManager, domain: Domain, user: User, name: string): Promise<Calendar> {\n const repository = tx.getRepository(Calendar)\n const found = await repository.findOne({ where: { domain: { id: domain.id }, name } as any })\n if (found) {\n if (found.kind !== CalendarKind.GENERAL) throw new Refusal('event-import-calendar-not-general', { name }, `'${name}' is not a calendar of meetings`)\n return found\n }\n return repository.save(repository.create({ domain, name, kind: CalendarKind.GENERAL, active: true, creator: user, updater: user } as any) as any) as any\n}\n\n/** What one reading of the other calendar covered: its window and the mailboxes it could read. */\nexport interface ImportReading {\n from: string\n to: string\n mailboxes: string[]\n failed?: { mailbox: string; reason?: string | null }[] | null\n}\n\n/**\n * Brings `events` from the calendar `source` onto the domain calendar `calendarName`. Answers how many were added,\n * changed, left and cancelled. Given the `reading` they came from, an event of that source in its window that a mailbox\n * it read holds and the reading no longer has was removed there: it is cancelled here - unless it was held.\n */\nexport async function importEvents(tx: EntityManager, domain: Domain, user: User, input: { calendarName: string; source: string; events: ImportedEvent[]; reading?: ImportReading | null }) {\n const calendarName = String(input.calendarName ?? '').trim()\n const source = String(input.source ?? '').trim().toUpperCase()\n if (!calendarName) throw new Refusal('event-import-calendar-required', {}, 'Name the calendar to bring the events onto')\n if (!source) throw new Refusal('event-import-source-required', {}, 'Name the calendar the events come from')\n const calendar = await calendarNamed(tx, domain, user, calendarName)\n const events = mergedReadings(input.events ?? [])\n\n /* The domain's users among the addresses, read once. */\n const addresses = [...new Set(events.flatMap(one => peopleOf(one).map(person => person.email)))]\n const found = addresses.length ? await tx.getRepository(User).find({ where: { email: In(addresses) } as any }) : []\n const users = new Map<string, User>()\n for (const one of found)\n if (one.status === UserStatus.ACTIVATED && (await entersDomainAsAssignee(domain, one, tx))) users.set(String(one.email).toLowerCase(), one)\n\n const repository = tx.getRepository(Event)\n let created = 0\n let updated = 0\n let left = 0\n for (const one of events) {\n const startAt = new Date(one.start)\n const endAt = new Date(one.end)\n if (isNaN(startAt.getTime()) || isNaN(endAt.getTime()) || !(endAt > startAt)) {\n left += 1\n continue\n }\n const people = peopleOf(one)\n const organizer = users.get(String(one.organizer ?? '').toLowerCase()) ?? null\n const held = await repository.findOne({ where: { domain: { id: domain.id }, source, externalId: one.id } as any })\n /*\n * A cancellation is handed on so a meeting brought in before is cancelled here too. One never brought in is\n * left: a series' cancelled occurrences came in as rows of their own - 20 「Canceled: 쉐프 스크럼」 on the first\n * reading (Office, 2026-11-09).\n */\n if (one.cancelled && !held) {\n left += 1\n continue\n }\n const status = one.cancelled ? EventStatus.CANCELLED : held?.status === EventStatus.HELD ? EventStatus.HELD : EventStatus.SCHEDULED\n const facts = {\n calendar,\n startAt,\n endAt,\n status,\n name: String(one.subject ?? '').trim().slice(0, 300) || NO_TITLE,\n location: one.location?.trim() || null,\n organizer,\n sourceMailboxes: one.mailboxes?.length ? [...one.mailboxes].sort() : null,\n updater: user\n }\n const saved = held\n ? (await repository.save({ ...held, ...facts }), held)\n : await repository.save(repository.create({ domain, series: null, scheduledAt: startAt, source, externalId: one.id, creator: user, ...facts } as any) as any)\n held ? (updated += 1) : (created += 1)\n\n const entries: AttendeeEntry[] = people.map(person => {\n const known = users.get(person.email)\n return known ? { key: attendeeKey({ userId: known.id }), userId: known.id, name: known.name || person.name } : { key: attendeeKey({ email: person.email }), email: person.email, name: person.name }\n })\n await replaceAttendees(tx, domain, user, { event: { id: (saved as any).id } }, entries)\n const rows = await attendeesOf(tx, domain, { event: { id: (saved as any).id } })\n const byKey = new Map(people.map((person, index) => [entries[index].key, person]))\n for (const row of rows) {\n const person = byKey.get(attendeeKey(row))\n if (!person) continue\n const change: Partial<Attendee> = {}\n if ((row.response ?? null) !== person.response) change.response = person.response\n if (person.seconds !== null && row.attendedSeconds !== person.seconds) change.attendedSeconds = person.seconds\n if (Object.keys(change).length) await tx.getRepository(Attendee).update({ id: row.id }, { ...change, updater: user } as any)\n }\n }\n const cancelled = input.reading ? await cancelRemoved(tx, domain, user, source, input.reading, new Set(events.map(one => one.id))) : 0\n if (input.reading) {\n const lastImport = {\n at: new Date().toISOString(),\n source,\n read: (input.reading.mailboxes ?? []).length,\n mailboxes: (input.reading.mailboxes ?? []).map(one => String(one).toLowerCase()),\n failed: (input.reading.failed ?? []).map(one => ({ mailbox: String(one.mailbox).toLowerCase(), reason: one.reason ?? null }))\n }\n await tx.getRepository(Calendar).update({ id: calendar.id }, { lastImport, updater: user } as any)\n }\n return { created, updated, left, cancelled }\n}\n\n/** The events of `source` in the reading's window, held by a mailbox it read, that it did not find - removed there. */\nasync function cancelRemoved(tx: EntityManager, domain: Domain, user: User, source: string, reading: ImportReading, found: Set<string>): Promise<number> {\n const from = new Date(reading.from)\n const to = new Date(reading.to)\n const read = new Set((reading.mailboxes ?? []).map(one => String(one).trim().toLowerCase()).filter(Boolean))\n if (isNaN(from.getTime()) || isNaN(to.getTime()) || !read.size) return 0\n const standing = await tx.getRepository(Event).find({\n where: { domain: { id: domain.id }, source, startAt: Between(from, to), status: In([EventStatus.SCHEDULED, EventStatus.POSTPONED]) } as any,\n relations: ['organizer']\n })\n const gone = standing.filter(one => one.externalId && !found.has(one.externalId))\n let cancelled = 0\n for (const event of gone) {\n const rows = await tx.getRepository(Attendee).find({ where: { domain: { id: domain.id }, event: { id: event.id } } as any, relations: ['user'] })\n const addresses = [event.organizer?.email, ...rows.map(row => row.email ?? row.user?.email)].map(one => String(one ?? '').toLowerCase())\n if (!addresses.some(one => read.has(one))) continue\n await tx.getRepository(Event).update({ id: event.id }, { status: EventStatus.CANCELLED, statusReason: 'removed from the calendar it was brought in from', updater: user } as any)\n cancelled += 1\n }\n return cancelled\n}\n"]}
@@ -28,6 +28,11 @@ export declare class Event {
28
28
  source?: string;
29
29
  /** The event's id in that calendar - bringing it in again changes this row, never adds a second. */
30
30
  externalId?: string;
31
+ /**
32
+ * The mailboxes the last reading found it in - whose calendar holds it. Without them a meeting no one could find in
33
+ * Teams or Outlook could not be traced to a person (Office, 2026-11-09).
34
+ */
35
+ sourceMailboxes?: string[];
31
36
  organizer?: User;
32
37
  organizerId?: string;
33
38
  createdAt?: Date;
@@ -101,6 +101,11 @@ tslib_1.__decorate([
101
101
  (0, type_graphql_1.Field)({ nullable: true, description: "The event's id in the calendar it was brought in from" }),
102
102
  tslib_1.__metadata("design:type", String)
103
103
  ], Event.prototype, "externalId", void 0);
104
+ tslib_1.__decorate([
105
+ (0, typeorm_1.Column)('simple-json', { nullable: true }),
106
+ (0, type_graphql_1.Field)(type => [String], { nullable: true, description: 'The mailboxes the last reading found it in - whose calendar holds it' }),
107
+ tslib_1.__metadata("design:type", Array)
108
+ ], Event.prototype, "sourceMailboxes", void 0);
104
109
  tslib_1.__decorate([
105
110
  (0, typeorm_1.ManyToOne)(type => auth_base_1.User, { nullable: true }),
106
111
  (0, type_graphql_1.Field)(type => auth_base_1.User, { nullable: true, description: 'The person responsible for the event' }),
@@ -1 +1 @@
1
- {"version":3,"file":"event.js","sourceRoot":"","sources":["../../../server/service/event/event.ts"],"names":[],"mappings":";;;;AAAA,qCAAoJ;AACpJ,+CAAoD;AAEpD,iDAA8C;AAC9C,yDAAgD;AAEhD,mDAA+C;AAC/C,+DAA0D;AAC1D,+CAA2C;AAE3C;;;;GAIG;AAaI,IAAM,KAAK,GAAX,MAAM,KAAK;CAuGjB,CAAA;AAvGY,sBAAK;AAGP;IAFR,IAAA,gCAAsB,EAAC,MAAM,CAAC;IAC9B,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAE,EAAE,EAAE,WAAW,EAAE,gCAAgC,EAAE,CAAC;;iCAClD;AAInB;IAFC,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,cAAM,CAAC;IACzB,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,cAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,iCAAiC,EAAE,CAAC;sCACjF,cAAM;qCAAA;AAGf;IADC,IAAA,oBAAU,EAAC,CAAC,KAAY,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC;;uCAC1B;AAIjB;IAFC,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,mBAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC/C,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,mBAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,2CAA2C,EAAE,CAAC;sCAC3F,mBAAQ;uCAAA;AAInB;IAFC,IAAA,oBAA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wCAC1B;gBAtGP,KAAK;IAZjB,IAAA,gBAAM,GAAE;IACR,IAAA,eAAK,EAAC,YAAY,EAAE,CAAC,KAAY,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,WAAW,CAAC,EAAE;QACtF,MAAM,EAAE,IAAI;QACZ,KAAK,EAAE,kDAAkD;KAC1D,CAAC;IACD,IAAA,eAAK,EAAC,YAAY,EAAE,CAAC,KAAY,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACpE,IAAA,eAAK,EAAC,YAAY,EAAE,CAAC,KAAY,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACpF,IAAA,eAAK,EAAC,YAAY,EAAE,CAAC,KAAY,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,EAAE;QACrF,MAAM,EAAE,IAAI;QACZ,KAAK,EAAE,oDAAoD;KAC5D,CAAC;IACD,IAAA,yBAAU,EAAC,EAAE,WAAW,EAAE,kFAAkF,EAAE,CAAC;GACnG,KAAK,CAuGjB","sourcesContent":["import { Column, CreateDateColumn, DeleteDateColumn, Entity, Index, ManyToOne, PrimaryGeneratedColumn, RelationId, UpdateDateColumn } from 'typeorm'\nimport { Field, ID, ObjectType } from 'type-graphql'\n\nimport { Domain } from '@things-factory/shell'\nimport { User } from '@things-factory/auth-base'\n\nimport { Calendar } from '../calendar/calendar'\nimport { EventSeries } from '../event-series/event-series'\nimport { EventStatus } from './event-rules'\n\n/**\n * Something that takes place at a time — on its own, or as one occurrence of a series. An occurrence is named by its\n * series and `scheduledAt`, the time the rule gave it; postponing moves `startAt`/`endAt` and never `scheduledAt`, so\n * creating the series' occurrences again finds it and makes no second one.\n */\n@Entity()\n@Index('ix_event_0', (event: Event) => [event.domain, event.series, event.scheduledAt], {\n unique: true,\n where: '\"deleted_at\" IS NULL AND \"series_id\" IS NOT NULL'\n})\n@Index('ix_event_1', (event: Event) => [event.domain, event.startAt])\n@Index('ix_event_2', (event: Event) => [event.domain, event.calendar, event.startAt])\n@Index('ix_event_3', (event: Event) => [event.domain, event.source, event.externalId], {\n unique: true,\n where: '\"deleted_at\" IS NULL AND \"external_id\" IS NOT NULL'\n})\n@ObjectType({ description: 'Something that takes place at a time, on its own or as an occurrence of a series' })\nexport class Event {\n @PrimaryGeneratedColumn('uuid')\n @Field(type => ID, { description: 'Unique identifier of the event' })\n readonly id: string\n\n @ManyToOne(type => Domain)\n @Field(type => Domain, { nullable: true, description: 'The domain the event belongs to' })\n domain?: Domain\n\n @RelationId((event: Event) => event.domain)\n domainId?: string\n\n @ManyToOne(type => Calendar, { nullable: true })\n @Field(type => Calendar, { nullable: true, description: 'The calendar the event belongs to, if any' })\n calendar?: Calendar\n\n @RelationId((event: Event) => event.calendar)\n @Field({ nullable: true, description: 'Id of the calendar the event belongs to' })\n calendarId?: string\n\n @ManyToOne(type => EventSeries, { nullable: true })\n @Field(type => EventSeries, { nullable: true, description: 'The series this event is an occurrence of; empty for a one-off event' })\n series?: EventSeries\n\n @RelationId((event: Event) => event.series)\n @Field({ nullable: true, description: 'Id of the series this event is an occurrence of' })\n seriesId?: string\n\n @Column()\n @Field({ description: 'The time the event was first given — the rule\\'s time for an occurrence. It never moves' })\n scheduledAt: Date\n\n @Column()\n @Field({ description: 'When the event starts' })\n startAt: Date\n\n @Column()\n @Field({ description: 'When the event ends' })\n endAt: Date\n\n @Column({ default: EventStatus.SCHEDULED })\n @Field(type => EventStatus, { description: 'Scheduled, postponed, cancelled or held' })\n status: EventStatus\n\n @Column({ type: 'text', nullable: true })\n @Field({ nullable: true, description: 'Why it was last postponed or cancelled' })\n statusReason?: string\n\n @Column()\n @Field({ description: 'Name of the event' })\n name: string\n\n @Column({ type: 'text', nullable: true })\n @Field({ nullable: true, description: 'What the event is about' })\n description?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'Where the event takes place' })\n location?: string\n\n /** Where an event brought in from another calendar came from (`importEvents`) - none for one made here. */\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'The calendar it was brought in from, such as MSGRAPH; empty for an event made here' })\n source?: string\n\n /** The event's id in that calendar - bringing it in again changes this row, never adds a second. */\n @Column({ nullable: true })\n @Field({ nullable: true, description: \"The event's id in the calendar it was brought in from\" })\n externalId?: string\n\n @ManyToOne(type => User, { nullable: true })\n @Field(type => User, { nullable: true, description: 'The person responsible for the event' })\n organizer?: User\n\n @RelationId((event: Event) => event.organizer)\n @Field({ nullable: true, description: 'Id of the person responsible for the event' })\n organizerId?: string\n\n @CreateDateColumn()\n @Field({ nullable: true, description: 'Creation timestamp' })\n createdAt?: Date\n\n @UpdateDateColumn()\n @Field({ nullable: true, description: 'Last update timestamp' })\n updatedAt?: Date\n\n @DeleteDateColumn()\n @Field({ nullable: true, description: 'Soft delete timestamp' })\n deletedAt?: Date\n\n @ManyToOne(type => User, { nullable: true })\n @Field(type => User, { nullable: true, description: 'Who created the event' })\n creator?: User\n\n @RelationId((event: Event) => event.creator)\n creatorId?: string\n\n @ManyToOne(type => User, { nullable: true })\n @Field(type => User, { nullable: true, description: 'Who last changed the event' })\n updater?: User\n\n @RelationId((event: Event) => event.updater)\n updaterId?: string\n}\n"]}
1
+ {"version":3,"file":"event.js","sourceRoot":"","sources":["../../../server/service/event/event.ts"],"names":[],"mappings":";;;;AAAA,qCAAoJ;AACpJ,+CAAoD;AAEpD,iDAA8C;AAC9C,yDAAgD;AAEhD,mDAA+C;AAC/C,+DAA0D;AAC1D,+CAA2C;AAE3C;;;;GAIG;AAaI,IAAM,KAAK,GAAX,MAAM,KAAK;CA+GjB,CAAA;AA/GY,sBAAK;AAGP;IAFR,IAAA,gCAAsB,EAAC,MAAM,CAAC;IAC9B,IAAA,oBA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E,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACpE,IAAA,eAAK,EAAC,YAAY,EAAE,CAAC,KAAY,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACpF,IAAA,eAAK,EAAC,YAAY,EAAE,CAAC,KAAY,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,EAAE;QACrF,MAAM,EAAE,IAAI;QACZ,KAAK,EAAE,oDAAoD;KAC5D,CAAC;IACD,IAAA,yBAAU,EAAC,EAAE,WAAW,EAAE,kFAAkF,EAAE,CAAC;GACnG,KAAK,CA+GjB","sourcesContent":["import { Column, CreateDateColumn, DeleteDateColumn, Entity, Index, ManyToOne, PrimaryGeneratedColumn, RelationId, UpdateDateColumn } from 'typeorm'\nimport { Field, ID, ObjectType } from 'type-graphql'\n\nimport { Domain } from '@things-factory/shell'\nimport { User } from '@things-factory/auth-base'\n\nimport { Calendar } from '../calendar/calendar'\nimport { EventSeries } from '../event-series/event-series'\nimport { EventStatus } from './event-rules'\n\n/**\n * Something that takes place at a time — on its own, or as one occurrence of a series. An occurrence is named by its\n * series and `scheduledAt`, the time the rule gave it; postponing moves `startAt`/`endAt` and never `scheduledAt`, so\n * creating the series' occurrences again finds it and makes no second one.\n */\n@Entity()\n@Index('ix_event_0', (event: Event) => [event.domain, event.series, event.scheduledAt], {\n unique: true,\n where: '\"deleted_at\" IS NULL AND \"series_id\" IS NOT NULL'\n})\n@Index('ix_event_1', (event: Event) => [event.domain, event.startAt])\n@Index('ix_event_2', (event: Event) => [event.domain, event.calendar, event.startAt])\n@Index('ix_event_3', (event: Event) => [event.domain, event.source, event.externalId], {\n unique: true,\n where: '\"deleted_at\" IS NULL AND \"external_id\" IS NOT NULL'\n})\n@ObjectType({ description: 'Something that takes place at a time, on its own or as an occurrence of a series' })\nexport class Event {\n @PrimaryGeneratedColumn('uuid')\n @Field(type => ID, { description: 'Unique identifier of the event' })\n readonly id: string\n\n @ManyToOne(type => Domain)\n @Field(type => Domain, { nullable: true, description: 'The domain the event belongs to' })\n domain?: Domain\n\n @RelationId((event: Event) => event.domain)\n domainId?: string\n\n @ManyToOne(type => Calendar, { nullable: true })\n @Field(type => Calendar, { nullable: true, description: 'The calendar the event belongs to, if any' })\n calendar?: Calendar\n\n @RelationId((event: Event) => event.calendar)\n @Field({ nullable: true, description: 'Id of the calendar the event belongs to' })\n calendarId?: string\n\n @ManyToOne(type => EventSeries, { nullable: true })\n @Field(type => EventSeries, { nullable: true, description: 'The series this event is an occurrence of; empty for a one-off event' })\n series?: EventSeries\n\n @RelationId((event: Event) => event.series)\n @Field({ nullable: true, description: 'Id of the series this event is an occurrence of' })\n seriesId?: string\n\n @Column()\n @Field({ description: 'The time the event was first given — the rule\\'s time for an occurrence. It never moves' })\n scheduledAt: Date\n\n @Column()\n @Field({ description: 'When the event starts' })\n startAt: Date\n\n @Column()\n @Field({ description: 'When the event ends' })\n endAt: Date\n\n @Column({ default: EventStatus.SCHEDULED })\n @Field(type => EventStatus, { description: 'Scheduled, postponed, cancelled or held' })\n status: EventStatus\n\n @Column({ type: 'text', nullable: true })\n @Field({ nullable: true, description: 'Why it was last postponed or cancelled' })\n statusReason?: string\n\n @Column()\n @Field({ description: 'Name of the event' })\n name: string\n\n @Column({ type: 'text', nullable: true })\n @Field({ nullable: true, description: 'What the event is about' })\n description?: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'Where the event takes place' })\n location?: string\n\n /** Where an event brought in from another calendar came from (`importEvents`) - none for one made here. */\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'The calendar it was brought in from, such as MSGRAPH; empty for an event made here' })\n source?: string\n\n /** The event's id in that calendar - bringing it in again changes this row, never adds a second. */\n @Column({ nullable: true })\n @Field({ nullable: true, description: \"The event's id in the calendar it was brought in from\" })\n externalId?: string\n\n /**\n * The mailboxes the last reading found it in - whose calendar holds it. Without them a meeting no one could find in\n * Teams or Outlook could not be traced to a person (Office, 2026-11-09).\n */\n @Column('simple-json', { nullable: true })\n @Field(type => [String], { nullable: true, description: 'The mailboxes the last reading found it in - whose calendar holds it' })\n sourceMailboxes?: string[]\n\n @ManyToOne(type => User, { nullable: true })\n @Field(type => User, { nullable: true, description: 'The person responsible for the event' })\n organizer?: User\n\n @RelationId((event: Event) => event.organizer)\n @Field({ nullable: true, description: 'Id of the person responsible for the event' })\n organizerId?: string\n\n @CreateDateColumn()\n @Field({ nullable: true, description: 'Creation timestamp' })\n createdAt?: Date\n\n @UpdateDateColumn()\n @Field({ nullable: true, description: 'Last update timestamp' })\n updatedAt?: Date\n\n @DeleteDateColumn()\n @Field({ nullable: true, description: 'Soft delete timestamp' })\n deletedAt?: Date\n\n @ManyToOne(type => User, { nullable: true })\n @Field(type => User, { nullable: true, description: 'Who created the event' })\n creator?: User\n\n @RelationId((event: Event) => event.creator)\n creatorId?: string\n\n @ManyToOne(type => User, { nullable: true })\n @Field(type => User, { nullable: true, description: 'Who last changed the event' })\n updater?: User\n\n @RelationId((event: Event) => event.updater)\n updaterId?: string\n}\n"]}
@@ -14,7 +14,7 @@ export { importEvents, mergedReadings, peopleOf } from './event/event-import';
14
14
  export * from './event-series/event-series-service';
15
15
  export * from './event-series/recurrence';
16
16
  export { attendeesOf } from './attendee/attendee-service';
17
- export declare const entities: (typeof import("./calendar/calendar").Calendar | typeof import("./event-series/event-series").EventSeries | typeof import("./event/event").Event | typeof import("./attendee/attendee").Attendee)[];
17
+ export declare const entities: (typeof import("./event/event").Event | typeof import("./calendar/calendar").Calendar | typeof import("./event-series/event-series").EventSeries | typeof import("./attendee/attendee").Attendee)[];
18
18
  export declare const subscribers: any[];
19
19
  export declare const schema: {
20
20
  resolverClasses: (typeof import("./calendar/calendar-query").CalendarQuery | typeof import("./calendar/calendar-mutation").CalendarMutation | typeof import("./calendar/working-days-resolver").WorkingDaysResolver | typeof import("./event/event-query").EventQuery | typeof import("./event/event-mutation").EventMutation | typeof import("./event-series/event-series-query").EventSeriesQuery | typeof import("./event-series/event-series-mutation").EventSeriesMutation | typeof import("./attendee/attendee-query").AttendeeQuery)[];