@adatechnology/notification-contracts 0.4.0 → 0.5.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/index.cjs CHANGED
@@ -76,8 +76,16 @@ __export(index_exports, {
76
76
  diffTemplateVariables: () => diffTemplateVariables,
77
77
  escapeEmailHtml: () => escapeEmailHtml,
78
78
  escapeTemplateHtml: () => escapeTemplateHtml,
79
+ extractCalendarEvent: () => extractCalendarEvent,
79
80
  extractTemplatePlaceholders: () => extractTemplatePlaceholders,
80
81
  findUnsafeEmailHtml: () => findUnsafeEmailHtml,
82
+ generateCalendarLinks: () => generateCalendarLinks,
83
+ generateGoogleCalendarUrl: () => generateGoogleCalendarUrl,
84
+ generateIcsContent: () => generateIcsContent,
85
+ generateIcsDataUri: () => generateIcsDataUri,
86
+ generateOffice365CalendarUrl: () => generateOffice365CalendarUrl,
87
+ generateOutlookCalendarUrl: () => generateOutlookCalendarUrl,
88
+ generateYahooCalendarUrl: () => generateYahooCalendarUrl,
81
89
  htmlToPlainText: () => htmlToPlainText,
82
90
  interpolateEmailHtml: () => interpolateEmailHtml,
83
91
  interpolateTemplate: () => interpolateTemplate,
@@ -1109,6 +1117,156 @@ function renderStandardEmail(params) {
1109
1117
  };
1110
1118
  }
1111
1119
  __name(renderStandardEmail, "renderStandardEmail");
1120
+
1121
+ // src/calendarEvent.ts
1122
+ function toIsoDate(value) {
1123
+ return value instanceof Date ? value : new Date(value);
1124
+ }
1125
+ __name(toIsoDate, "toIsoDate");
1126
+ function formatUtcCompact(date) {
1127
+ return date.toISOString().replace(/[-:]/g, "").replace(/\.\d{3}/, "");
1128
+ }
1129
+ __name(formatUtcCompact, "formatUtcCompact");
1130
+ function escapeIcsText(text) {
1131
+ return text.replace(/\\/g, "\\\\").replace(/;/g, "\\;").replace(/,/g, "\\,").replace(/\r\n/g, "\\n").replace(/\n/g, "\\n");
1132
+ }
1133
+ __name(escapeIcsText, "escapeIcsText");
1134
+ function generateGoogleCalendarUrl(event) {
1135
+ const start = toIsoDate(event.startsAt);
1136
+ const end = event.endsAt ? toIsoDate(event.endsAt) : new Date(start.getTime() + 60 * 60 * 1e3);
1137
+ const params = new URLSearchParams({
1138
+ action: "TEMPLATE",
1139
+ text: event.title,
1140
+ dates: `${formatUtcCompact(start)}/${formatUtcCompact(end)}`
1141
+ });
1142
+ if (event.description) params.set("details", event.description);
1143
+ if (event.location) params.set("location", event.location);
1144
+ return `https://calendar.google.com/calendar/render?${params.toString()}`;
1145
+ }
1146
+ __name(generateGoogleCalendarUrl, "generateGoogleCalendarUrl");
1147
+ function generateOutlookCalendarUrl(event) {
1148
+ const start = toIsoDate(event.startsAt);
1149
+ const end = event.endsAt ? toIsoDate(event.endsAt) : new Date(start.getTime() + 60 * 60 * 1e3);
1150
+ const params = new URLSearchParams({
1151
+ path: "/calendar/action/compose",
1152
+ rru: "addevent",
1153
+ subject: event.title,
1154
+ startdt: start.toISOString(),
1155
+ enddt: end.toISOString()
1156
+ });
1157
+ if (event.description) params.set("body", event.description);
1158
+ if (event.location) params.set("location", event.location);
1159
+ return `https://outlook.live.com/calendar/0/deeplink/compose?${params.toString()}`;
1160
+ }
1161
+ __name(generateOutlookCalendarUrl, "generateOutlookCalendarUrl");
1162
+ function generateOffice365CalendarUrl(event) {
1163
+ const start = toIsoDate(event.startsAt);
1164
+ const end = event.endsAt ? toIsoDate(event.endsAt) : new Date(start.getTime() + 60 * 60 * 1e3);
1165
+ const params = new URLSearchParams({
1166
+ path: "/calendar/action/compose",
1167
+ rru: "addevent",
1168
+ subject: event.title,
1169
+ startdt: start.toISOString(),
1170
+ enddt: end.toISOString()
1171
+ });
1172
+ if (event.description) params.set("body", event.description);
1173
+ if (event.location) params.set("location", event.location);
1174
+ return `https://outlook.office.com/calendar/0/deeplink/compose?${params.toString()}`;
1175
+ }
1176
+ __name(generateOffice365CalendarUrl, "generateOffice365CalendarUrl");
1177
+ function generateYahooCalendarUrl(event) {
1178
+ const start = toIsoDate(event.startsAt);
1179
+ const end = event.endsAt ? toIsoDate(event.endsAt) : new Date(start.getTime() + 60 * 60 * 1e3);
1180
+ const durationMs = Math.max(0, end.getTime() - start.getTime());
1181
+ const durationHours = Math.floor(durationMs / (60 * 60 * 1e3));
1182
+ const durationMinutes = Math.floor(durationMs % (60 * 60 * 1e3) / (60 * 1e3));
1183
+ const durStr = `${String(durationHours).padStart(2, "0")}${String(durationMinutes).padStart(2, "0")}`;
1184
+ const params = new URLSearchParams({
1185
+ v: "60",
1186
+ view: "d",
1187
+ type: "20",
1188
+ title: event.title,
1189
+ st: formatUtcCompact(start),
1190
+ dur: durStr
1191
+ });
1192
+ if (event.description) params.set("desc", event.description);
1193
+ if (event.location) params.set("in_loc", event.location);
1194
+ return `https://calendar.yahoo.com/?${params.toString()}`;
1195
+ }
1196
+ __name(generateYahooCalendarUrl, "generateYahooCalendarUrl");
1197
+ function generateIcsDataUri(event, now = /* @__PURE__ */ new Date()) {
1198
+ const ics = generateIcsContent(event, now);
1199
+ return `data:text/calendar;charset=utf-8,${encodeURIComponent(ics)}`;
1200
+ }
1201
+ __name(generateIcsDataUri, "generateIcsDataUri");
1202
+ function generateCalendarLinks(event) {
1203
+ return {
1204
+ google: generateGoogleCalendarUrl(event),
1205
+ outlook: generateOutlookCalendarUrl(event),
1206
+ office365: generateOffice365CalendarUrl(event),
1207
+ yahoo: generateYahooCalendarUrl(event),
1208
+ icsDataUri: generateIcsDataUri(event)
1209
+ };
1210
+ }
1211
+ __name(generateCalendarLinks, "generateCalendarLinks");
1212
+ function generateIcsContent(event, now = /* @__PURE__ */ new Date()) {
1213
+ const start = toIsoDate(event.startsAt);
1214
+ const end = event.endsAt ? toIsoDate(event.endsAt) : new Date(start.getTime() + 60 * 60 * 1e3);
1215
+ const uid = `${now.getTime()}-${Math.random().toString(36).substring(2, 9)}@adatechnology.com.br`;
1216
+ const lines = [
1217
+ "BEGIN:VCALENDAR",
1218
+ "VERSION:2.0",
1219
+ "PRODID:-//Ada Technology//Notification Calendar//PT",
1220
+ "CALSCALE:GREGORIAN",
1221
+ "METHOD:PUBLISH",
1222
+ "BEGIN:VEVENT",
1223
+ `UID:${uid}`,
1224
+ `DTSTAMP:${formatUtcCompact(now)}`,
1225
+ `DTSTART:${formatUtcCompact(start)}`,
1226
+ `DTEND:${formatUtcCompact(end)}`,
1227
+ `SUMMARY:${escapeIcsText(event.title)}`
1228
+ ];
1229
+ if (event.description) {
1230
+ lines.push(`DESCRIPTION:${escapeIcsText(event.description)}`);
1231
+ }
1232
+ if (event.location) {
1233
+ lines.push(`LOCATION:${escapeIcsText(event.location)}`);
1234
+ }
1235
+ if (event.url) {
1236
+ lines.push(`URL:${event.url}`);
1237
+ }
1238
+ lines.push("END:VEVENT", "END:VCALENDAR");
1239
+ return lines.join("\r\n");
1240
+ }
1241
+ __name(generateIcsContent, "generateIcsContent");
1242
+ function extractCalendarEvent(payload) {
1243
+ if (!payload || typeof payload !== "object") return void 0;
1244
+ const raw = payload.calendarEvent && typeof payload.calendarEvent === "object" ? payload.calendarEvent : payload;
1245
+ const title = typeof raw.calendarTitle === "string" ? raw.calendarTitle : typeof raw.title === "string" ? raw.title : void 0;
1246
+ const startsAt = typeof raw.calendarStartsAt === "string" ? raw.calendarStartsAt : raw.startsAt instanceof Date || typeof raw.startsAt === "string" ? raw.startsAt : typeof raw.activityDate === "string" ? typeof raw.activityTime === "string" ? `${raw.activityDate}T${raw.activityTime}:00` : `${raw.activityDate}T09:00:00` : void 0;
1247
+ if (!title || !startsAt) return void 0;
1248
+ const description = typeof raw.calendarDescription === "string" ? raw.calendarDescription : typeof raw.description === "string" ? raw.description : void 0;
1249
+ const endsAt = typeof raw.calendarEndsAt === "string" ? raw.calendarEndsAt : raw.endsAt instanceof Date || typeof raw.endsAt === "string" ? raw.endsAt : void 0;
1250
+ const location = typeof raw.location === "string" ? raw.location : void 0;
1251
+ const url = typeof raw.url === "string" ? raw.url : void 0;
1252
+ return {
1253
+ title,
1254
+ startsAt,
1255
+ ...description ? {
1256
+ description
1257
+ } : {},
1258
+ ...endsAt ? {
1259
+ endsAt
1260
+ } : {},
1261
+ ...location ? {
1262
+ location
1263
+ } : {},
1264
+ ...url ? {
1265
+ url
1266
+ } : {}
1267
+ };
1268
+ }
1269
+ __name(extractCalendarEvent, "extractCalendarEvent");
1112
1270
  // Annotate the CommonJS export names for ESM import in node:
1113
1271
  0 && (module.exports = {
1114
1272
  ChannelNotConfiguredError,
@@ -1166,8 +1324,16 @@ __name(renderStandardEmail, "renderStandardEmail");
1166
1324
  diffTemplateVariables,
1167
1325
  escapeEmailHtml,
1168
1326
  escapeTemplateHtml,
1327
+ extractCalendarEvent,
1169
1328
  extractTemplatePlaceholders,
1170
1329
  findUnsafeEmailHtml,
1330
+ generateCalendarLinks,
1331
+ generateGoogleCalendarUrl,
1332
+ generateIcsContent,
1333
+ generateIcsDataUri,
1334
+ generateOffice365CalendarUrl,
1335
+ generateOutlookCalendarUrl,
1336
+ generateYahooCalendarUrl,
1171
1337
  htmlToPlainText,
1172
1338
  interpolateEmailHtml,
1173
1339
  interpolateTemplate,