@dv4resi/dvss-backend-module-calendar-im 0.0.7 → 0.0.9

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/index.js CHANGED
@@ -977,6 +977,7 @@ var GET_PAYMENTS_SORTING_ENUM = /* @__PURE__ */ (function(GET_PAYMENTS_SORTING_E
977
977
  GET_PAYMENTS_SORTING_ENUM2["NOTES"] = "NOTES";
978
978
  GET_PAYMENTS_SORTING_ENUM2["PAYMENT_MODE"] = "PAYMENT_MODE";
979
979
  GET_PAYMENTS_SORTING_ENUM2["CREATED_TIME"] = "CREATED_TIME";
980
+ GET_PAYMENTS_SORTING_ENUM2["DUE_AMOUNT"] = "DUE_AMOUNT";
980
981
  return GET_PAYMENTS_SORTING_ENUM2;
981
982
  })({});
982
983
  var EVENT_INSTANCE_KIND = /* @__PURE__ */ (function(EVENT_INSTANCE_KIND2) {
@@ -3524,9 +3525,17 @@ var MICROSOFT_GRAPH_PATHS = {
3524
3525
  userCalendarEvents: /* @__PURE__ */ __name((mailboxEmail) => `/users/${encodeURIComponent(mailboxEmail)}/calendar/events`, "userCalendarEvents"),
3525
3526
  userCalendarEvent: /* @__PURE__ */ __name((mailboxEmail, eventId) => `/users/${encodeURIComponent(mailboxEmail)}/calendar/events/${encodeURIComponent(eventId)}`, "userCalendarEvent"),
3526
3527
  userCalendarView: /* @__PURE__ */ __name((mailboxEmail, startDateTime, endDateTime) => `/users/${encodeURIComponent(mailboxEmail)}/calendarView?startDateTime=${encodeURIComponent(startDateTime)}&endDateTime=${encodeURIComponent(endDateTime)}`, "userCalendarView"),
3528
+ userCalendarViewDelta: /* @__PURE__ */ __name((mailboxEmail, startDateTime, endDateTime) => `/users/${encodeURIComponent(mailboxEmail)}/calendarView/delta?startDateTime=${encodeURIComponent(startDateTime)}&endDateTime=${encodeURIComponent(endDateTime)}`, "userCalendarViewDelta"),
3529
+ userCalendarEventAccept: /* @__PURE__ */ __name((mailboxEmail, eventId) => `/users/${encodeURIComponent(mailboxEmail)}/events/${encodeURIComponent(eventId)}/accept`, "userCalendarEventAccept"),
3530
+ userCalendarEventDecline: /* @__PURE__ */ __name((mailboxEmail, eventId) => `/users/${encodeURIComponent(mailboxEmail)}/events/${encodeURIComponent(eventId)}/decline`, "userCalendarEventDecline"),
3531
+ /** Real Graph instance ids of a recurring series in a date window - backs "this and following" edits. */
3532
+ userCalendarEventInstances: /* @__PURE__ */ __name((mailboxEmail, seriesMasterEventId, startDateTime, endDateTime) => `/users/${encodeURIComponent(mailboxEmail)}/calendar/events/${encodeURIComponent(seriesMasterEventId)}/instances?startDateTime=${encodeURIComponent(startDateTime)}&endDateTime=${encodeURIComponent(endDateTime)}`, "userCalendarEventInstances"),
3527
3533
  subscriptions: "/subscriptions",
3528
- subscription: /* @__PURE__ */ __name((subscriptionId) => `/subscriptions/${encodeURIComponent(subscriptionId)}`, "subscription")
3534
+ subscription: /* @__PURE__ */ __name((subscriptionId) => `/subscriptions/${encodeURIComponent(subscriptionId)}`, "subscription"),
3535
+ /** Graph JSON batching endpoint - up to 20 sub-requests per call. */
3536
+ batch: "/$batch"
3529
3537
  };
3538
+ var MICROSOFT_CALENDAR_DELTA_DEFAULT_WINDOW_YEARS = 10;
3530
3539
  var MICROSOFT_DEFAULT_GRAPH_BASE_URL = "https://graph.microsoft.com/v1.0";
3531
3540
  var MICROSOFT_DEFAULT_AUTH_URL = "https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/token";
3532
3541
 
@@ -4032,7 +4041,10 @@ function graphEventsToInstances(response) {
4032
4041
  return (response.value ?? []).filter((graph) => Boolean(graph.id && graph.start?.dateTime)).map((graph) => omitUndefined({
4033
4042
  id: graph.id,
4034
4043
  startDateLabel: graph.start.dateTime.slice(0, 10),
4035
- seriesId: graph.seriesMasterId
4044
+ seriesId: graph.seriesMasterId,
4045
+ iCalUId: graph.iCalUId,
4046
+ transactionId: graph.transactionId,
4047
+ subject: graph.subject
4036
4048
  }));
4037
4049
  }
4038
4050
  __name(graphEventsToInstances, "graphEventsToInstances");
@@ -4064,6 +4076,7 @@ function _ts_metadata23(k, v) {
4064
4076
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
4065
4077
  }
4066
4078
  __name(_ts_metadata23, "_ts_metadata");
4079
+ var GRAPH_BATCH_MAX_SIZE = 20;
4067
4080
  exports.MicrosoftCalendarBookingService = class MicrosoftCalendarBookingService extends BaseCalendarBookingManagement {
4068
4081
  static {
4069
4082
  __name(this, "MicrosoftCalendarBookingService");
@@ -4169,6 +4182,81 @@ exports.MicrosoftCalendarBookingService = class MicrosoftCalendarBookingService
4169
4182
  throw error;
4170
4183
  }
4171
4184
  }
4185
+ async getEvent(request, integration, loggedInUserId) {
4186
+ try {
4187
+ const mailboxEmail = this.pickMailbox(request.organizerUserEmail, request.resourceId);
4188
+ this.assertMailbox(mailboxEmail);
4189
+ this.assertEventId(request.eventId);
4190
+ let url = MICROSOFT_GRAPH_PATHS.userCalendarEvent(mailboxEmail, request.eventId);
4191
+ const queryParams = [];
4192
+ const selectFields = [
4193
+ "id",
4194
+ "seriesMasterId",
4195
+ "type",
4196
+ "subject",
4197
+ "body",
4198
+ "start",
4199
+ "end",
4200
+ "isAllDay",
4201
+ "location",
4202
+ "recurrence",
4203
+ "attendees",
4204
+ "organizer",
4205
+ "isOrganizer",
4206
+ "transactionId",
4207
+ "iCalUId"
4208
+ ];
4209
+ if (request.expandSeriesExceptions) {
4210
+ selectFields.push("cancelledOccurrences");
4211
+ queryParams.push("$expand=exceptionOccurrences");
4212
+ }
4213
+ queryParams.push(`$select=${selectFields.join(",")}`);
4214
+ if (queryParams.length > 0) {
4215
+ url += `?${queryParams.join("&")}`;
4216
+ }
4217
+ this.logger.info(loggedInUserId, this.getEvent.name, this.fileName, "Get Microsoft Graph calendar event", {
4218
+ mailboxEmail,
4219
+ eventId: request.eventId,
4220
+ url
4221
+ });
4222
+ const response = await this.microsoftApiClient.apiCall({
4223
+ apiMethod: HTTP_METHOD.GET,
4224
+ url
4225
+ }, integration, loggedInUserId);
4226
+ return graphEventToRef(response, {
4227
+ resourceId: request.resourceId,
4228
+ organizerUserEmail: this.organizerUserMailbox(request.organizerUserEmail)
4229
+ });
4230
+ } catch (error) {
4231
+ this.logger.error(loggedInUserId, this.getEvent.name, this.fileName, "Error getting Microsoft Graph calendar event", error);
4232
+ throw error;
4233
+ }
4234
+ }
4235
+ async acceptEvent(request, integration, loggedInUserId) {
4236
+ try {
4237
+ const mailboxEmail = this.pickMailbox(request.organizerUserEmail, request.resourceEmail);
4238
+ this.assertMailbox(mailboxEmail);
4239
+ this.assertEventId(request.eventId);
4240
+ this.logger.info(loggedInUserId, this.acceptEvent.name, this.fileName, "Accept Microsoft Graph calendar event", {
4241
+ mailboxEmail,
4242
+ eventId: request.eventId
4243
+ });
4244
+ const shouldSendResponse = request.sendResponse ?? false;
4245
+ await this.microsoftApiClient.apiCall({
4246
+ apiMethod: HTTP_METHOD.POST,
4247
+ url: `${MICROSOFT_GRAPH_PATHS.userCalendarEvent(mailboxEmail, request.eventId)}/accept`,
4248
+ body: {
4249
+ sendResponse: shouldSendResponse,
4250
+ ...shouldSendResponse && request.comment ? {
4251
+ comment: request.comment
4252
+ } : {}
4253
+ }
4254
+ }, integration, loggedInUserId);
4255
+ } catch (error) {
4256
+ this.logger.error(loggedInUserId, this.acceptEvent.name, this.fileName, "Error accepting Microsoft Graph calendar event", error);
4257
+ throw error;
4258
+ }
4259
+ }
4172
4260
  async getEvents(request, integration, loggedInUserId) {
4173
4261
  try {
4174
4262
  const mailboxEmail = this.pickMailbox(request.organizerUserEmail, request.resourceEmail);
@@ -4197,6 +4285,117 @@ exports.MicrosoftCalendarBookingService = class MicrosoftCalendarBookingService
4197
4285
  throw error;
4198
4286
  }
4199
4287
  }
4288
+ /**
4289
+ * Resolves the real Graph instance ids of a recurring series over a date window — the
4290
+ * per-occurrence exception model needs these to PATCH an occurrence directly rather than the
4291
+ * series master, so an edit never touches the master's own `start`/`recurrence.range`.
4292
+ */
4293
+ async getEventInstances(request, integration, loggedInUserId) {
4294
+ try {
4295
+ const mailboxEmail = this.pickMailbox(request.organizerUserEmail, request.resourceEmail);
4296
+ this.assertMailbox(mailboxEmail);
4297
+ this.assertEventId(request.seriesEventId);
4298
+ const url = MICROSOFT_GRAPH_PATHS.userCalendarEventInstances(mailboxEmail, request.seriesEventId, `${request.startDateLabel}T00:00:00`, `${request.endDateLabel}T23:59:59`);
4299
+ this.logger.info(loggedInUserId, this.getEventInstances.name, this.fileName, "List Microsoft Graph series instances", {
4300
+ mailboxEmail,
4301
+ seriesEventId: request.seriesEventId,
4302
+ path: url
4303
+ });
4304
+ const response = await this.microsoftApiClient.apiCall({
4305
+ apiMethod: HTTP_METHOD.GET,
4306
+ url
4307
+ }, integration, loggedInUserId);
4308
+ const events = graphEventsToInstances(response);
4309
+ this.logger.info(loggedInUserId, this.getEventInstances.name, this.fileName, "Listed Microsoft Graph series instances", {
4310
+ mailboxEmail,
4311
+ seriesEventId: request.seriesEventId,
4312
+ count: events.length
4313
+ });
4314
+ return {
4315
+ events
4316
+ };
4317
+ } catch (error) {
4318
+ this.logger.error(loggedInUserId, this.getEventInstances.name, this.fileName, "Error listing Microsoft Graph series instances", error);
4319
+ throw error;
4320
+ }
4321
+ }
4322
+ /**
4323
+ * PATCHes a set of a series' own instances as provider-native exceptions, batched via Graph
4324
+ * `$batch` (≤20 sub-requests per call). Never throws on a partial failure — each instance's
4325
+ * outcome is reported individually so the caller can persist what succeeded and retry the rest.
4326
+ */
4327
+ async updateEventInstances(request, integration, loggedInUserId) {
4328
+ try {
4329
+ const mailboxEmail = this.pickMailbox(request.organizerUserEmail, request.resourceEmail);
4330
+ this.assertMailbox(mailboxEmail);
4331
+ this.logger.info(loggedInUserId, this.updateEventInstances.name, this.fileName, "Batch-update Microsoft Graph series instances", {
4332
+ mailboxEmail,
4333
+ instanceCount: request.updates.length
4334
+ });
4335
+ const results = [];
4336
+ for (const chunk of this.chunkInstanceUpdates(request.updates)) {
4337
+ const batchRequests = chunk.map((update, index) => ({
4338
+ id: String(index),
4339
+ method: "PATCH",
4340
+ url: MICROSOFT_GRAPH_PATHS.userCalendarEvent(mailboxEmail, update.instanceId),
4341
+ body: toGraphEvent(update.event, {
4342
+ targetMailbox: mailboxEmail
4343
+ })
4344
+ }));
4345
+ const batchResponse = await this.microsoftApiClient.apiCall({
4346
+ apiMethod: HTTP_METHOD.POST,
4347
+ url: MICROSOFT_GRAPH_PATHS.batch,
4348
+ body: {
4349
+ requests: batchRequests
4350
+ }
4351
+ }, integration, loggedInUserId);
4352
+ const responseById = new Map(batchResponse.responses.map((entry) => [
4353
+ entry.id,
4354
+ entry
4355
+ ]));
4356
+ chunk.forEach((update, index) => {
4357
+ const entry = responseById.get(String(index));
4358
+ if (!entry || entry.status >= 300) {
4359
+ this.logger.warn(loggedInUserId, this.updateEventInstances.name, this.fileName, "Failed to update a series instance", {
4360
+ mailboxEmail,
4361
+ instanceId: update.instanceId,
4362
+ status: entry?.status
4363
+ });
4364
+ results.push({
4365
+ instanceId: update.instanceId,
4366
+ error: entry ? `Graph responded ${entry.status}` : "No batch response entry"
4367
+ });
4368
+ return;
4369
+ }
4370
+ results.push({
4371
+ instanceId: update.instanceId,
4372
+ ref: graphEventToRef(entry.body ?? {}, {
4373
+ organizerUserEmail: request.organizerUserEmail
4374
+ })
4375
+ });
4376
+ });
4377
+ }
4378
+ this.logger.info(loggedInUserId, this.updateEventInstances.name, this.fileName, "Batch-updated Microsoft Graph series instances", {
4379
+ mailboxEmail,
4380
+ succeeded: results.filter((result) => !result.error).length,
4381
+ failed: results.filter((result) => result.error).length
4382
+ });
4383
+ return {
4384
+ results
4385
+ };
4386
+ } catch (error) {
4387
+ this.logger.error(loggedInUserId, this.updateEventInstances.name, this.fileName, "Error batch-updating Microsoft Graph series instances", error);
4388
+ throw error;
4389
+ }
4390
+ }
4391
+ /** Splits instance updates into Graph-`$batch`-sized chunks (≤20 sub-requests each). */
4392
+ chunkInstanceUpdates(updates) {
4393
+ const chunks = [];
4394
+ for (let i = 0; i < updates.length; i += GRAPH_BATCH_MAX_SIZE) {
4395
+ chunks.push(updates.slice(i, i + GRAPH_BATCH_MAX_SIZE));
4396
+ }
4397
+ return chunks;
4398
+ }
4200
4399
  async deleteGraphEvent(mailboxEmail, eventId, integration, loggedInUserId) {
4201
4400
  this.assertMailbox(mailboxEmail);
4202
4401
  this.assertEventId(eventId);
@@ -4367,6 +4566,7 @@ var GRAPH_SUBSCRIPTION_KNOWN_KEYS = /* @__PURE__ */ new Set([
4367
4566
  "resource",
4368
4567
  "changeType",
4369
4568
  "notificationUrl",
4569
+ "lifecycleNotificationUrl",
4370
4570
  "expirationDateTime",
4371
4571
  "clientState"
4372
4572
  ]);
@@ -4456,6 +4656,66 @@ exports.MicrosoftCalendarWebhookService = class MicrosoftCalendarWebhookService
4456
4656
  throw error;
4457
4657
  }
4458
4658
  }
4659
+ async batchRefreshSubscriptions(items, integration, loggedInUserId) {
4660
+ if (items.length === 0) {
4661
+ return [];
4662
+ }
4663
+ const batchBody = {
4664
+ requests: items.map((item) => ({
4665
+ id: item.requestId,
4666
+ method: HTTP_METHOD.PATCH,
4667
+ url: MICROSOFT_GRAPH_PATHS.subscription(item.subscriptionId),
4668
+ body: {
4669
+ expirationDateTime: item.expirationDateTime
4670
+ },
4671
+ headers: {
4672
+ ["Content-Type"]: "application/json"
4673
+ }
4674
+ }))
4675
+ };
4676
+ try {
4677
+ this.logger.info(loggedInUserId, this.batchRefreshSubscriptions.name, this.fileName, "Batch refresh Microsoft Graph subscriptions", {
4678
+ count: items.length
4679
+ });
4680
+ const batchResponse = await this.microsoftApiClient.apiCall({
4681
+ apiMethod: HTTP_METHOD.POST,
4682
+ url: "/$batch",
4683
+ body: batchBody
4684
+ }, integration, loggedInUserId);
4685
+ return items.map((item) => {
4686
+ const response = batchResponse.responses.find((entry) => entry.id === item.requestId);
4687
+ if (!response) {
4688
+ return {
4689
+ requestId: item.requestId,
4690
+ subscriptionId: item.subscriptionId,
4691
+ success: false,
4692
+ error: "Missing batch response entry"
4693
+ };
4694
+ }
4695
+ if (response.status >= 200 && response.status < 300) {
4696
+ const subscription = this.fromGraphSubscription(response.body ?? {});
4697
+ return {
4698
+ requestId: item.requestId,
4699
+ subscriptionId: item.subscriptionId,
4700
+ success: true,
4701
+ subscription,
4702
+ status: response.status
4703
+ };
4704
+ }
4705
+ const errorBody = response.body;
4706
+ return {
4707
+ requestId: item.requestId,
4708
+ subscriptionId: item.subscriptionId,
4709
+ success: false,
4710
+ status: response.status,
4711
+ error: errorBody?.error?.message ?? `Graph batch PATCH failed with status ${response.status}`
4712
+ };
4713
+ });
4714
+ } catch (error) {
4715
+ this.logger.error(loggedInUserId, this.batchRefreshSubscriptions.name, this.fileName, "Error batch refreshing subscriptions", error);
4716
+ throw error;
4717
+ }
4718
+ }
4459
4719
  toGraphSubscription(request) {
4460
4720
  const graph = {
4461
4721
  changeType: request.changeTypes.join(","),
@@ -4463,6 +4723,9 @@ exports.MicrosoftCalendarWebhookService = class MicrosoftCalendarWebhookService
4463
4723
  resource: request.resource,
4464
4724
  expirationDateTime: request.expirationDateTime
4465
4725
  };
4726
+ if (request.lifecycleNotificationUrl) {
4727
+ graph.lifecycleNotificationUrl = request.lifecycleNotificationUrl;
4728
+ }
4466
4729
  if (request.clientState !== void 0) {
4467
4730
  graph.clientState = request.clientState;
4468
4731
  }
@@ -4822,6 +5085,18 @@ exports.MicrosoftCalendarBookingHandler = class MicrosoftCalendarBookingHandler
4822
5085
  async getCalendarBookings(request, integration, loggedInUserId) {
4823
5086
  return this.microsoftCalendarBookingService.getEvents(request, integration, loggedInUserId);
4824
5087
  }
5088
+ async getCalendarBooking(request, integration, loggedInUserId) {
5089
+ return this.microsoftCalendarBookingService.getEvent(request, integration, loggedInUserId);
5090
+ }
5091
+ async acceptCalendarBooking(request, integration, loggedInUserId) {
5092
+ return this.microsoftCalendarBookingService.acceptEvent(request, integration, loggedInUserId);
5093
+ }
5094
+ async getCalendarBookingInstances(request, integration, loggedInUserId) {
5095
+ return this.microsoftCalendarBookingService.getEventInstances(request, integration, loggedInUserId);
5096
+ }
5097
+ async updateCalendarBookingInstances(request, integration, loggedInUserId) {
5098
+ return this.microsoftCalendarBookingService.updateEventInstances(request, integration, loggedInUserId);
5099
+ }
4825
5100
  };
4826
5101
  exports.MicrosoftCalendarBookingHandler = _ts_decorate36([
4827
5102
  common.Injectable(),
@@ -5019,6 +5294,31 @@ var ICalendarWebhookHandler = class {
5019
5294
  static {
5020
5295
  __name(this, "ICalendarWebhookHandler");
5021
5296
  }
5297
+ async batchRefreshCalendarWebhooks(items, integration, loggedInUserId) {
5298
+ const results = [];
5299
+ for (const item of items) {
5300
+ try {
5301
+ const response = await this.refreshCalendarWebhook({
5302
+ subscriptionId: item.subscriptionId,
5303
+ expirationDateTime: item.expirationDateTime
5304
+ }, integration, loggedInUserId);
5305
+ results.push({
5306
+ requestId: item.requestId,
5307
+ subscriptionId: item.subscriptionId,
5308
+ success: true,
5309
+ subscription: response.subscription
5310
+ });
5311
+ } catch (error) {
5312
+ results.push({
5313
+ requestId: item.requestId,
5314
+ subscriptionId: item.subscriptionId,
5315
+ success: false,
5316
+ error: error instanceof Error ? error.message : String(error)
5317
+ });
5318
+ }
5319
+ }
5320
+ return results;
5321
+ }
5022
5322
  };
5023
5323
 
5024
5324
  // src/providers/microsoft/microsoft-calendar-webhook.handler.ts
@@ -5050,6 +5350,9 @@ exports.MicrosoftCalendarWebhookHandler = class MicrosoftCalendarWebhookHandler
5050
5350
  async deleteCalendarWebhook(request, integration, loggedInUserId) {
5051
5351
  return this.microsoftCalendarWebhookService.deleteSubscription(request, integration, loggedInUserId);
5052
5352
  }
5353
+ async batchRefreshCalendarWebhooks(items, integration, loggedInUserId) {
5354
+ return this.microsoftCalendarWebhookService.batchRefreshSubscriptions(items, integration, loggedInUserId);
5355
+ }
5053
5356
  };
5054
5357
  exports.MicrosoftCalendarWebhookHandler = _ts_decorate42([
5055
5358
  common.Injectable(),
@@ -5210,6 +5513,7 @@ exports.ICalendarResourceHandler = ICalendarResourceHandler;
5210
5513
  exports.ICalendarWebhookHandler = ICalendarWebhookHandler;
5211
5514
  exports.INVOICE_STATUS_ENUM = INVOICE_STATUS_ENUM;
5212
5515
  exports.IntegrationVisitorCredentialMappingDao = IntegrationVisitorCredentialMappingDao;
5516
+ exports.MICROSOFT_CALENDAR_DELTA_DEFAULT_WINDOW_YEARS = MICROSOFT_CALENDAR_DELTA_DEFAULT_WINDOW_YEARS;
5213
5517
  exports.MICROSOFT_CLIENT_CREDENTIALS_GRANT_TYPE = MICROSOFT_CLIENT_CREDENTIALS_GRANT_TYPE;
5214
5518
  exports.MICROSOFT_DEFAULT_ACCESS_TOKEN_TYPE = MICROSOFT_DEFAULT_ACCESS_TOKEN_TYPE;
5215
5519
  exports.MICROSOFT_DEFAULT_AUTH_URL = MICROSOFT_DEFAULT_AUTH_URL;