@memberjunction/ai-bridge-server 5.44.0 → 5.45.0
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-clients.d.ts +149 -0
- package/dist/calendar-clients.d.ts.map +1 -0
- package/dist/calendar-clients.js +190 -0
- package/dist/calendar-clients.js.map +1 -0
- package/dist/calendar-source.d.ts +241 -26
- package/dist/calendar-source.d.ts.map +1 -1
- package/dist/calendar-source.js +290 -32
- package/dist/calendar-source.js.map +1 -1
- package/dist/identity-provisioner.d.ts +141 -13
- package/dist/identity-provisioner.d.ts.map +1 -1
- package/dist/identity-provisioner.js +137 -16
- package/dist/identity-provisioner.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +11 -6
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Concrete production bindings for the calendar seams declared in
|
|
3
|
+
* {@link ./calendar-source}. Each wraps an OPTIONAL PEER SDK behind the existing injected
|
|
4
|
+
* surface (`IGraphCalendarLike` / `IGoogleCalendarLike`) so the package still builds and
|
|
5
|
+
* unit-tests with no SDK installed and no network (CLAUDE rule 8, category 2 — optional peer
|
|
6
|
+
* SDK loaded only when a calendar-backed identity is configured at deployment).
|
|
7
|
+
*
|
|
8
|
+
* Mirrors the Teams `RealGraphCallsClient` pattern: a lazy, memoized module loader + a structural
|
|
9
|
+
* surface so the vendor SDK's real types never leak. Auth tokens are **pre-resolved upstream** (the
|
|
10
|
+
* host acquires an app/delegated token from the provider `Configuration` via MJ's credential system
|
|
11
|
+
* and injects it here) — token ACQUISITION is deliberately not this client's job, keeping it pure
|
|
12
|
+
* and testable; the deployment-specific client-credentials flow lives in the host wiring.
|
|
13
|
+
*
|
|
14
|
+
* @module @memberjunction/ai-bridge-server
|
|
15
|
+
*/
|
|
16
|
+
import type { IGraphCalendarLike, GraphEventPage, IGoogleCalendarLike, GoogleEventPage, GoogleListEventsArgs } from './calendar-source.js';
|
|
17
|
+
/** One fluent Graph request — the subset of verbs/headers the calendar reader issues. */
|
|
18
|
+
export interface GraphCalendarRequestLike {
|
|
19
|
+
/** Adds a request header (used for `Prefer: outlook.timezone="UTC"`); returns `this` for chaining. */
|
|
20
|
+
header(name: string, value: string): GraphCalendarRequestLike;
|
|
21
|
+
/** Issues `GET {path}`; resolves the parsed JSON response. */
|
|
22
|
+
get(): Promise<unknown>;
|
|
23
|
+
}
|
|
24
|
+
/** The constructed Graph client surface — just the `api(path)` request-builder entry point. */
|
|
25
|
+
export interface GraphCalendarClientLike {
|
|
26
|
+
/** Begins a fluent request against a Graph resource path (e.g. `/users/{id}/calendarView/delta`). */
|
|
27
|
+
api(path: string): GraphCalendarRequestLike;
|
|
28
|
+
}
|
|
29
|
+
/** The `@microsoft/microsoft-graph-client` module surface we use (`Client.init({ authProvider })`). */
|
|
30
|
+
export interface GraphCalendarModuleLike {
|
|
31
|
+
/** The `Client` class with its `init` static factory. */
|
|
32
|
+
Client: {
|
|
33
|
+
init(options: GraphCalendarInitOptions): GraphCalendarClientLike;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** The `Client.init` options subset — just the bearer-token `authProvider` callback. */
|
|
37
|
+
export interface GraphCalendarInitOptions {
|
|
38
|
+
/** The Graph auth-provider callback; the SDK calls it per request and expects `done(error, token)`. */
|
|
39
|
+
authProvider(done: (error: Error | null, accessToken: string | null) => void): void;
|
|
40
|
+
}
|
|
41
|
+
/** Loads the `@microsoft/microsoft-graph-client` module. Overridable in tests; defaults to a lazy import. */
|
|
42
|
+
export type GraphCalendarModuleLoader = () => Promise<GraphCalendarModuleLike>;
|
|
43
|
+
/** Credentials the {@link GraphCalendarClient} authenticates with — a pre-resolved bearer token. */
|
|
44
|
+
export interface GraphCalendarCredentials {
|
|
45
|
+
/** A pre-resolved OAuth bearer / application token with `Calendars.Read` scope (resolved upstream). */
|
|
46
|
+
AccessToken: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Options for {@link GraphCalendarClient}. The first-poll window bounds the initial
|
|
50
|
+
* `calendarView` delta; subsequent polls follow the opaque `@odata.deltaLink` cursor.
|
|
51
|
+
*/
|
|
52
|
+
export interface GraphCalendarClientOptions {
|
|
53
|
+
/** Pre-resolved Graph credentials. */
|
|
54
|
+
Credentials: GraphCalendarCredentials;
|
|
55
|
+
/** How far forward the FIRST poll's calendarView window extends (days). Defaults to 30. */
|
|
56
|
+
LookaheadDays?: number;
|
|
57
|
+
/** Test seam: override the module loader. Defaults to the lazy dynamic import. */
|
|
58
|
+
ModuleLoader?: GraphCalendarModuleLoader;
|
|
59
|
+
/** Test seam: a fixed "now" for the first-poll window (so window math is deterministic). */
|
|
60
|
+
Now?: Date;
|
|
61
|
+
}
|
|
62
|
+
/** Lazily loads + memoizes `@microsoft/microsoft-graph-client`; throws a clear install hint on failure. */
|
|
63
|
+
export declare const defaultGraphCalendarModuleLoader: GraphCalendarModuleLoader;
|
|
64
|
+
/**
|
|
65
|
+
* A real {@link IGraphCalendarLike} over Microsoft Graph (`GET /users/{id}/calendarView/delta`).
|
|
66
|
+
* The first poll requests a forward window (`startDateTime`..`endDateTime`) in UTC; later polls pass
|
|
67
|
+
* the opaque cursor (`@odata.nextLink` within a poll, `@odata.deltaLink` between polls) straight back
|
|
68
|
+
* to Graph. The constructed client is built once on first use and reused.
|
|
69
|
+
*/
|
|
70
|
+
export declare class GraphCalendarClient implements IGraphCalendarLike {
|
|
71
|
+
private readonly options;
|
|
72
|
+
private readonly loadModule;
|
|
73
|
+
private clientPromise?;
|
|
74
|
+
constructor(options: GraphCalendarClientOptions);
|
|
75
|
+
/** @inheritdoc */
|
|
76
|
+
listEvents(userId: string, cursor?: string): Promise<GraphEventPage>;
|
|
77
|
+
/** Builds the first-poll `calendarView/delta` path with a UTC `[now, now+lookahead]` window. */
|
|
78
|
+
private firstPollPath;
|
|
79
|
+
/** Normalizes the raw Graph delta response to the seam's {@link GraphEventPage} shape. */
|
|
80
|
+
private toEventPage;
|
|
81
|
+
/** Builds (once) + memoizes the authenticated Graph client. */
|
|
82
|
+
private client;
|
|
83
|
+
}
|
|
84
|
+
/** The `calendar.events.list` surface we call — resolves a page of events. */
|
|
85
|
+
export interface GoogleEventsApiLike {
|
|
86
|
+
/** Lists one page of events; resolves `{ data: { items, nextPageToken, nextSyncToken } }`. */
|
|
87
|
+
list(params: Record<string, unknown>): Promise<{
|
|
88
|
+
data?: unknown;
|
|
89
|
+
}>;
|
|
90
|
+
}
|
|
91
|
+
/** The constructed Google Calendar client surface — `events.list`. */
|
|
92
|
+
export interface GoogleCalendarClientLike {
|
|
93
|
+
/** The `events` resource collection. */
|
|
94
|
+
events: GoogleEventsApiLike;
|
|
95
|
+
}
|
|
96
|
+
/** The `googleapis` module surface we use (`google.calendar({ version, auth })`). */
|
|
97
|
+
export interface GoogleApisModuleLike {
|
|
98
|
+
/** The `google` namespace with the `calendar` client factory. */
|
|
99
|
+
google: {
|
|
100
|
+
calendar(options: {
|
|
101
|
+
version: string;
|
|
102
|
+
auth: unknown;
|
|
103
|
+
}): GoogleCalendarClientLike;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** Loads the `googleapis` module. Overridable in tests; defaults to a lazy import. */
|
|
107
|
+
export type GoogleApisModuleLoader = () => Promise<GoogleApisModuleLike>;
|
|
108
|
+
/**
|
|
109
|
+
* Options for {@link GoogleCalendarClient}. `Auth` is a pre-built `googleapis` auth client (an
|
|
110
|
+
* OAuth2 client or a JWT/service-account client) resolved upstream from the provider `Configuration`
|
|
111
|
+
* via MJ's credential system — token acquisition is not this client's job.
|
|
112
|
+
*/
|
|
113
|
+
export interface GoogleCalendarClientOptions {
|
|
114
|
+
/** A pre-built googleapis auth client (OAuth2 / JWT / service-account), resolved upstream. */
|
|
115
|
+
Auth: unknown;
|
|
116
|
+
/** How far forward the FIRST poll's `timeMin`..`timeMax` window extends (days). Defaults to 30. */
|
|
117
|
+
LookaheadDays?: number;
|
|
118
|
+
/** Test seam: override the module loader. Defaults to the lazy dynamic import. */
|
|
119
|
+
ModuleLoader?: GoogleApisModuleLoader;
|
|
120
|
+
/** Test seam: a fixed "now" for the first-poll window. */
|
|
121
|
+
Now?: Date;
|
|
122
|
+
}
|
|
123
|
+
/** Lazily loads + memoizes `googleapis`; throws a clear install hint on failure. */
|
|
124
|
+
export declare const defaultGoogleApisModuleLoader: GoogleApisModuleLoader;
|
|
125
|
+
/**
|
|
126
|
+
* A real {@link IGoogleCalendarLike} over `calendar.events.list`. The first poll requests a forward
|
|
127
|
+
* window (`timeMin`..`timeMax`, `singleEvents`, ordered) so Google returns an initial `nextSyncToken`;
|
|
128
|
+
* later polls pass the `syncToken` (between polls) or `pageToken` (within a poll) verbatim. The
|
|
129
|
+
* constructed client is built once on first use and reused.
|
|
130
|
+
*/
|
|
131
|
+
export declare class GoogleCalendarClient implements IGoogleCalendarLike {
|
|
132
|
+
private readonly options;
|
|
133
|
+
private readonly loadModule;
|
|
134
|
+
private clientPromise?;
|
|
135
|
+
constructor(options: GoogleCalendarClientOptions);
|
|
136
|
+
/** @inheritdoc */
|
|
137
|
+
listEvents(args: GoogleListEventsArgs): Promise<GoogleEventPage>;
|
|
138
|
+
/**
|
|
139
|
+
* Builds `events.list` params. A `syncToken`/`pageToken` poll passes only the token (Google
|
|
140
|
+
* rejects window params alongside a sync token); a fresh poll sends the forward window + the
|
|
141
|
+
* `singleEvents`/`orderBy` flags that make Google issue an initial `nextSyncToken`.
|
|
142
|
+
*/
|
|
143
|
+
private buildListParams;
|
|
144
|
+
/** Normalizes the raw `events.list` data to the seam's {@link GoogleEventPage} shape. */
|
|
145
|
+
private toEventPage;
|
|
146
|
+
/** Builds (once) + memoizes the Google Calendar client. */
|
|
147
|
+
private client;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=calendar-clients.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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I,EAAE,OAAO,CAAC;IACd,mGAAmG;IACnG,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kFAAkF;IAClF,YAAY,CAAC,EAAE,sBAAsB,CAAC;IACtC,0DAA0D;IAC1D,GAAG,CAAC,EAAE,IAAI,CAAC;CACd;AAED,oFAAoF;AACpF,eAAO,MAAM,6BAA6B,EAAE,sBAe3C,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,oBAAqB,YAAW,mBAAmB;IAC5D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8B;IACtD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyB;IACpD,OAAO,CAAC,aAAa,CAAC,CAAoC;gBAE9C,OAAO,EAAE,2BAA2B;IAKhD,kBAAkB;IACL,UAAU,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,eAAe,CAAC;IAM7E;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAmBvB,yFAAyF;IACzF,OAAO,CAAC,WAAW;IAYnB,2DAA2D;IAC3D,OAAO,CAAC,MAAM;CAQjB"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Concrete production bindings for the calendar seams declared in
|
|
3
|
+
* {@link ./calendar-source}. Each wraps an OPTIONAL PEER SDK behind the existing injected
|
|
4
|
+
* surface (`IGraphCalendarLike` / `IGoogleCalendarLike`) so the package still builds and
|
|
5
|
+
* unit-tests with no SDK installed and no network (CLAUDE rule 8, category 2 — optional peer
|
|
6
|
+
* SDK loaded only when a calendar-backed identity is configured at deployment).
|
|
7
|
+
*
|
|
8
|
+
* Mirrors the Teams `RealGraphCallsClient` pattern: a lazy, memoized module loader + a structural
|
|
9
|
+
* surface so the vendor SDK's real types never leak. Auth tokens are **pre-resolved upstream** (the
|
|
10
|
+
* host acquires an app/delegated token from the provider `Configuration` via MJ's credential system
|
|
11
|
+
* and injects it here) — token ACQUISITION is deliberately not this client's job, keeping it pure
|
|
12
|
+
* and testable; the deployment-specific client-credentials flow lives in the host wiring.
|
|
13
|
+
*
|
|
14
|
+
* @module @memberjunction/ai-bridge-server
|
|
15
|
+
*/
|
|
16
|
+
/** Lazily loads + memoizes `@microsoft/microsoft-graph-client`; throws a clear install hint on failure. */
|
|
17
|
+
export const defaultGraphCalendarModuleLoader = async () => {
|
|
18
|
+
try {
|
|
19
|
+
const mod = await import('@microsoft/microsoft-graph-client');
|
|
20
|
+
const resolved = unwrap(mod);
|
|
21
|
+
if (!isGraphModule(resolved)) {
|
|
22
|
+
throw new Error('the @microsoft/microsoft-graph-client module did not export a Client.init factory');
|
|
23
|
+
}
|
|
24
|
+
return resolved;
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
28
|
+
throw new Error("GraphCalendarClient could not load '@microsoft/microsoft-graph-client'. Install it in the deployment " +
|
|
29
|
+
`that polls Graph calendars (it is an optional peer dependency). Underlying error: ${message}`);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* A real {@link IGraphCalendarLike} over Microsoft Graph (`GET /users/{id}/calendarView/delta`).
|
|
34
|
+
* The first poll requests a forward window (`startDateTime`..`endDateTime`) in UTC; later polls pass
|
|
35
|
+
* the opaque cursor (`@odata.nextLink` within a poll, `@odata.deltaLink` between polls) straight back
|
|
36
|
+
* to Graph. The constructed client is built once on first use and reused.
|
|
37
|
+
*/
|
|
38
|
+
export class GraphCalendarClient {
|
|
39
|
+
constructor(options) {
|
|
40
|
+
this.options = options;
|
|
41
|
+
this.loadModule = options.ModuleLoader ?? defaultGraphCalendarModuleLoader;
|
|
42
|
+
}
|
|
43
|
+
/** @inheritdoc */
|
|
44
|
+
async listEvents(userId, cursor) {
|
|
45
|
+
const client = await this.client();
|
|
46
|
+
// A cursor is a full Graph nextLink/deltaLink URL — request it verbatim. The first poll builds
|
|
47
|
+
// a fresh calendarView/delta path with a UTC forward window and the UTC timezone preference.
|
|
48
|
+
const path = cursor ?? this.firstPollPath(userId);
|
|
49
|
+
const raw = await client.api(path).header('Prefer', 'outlook.timezone="UTC"').get();
|
|
50
|
+
return this.toEventPage(raw);
|
|
51
|
+
}
|
|
52
|
+
/** Builds the first-poll `calendarView/delta` path with a UTC `[now, now+lookahead]` window. */
|
|
53
|
+
firstPollPath(userId) {
|
|
54
|
+
const now = this.options.Now ?? new Date();
|
|
55
|
+
const lookaheadDays = this.options.LookaheadDays ?? DEFAULT_LOOKAHEAD_DAYS;
|
|
56
|
+
const end = new Date(now.getTime() + lookaheadDays * MS_PER_DAY);
|
|
57
|
+
const start = encodeURIComponent(now.toISOString());
|
|
58
|
+
const finish = encodeURIComponent(end.toISOString());
|
|
59
|
+
const id = encodeURIComponent(userId);
|
|
60
|
+
return `/users/${id}/calendarView/delta?startDateTime=${start}&endDateTime=${finish}`;
|
|
61
|
+
}
|
|
62
|
+
/** Normalizes the raw Graph delta response to the seam's {@link GraphEventPage} shape. */
|
|
63
|
+
toEventPage(raw) {
|
|
64
|
+
const obj = (raw ?? {});
|
|
65
|
+
const value = Array.isArray(obj.value) ? obj.value : [];
|
|
66
|
+
const nextLink = readString(obj['@odata.nextLink']);
|
|
67
|
+
const deltaLink = readString(obj['@odata.deltaLink']);
|
|
68
|
+
return {
|
|
69
|
+
value,
|
|
70
|
+
...(nextLink ? { nextLink } : {}),
|
|
71
|
+
...(deltaLink ? { deltaLink } : {}),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** Builds (once) + memoizes the authenticated Graph client. */
|
|
75
|
+
client() {
|
|
76
|
+
if (!this.clientPromise) {
|
|
77
|
+
this.clientPromise = this.loadModule().then((mod) => mod.Client.init({
|
|
78
|
+
authProvider: (done) => done(null, this.options.Credentials.AccessToken),
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
return this.clientPromise;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Lazily loads + memoizes `googleapis`; throws a clear install hint on failure. */
|
|
85
|
+
export const defaultGoogleApisModuleLoader = async () => {
|
|
86
|
+
try {
|
|
87
|
+
const mod = await import('googleapis');
|
|
88
|
+
const resolved = unwrap(mod);
|
|
89
|
+
if (!isGoogleModule(resolved)) {
|
|
90
|
+
throw new Error('the googleapis module did not export a google.calendar factory');
|
|
91
|
+
}
|
|
92
|
+
return resolved;
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
96
|
+
throw new Error("GoogleCalendarClient could not load 'googleapis'. Install it in the deployment that polls Google " +
|
|
97
|
+
`calendars (it is an optional peer dependency). Underlying error: ${message}`);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* A real {@link IGoogleCalendarLike} over `calendar.events.list`. The first poll requests a forward
|
|
102
|
+
* window (`timeMin`..`timeMax`, `singleEvents`, ordered) so Google returns an initial `nextSyncToken`;
|
|
103
|
+
* later polls pass the `syncToken` (between polls) or `pageToken` (within a poll) verbatim. The
|
|
104
|
+
* constructed client is built once on first use and reused.
|
|
105
|
+
*/
|
|
106
|
+
export class GoogleCalendarClient {
|
|
107
|
+
constructor(options) {
|
|
108
|
+
this.options = options;
|
|
109
|
+
this.loadModule = options.ModuleLoader ?? defaultGoogleApisModuleLoader;
|
|
110
|
+
}
|
|
111
|
+
/** @inheritdoc */
|
|
112
|
+
async listEvents(args) {
|
|
113
|
+
const client = await this.client();
|
|
114
|
+
const response = await client.events.list(this.buildListParams(args));
|
|
115
|
+
return this.toEventPage(response?.data);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Builds `events.list` params. A `syncToken`/`pageToken` poll passes only the token (Google
|
|
119
|
+
* rejects window params alongside a sync token); a fresh poll sends the forward window + the
|
|
120
|
+
* `singleEvents`/`orderBy` flags that make Google issue an initial `nextSyncToken`.
|
|
121
|
+
*/
|
|
122
|
+
buildListParams(args) {
|
|
123
|
+
const base = { calendarId: args.calendarId };
|
|
124
|
+
if (args.pageToken) {
|
|
125
|
+
return { ...base, pageToken: args.pageToken };
|
|
126
|
+
}
|
|
127
|
+
if (args.syncToken) {
|
|
128
|
+
return { ...base, syncToken: args.syncToken };
|
|
129
|
+
}
|
|
130
|
+
const now = this.options.Now ?? new Date();
|
|
131
|
+
const lookaheadDays = this.options.LookaheadDays ?? DEFAULT_LOOKAHEAD_DAYS;
|
|
132
|
+
return {
|
|
133
|
+
...base,
|
|
134
|
+
timeMin: now.toISOString(),
|
|
135
|
+
timeMax: new Date(now.getTime() + lookaheadDays * MS_PER_DAY).toISOString(),
|
|
136
|
+
singleEvents: true,
|
|
137
|
+
orderBy: 'startTime',
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/** Normalizes the raw `events.list` data to the seam's {@link GoogleEventPage} shape. */
|
|
141
|
+
toEventPage(data) {
|
|
142
|
+
const obj = (data ?? {});
|
|
143
|
+
const items = Array.isArray(obj.items) ? obj.items : [];
|
|
144
|
+
const nextPageToken = readString(obj.nextPageToken);
|
|
145
|
+
const nextSyncToken = readString(obj.nextSyncToken);
|
|
146
|
+
return {
|
|
147
|
+
items,
|
|
148
|
+
...(nextPageToken ? { nextPageToken } : {}),
|
|
149
|
+
...(nextSyncToken ? { nextSyncToken } : {}),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/** Builds (once) + memoizes the Google Calendar client. */
|
|
153
|
+
client() {
|
|
154
|
+
if (!this.clientPromise) {
|
|
155
|
+
this.clientPromise = this.loadModule().then((mod) => mod.google.calendar({ version: 'v3', auth: this.options.Auth }));
|
|
156
|
+
}
|
|
157
|
+
return this.clientPromise;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
161
|
+
// Shared helpers.
|
|
162
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
163
|
+
/** Forward-window default (days) shared by both first-poll path builders. */
|
|
164
|
+
const DEFAULT_LOOKAHEAD_DAYS = 30;
|
|
165
|
+
const MS_PER_DAY = 24 * 60 * 60 * 1000;
|
|
166
|
+
/** Returns a non-empty trimmed string, or `undefined` for anything else. */
|
|
167
|
+
function readString(value) {
|
|
168
|
+
return typeof value === 'string' && value.trim().length > 0 ? value : undefined;
|
|
169
|
+
}
|
|
170
|
+
/** Unwraps a module from CJS/ESM interop (`module` or `module.default`). */
|
|
171
|
+
function unwrap(mod) {
|
|
172
|
+
if (mod && typeof mod === 'object' && 'default' in mod) {
|
|
173
|
+
const inner = mod.default;
|
|
174
|
+
if (inner && typeof inner === 'object') {
|
|
175
|
+
return inner;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return mod;
|
|
179
|
+
}
|
|
180
|
+
/** Structural guard: exposes `Client.init`. */
|
|
181
|
+
function isGraphModule(value) {
|
|
182
|
+
const client = value?.Client;
|
|
183
|
+
return client != null && typeof client.init === 'function';
|
|
184
|
+
}
|
|
185
|
+
/** Structural guard: exposes `google.calendar`. */
|
|
186
|
+
function isGoogleModule(value) {
|
|
187
|
+
const google = value?.google;
|
|
188
|
+
return google != null && typeof google.calendar === 'function';
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=calendar-clients.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar-clients.js","sourceRoot":"","sources":["../src/calendar-clients.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAkEH,2GAA2G;AAC3G,MAAM,CAAC,MAAM,gCAAgC,GAA8B,KAAK,IAAI,EAAE;IAClF,IAAI,CAAC;QACD,MAAM,GAAG,GAAY,MAAM,MAAM,CAAC,mCAAmC,CAAC,CAAC;QACvE,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,mFAAmF,CAAC,CAAC;QACzG,CAAC;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;IAAC,OAA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IAClE,OAAO,MAAM,IAAI,IAAI,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,CAAC;AAC/D,CAAC;AAED,mDAAmD;AACnD,SAAS,cAAc,CAAC,KAAc;IAClC,MAAM,MAAM,GAAI,KAA6C,EAAE,MAAM,CAAC;IACtE,OAAO,MAAM,IAAI,IAAI,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,UAAU,CAAC;AACnE,CAAC"}
|
|
@@ -97,46 +97,261 @@ export interface ICalendarSource {
|
|
|
97
97
|
export declare class CalendarSourceNotBoundError extends Error {
|
|
98
98
|
constructor(providerLabel: string);
|
|
99
99
|
}
|
|
100
|
+
/** A Graph `dateTimeTimeZone` value (`{ dateTime, timeZone }`) as `/me/events` reports start/end. */
|
|
101
|
+
export interface GraphDateTimeTimeZone {
|
|
102
|
+
/** The local date-time string (e.g. `2026-06-24T15:00:00.0000000`). */
|
|
103
|
+
dateTime?: string;
|
|
104
|
+
/** The IANA/Windows time-zone name (e.g. `UTC`, `Pacific Standard Time`). `UTC` is the common case. */
|
|
105
|
+
timeZone?: string;
|
|
106
|
+
}
|
|
107
|
+
/** A Graph `emailAddress` value (`{ address, name }`) used by attendees + organizer. */
|
|
108
|
+
export interface GraphEmailAddress {
|
|
109
|
+
/** The email address. */
|
|
110
|
+
address?: string;
|
|
111
|
+
/** The display name, when Graph provides one. */
|
|
112
|
+
name?: string;
|
|
113
|
+
}
|
|
114
|
+
/** One Graph attendee (`event.attendees[]`). */
|
|
115
|
+
export interface GraphAttendee {
|
|
116
|
+
/** The attendee's email-address block. */
|
|
117
|
+
emailAddress?: GraphEmailAddress;
|
|
118
|
+
/** The attendee's response (`{ response, time }`). */
|
|
119
|
+
status?: {
|
|
120
|
+
response?: string;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/** The Graph `onlineMeeting` facet (`event.onlineMeeting.joinUrl`). */
|
|
124
|
+
export interface GraphOnlineMeeting {
|
|
125
|
+
/** The online-meeting join URL. */
|
|
126
|
+
joinUrl?: string;
|
|
127
|
+
}
|
|
128
|
+
/** The Graph `event.body` facet — HTML/text body that may carry a join URL when `onlineMeeting` is absent. */
|
|
129
|
+
export interface GraphItemBody {
|
|
130
|
+
/** `'html'` or `'text'`. */
|
|
131
|
+
contentType?: string;
|
|
132
|
+
/** The body content (HTML or plain text). */
|
|
133
|
+
content?: string;
|
|
134
|
+
}
|
|
135
|
+
/** The subset of a Graph calendar `event` resource this adapter normalizes. */
|
|
136
|
+
export interface GraphCalendarEvent {
|
|
137
|
+
/** Graph `event.id` — the stable external event id. */
|
|
138
|
+
id?: string;
|
|
139
|
+
/** Graph `event.subject` — the meeting title. */
|
|
140
|
+
subject?: string;
|
|
141
|
+
/** Graph `event.onlineMeeting.joinUrl`. */
|
|
142
|
+
onlineMeeting?: GraphOnlineMeeting;
|
|
143
|
+
/** Graph `event.onlineMeetingUrl` (legacy flat field, when present). */
|
|
144
|
+
onlineMeetingUrl?: string;
|
|
145
|
+
/** Graph `event.body` — searched for a join URL when no structured field is present. */
|
|
146
|
+
body?: GraphItemBody;
|
|
147
|
+
/** Graph `event.start`. */
|
|
148
|
+
start?: GraphDateTimeTimeZone;
|
|
149
|
+
/** Graph `event.end`. */
|
|
150
|
+
end?: GraphDateTimeTimeZone;
|
|
151
|
+
/** Graph `event.attendees`. */
|
|
152
|
+
attendees?: GraphAttendee[];
|
|
153
|
+
/** Graph `event.organizer.emailAddress`. */
|
|
154
|
+
organizer?: {
|
|
155
|
+
emailAddress?: GraphEmailAddress;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/** One page of Graph delta results — the events + the cursor for the next call. */
|
|
159
|
+
export interface GraphEventPage {
|
|
160
|
+
/** The events on this page. */
|
|
161
|
+
value: GraphCalendarEvent[];
|
|
162
|
+
/** Graph `@odata.nextLink` — present when more pages remain in this poll. */
|
|
163
|
+
nextLink?: string;
|
|
164
|
+
/** Graph `@odata.deltaLink` — present on the final page; becomes the next poll's `sinceCursor`. */
|
|
165
|
+
deltaLink?: string;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The minimal Microsoft Graph calendar surface {@link GraphCalendarSource} drives. A production wiring
|
|
169
|
+
* implements this over `@microsoft/microsoft-graph-client` — `GET /users/{userId}/calendarView/delta`
|
|
170
|
+
* (or `/me/events/delta`), following `@odata.nextLink` page-to-page and capturing the final
|
|
171
|
+
* `@odata.deltaLink`. Tests inject a fake. NO Graph SDK types leak through this surface.
|
|
172
|
+
*/
|
|
173
|
+
export interface IGraphCalendarLike {
|
|
174
|
+
/**
|
|
175
|
+
* Lists one page of calendar events for `userId`. `deltaLink` is the opaque cursor from a prior
|
|
176
|
+
* poll's final page (or `undefined` for the first poll); `nextLink` is the in-poll continuation
|
|
177
|
+
* token. The adapter pages by following `nextLink` until the surface returns a `deltaLink`.
|
|
178
|
+
*
|
|
179
|
+
* @param userId The mailbox/identity address whose calendar to read.
|
|
180
|
+
* @param cursor The Graph delta/next link to resume from (opaque), or `undefined` to start fresh.
|
|
181
|
+
*/
|
|
182
|
+
listEvents(userId: string, cursor?: string): Promise<GraphEventPage>;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* **Pure** parse of a Graph {@link GraphDateTimeTimeZone} to a UTC {@link Date}. Treats a missing or
|
|
186
|
+
* `UTC`/`Z` time zone as UTC (the common case for Graph delta queries, which can be requested in UTC);
|
|
187
|
+
* for a non-UTC named zone it parses the wall-clock string and appends `Z` (best-effort — production
|
|
188
|
+
* SHOULD request UTC via the `Prefer: outlook.timezone="UTC"` header). Returns `null` on absent/invalid.
|
|
189
|
+
*/
|
|
190
|
+
export declare function parseGraphDateTime(value?: GraphDateTimeTimeZone): Date | null;
|
|
191
|
+
/** Maps a Graph attendee `status.response` to the normalized {@link CalendarInviteAttendee.ResponseStatus}. */
|
|
192
|
+
export declare function mapGraphResponseStatus(response?: string): CalendarInviteAttendee['ResponseStatus'] | undefined;
|
|
100
193
|
/**
|
|
101
|
-
* **
|
|
194
|
+
* **Pure** extraction of an online-meeting join URL from a Graph event. Prefers the structured
|
|
195
|
+
* `onlineMeeting.joinUrl`, then the legacy flat `onlineMeetingUrl`, then the first Teams `meetup-join`
|
|
196
|
+
* URL found in the event body (HTML or text). Returns `undefined` when no join URL is present.
|
|
197
|
+
*/
|
|
198
|
+
export declare function extractGraphJoinUrl(event: GraphCalendarEvent): string | undefined;
|
|
199
|
+
/**
|
|
200
|
+
* **Pure** normalization of one Graph calendar event to a {@link NormalizedCalendarInvite}. Skips
|
|
201
|
+
* (returns `null`) an event with no id or no resolvable start time, so the caller can drop it cleanly.
|
|
202
|
+
*/
|
|
203
|
+
export declare function normalizeGraphEvent(event: GraphCalendarEvent): NormalizedCalendarInvite | null;
|
|
204
|
+
/**
|
|
205
|
+
* **Production binding** for Microsoft Graph calendars over an injected {@link IGraphCalendarLike}
|
|
206
|
+
* surface, so it builds + unit-tests with no Graph SDK install and no network.
|
|
102
207
|
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* `start.dateTime`+`start.timeZone` → UTC `StartTime`) and carry the Graph `@odata.deltaLink` as the
|
|
109
|
-
* cursor.
|
|
208
|
+
* Pages a Graph delta poll: starting from `sinceCursor` (a prior `@odata.deltaLink`), it follows
|
|
209
|
+
* `@odata.nextLink` page-to-page, normalizing every event via {@link normalizeGraphEvent}, until the
|
|
210
|
+
* surface returns a `@odata.deltaLink` — which becomes the {@link CalendarPollResult.NextCursor} for the
|
|
211
|
+
* next poll. Credentials are resolved upstream (the host binds {@link IGraphCalendarLike} with a Graph
|
|
212
|
+
* client authenticated from the provider `Configuration` via MJ's credential system — never inline).
|
|
110
213
|
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
214
|
+
* When no surface is supplied it preserves the original not-bound behavior, throwing
|
|
215
|
+
* {@link CalendarSourceNotBoundError} so a misconfigured deployment fails loudly.
|
|
113
216
|
*
|
|
114
|
-
* @remarks **TODO (production):** bind `@microsoft/microsoft-graph-client` (an
|
|
115
|
-
* loaded only when a Graph-backed identity is configured),
|
|
116
|
-
*
|
|
217
|
+
* @remarks **TODO (production):** bind `@microsoft/microsoft-graph-client` (an optionalDependency,
|
|
218
|
+
* loaded only when a Graph-backed identity is configured), request UTC via
|
|
219
|
+
* `Prefer: outlook.timezone="UTC"`, and inject it as {@link IGraphCalendarLike}.
|
|
117
220
|
*/
|
|
118
221
|
export declare class GraphCalendarSource implements ICalendarSource {
|
|
222
|
+
private readonly graph?;
|
|
223
|
+
/**
|
|
224
|
+
* @param graph The injected Graph calendar surface. Omit to preserve the not-bound seam behavior
|
|
225
|
+
* (every poll throws {@link CalendarSourceNotBoundError}).
|
|
226
|
+
*/
|
|
227
|
+
constructor(graph?: IGraphCalendarLike);
|
|
119
228
|
/** @inheritdoc */
|
|
120
|
-
ListUpcomingInvites(
|
|
229
|
+
ListUpcomingInvites(identityValue: string, sinceCursor?: string): Promise<CalendarPollResult>;
|
|
230
|
+
}
|
|
231
|
+
/** A Google `EventDateTime` (`{ dateTime, date, timeZone }`). `dateTime` is RFC3339 with offset. */
|
|
232
|
+
export interface GoogleEventDateTime {
|
|
233
|
+
/** RFC3339 timed value with offset (e.g. `2026-06-24T15:00:00-07:00` or `…Z`). */
|
|
234
|
+
dateTime?: string;
|
|
235
|
+
/** All-day `date` value (`YYYY-MM-DD`) — treated as UTC midnight when no `dateTime` is present. */
|
|
236
|
+
date?: string;
|
|
237
|
+
/** The IANA time zone, when supplied. */
|
|
238
|
+
timeZone?: string;
|
|
239
|
+
}
|
|
240
|
+
/** One Google `Event.attendees[]`. */
|
|
241
|
+
export interface GoogleAttendee {
|
|
242
|
+
/** The attendee's email address. */
|
|
243
|
+
email?: string;
|
|
244
|
+
/** The attendee's display name, when present. */
|
|
245
|
+
displayName?: string;
|
|
246
|
+
/** Google response status (`accepted` / `declined` / `tentative` / `needsAction`). */
|
|
247
|
+
responseStatus?: string;
|
|
248
|
+
/** Whether this attendee is the organizer. */
|
|
249
|
+
organizer?: boolean;
|
|
250
|
+
}
|
|
251
|
+
/** One Google `conferenceData.entryPoints[]`. */
|
|
252
|
+
export interface GoogleConferenceEntryPoint {
|
|
253
|
+
/** Entry-point type (`video` / `phone` / `more` / `sip`). Only `video` carries a join URL we use. */
|
|
254
|
+
entryPointType?: string;
|
|
255
|
+
/** The entry-point URI (the join URL for `video`). */
|
|
256
|
+
uri?: string;
|
|
257
|
+
}
|
|
258
|
+
/** The subset of a Google Calendar `Event` resource this adapter normalizes. */
|
|
259
|
+
export interface GoogleCalendarEvent {
|
|
260
|
+
/** Google `event.id` — the stable external event id. */
|
|
261
|
+
id?: string;
|
|
262
|
+
/** Google `event.summary` — the meeting title. */
|
|
263
|
+
summary?: string;
|
|
264
|
+
/** Google `event.hangoutLink` — the Meet join URL (legacy flat field). */
|
|
265
|
+
hangoutLink?: string;
|
|
266
|
+
/** Google `event.conferenceData.entryPoints` — the modern conferencing block. */
|
|
267
|
+
conferenceData?: {
|
|
268
|
+
entryPoints?: GoogleConferenceEntryPoint[];
|
|
269
|
+
};
|
|
270
|
+
/** Google `event.start`. */
|
|
271
|
+
start?: GoogleEventDateTime;
|
|
272
|
+
/** Google `event.end`. */
|
|
273
|
+
end?: GoogleEventDateTime;
|
|
274
|
+
/** Google `event.attendees`. */
|
|
275
|
+
attendees?: GoogleAttendee[];
|
|
276
|
+
/** Google `event.organizer` (`{ email, displayName }`). */
|
|
277
|
+
organizer?: {
|
|
278
|
+
email?: string;
|
|
279
|
+
displayName?: string;
|
|
280
|
+
};
|
|
281
|
+
/** Google `event.status` — `cancelled` events are dropped from the normalized result. */
|
|
282
|
+
status?: string;
|
|
283
|
+
}
|
|
284
|
+
/** One page of Google `events.list` results — events + paging/sync tokens. */
|
|
285
|
+
export interface GoogleEventPage {
|
|
286
|
+
/** The events on this page. */
|
|
287
|
+
items: GoogleCalendarEvent[];
|
|
288
|
+
/** Google `nextPageToken` — present when more pages remain in this poll. */
|
|
289
|
+
nextPageToken?: string;
|
|
290
|
+
/** Google `nextSyncToken` — present on the final page; becomes the next poll's `sinceCursor`. */
|
|
291
|
+
nextSyncToken?: string;
|
|
292
|
+
}
|
|
293
|
+
/** Arguments for one {@link IGoogleCalendarLike.listEvents} call — sync-token OR page-token paging. */
|
|
294
|
+
export interface GoogleListEventsArgs {
|
|
295
|
+
/** The calendar id to read (the agent's mailbox/identity address; `primary` for the user's default). */
|
|
296
|
+
calendarId: string;
|
|
297
|
+
/** Incremental-sync token from a prior poll's final page (mutually exclusive with `pageToken`). */
|
|
298
|
+
syncToken?: string;
|
|
299
|
+
/** In-poll continuation token (`nextPageToken`) when following pages of the current poll. */
|
|
300
|
+
pageToken?: string;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* The minimal Google Calendar surface {@link GoogleCalendarSource} drives. A production wiring
|
|
304
|
+
* implements this over `googleapis` — `calendar.events.list({ calendarId, syncToken | pageToken })` —
|
|
305
|
+
* following `nextPageToken` page-to-page and capturing the final `nextSyncToken`. Tests inject a fake.
|
|
306
|
+
* NO googleapis types leak through this surface.
|
|
307
|
+
*/
|
|
308
|
+
export interface IGoogleCalendarLike {
|
|
309
|
+
/** Lists one page of events for a calendar, paging via `pageToken` and syncing via `syncToken`. */
|
|
310
|
+
listEvents(args: GoogleListEventsArgs): Promise<GoogleEventPage>;
|
|
121
311
|
}
|
|
122
312
|
/**
|
|
123
|
-
* **
|
|
313
|
+
* **Pure** parse of a Google {@link GoogleEventDateTime} to a UTC {@link Date}. Uses the RFC3339
|
|
314
|
+
* `dateTime` (which carries its own offset) when present, else an all-day `date` as UTC midnight.
|
|
315
|
+
* Returns `null` on absent/invalid.
|
|
316
|
+
*/
|
|
317
|
+
export declare function parseGoogleDateTime(value?: GoogleEventDateTime): Date | null;
|
|
318
|
+
/** Maps a Google `responseStatus` to the normalized {@link CalendarInviteAttendee.ResponseStatus}. */
|
|
319
|
+
export declare function mapGoogleResponseStatus(response?: string): CalendarInviteAttendee['ResponseStatus'] | undefined;
|
|
320
|
+
/**
|
|
321
|
+
* **Pure** extraction of the Meet/online-meeting join URL from a Google event. Prefers the first
|
|
322
|
+
* `video` entry-point in `conferenceData`, then the legacy `hangoutLink`. Returns `undefined` when no
|
|
323
|
+
* video conferencing is attached.
|
|
324
|
+
*/
|
|
325
|
+
export declare function extractGoogleJoinUrl(event: GoogleCalendarEvent): string | undefined;
|
|
326
|
+
/**
|
|
327
|
+
* **Pure** normalization of one Google calendar event to a {@link NormalizedCalendarInvite}. Skips
|
|
328
|
+
* (returns `null`) a cancelled event or one with no id or no resolvable start time.
|
|
329
|
+
*/
|
|
330
|
+
export declare function normalizeGoogleEvent(event: GoogleCalendarEvent): NormalizedCalendarInvite | null;
|
|
331
|
+
/**
|
|
332
|
+
* **Production binding** for Google Calendar over an injected {@link IGoogleCalendarLike} surface, so
|
|
333
|
+
* it builds + unit-tests with no `googleapis` install and no network.
|
|
124
334
|
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* `start.dateTime` → UTC `StartTime`) and carries the Google `nextSyncToken` as the cursor.
|
|
335
|
+
* Pages an incremental sync: starting from `sinceCursor` (a prior `nextSyncToken`), it follows
|
|
336
|
+
* `nextPageToken` page-to-page, normalizing every event via {@link normalizeGoogleEvent}, until the
|
|
337
|
+
* surface returns a `nextSyncToken` — which becomes the {@link CalendarPollResult.NextCursor}.
|
|
338
|
+
* Credentials are resolved upstream (the host binds {@link IGoogleCalendarLike} with a Calendar client
|
|
339
|
+
* authenticated from the provider `Configuration` via MJ's credential system — never inline).
|
|
131
340
|
*
|
|
132
|
-
*
|
|
341
|
+
* When no surface is supplied it preserves the original not-bound behavior, throwing
|
|
342
|
+
* {@link CalendarSourceNotBoundError}.
|
|
133
343
|
*
|
|
134
|
-
* @remarks **TODO (production):** bind `googleapis` (an
|
|
135
|
-
* Google-backed identity is configured)
|
|
136
|
-
* normalization. Keep this class as the seam.
|
|
344
|
+
* @remarks **TODO (production):** bind `googleapis` (an optionalDependency, loaded only when a
|
|
345
|
+
* Google-backed identity is configured) and inject it as {@link IGoogleCalendarLike}.
|
|
137
346
|
*/
|
|
138
347
|
export declare class GoogleCalendarSource implements ICalendarSource {
|
|
348
|
+
private readonly calendar?;
|
|
349
|
+
/**
|
|
350
|
+
* @param calendar The injected Google calendar surface. Omit to preserve the not-bound seam
|
|
351
|
+
* behavior (every poll throws {@link CalendarSourceNotBoundError}).
|
|
352
|
+
*/
|
|
353
|
+
constructor(calendar?: IGoogleCalendarLike);
|
|
139
354
|
/** @inheritdoc */
|
|
140
|
-
ListUpcomingInvites(
|
|
355
|
+
ListUpcomingInvites(identityValue: string, sinceCursor?: string): Promise<CalendarPollResult>;
|
|
141
356
|
}
|
|
142
357
|
//# sourceMappingURL=calendar-source.d.ts.map
|