@adatechnology/notification-contracts 0.3.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 +281 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +682 -5
- package/dist/index.d.ts +682 -5
- package/dist/index.js +261 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -37,7 +37,8 @@ var DEVICE_PLATFORM = {
|
|
|
37
37
|
};
|
|
38
38
|
var PUSH_DRIVER = {
|
|
39
39
|
EXPO: "expo",
|
|
40
|
-
FCM: "fcm"
|
|
40
|
+
FCM: "fcm",
|
|
41
|
+
WEBPUSH: "webpush"
|
|
41
42
|
};
|
|
42
43
|
var EMAIL_DRIVER = {
|
|
43
44
|
SMTP: "smtp",
|
|
@@ -159,6 +160,64 @@ var deliveryWebhookSchema = z.object({
|
|
|
159
160
|
occurredAt: z.coerce.date(),
|
|
160
161
|
suppressionReason: z.nativeEnum(SUPPRESSION_REASON).optional()
|
|
161
162
|
});
|
|
163
|
+
var webPushKeysSchema = z.object({
|
|
164
|
+
p256dh: z.string().min(1),
|
|
165
|
+
auth: z.string().min(1)
|
|
166
|
+
});
|
|
167
|
+
var webPushSubscriptionSchema = z.object({
|
|
168
|
+
endpoint: z.string().url(),
|
|
169
|
+
keys: webPushKeysSchema,
|
|
170
|
+
expirationTime: z.number().nullable().optional()
|
|
171
|
+
});
|
|
172
|
+
var pushNotificationPayloadSchema = z.object({
|
|
173
|
+
title: z.string().min(1).max(256),
|
|
174
|
+
body: z.string().min(1).max(4096),
|
|
175
|
+
icon: z.string().url().optional(),
|
|
176
|
+
badge: z.number().int().nonnegative().optional(),
|
|
177
|
+
image: z.string().url().optional(),
|
|
178
|
+
tag: z.string().max(64).optional(),
|
|
179
|
+
url: z.string().optional(),
|
|
180
|
+
data: z.record(z.unknown()).optional()
|
|
181
|
+
});
|
|
182
|
+
var sendPushDirectTargetSchema = z.discriminatedUnion("type", [
|
|
183
|
+
z.object({
|
|
184
|
+
type: z.literal("token"),
|
|
185
|
+
token: z.string().min(1),
|
|
186
|
+
platform: z.nativeEnum(DEVICE_PLATFORM),
|
|
187
|
+
driver: z.nativeEnum(PUSH_DRIVER).optional()
|
|
188
|
+
}),
|
|
189
|
+
z.object({
|
|
190
|
+
type: z.literal("user"),
|
|
191
|
+
userId: z.string().min(1)
|
|
192
|
+
}),
|
|
193
|
+
z.object({
|
|
194
|
+
type: z.literal("subscription"),
|
|
195
|
+
subscription: webPushSubscriptionSchema
|
|
196
|
+
})
|
|
197
|
+
]);
|
|
198
|
+
var sendPushDirectSchema = z.object({
|
|
199
|
+
target: sendPushDirectTargetSchema,
|
|
200
|
+
notification: pushNotificationPayloadSchema,
|
|
201
|
+
dedupeKey: z.string().max(256).optional()
|
|
202
|
+
});
|
|
203
|
+
var broadcastPushFilterSchema = z.object({
|
|
204
|
+
topic: z.string().max(128).optional(),
|
|
205
|
+
tags: z.array(z.string().max(64)).optional(),
|
|
206
|
+
platform: z.nativeEnum(DEVICE_PLATFORM).optional()
|
|
207
|
+
});
|
|
208
|
+
var broadcastPushSchema = z.object({
|
|
209
|
+
filter: broadcastPushFilterSchema.optional(),
|
|
210
|
+
notification: pushNotificationPayloadSchema
|
|
211
|
+
});
|
|
212
|
+
var registerPushSubscriptionSchema = z.object({
|
|
213
|
+
platform: z.nativeEnum(DEVICE_PLATFORM),
|
|
214
|
+
driver: z.nativeEnum(PUSH_DRIVER),
|
|
215
|
+
subscription: webPushSubscriptionSchema,
|
|
216
|
+
appVersion: z.string().max(32).optional(),
|
|
217
|
+
locale: z.string().min(2).max(16).optional(),
|
|
218
|
+
timezone: z.string().min(1).max(64).optional(),
|
|
219
|
+
tags: z.array(z.string().max(64)).optional()
|
|
220
|
+
});
|
|
162
221
|
|
|
163
222
|
// src/events.ts
|
|
164
223
|
var NOTIFICATION_EVENT = {
|
|
@@ -197,7 +256,10 @@ var NOTIFICATION_ERROR_CODES = {
|
|
|
197
256
|
DEVICE_NOT_FOUND: "NOTIFICATION_DEVICE_NOT_FOUND",
|
|
198
257
|
THROTTLED: "NOTIFICATION_THROTTLED",
|
|
199
258
|
CONFIG_MISSING: "NOTIFICATION_CONFIG_MISSING",
|
|
200
|
-
TEMPLATE_UNKNOWN_VARIABLE: "NOTIFICATION_TEMPLATE_UNKNOWN_VARIABLE"
|
|
259
|
+
TEMPLATE_UNKNOWN_VARIABLE: "NOTIFICATION_TEMPLATE_UNKNOWN_VARIABLE",
|
|
260
|
+
WEBPUSH_ENCRYPTION_FAILED: "NOTIFICATION_WEBPUSH_ENCRYPTION_FAILED",
|
|
261
|
+
INVALID_VAPID_KEYS: "NOTIFICATION_INVALID_VAPID_KEYS",
|
|
262
|
+
SUBSCRIPTION_NOT_FOUND: "NOTIFICATION_SUBSCRIPTION_NOT_FOUND"
|
|
201
263
|
};
|
|
202
264
|
var TemplateIdNotFoundError = class extends NotificationError {
|
|
203
265
|
static {
|
|
@@ -346,6 +408,33 @@ var ConfigMissingError = class extends NotificationError {
|
|
|
346
408
|
}), this.field = field;
|
|
347
409
|
}
|
|
348
410
|
};
|
|
411
|
+
var WebPushEncryptionError = class extends NotificationError {
|
|
412
|
+
static {
|
|
413
|
+
__name(this, "WebPushEncryptionError");
|
|
414
|
+
}
|
|
415
|
+
constructor(message, details) {
|
|
416
|
+
super(message, 500, NOTIFICATION_ERROR_CODES.WEBPUSH_ENCRYPTION_FAILED, details);
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
var InvalidVapidKeysError = class extends NotificationError {
|
|
420
|
+
static {
|
|
421
|
+
__name(this, "InvalidVapidKeysError");
|
|
422
|
+
}
|
|
423
|
+
constructor(message) {
|
|
424
|
+
super(message, 500, NOTIFICATION_ERROR_CODES.INVALID_VAPID_KEYS);
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
var SubscriptionNotFoundError = class extends NotificationError {
|
|
428
|
+
static {
|
|
429
|
+
__name(this, "SubscriptionNotFoundError");
|
|
430
|
+
}
|
|
431
|
+
endpoint;
|
|
432
|
+
constructor(endpoint) {
|
|
433
|
+
super(`Assinatura de push n\xE3o encontrada.`, 404, NOTIFICATION_ERROR_CODES.SUBSCRIPTION_NOT_FOUND, {
|
|
434
|
+
endpoint
|
|
435
|
+
}), this.endpoint = endpoint;
|
|
436
|
+
}
|
|
437
|
+
};
|
|
349
438
|
|
|
350
439
|
// src/whatsappDriver.ts
|
|
351
440
|
var INVALID_TARGET_CODES = /* @__PURE__ */ new Set([
|
|
@@ -920,6 +1009,156 @@ function renderStandardEmail(params) {
|
|
|
920
1009
|
};
|
|
921
1010
|
}
|
|
922
1011
|
__name(renderStandardEmail, "renderStandardEmail");
|
|
1012
|
+
|
|
1013
|
+
// src/calendarEvent.ts
|
|
1014
|
+
function toIsoDate(value) {
|
|
1015
|
+
return value instanceof Date ? value : new Date(value);
|
|
1016
|
+
}
|
|
1017
|
+
__name(toIsoDate, "toIsoDate");
|
|
1018
|
+
function formatUtcCompact(date) {
|
|
1019
|
+
return date.toISOString().replace(/[-:]/g, "").replace(/\.\d{3}/, "");
|
|
1020
|
+
}
|
|
1021
|
+
__name(formatUtcCompact, "formatUtcCompact");
|
|
1022
|
+
function escapeIcsText(text) {
|
|
1023
|
+
return text.replace(/\\/g, "\\\\").replace(/;/g, "\\;").replace(/,/g, "\\,").replace(/\r\n/g, "\\n").replace(/\n/g, "\\n");
|
|
1024
|
+
}
|
|
1025
|
+
__name(escapeIcsText, "escapeIcsText");
|
|
1026
|
+
function generateGoogleCalendarUrl(event) {
|
|
1027
|
+
const start = toIsoDate(event.startsAt);
|
|
1028
|
+
const end = event.endsAt ? toIsoDate(event.endsAt) : new Date(start.getTime() + 60 * 60 * 1e3);
|
|
1029
|
+
const params = new URLSearchParams({
|
|
1030
|
+
action: "TEMPLATE",
|
|
1031
|
+
text: event.title,
|
|
1032
|
+
dates: `${formatUtcCompact(start)}/${formatUtcCompact(end)}`
|
|
1033
|
+
});
|
|
1034
|
+
if (event.description) params.set("details", event.description);
|
|
1035
|
+
if (event.location) params.set("location", event.location);
|
|
1036
|
+
return `https://calendar.google.com/calendar/render?${params.toString()}`;
|
|
1037
|
+
}
|
|
1038
|
+
__name(generateGoogleCalendarUrl, "generateGoogleCalendarUrl");
|
|
1039
|
+
function generateOutlookCalendarUrl(event) {
|
|
1040
|
+
const start = toIsoDate(event.startsAt);
|
|
1041
|
+
const end = event.endsAt ? toIsoDate(event.endsAt) : new Date(start.getTime() + 60 * 60 * 1e3);
|
|
1042
|
+
const params = new URLSearchParams({
|
|
1043
|
+
path: "/calendar/action/compose",
|
|
1044
|
+
rru: "addevent",
|
|
1045
|
+
subject: event.title,
|
|
1046
|
+
startdt: start.toISOString(),
|
|
1047
|
+
enddt: end.toISOString()
|
|
1048
|
+
});
|
|
1049
|
+
if (event.description) params.set("body", event.description);
|
|
1050
|
+
if (event.location) params.set("location", event.location);
|
|
1051
|
+
return `https://outlook.live.com/calendar/0/deeplink/compose?${params.toString()}`;
|
|
1052
|
+
}
|
|
1053
|
+
__name(generateOutlookCalendarUrl, "generateOutlookCalendarUrl");
|
|
1054
|
+
function generateOffice365CalendarUrl(event) {
|
|
1055
|
+
const start = toIsoDate(event.startsAt);
|
|
1056
|
+
const end = event.endsAt ? toIsoDate(event.endsAt) : new Date(start.getTime() + 60 * 60 * 1e3);
|
|
1057
|
+
const params = new URLSearchParams({
|
|
1058
|
+
path: "/calendar/action/compose",
|
|
1059
|
+
rru: "addevent",
|
|
1060
|
+
subject: event.title,
|
|
1061
|
+
startdt: start.toISOString(),
|
|
1062
|
+
enddt: end.toISOString()
|
|
1063
|
+
});
|
|
1064
|
+
if (event.description) params.set("body", event.description);
|
|
1065
|
+
if (event.location) params.set("location", event.location);
|
|
1066
|
+
return `https://outlook.office.com/calendar/0/deeplink/compose?${params.toString()}`;
|
|
1067
|
+
}
|
|
1068
|
+
__name(generateOffice365CalendarUrl, "generateOffice365CalendarUrl");
|
|
1069
|
+
function generateYahooCalendarUrl(event) {
|
|
1070
|
+
const start = toIsoDate(event.startsAt);
|
|
1071
|
+
const end = event.endsAt ? toIsoDate(event.endsAt) : new Date(start.getTime() + 60 * 60 * 1e3);
|
|
1072
|
+
const durationMs = Math.max(0, end.getTime() - start.getTime());
|
|
1073
|
+
const durationHours = Math.floor(durationMs / (60 * 60 * 1e3));
|
|
1074
|
+
const durationMinutes = Math.floor(durationMs % (60 * 60 * 1e3) / (60 * 1e3));
|
|
1075
|
+
const durStr = `${String(durationHours).padStart(2, "0")}${String(durationMinutes).padStart(2, "0")}`;
|
|
1076
|
+
const params = new URLSearchParams({
|
|
1077
|
+
v: "60",
|
|
1078
|
+
view: "d",
|
|
1079
|
+
type: "20",
|
|
1080
|
+
title: event.title,
|
|
1081
|
+
st: formatUtcCompact(start),
|
|
1082
|
+
dur: durStr
|
|
1083
|
+
});
|
|
1084
|
+
if (event.description) params.set("desc", event.description);
|
|
1085
|
+
if (event.location) params.set("in_loc", event.location);
|
|
1086
|
+
return `https://calendar.yahoo.com/?${params.toString()}`;
|
|
1087
|
+
}
|
|
1088
|
+
__name(generateYahooCalendarUrl, "generateYahooCalendarUrl");
|
|
1089
|
+
function generateIcsDataUri(event, now = /* @__PURE__ */ new Date()) {
|
|
1090
|
+
const ics = generateIcsContent(event, now);
|
|
1091
|
+
return `data:text/calendar;charset=utf-8,${encodeURIComponent(ics)}`;
|
|
1092
|
+
}
|
|
1093
|
+
__name(generateIcsDataUri, "generateIcsDataUri");
|
|
1094
|
+
function generateCalendarLinks(event) {
|
|
1095
|
+
return {
|
|
1096
|
+
google: generateGoogleCalendarUrl(event),
|
|
1097
|
+
outlook: generateOutlookCalendarUrl(event),
|
|
1098
|
+
office365: generateOffice365CalendarUrl(event),
|
|
1099
|
+
yahoo: generateYahooCalendarUrl(event),
|
|
1100
|
+
icsDataUri: generateIcsDataUri(event)
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
__name(generateCalendarLinks, "generateCalendarLinks");
|
|
1104
|
+
function generateIcsContent(event, now = /* @__PURE__ */ new Date()) {
|
|
1105
|
+
const start = toIsoDate(event.startsAt);
|
|
1106
|
+
const end = event.endsAt ? toIsoDate(event.endsAt) : new Date(start.getTime() + 60 * 60 * 1e3);
|
|
1107
|
+
const uid = `${now.getTime()}-${Math.random().toString(36).substring(2, 9)}@adatechnology.com.br`;
|
|
1108
|
+
const lines = [
|
|
1109
|
+
"BEGIN:VCALENDAR",
|
|
1110
|
+
"VERSION:2.0",
|
|
1111
|
+
"PRODID:-//Ada Technology//Notification Calendar//PT",
|
|
1112
|
+
"CALSCALE:GREGORIAN",
|
|
1113
|
+
"METHOD:PUBLISH",
|
|
1114
|
+
"BEGIN:VEVENT",
|
|
1115
|
+
`UID:${uid}`,
|
|
1116
|
+
`DTSTAMP:${formatUtcCompact(now)}`,
|
|
1117
|
+
`DTSTART:${formatUtcCompact(start)}`,
|
|
1118
|
+
`DTEND:${formatUtcCompact(end)}`,
|
|
1119
|
+
`SUMMARY:${escapeIcsText(event.title)}`
|
|
1120
|
+
];
|
|
1121
|
+
if (event.description) {
|
|
1122
|
+
lines.push(`DESCRIPTION:${escapeIcsText(event.description)}`);
|
|
1123
|
+
}
|
|
1124
|
+
if (event.location) {
|
|
1125
|
+
lines.push(`LOCATION:${escapeIcsText(event.location)}`);
|
|
1126
|
+
}
|
|
1127
|
+
if (event.url) {
|
|
1128
|
+
lines.push(`URL:${event.url}`);
|
|
1129
|
+
}
|
|
1130
|
+
lines.push("END:VEVENT", "END:VCALENDAR");
|
|
1131
|
+
return lines.join("\r\n");
|
|
1132
|
+
}
|
|
1133
|
+
__name(generateIcsContent, "generateIcsContent");
|
|
1134
|
+
function extractCalendarEvent(payload) {
|
|
1135
|
+
if (!payload || typeof payload !== "object") return void 0;
|
|
1136
|
+
const raw = payload.calendarEvent && typeof payload.calendarEvent === "object" ? payload.calendarEvent : payload;
|
|
1137
|
+
const title = typeof raw.calendarTitle === "string" ? raw.calendarTitle : typeof raw.title === "string" ? raw.title : void 0;
|
|
1138
|
+
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;
|
|
1139
|
+
if (!title || !startsAt) return void 0;
|
|
1140
|
+
const description = typeof raw.calendarDescription === "string" ? raw.calendarDescription : typeof raw.description === "string" ? raw.description : void 0;
|
|
1141
|
+
const endsAt = typeof raw.calendarEndsAt === "string" ? raw.calendarEndsAt : raw.endsAt instanceof Date || typeof raw.endsAt === "string" ? raw.endsAt : void 0;
|
|
1142
|
+
const location = typeof raw.location === "string" ? raw.location : void 0;
|
|
1143
|
+
const url = typeof raw.url === "string" ? raw.url : void 0;
|
|
1144
|
+
return {
|
|
1145
|
+
title,
|
|
1146
|
+
startsAt,
|
|
1147
|
+
...description ? {
|
|
1148
|
+
description
|
|
1149
|
+
} : {},
|
|
1150
|
+
...endsAt ? {
|
|
1151
|
+
endsAt
|
|
1152
|
+
} : {},
|
|
1153
|
+
...location ? {
|
|
1154
|
+
location
|
|
1155
|
+
} : {},
|
|
1156
|
+
...url ? {
|
|
1157
|
+
url
|
|
1158
|
+
} : {}
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1161
|
+
__name(extractCalendarEvent, "extractCalendarEvent");
|
|
923
1162
|
export {
|
|
924
1163
|
ChannelNotConfiguredError,
|
|
925
1164
|
ConfigMissingError,
|
|
@@ -931,6 +1170,7 @@ export {
|
|
|
931
1170
|
EMAIL_ATTACHMENT_MAX_COUNT,
|
|
932
1171
|
EMAIL_DRIVER,
|
|
933
1172
|
INTRUSIVE_CHANNELS,
|
|
1173
|
+
InvalidVapidKeysError,
|
|
934
1174
|
InvalidWebhookSignatureError,
|
|
935
1175
|
NOTIFICATION_CATEGORY_HINT,
|
|
936
1176
|
NOTIFICATION_CHANNEL,
|
|
@@ -953,6 +1193,7 @@ export {
|
|
|
953
1193
|
STANDARD_EMAIL_THEME,
|
|
954
1194
|
STANDARD_EMAIL_VARIABLES,
|
|
955
1195
|
SUPPRESSION_REASON,
|
|
1196
|
+
SubscriptionNotFoundError,
|
|
956
1197
|
SuppressedTargetError,
|
|
957
1198
|
TEMPLATE_CONSTRAINTS_BY_CHANNEL,
|
|
958
1199
|
TEMPLATE_VARIABLE_KIND,
|
|
@@ -960,7 +1201,10 @@ export {
|
|
|
960
1201
|
TemplateNotFoundError,
|
|
961
1202
|
ThrottledError,
|
|
962
1203
|
UnknownTemplateVariablesError,
|
|
1204
|
+
WebPushEncryptionError,
|
|
963
1205
|
assessStandardEmailTemplate,
|
|
1206
|
+
broadcastPushFilterSchema,
|
|
1207
|
+
broadcastPushSchema,
|
|
964
1208
|
buildInitials,
|
|
965
1209
|
buildPreviewPayload,
|
|
966
1210
|
categoryPolicyEntrySchema,
|
|
@@ -971,21 +1215,35 @@ export {
|
|
|
971
1215
|
diffTemplateVariables,
|
|
972
1216
|
escapeEmailHtml,
|
|
973
1217
|
escapeTemplateHtml,
|
|
1218
|
+
extractCalendarEvent,
|
|
974
1219
|
extractTemplatePlaceholders,
|
|
975
1220
|
findUnsafeEmailHtml,
|
|
1221
|
+
generateCalendarLinks,
|
|
1222
|
+
generateGoogleCalendarUrl,
|
|
1223
|
+
generateIcsContent,
|
|
1224
|
+
generateIcsDataUri,
|
|
1225
|
+
generateOffice365CalendarUrl,
|
|
1226
|
+
generateOutlookCalendarUrl,
|
|
1227
|
+
generateYahooCalendarUrl,
|
|
976
1228
|
htmlToPlainText,
|
|
977
1229
|
interpolateEmailHtml,
|
|
978
1230
|
interpolateTemplate,
|
|
979
1231
|
listNotificationsQuerySchema,
|
|
980
1232
|
preferenceEntrySchema,
|
|
1233
|
+
pushNotificationPayloadSchema,
|
|
981
1234
|
registerDeviceSchema,
|
|
1235
|
+
registerPushSubscriptionSchema,
|
|
982
1236
|
renderEmailLogoHtml,
|
|
983
1237
|
renderEmailMarksHtml,
|
|
984
1238
|
renderStandardEmail,
|
|
985
1239
|
renderTemplate,
|
|
986
1240
|
sendNotificationSchema,
|
|
1241
|
+
sendPushDirectSchema,
|
|
1242
|
+
sendPushDirectTargetSchema,
|
|
987
1243
|
updateCategoryPoliciesSchema,
|
|
988
1244
|
updatePreferencesSchema,
|
|
989
|
-
upsertTemplateSchema
|
|
1245
|
+
upsertTemplateSchema,
|
|
1246
|
+
webPushKeysSchema,
|
|
1247
|
+
webPushSubscriptionSchema
|
|
990
1248
|
};
|
|
991
1249
|
//# sourceMappingURL=index.js.map
|