@memberjunction/ai-bridge-server 6.2.0-edge.5 → 6.2.0-edge.6
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/calendar-source.d.ts +47 -265
- package/dist/calendar-source.d.ts.map +1 -1
- package/dist/calendar-source.js +108 -309
- package/dist/calendar-source.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/package.json +7 -11
- package/dist/calendar-clients.d.ts +0 -153
- package/dist/calendar-clients.d.ts.map +0 -1
- package/dist/calendar-clients.js +0 -194
- package/dist/calendar-clients.js.map +0 -1
package/dist/calendar-source.js
CHANGED
|
@@ -1,353 +1,152 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The error
|
|
3
|
-
*
|
|
4
|
-
* detect "not yet bound" vs. a genuine transport failure.
|
|
2
|
+
* The error a {@link CommunicationCalendarSource} throws when it was built with no provider. Distinct
|
|
3
|
+
* type so a host can detect "not yet bound" vs. a genuine transport failure.
|
|
5
4
|
*/
|
|
6
5
|
export class CalendarSourceNotBoundError extends Error {
|
|
7
6
|
constructor(providerLabel) {
|
|
8
7
|
super(`Calendar source for '${providerLabel}' is not bound. ` +
|
|
9
|
-
`
|
|
8
|
+
`Construct it with the ${providerLabel} communication provider before use.`);
|
|
10
9
|
this.name = 'CalendarSourceNotBoundError';
|
|
11
10
|
}
|
|
12
11
|
}
|
|
13
12
|
/**
|
|
14
|
-
*
|
|
15
|
-
* `UTC`/`Z` time zone as UTC (the common case for Graph delta queries, which can be requested in UTC);
|
|
16
|
-
* for a non-UTC named zone it parses the wall-clock string and appends `Z` (best-effort — production
|
|
17
|
-
* SHOULD request UTC via the `Prefer: outlook.timezone="UTC"` header). Returns `null` on absent/invalid.
|
|
18
|
-
*/
|
|
19
|
-
export function ParseGraphDateTime(value) {
|
|
20
|
-
const raw = value?.dateTime?.trim();
|
|
21
|
-
if (!raw) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
const zone = (value?.timeZone ?? '').trim().toLowerCase();
|
|
25
|
-
const hasZoneSuffix = /[zZ]$|[+-]\d{2}:?\d{2}$/.test(raw);
|
|
26
|
-
const iso = hasZoneSuffix || zone === 'utc' || zone === '' ? ensureUtcSuffix(raw) : `${raw}Z`;
|
|
27
|
-
const parsed = new Date(iso);
|
|
28
|
-
return Number.isNaN(parsed.getTime()) ? null : parsed;
|
|
29
|
-
}
|
|
30
|
-
/** @deprecated Use {@link ParseGraphDateTime}. */
|
|
31
|
-
export function parseGraphDateTime(value) {
|
|
32
|
-
return ParseGraphDateTime(value);
|
|
33
|
-
}
|
|
34
|
-
/** Appends `Z` to a bare wall-clock string that lacks any zone suffix, leaving zoned strings untouched. */
|
|
35
|
-
function ensureUtcSuffix(raw) {
|
|
36
|
-
return /[zZ]$|[+-]\d{2}:?\d{2}$/.test(raw) ? raw : `${raw}Z`;
|
|
37
|
-
}
|
|
38
|
-
/** Maps a Graph attendee `status.response` to the normalized {@link CalendarInviteAttendee.ResponseStatus}. */
|
|
39
|
-
export function MapGraphResponseStatus(response) {
|
|
40
|
-
switch ((response ?? '').trim().toLowerCase()) {
|
|
41
|
-
case 'accepted':
|
|
42
|
-
case 'organizer':
|
|
43
|
-
return 'Accepted';
|
|
44
|
-
case 'declined':
|
|
45
|
-
return 'Declined';
|
|
46
|
-
case 'tentativelyaccepted':
|
|
47
|
-
return 'Tentative';
|
|
48
|
-
case 'notresponded':
|
|
49
|
-
case 'none':
|
|
50
|
-
return 'NeedsAction';
|
|
51
|
-
default:
|
|
52
|
-
return undefined;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/** @deprecated Use {@link MapGraphResponseStatus}. */
|
|
56
|
-
export function mapGraphResponseStatus(response) {
|
|
57
|
-
return MapGraphResponseStatus(response);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* **Pure** extraction of an online-meeting join URL from a Graph event. Prefers the structured
|
|
61
|
-
* `onlineMeeting.joinUrl`, then the legacy flat `onlineMeetingUrl`, then the first Teams `meetup-join`
|
|
62
|
-
* URL found in the event body (HTML or text). Returns `undefined` when no join URL is present.
|
|
63
|
-
*/
|
|
64
|
-
export function ExtractGraphJoinUrl(event) {
|
|
65
|
-
const structured = event.onlineMeeting?.joinUrl?.trim() || event.onlineMeetingUrl?.trim();
|
|
66
|
-
if (structured) {
|
|
67
|
-
return structured;
|
|
68
|
-
}
|
|
69
|
-
return extractJoinUrlFromText(event.body?.content);
|
|
70
|
-
}
|
|
71
|
-
/** @deprecated Use {@link ExtractGraphJoinUrl}. */
|
|
72
|
-
export function extractGraphJoinUrl(event) {
|
|
73
|
-
return ExtractGraphJoinUrl(event);
|
|
74
|
-
}
|
|
75
|
-
/** Best-effort first online-meeting join URL embedded in a free-text/HTML body. Never throws. */
|
|
76
|
-
function extractJoinUrlFromText(content) {
|
|
77
|
-
if (!content) {
|
|
78
|
-
return undefined;
|
|
79
|
-
}
|
|
80
|
-
const match = content.match(/https?:\/\/[^\s"'<>]*(?:teams\.microsoft\.com\/l\/meetup-join|meet\.google\.com|zoom\.us\/j)[^\s"'<>]*/i);
|
|
81
|
-
return match ? match[0] : undefined;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* **Pure** normalization of one Graph calendar event to a {@link NormalizedCalendarInvite}. Skips
|
|
85
|
-
* (returns `null`) an event with no id or no resolvable start time, so the caller can drop it cleanly.
|
|
86
|
-
*/
|
|
87
|
-
export function NormalizeGraphEvent(event) {
|
|
88
|
-
const start = ParseGraphDateTime(event.start);
|
|
89
|
-
if (!event.id || !start) {
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
const attendees = (event.attendees ?? [])
|
|
93
|
-
.map(toNormalizedAttendee)
|
|
94
|
-
.filter((a) => a !== null);
|
|
95
|
-
const organizerEmail = event.organizer?.emailAddress?.address?.trim();
|
|
96
|
-
const end = ParseGraphDateTime(event.end);
|
|
97
|
-
return {
|
|
98
|
-
ExternalEventID: event.id,
|
|
99
|
-
...(event.subject ? { Subject: event.subject } : {}),
|
|
100
|
-
...(ExtractGraphJoinUrl(event) ? { JoinUrl: ExtractGraphJoinUrl(event) } : {}),
|
|
101
|
-
StartTime: start,
|
|
102
|
-
...(end ? { EndTime: end } : {}),
|
|
103
|
-
Attendees: attendees,
|
|
104
|
-
...(organizerEmail
|
|
105
|
-
? {
|
|
106
|
-
Organizer: {
|
|
107
|
-
Email: organizerEmail,
|
|
108
|
-
...(event.organizer?.emailAddress?.name
|
|
109
|
-
? { DisplayName: event.organizer.emailAddress.name }
|
|
110
|
-
: {}),
|
|
111
|
-
},
|
|
112
|
-
}
|
|
113
|
-
: {}),
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
/** @deprecated Use {@link NormalizeGraphEvent}. */
|
|
117
|
-
export function normalizeGraphEvent(event) {
|
|
118
|
-
return NormalizeGraphEvent(event);
|
|
119
|
-
}
|
|
120
|
-
/** Maps one Graph attendee to a normalized attendee, or `null` when it carries no email address. */
|
|
121
|
-
function toNormalizedAttendee(attendee) {
|
|
122
|
-
const email = attendee.emailAddress?.address?.trim();
|
|
123
|
-
if (!email) {
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
const responseStatus = MapGraphResponseStatus(attendee.status?.response);
|
|
127
|
-
return {
|
|
128
|
-
Email: email,
|
|
129
|
-
...(attendee.emailAddress?.name ? { DisplayName: attendee.emailAddress.name } : {}),
|
|
130
|
-
...(responseStatus ? { ResponseStatus: responseStatus } : {}),
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* **Production binding** for Microsoft Graph calendars over an injected {@link IGraphCalendarLike}
|
|
135
|
-
* surface, so it builds + unit-tests with no Graph SDK install and no network.
|
|
13
|
+
* An {@link ICalendarSource} over a Communication provider's `SyncEvents`.
|
|
136
14
|
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* next poll. Credentials are resolved upstream (the host binds {@link IGraphCalendarLike} with a Graph
|
|
141
|
-
* client authenticated from the provider `Configuration` via MJ's credential system — never inline).
|
|
142
|
-
*
|
|
143
|
-
* When no surface is supplied it preserves the original not-bound behavior, throwing
|
|
144
|
-
* {@link CalendarSourceNotBoundError} so a misconfigured deployment fails loudly.
|
|
145
|
-
*
|
|
146
|
-
* @remarks **TODO (production):** bind `@microsoft/microsoft-graph-client` (an optionalDependency,
|
|
147
|
-
* loaded only when a Graph-backed identity is configured), request UTC via
|
|
148
|
-
* `Prefer: outlook.timezone="UTC"`, and inject it as {@link IGraphCalendarLike}.
|
|
15
|
+
* The first poll reads `[now, now + LookaheadDays]`; later polls pass the provider's token back as
|
|
16
|
+
* the cursor. A token the provider refuses (expired) is dropped and the window is read again, which
|
|
17
|
+
* the watcher's dedupe makes harmless. Removed and cancelled events are not invites and are skipped.
|
|
149
18
|
*/
|
|
150
|
-
export class
|
|
19
|
+
export class CommunicationCalendarSource {
|
|
151
20
|
/**
|
|
152
|
-
* @param
|
|
153
|
-
* (every poll throws {@link CalendarSourceNotBoundError}).
|
|
21
|
+
* @param provider The communication provider to read through. Omit to keep the not-bound
|
|
22
|
+
* behaviour (every poll throws {@link CalendarSourceNotBoundError}).
|
|
23
|
+
* @param credentials Passed to every call (for Graph, `{ accessToken }` with a bot token).
|
|
24
|
+
* @param options Window and clock settings.
|
|
25
|
+
* @param providerLabel Names the provider in errors.
|
|
154
26
|
*/
|
|
155
|
-
constructor(
|
|
156
|
-
this.
|
|
27
|
+
constructor(provider, credentials, options = {}, providerLabel = 'calendar') {
|
|
28
|
+
this.provider = provider;
|
|
29
|
+
this.credentials = credentials;
|
|
30
|
+
this.options = options;
|
|
31
|
+
this.providerLabel = providerLabel;
|
|
157
32
|
}
|
|
158
33
|
/** @inheritdoc */
|
|
159
34
|
async ListUpcomingInvites(identityValue, sinceCursor) {
|
|
160
|
-
if (!this.
|
|
161
|
-
throw new CalendarSourceNotBoundError(
|
|
35
|
+
if (!this.provider) {
|
|
36
|
+
throw new CalendarSourceNotBoundError(this.providerLabel);
|
|
37
|
+
}
|
|
38
|
+
let result = await this.sync(this.provider, identityValue, sinceCursor);
|
|
39
|
+
if (sinceCursor && result.ResyncRequired) {
|
|
40
|
+
result = await this.sync(this.provider, identityValue, undefined);
|
|
162
41
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
let nextCursor;
|
|
166
|
-
// Follow @odata.nextLink within the poll; stop once a @odata.deltaLink (the next poll's cursor)
|
|
167
|
-
// is returned. A defensive page cap guards a misbehaving surface from an unbounded loop.
|
|
168
|
-
for (let page = 0; page < MAX_GRAPH_PAGES; page++) {
|
|
169
|
-
const result = await this.graph.listEvents(identityValue, cursor);
|
|
170
|
-
for (const event of result.value ?? []) {
|
|
171
|
-
const invite = NormalizeGraphEvent(event);
|
|
172
|
-
if (invite) {
|
|
173
|
-
invites.push(invite);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
if (result.deltaLink) {
|
|
177
|
-
nextCursor = result.deltaLink;
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
if (!result.nextLink) {
|
|
181
|
-
break; // no further pages and no delta link — leave the stored cursor unchanged.
|
|
182
|
-
}
|
|
183
|
-
cursor = result.nextLink;
|
|
42
|
+
if (!result.Success) {
|
|
43
|
+
throw new Error(result.ErrorMessage ?? `${this.providerLabel} calendar sync failed for ${identityValue}`);
|
|
184
44
|
}
|
|
185
|
-
|
|
45
|
+
const invites = result.Changes.map((change) => (change.Kind === 'Upserted' && change.Event ? NormalizeCalendarEvent(change.Event) : null)).filter((invite) => invite !== null);
|
|
46
|
+
return { Invites: invites, ...(result.NextSyncToken ? { NextCursor: result.NextSyncToken } : {}) };
|
|
186
47
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* **Pure** parse of a Google {@link GoogleEventDateTime} to a UTC {@link Date}. Uses the RFC3339
|
|
192
|
-
* `dateTime` (which carries its own offset) when present, else an all-day `date` as UTC midnight.
|
|
193
|
-
* Returns `null` on absent/invalid.
|
|
194
|
-
*/
|
|
195
|
-
export function ParseGoogleDateTime(value) {
|
|
196
|
-
const timed = value?.dateTime?.trim();
|
|
197
|
-
if (timed) {
|
|
198
|
-
const parsed = new Date(timed);
|
|
199
|
-
return Number.isNaN(parsed.getTime()) ? null : parsed;
|
|
48
|
+
/** Whose calendar a poll reads. The identity's address, in the account's default calendar. */
|
|
49
|
+
BuildTarget(identityValue) {
|
|
50
|
+
return { Identifier: identityValue };
|
|
200
51
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const
|
|
204
|
-
return
|
|
52
|
+
sync(provider, identityValue, cursor) {
|
|
53
|
+
const now = (this.options.Now ?? Date.now)();
|
|
54
|
+
const lookaheadDays = this.options.LookaheadDays ?? DEFAULT_LOOKAHEAD_DAYS;
|
|
55
|
+
return provider.SyncEvents({
|
|
56
|
+
Target: this.BuildTarget(identityValue),
|
|
57
|
+
SyncToken: cursor,
|
|
58
|
+
WindowStart: new Date(now),
|
|
59
|
+
WindowEnd: new Date(now + lookaheadDays * MS_PER_DAY),
|
|
60
|
+
}, this.credentials);
|
|
205
61
|
}
|
|
206
|
-
return null;
|
|
207
|
-
}
|
|
208
|
-
/** @deprecated Use {@link ParseGoogleDateTime}. */
|
|
209
|
-
export function parseGoogleDateTime(value) {
|
|
210
|
-
return ParseGoogleDateTime(value);
|
|
211
62
|
}
|
|
212
|
-
/**
|
|
213
|
-
export
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return 'Accepted';
|
|
217
|
-
case 'declined':
|
|
218
|
-
return 'Declined';
|
|
219
|
-
case 'tentative':
|
|
220
|
-
return 'Tentative';
|
|
221
|
-
case 'needsaction':
|
|
222
|
-
return 'NeedsAction';
|
|
223
|
-
default:
|
|
224
|
-
return undefined;
|
|
63
|
+
/** Microsoft Graph calendars, read through `@memberjunction/communication-ms-graph`'s `MSGraphProvider`. */
|
|
64
|
+
export class GraphCalendarSource extends CommunicationCalendarSource {
|
|
65
|
+
constructor(provider, credentials, options = {}) {
|
|
66
|
+
super(provider, credentials, options, 'Microsoft Graph');
|
|
225
67
|
}
|
|
226
68
|
}
|
|
227
|
-
/** @deprecated Use {@link MapGoogleResponseStatus}. */
|
|
228
|
-
export function mapGoogleResponseStatus(response) {
|
|
229
|
-
return MapGoogleResponseStatus(response);
|
|
230
|
-
}
|
|
231
69
|
/**
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
70
|
+
* Google calendars, read through `@memberjunction/communication-gmail`'s `GmailProvider`. Reads the
|
|
71
|
+
* calendar whose ID is the identity's address, as the bridge always has: that is the account's
|
|
72
|
+
* primary calendar when the credentials are the agent's own, and a shared one otherwise.
|
|
235
73
|
*/
|
|
236
|
-
export
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
/** @
|
|
241
|
-
|
|
242
|
-
|
|
74
|
+
export class GoogleCalendarSource extends CommunicationCalendarSource {
|
|
75
|
+
constructor(provider, credentials, options = {}) {
|
|
76
|
+
super(provider, credentials, options, 'Google Calendar');
|
|
77
|
+
}
|
|
78
|
+
/** @inheritdoc */
|
|
79
|
+
BuildTarget(identityValue) {
|
|
80
|
+
return { Identifier: identityValue, CalendarID: identityValue };
|
|
81
|
+
}
|
|
243
82
|
}
|
|
244
83
|
/**
|
|
245
|
-
* **Pure** normalization of
|
|
246
|
-
*
|
|
84
|
+
* **Pure** normalization of a Communication calendar event to a {@link NormalizedCalendarInvite}.
|
|
85
|
+
* Returns `null` for a cancelled event or one with no id or no start. The join URL is the provider's
|
|
86
|
+
* online-meeting URL, else the first Teams/Meet/Zoom link in the body.
|
|
247
87
|
*/
|
|
248
|
-
export function
|
|
249
|
-
if (
|
|
250
|
-
return null;
|
|
251
|
-
}
|
|
252
|
-
const start = ParseGoogleDateTime(event.start);
|
|
253
|
-
if (!event.id || !start) {
|
|
88
|
+
export function NormalizeCalendarEvent(event) {
|
|
89
|
+
if (event.IsCancelled || !event.ExternalEventID || !event.Start) {
|
|
254
90
|
return null;
|
|
255
91
|
}
|
|
256
|
-
const
|
|
257
|
-
.map(toNormalizedGoogleAttendee)
|
|
258
|
-
.filter((a) => a !== null);
|
|
259
|
-
const organizerEmail = event.organizer?.email?.trim();
|
|
260
|
-
const joinUrl = ExtractGoogleJoinUrl(event);
|
|
261
|
-
const end = ParseGoogleDateTime(event.end);
|
|
92
|
+
const joinUrl = event.OnlineMeetingUrl?.trim() || extractJoinUrlFromText(event.Body);
|
|
262
93
|
return {
|
|
263
|
-
ExternalEventID: event.
|
|
264
|
-
...(event.
|
|
94
|
+
ExternalEventID: event.ExternalEventID,
|
|
95
|
+
...(event.Subject ? { Subject: event.Subject } : {}),
|
|
265
96
|
...(joinUrl ? { JoinUrl: joinUrl } : {}),
|
|
266
|
-
StartTime:
|
|
267
|
-
...(
|
|
268
|
-
Attendees:
|
|
269
|
-
|
|
270
|
-
? {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
97
|
+
StartTime: event.Start,
|
|
98
|
+
...(event.End ? { EndTime: event.End } : {}),
|
|
99
|
+
Attendees: event.Attendees.map((a) => ({
|
|
100
|
+
Email: a.Email,
|
|
101
|
+
...(a.Name ? { DisplayName: a.Name } : {}),
|
|
102
|
+
ResponseStatus: a.Response === 'None' ? 'NeedsAction' : a.Response,
|
|
103
|
+
})),
|
|
104
|
+
...(event.Organizer
|
|
105
|
+
? { Organizer: { Email: event.Organizer.Email, ...(event.Organizer.Name ? { DisplayName: event.Organizer.Name } : {}) } }
|
|
276
106
|
: {}),
|
|
277
107
|
};
|
|
278
108
|
}
|
|
279
|
-
/**
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
/** Maps one Google attendee to a normalized attendee, or `null` when it carries no email address. */
|
|
284
|
-
function toNormalizedGoogleAttendee(attendee) {
|
|
285
|
-
const email = attendee.email?.trim();
|
|
286
|
-
if (!email) {
|
|
287
|
-
return null;
|
|
109
|
+
/** Best-effort first online-meeting join URL embedded in a free-text/HTML body. Never throws. */
|
|
110
|
+
function extractJoinUrlFromText(content) {
|
|
111
|
+
if (!content) {
|
|
112
|
+
return undefined;
|
|
288
113
|
}
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
114
|
+
for (const rawToken of content.split(/[\s"'<>]+/)) {
|
|
115
|
+
const token = trimCandidateUrl(rawToken);
|
|
116
|
+
if (token &&
|
|
117
|
+
/^https?:\/\/(?:teams\.microsoft\.com\/l\/meetup-join|meet\.google\.com|zoom\.us\/j|[a-z0-9.-]+\.(?:teams\.microsoft\.com\/l\/meetup-join|zoom\.us\/j))/i.test(token)) {
|
|
118
|
+
return token;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return undefined;
|
|
295
122
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
* `nextPageToken` page-to-page, normalizing every event via {@link normalizeGoogleEvent}, until the
|
|
302
|
-
* surface returns a `nextSyncToken` — which becomes the {@link CalendarPollResult.NextCursor}.
|
|
303
|
-
* Credentials are resolved upstream (the host binds {@link IGoogleCalendarLike} with a Calendar client
|
|
304
|
-
* authenticated from the provider `Configuration` via MJ's credential system — never inline).
|
|
305
|
-
*
|
|
306
|
-
* When no surface is supplied it preserves the original not-bound behavior, throwing
|
|
307
|
-
* {@link CalendarSourceNotBoundError}.
|
|
308
|
-
*
|
|
309
|
-
* @remarks **TODO (production):** bind `googleapis` (an optionalDependency, loaded only when a
|
|
310
|
-
* Google-backed identity is configured) and inject it as {@link IGoogleCalendarLike}.
|
|
311
|
-
*/
|
|
312
|
-
export class GoogleCalendarSource {
|
|
313
|
-
/**
|
|
314
|
-
* @param calendar The injected Google calendar surface. Omit to preserve the not-bound seam
|
|
315
|
-
* behavior (every poll throws {@link CalendarSourceNotBoundError}).
|
|
316
|
-
*/
|
|
317
|
-
constructor(calendar) {
|
|
318
|
-
this.calendar = calendar;
|
|
123
|
+
const TRAILING_URL_PUNCTUATION = ')]}.,;:!?';
|
|
124
|
+
function trimCandidateUrl(rawToken) {
|
|
125
|
+
const httpIdx = rawToken.search(/https?:\/\//i);
|
|
126
|
+
if (httpIdx < 0) {
|
|
127
|
+
return undefined;
|
|
319
128
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
129
|
+
let candidate = rawToken.slice(httpIdx);
|
|
130
|
+
let changed = true;
|
|
131
|
+
while (changed && candidate.length > 0) {
|
|
132
|
+
changed = false;
|
|
133
|
+
const lower = candidate.toLowerCase();
|
|
134
|
+
if (lower.endsWith('"')) {
|
|
135
|
+
candidate = candidate.slice(0, -6);
|
|
136
|
+
changed = true;
|
|
137
|
+
}
|
|
138
|
+
else if (lower.endsWith('"')) {
|
|
139
|
+
candidate = candidate.slice(0, -5);
|
|
140
|
+
changed = true;
|
|
324
141
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
for (let page = 0; page < MAX_GOOGLE_PAGES; page++) {
|
|
329
|
-
// syncToken and pageToken are mutually exclusive: use the sync token only on the first
|
|
330
|
-
// request of a poll, then switch to page tokens for in-poll continuation.
|
|
331
|
-
const args = pageToken !== undefined
|
|
332
|
-
? { calendarId: identityValue, pageToken }
|
|
333
|
-
: { calendarId: identityValue, ...(sinceCursor ? { syncToken: sinceCursor } : {}) };
|
|
334
|
-
const result = await this.calendar.listEvents(args);
|
|
335
|
-
for (const event of result.items ?? []) {
|
|
336
|
-
const invite = NormalizeGoogleEvent(event);
|
|
337
|
-
if (invite) {
|
|
338
|
-
invites.push(invite);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
if (result.nextPageToken) {
|
|
342
|
-
pageToken = result.nextPageToken;
|
|
343
|
-
continue;
|
|
344
|
-
}
|
|
345
|
-
nextCursor = result.nextSyncToken; // final page carries the sync token for the next poll.
|
|
346
|
-
break;
|
|
142
|
+
else if (TRAILING_URL_PUNCTUATION.includes(candidate[candidate.length - 1])) {
|
|
143
|
+
candidate = candidate.slice(0, -1);
|
|
144
|
+
changed = true;
|
|
347
145
|
}
|
|
348
|
-
return { Invites: invites, ...(nextCursor ? { NextCursor: nextCursor } : {}) };
|
|
349
146
|
}
|
|
147
|
+
return candidate;
|
|
350
148
|
}
|
|
351
|
-
/**
|
|
352
|
-
const
|
|
149
|
+
/** First-poll window default (days). */
|
|
150
|
+
const DEFAULT_LOOKAHEAD_DAYS = 30;
|
|
151
|
+
const MS_PER_DAY = 24 * 60 * 60 * 1000;
|
|
353
152
|
//# sourceMappingURL=calendar-source.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calendar-source.js","sourceRoot":"","sources":["../src/calendar-source.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"calendar-source.js","sourceRoot":"","sources":["../src/calendar-source.ts"],"names":[],"mappings":"AAkHA;;;GAGG;AACH,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IAClD,YAAY,aAAqB;QAC7B,KAAK,CACD,wBAAwB,aAAa,kBAAkB;YACnD,yBAAyB,aAAa,qCAAqC,CAClF,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC9C,CAAC;CACJ;AAqBD;;;;;;GAMG;AACH,MAAM,OAAO,2BAA2B;IAMpC;;;;;;OAMG;IACH,YAAY,QAA+B,EAAE,WAAqC,EAAE,UAA8C,EAAE,EAAE,gBAAwB,UAAU;QACpK,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACvC,CAAC;IAED,kBAAkB;IACX,KAAK,CAAC,mBAAmB,CAAC,aAAqB,EAAE,WAA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nB,CAAC;aAAM,IAAI,wBAAwB,CAAC,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5E,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACnC,OAAO,GAAG,IAAI,CAAC;QACnB,CAAC;IACL,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC;AAED,wCAAwC;AACxC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAClC,MAAM,UAAU,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ export * from './loopback-bridge.js';
|
|
|
5
5
|
export * from './openai-sip-bridge.js';
|
|
6
6
|
export * from './join-url-resolver.js';
|
|
7
7
|
export * from './calendar-source.js';
|
|
8
|
-
export * from './calendar-clients.js';
|
|
9
8
|
export * from './calendar-watcher.js';
|
|
10
9
|
export * from './scheduled-bridge-runner.js';
|
|
11
10
|
export * from './identity-provisioner.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,6 @@ export * from './loopback-bridge.js';
|
|
|
5
5
|
export * from './openai-sip-bridge.js';
|
|
6
6
|
export * from './join-url-resolver.js';
|
|
7
7
|
export * from './calendar-source.js';
|
|
8
|
-
export * from './calendar-clients.js';
|
|
9
8
|
export * from './calendar-watcher.js';
|
|
10
9
|
export * from './scheduled-bridge-runner.js';
|
|
11
10
|
export * from './identity-provisioner.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ai-bridge-server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.2.0-edge.
|
|
4
|
+
"version": "6.2.0-edge.6",
|
|
5
5
|
"description": "MemberJunction: Server-tier coordination + execution for Realtime Bridges — completes the unified media-transport seam (the bridge ↔ IRealtimeSession pipe), bot-session lifecycle, host affinity + janitor, participant tracking, and turn-taking integration. Mirrors the AIEngineBase/AIEngine pair.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -11,18 +11,14 @@
|
|
|
11
11
|
"author": "MemberJunction.com",
|
|
12
12
|
"license": "BUSL-1.1",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@memberjunction/core": "6.2.0-edge.
|
|
15
|
-
"@memberjunction/global": "6.2.0-edge.
|
|
16
|
-
"@memberjunction/core-entities": "6.2.0-edge.
|
|
17
|
-
"@memberjunction/ai": "6.2.0-edge.
|
|
18
|
-
"@memberjunction/ai-bridge-base": "6.2.0-edge.
|
|
14
|
+
"@memberjunction/core": "6.2.0-edge.6",
|
|
15
|
+
"@memberjunction/global": "6.2.0-edge.6",
|
|
16
|
+
"@memberjunction/core-entities": "6.2.0-edge.6",
|
|
17
|
+
"@memberjunction/ai": "6.2.0-edge.6",
|
|
18
|
+
"@memberjunction/ai-bridge-base": "6.2.0-edge.6",
|
|
19
|
+
"@memberjunction/communication-types": "6.2.0-edge.6",
|
|
19
20
|
"rxjs": "^7.8.2"
|
|
20
21
|
},
|
|
21
|
-
"//optionalDependencies": "@microsoft/microsoft-graph-client and googleapis are OPTIONAL PEER SDKs (CLAUDE rule 8, category 2): this package never statically imports either. They back the calendar + identity-provisioner seams only. GraphCalendarSource/GraphAdmin provisioning wire IGraphCalendarLike/IGraphAdminLike over @microsoft/microsoft-graph-client (calendarView delta + POST /users); GoogleCalendarSource/Google Workspace provisioning wire IGoogleCalendarLike/IGoogleWorkspaceAdminLike over googleapis (calendar.events.list syncToken + admin.users.insert). The telephony-carrier number-order path is injected via ITelephonyCarrierLike (the carrier SDK is declared by each telephony provider package, not here). All surfaces are injected behind structural interfaces so the package builds + unit-tests with no install and no network, and are loaded only when a Graph/Google-backed identity is configured at deployment.",
|
|
22
|
-
"optionalDependencies": {
|
|
23
|
-
"@microsoft/microsoft-graph-client": "^3.0.7",
|
|
24
|
-
"googleapis": "^144.0.0"
|
|
25
|
-
},
|
|
26
22
|
"devDependencies": {
|
|
27
23
|
"@types/node": "24.10.11",
|
|
28
24
|
"ts-node-dev": "^2.0.0",
|