90dc-core 1.14.4 → 1.15.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.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/clients/EmailClient.d.ts +44 -0
- package/dist/lib/clients/EmailClient.d.ts.map +1 -0
- package/dist/lib/clients/EmailClient.js +154 -0
- package/dist/lib/clients/EmailClient.js.map +1 -0
- package/dist/lib/clients/PushNotificationClient.d.ts +77 -0
- package/dist/lib/clients/PushNotificationClient.d.ts.map +1 -0
- package/dist/lib/clients/PushNotificationClient.js +467 -0
- package/dist/lib/clients/PushNotificationClient.js.map +1 -0
- package/dist/lib/clients/index.d.ts +5 -0
- package/dist/lib/clients/index.d.ts.map +1 -0
- package/dist/lib/clients/index.js +4 -0
- package/dist/lib/clients/index.js.map +1 -0
- package/dist/lib/config/ConfigValidator.d.ts +21 -0
- package/dist/lib/config/ConfigValidator.d.ts.map +1 -1
- package/dist/lib/config/ConfigValidator.js +23 -0
- package/dist/lib/config/ConfigValidator.js.map +1 -1
- package/dist/lib/utils/NotificationsUtil.d.ts +8 -26
- package/dist/lib/utils/NotificationsUtil.d.ts.map +1 -1
- package/dist/lib/utils/NotificationsUtil.js +27 -170
- package/dist/lib/utils/NotificationsUtil.js.map +1 -1
- package/package.json +1 -1
- package/dist/lib/dbmodels/diet/DietDayBlueprint.d.ts +0 -30
- package/dist/lib/dbmodels/diet/DietDayBlueprint.d.ts.map +0 -1
- package/dist/lib/dbmodels/diet/DietDayBlueprint.js +0 -64
- package/dist/lib/dbmodels/diet/DietDayBlueprint.js.map +0 -1
- package/dist/lib/dbmodels/diet/DietProgramBlueprint.d.ts +0 -17
- package/dist/lib/dbmodels/diet/DietProgramBlueprint.d.ts.map +0 -1
- package/dist/lib/dbmodels/diet/DietProgramBlueprint.js +0 -82
- package/dist/lib/dbmodels/diet/DietProgramBlueprint.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from "./lib/models/WorkoutInterfaces.js";
|
|
|
4
4
|
export * from "./lib/models/UserInterfaces.js";
|
|
5
5
|
export * from "./lib/models/NotificationInterfaces.js";
|
|
6
6
|
export * from "./lib/dbmodels/index.js";
|
|
7
|
+
export { EmailClient, PushNotificationClient, type SendTemplateEmailRequest, type BatchTemplateEmailRequest, type EmailResponse, type NotificationPayload, } from "./lib/clients/index.js";
|
|
7
8
|
export { AuthenticationUtil } from "./lib/utils/AuthenticationUtil.js";
|
|
8
9
|
export { NotificationsUtil } from "./lib/utils/NotificationsUtil.js";
|
|
9
10
|
export { NotificationClient } from "./lib/utils/NotificationClient.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC;AACnD,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,wCAAwC,CAAC;AAGvD,cAAc,yBAAyB,CAAA;AAGvC,OAAO,EAAC,kBAAkB,EAAC,MAAM,mCAAmC,CAAA;AACpE,OAAO,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAA;AAClE,OAAO,EAAC,kBAAkB,EAAC,MAAM,mCAAmC,CAAA;AACpE,OAAO,EAAC,GAAG,EAAC,MAAM,uBAAuB,CAAA;AACzC,OAAO,EAAC,aAAa,EAAC,MAAM,8BAA8B,CAAA;AAC1D,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,KAAK,kBAAkB,EACvB,KAAK,aAAa,GACnB,MAAM,2BAA2B,CAAA;AAGlC,OAAO,EACL,iBAAiB,EACjB,cAA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,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAGvF,OAAO,EAAC,WAAW,EAAC,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAC,cAAc,EAAE,KAAK,cAAc,EAAC,MAAM,2BAA2B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,8 @@ export * from "./lib/models/UserInterfaces.js";
|
|
|
6
6
|
export * from "./lib/models/NotificationInterfaces.js";
|
|
7
7
|
//DB Models - Export all models and model arrays
|
|
8
8
|
export * from "./lib/dbmodels/index.js";
|
|
9
|
+
//Clients
|
|
10
|
+
export { EmailClient, PushNotificationClient } from "./lib/clients";
|
|
9
11
|
//Utils
|
|
10
12
|
export { AuthenticationUtil } from "./lib/utils/AuthenticationUtil.js";
|
|
11
13
|
export { NotificationsUtil } from "./lib/utils/NotificationsUtil.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["//Interfaces\nexport * from \"./lib/models/ProgramInterfaces.js\";\nexport * from \"./lib/models/ExerciseInterfaces.js\";\nexport * from \"./lib/models/WorkoutInterfaces.js\";\nexport * from \"./lib/models/UserInterfaces.js\";\nexport * from \"./lib/models/NotificationInterfaces.js\";\n\n//DB Models - Export all models and model arrays\nexport * from \"./lib/dbmodels/index.js\"\n\n//Utils\nexport {AuthenticationUtil} from \"./lib/utils/AuthenticationUtil.js\"\nexport {NotificationsUtil} from \"./lib/utils/NotificationsUtil.js\"\nexport {NotificationClient} from \"./lib/utils/NotificationClient.js\"\nexport {Log} from \"./lib/utils/Logger.js\"\nexport {SecretManager} from \"./lib/utils/SecretManager.js\"\nexport {\n initializeSentry,\n isSentryEnabled,\n scrubObject,\n captureRequestBody,\n extractUserContext,\n buildRequestContext,\n buildResponseContext,\n reportErrorToSentry,\n reportMessageToSentry,\n type ErrorReportOptions,\n type SeverityLevel,\n} from \"./lib/utils/SentryUtil.js\"\n\n//Testing Utilities\nexport {\n createMockContext,\n createMockUser,\n createAuthenticatedContext,\n mockDatabase,\n flushPromises,\n assertions,\n executeRoute,\n type BaseContext,\n type AuthenticatedContext,\n type RouterContext,\n type RouterMiddleware,\n type RouterLayer,\n type RouterLike,\n type SequelizeModelMethods,\n} from \"./lib/testing/testHelpers.js\"\n\n//Config\nexport {\n ConfigValidator,\n BaseConfigSchema,\n CommonSchemas,\n createConfig,\n ConfigurationError,\n type BaseConfig\n} from \"./lib/config/ConfigValidator.js\"\n\n//Errors\nexport {\n AppError,\n ValidationError,\n AuthenticationError,\n ForbiddenError,\n NotFoundError,\n ConflictError,\n UnprocessableEntityError,\n RateLimitError,\n InternalServerError,\n ServiceUnavailableError,\n DatabaseError,\n ExternalAPIError,\n isAppError,\n isOperationalError,\n toAppError\n} from \"./lib/Errors/AppError.js\"\n\n//Middlewares\nexport {\n ErrorMiddleware,\n} from \"./lib/middlewares/ErrorMiddleware.js\"\nexport { validate, type ValidationConfig } from \"./lib/middlewares/ValidationMiddleware.js\";\n\n//Controllers\nexport { BaseController, type RouteConfig } from \"./lib/controllers/BaseController.js\";\n\n\nexport {RedisClient} from \"./lib/classes/Redis.js\"\nexport {DatabaseClient, type DatabaseConfig} from \"./lib/classes/Database.js\""],"names":["AuthenticationUtil","NotificationsUtil","NotificationClient","Log","SecretManager","initializeSentry","isSentryEnabled","scrubObject","captureRequestBody","extractUserContext","buildRequestContext","buildResponseContext","reportErrorToSentry","reportMessageToSentry","createMockContext","createMockUser","createAuthenticatedContext","mockDatabase","flushPromises","assertions","executeRoute","ConfigValidator","BaseConfigSchema","CommonSchemas","createConfig","ConfigurationError","AppError","ValidationError","AuthenticationError","ForbiddenError","NotFoundError","ConflictError","UnprocessableEntityError","RateLimitError","InternalServerError","ServiceUnavailableError","DatabaseError","ExternalAPIError","isAppError","isOperationalError","toAppError","ErrorMiddleware","validate","BaseController","RedisClient","DatabaseClient"],"mappings":"AAAA,YAAY;AACZ,cAAc,oCAAoC;AAClD,cAAc,qCAAqC;AACnD,cAAc,oCAAoC;AAClD,cAAc,iCAAiC;AAC/C,cAAc,yCAAyC;AAEvD,gDAAgD;AAChD,cAAc,iBAAyB;AAEvC,OAAO;AACP,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["//Interfaces\nexport * from \"./lib/models/ProgramInterfaces.js\";\nexport * from \"./lib/models/ExerciseInterfaces.js\";\nexport * from \"./lib/models/WorkoutInterfaces.js\";\nexport * from \"./lib/models/UserInterfaces.js\";\nexport * from \"./lib/models/NotificationInterfaces.js\";\n\n//DB Models - Export all models and model arrays\nexport * from \"./lib/dbmodels/index.js\"\n\n//Clients\nexport {\n EmailClient,\n PushNotificationClient,\n type SendTemplateEmailRequest,\n type BatchTemplateEmailRequest,\n type EmailResponse,\n type NotificationPayload,\n} from \"./lib/clients/index.js\"\n\n//Utils\nexport {AuthenticationUtil} from \"./lib/utils/AuthenticationUtil.js\"\nexport {NotificationsUtil} from \"./lib/utils/NotificationsUtil.js\"\nexport {NotificationClient} from \"./lib/utils/NotificationClient.js\"\nexport {Log} from \"./lib/utils/Logger.js\"\nexport {SecretManager} from \"./lib/utils/SecretManager.js\"\nexport {\n initializeSentry,\n isSentryEnabled,\n scrubObject,\n captureRequestBody,\n extractUserContext,\n buildRequestContext,\n buildResponseContext,\n reportErrorToSentry,\n reportMessageToSentry,\n type ErrorReportOptions,\n type SeverityLevel,\n} from \"./lib/utils/SentryUtil.js\"\n\n//Testing Utilities\nexport {\n createMockContext,\n createMockUser,\n createAuthenticatedContext,\n mockDatabase,\n flushPromises,\n assertions,\n executeRoute,\n type BaseContext,\n type AuthenticatedContext,\n type RouterContext,\n type RouterMiddleware,\n type RouterLayer,\n type RouterLike,\n type SequelizeModelMethods,\n} from \"./lib/testing/testHelpers.js\"\n\n//Config\nexport {\n ConfigValidator,\n BaseConfigSchema,\n CommonSchemas,\n createConfig,\n ConfigurationError,\n type BaseConfig\n} from \"./lib/config/ConfigValidator.js\"\n\n//Errors\nexport {\n AppError,\n ValidationError,\n AuthenticationError,\n ForbiddenError,\n NotFoundError,\n ConflictError,\n UnprocessableEntityError,\n RateLimitError,\n InternalServerError,\n ServiceUnavailableError,\n DatabaseError,\n ExternalAPIError,\n isAppError,\n isOperationalError,\n toAppError\n} from \"./lib/Errors/AppError.js\"\n\n//Middlewares\nexport {\n ErrorMiddleware,\n} from \"./lib/middlewares/ErrorMiddleware.js\"\nexport { validate, type ValidationConfig } from \"./lib/middlewares/ValidationMiddleware.js\";\n\n//Controllers\nexport { BaseController, type RouteConfig } from \"./lib/controllers/BaseController.js\";\n\n\nexport {RedisClient} from \"./lib/classes/Redis.js\"\nexport {DatabaseClient, type DatabaseConfig} from \"./lib/classes/Database.js\""],"names":["EmailClient","PushNotificationClient","AuthenticationUtil","NotificationsUtil","NotificationClient","Log","SecretManager","initializeSentry","isSentryEnabled","scrubObject","captureRequestBody","extractUserContext","buildRequestContext","buildResponseContext","reportErrorToSentry","reportMessageToSentry","createMockContext","createMockUser","createAuthenticatedContext","mockDatabase","flushPromises","assertions","executeRoute","ConfigValidator","BaseConfigSchema","CommonSchemas","createConfig","ConfigurationError","AppError","ValidationError","AuthenticationError","ForbiddenError","NotFoundError","ConflictError","UnprocessableEntityError","RateLimitError","InternalServerError","ServiceUnavailableError","DatabaseError","ExternalAPIError","isAppError","isOperationalError","toAppError","ErrorMiddleware","validate","BaseController","RedisClient","DatabaseClient"],"mappings":"AAAA,YAAY;AACZ,cAAc,oCAAoC;AAClD,cAAc,qCAAqC;AACnD,cAAc,oCAAoC;AAClD,cAAc,iCAAiC;AAC/C,cAAc,yCAAyC;AAEvD,gDAAgD;AAChD,cAAc,iBAAyB;AAEvC,SAAS;AACT,SACEA,WAAW,EACXC,sBAAsB,QAKjB,gBAAwB;AAE/B,OAAO;AACP,SAAQC,kBAAkB,QAAO,oCAAmC;AACpE,SAAQC,iBAAiB,QAAO,mCAAkC;AAClE,SAAQC,kBAAkB,QAAO,oCAAmC;AACpE,SAAQC,GAAG,QAAO,wBAAuB;AACzC,SAAQC,aAAa,QAAO,+BAA8B;AAC1D,SACEC,gBAAgB,EAChBC,eAAe,EACfC,WAAW,EACXC,kBAAkB,EAClBC,kBAAkB,EAClBC,mBAAmB,EACnBC,oBAAoB,EACpBC,mBAAmB,EACnBC,qBAAqB,QAGhB,4BAA2B;AAElC,mBAAmB;AACnB,SACEC,iBAAiB,EACjBC,cAAc,EACdC,0BAA0B,EAC1BC,YAAY,EACZC,aAAa,EACbC,UAAU,EACVC,YAAY,QAQP,+BAA8B;AAErC,QAAQ;AACR,SACEC,eAAe,EACfC,gBAAgB,EAChBC,aAAa,EACbC,YAAY,EACZC,kBAAkB,QAEb,kCAAiC;AAExC,QAAQ;AACR,SACEC,QAAQ,EACRC,eAAe,EACfC,mBAAmB,EACnBC,cAAc,EACdC,aAAa,EACbC,aAAa,EACbC,wBAAwB,EACxBC,cAAc,EACdC,mBAAmB,EACnBC,uBAAuB,EACvBC,aAAa,EACbC,gBAAgB,EAChBC,UAAU,EACVC,kBAAkB,EAClBC,UAAU,QACL,2BAA0B;AAEjC,aAAa;AACb,SACEC,eAAe,QACV,uCAAsC;AAC7C,SAASC,QAAQ,QAA+B,4CAA4C;AAE5F,aAAa;AACb,SAASC,cAAc,QAA0B,sCAAsC;AAGvF,SAAQC,WAAW,QAAO,yBAAwB;AAClD,SAAQC,cAAc,QAA4B,4BAA2B"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface SendTemplateEmailRequest {
|
|
2
|
+
to: string | string[];
|
|
3
|
+
templateId: string | number;
|
|
4
|
+
templateData: Record<string, any>;
|
|
5
|
+
cc?: string | string[];
|
|
6
|
+
bcc?: string | string[];
|
|
7
|
+
replyTo?: string;
|
|
8
|
+
tag?: string;
|
|
9
|
+
metadata?: Record<string, string>;
|
|
10
|
+
trackOpens?: boolean;
|
|
11
|
+
trackLinks?: "None" | "HtmlAndText" | "HtmlOnly" | "TextOnly";
|
|
12
|
+
}
|
|
13
|
+
export interface BatchTemplateEmailRequest {
|
|
14
|
+
emails: Array<{
|
|
15
|
+
to: string;
|
|
16
|
+
templateId: string | number;
|
|
17
|
+
templateData: Record<string, any>;
|
|
18
|
+
tag?: string;
|
|
19
|
+
metadata?: Record<string, string>;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
export interface EmailResponse {
|
|
23
|
+
messageId: string;
|
|
24
|
+
to: string;
|
|
25
|
+
submittedAt: string;
|
|
26
|
+
errorCode?: number;
|
|
27
|
+
message?: string;
|
|
28
|
+
}
|
|
29
|
+
export declare class EmailClient {
|
|
30
|
+
private static instance;
|
|
31
|
+
private client;
|
|
32
|
+
private config;
|
|
33
|
+
private logger;
|
|
34
|
+
private constructor();
|
|
35
|
+
static getInstance(): EmailClient;
|
|
36
|
+
static resetInstance(): void;
|
|
37
|
+
sendWithTemplate(request: SendTemplateEmailRequest): Promise<EmailResponse>;
|
|
38
|
+
sendBatchWithTemplate(request: BatchTemplateEmailRequest): Promise<EmailResponse[]>;
|
|
39
|
+
sendPasswordReset(to: string, resetToken: string, userName: string): Promise<EmailResponse>;
|
|
40
|
+
sendEmailConfirmation(to: string, confirmToken: string, userName: string): Promise<EmailResponse>;
|
|
41
|
+
sendWelcome(to: string, userName: string): Promise<EmailResponse>;
|
|
42
|
+
private handleError;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=EmailClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EmailClient.d.ts","sourceRoot":"","sources":["../../../src/lib/clients/EmailClient.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,wBAAwB;IACvC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACtB,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAClC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACvB,GAAG,CAAC,EAAE,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QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAa3F,qBAAqB,CAAC,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAajG,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAS9E,OAAO,CAAC,WAAW;CAwBpB"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { CommonSchemas } from "../config/ConfigValidator.js";
|
|
3
|
+
import { ExternalAPIError } from "../Errors/AppError.js";
|
|
4
|
+
import { Log } from "../utils/Logger.js";
|
|
5
|
+
export class EmailClient {
|
|
6
|
+
static instance;
|
|
7
|
+
client;
|
|
8
|
+
config;
|
|
9
|
+
logger = Log.getInstance().extend("email-client");
|
|
10
|
+
constructor(config){
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.client = axios.create({
|
|
13
|
+
baseURL: "https://api.postmarkapp.com",
|
|
14
|
+
timeout: config.POSTMARK_TIMEOUT_MS,
|
|
15
|
+
headers: {
|
|
16
|
+
Accept: "application/json",
|
|
17
|
+
"Content-Type": "application/json",
|
|
18
|
+
"X-Postmark-Server-Token": config.POSTMARK_API_KEY
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
static getInstance() {
|
|
23
|
+
if (!EmailClient.instance) {
|
|
24
|
+
const config = CommonSchemas.postmark.parse(process.env);
|
|
25
|
+
EmailClient.instance = new EmailClient(config);
|
|
26
|
+
}
|
|
27
|
+
return EmailClient.instance;
|
|
28
|
+
}
|
|
29
|
+
static resetInstance() {
|
|
30
|
+
EmailClient.instance = undefined;
|
|
31
|
+
}
|
|
32
|
+
async sendWithTemplate(request) {
|
|
33
|
+
try {
|
|
34
|
+
this.logger.info("Sending templated email", {
|
|
35
|
+
to: request.to,
|
|
36
|
+
templateId: request.templateId,
|
|
37
|
+
tag: request.tag
|
|
38
|
+
});
|
|
39
|
+
const payload = {
|
|
40
|
+
From: this.config.POSTMARK_FROM_EMAIL,
|
|
41
|
+
To: Array.isArray(request.to) ? request.to.join(",") : request.to,
|
|
42
|
+
TemplateId: request.templateId,
|
|
43
|
+
TemplateModel: request.templateData,
|
|
44
|
+
Cc: request.cc ? Array.isArray(request.cc) ? request.cc.join(",") : request.cc : undefined,
|
|
45
|
+
Bcc: request.bcc ? Array.isArray(request.bcc) ? request.bcc.join(",") : request.bcc : undefined,
|
|
46
|
+
ReplyTo: request.replyTo || this.config.POSTMARK_REPLY_TO_EMAIL,
|
|
47
|
+
Tag: request.tag,
|
|
48
|
+
Metadata: request.metadata,
|
|
49
|
+
TrackOpens: request.trackOpens ?? true,
|
|
50
|
+
TrackLinks: request.trackLinks ?? "HtmlAndText"
|
|
51
|
+
};
|
|
52
|
+
const response = await this.client.post("/email/withTemplate", payload);
|
|
53
|
+
this.logger.info("Email sent successfully", {
|
|
54
|
+
messageId: response.data.MessageID,
|
|
55
|
+
to: response.data.To
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
messageId: response.data.MessageID,
|
|
59
|
+
to: response.data.To,
|
|
60
|
+
submittedAt: response.data.SubmittedAt,
|
|
61
|
+
errorCode: response.data.ErrorCode,
|
|
62
|
+
message: response.data.Message
|
|
63
|
+
};
|
|
64
|
+
} catch (error) {
|
|
65
|
+
this.handleError(error, "sendWithTemplate");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async sendBatchWithTemplate(request) {
|
|
69
|
+
try {
|
|
70
|
+
this.logger.info("Sending batch templated emails", {
|
|
71
|
+
count: request.emails.length
|
|
72
|
+
});
|
|
73
|
+
const payload = {
|
|
74
|
+
Messages: request.emails.map((email)=>({
|
|
75
|
+
From: this.config.POSTMARK_FROM_EMAIL,
|
|
76
|
+
To: email.to,
|
|
77
|
+
TemplateId: email.templateId,
|
|
78
|
+
TemplateModel: email.templateData,
|
|
79
|
+
ReplyTo: this.config.POSTMARK_REPLY_TO_EMAIL,
|
|
80
|
+
Tag: email.tag,
|
|
81
|
+
Metadata: email.metadata,
|
|
82
|
+
TrackOpens: true,
|
|
83
|
+
TrackLinks: "HtmlAndText"
|
|
84
|
+
}))
|
|
85
|
+
};
|
|
86
|
+
const response = await this.client.post("/email/batchWithTemplates", payload);
|
|
87
|
+
this.logger.info("Batch emails sent", {
|
|
88
|
+
count: response.data.length
|
|
89
|
+
});
|
|
90
|
+
return response.data.map((item)=>({
|
|
91
|
+
messageId: item.MessageID,
|
|
92
|
+
to: item.To,
|
|
93
|
+
submittedAt: item.SubmittedAt,
|
|
94
|
+
errorCode: item.ErrorCode,
|
|
95
|
+
message: item.Message
|
|
96
|
+
}));
|
|
97
|
+
} catch (error) {
|
|
98
|
+
this.handleError(error, "sendBatchWithTemplate");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async sendPasswordReset(to, resetToken, userName) {
|
|
102
|
+
return this.sendWithTemplate({
|
|
103
|
+
to,
|
|
104
|
+
templateId: "password-reset",
|
|
105
|
+
templateData: {
|
|
106
|
+
userName,
|
|
107
|
+
resetToken,
|
|
108
|
+
resetLink: `https://yourapp.com/reset/${resetToken}`
|
|
109
|
+
},
|
|
110
|
+
tag: "password-reset"
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
async sendEmailConfirmation(to, confirmToken, userName) {
|
|
114
|
+
return this.sendWithTemplate({
|
|
115
|
+
to,
|
|
116
|
+
templateId: "email-confirmation",
|
|
117
|
+
templateData: {
|
|
118
|
+
userName,
|
|
119
|
+
confirmToken,
|
|
120
|
+
confirmLink: `https://yourapp.com/confirm/${confirmToken}`
|
|
121
|
+
},
|
|
122
|
+
tag: "email-confirmation"
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
async sendWelcome(to, userName) {
|
|
126
|
+
return this.sendWithTemplate({
|
|
127
|
+
to,
|
|
128
|
+
templateId: "welcome",
|
|
129
|
+
templateData: {
|
|
130
|
+
userName
|
|
131
|
+
},
|
|
132
|
+
tag: "welcome"
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
handleError(error, method) {
|
|
136
|
+
if (axios.isAxiosError(error)) {
|
|
137
|
+
const status = error.response?.status;
|
|
138
|
+
const data = error.response?.data;
|
|
139
|
+
this.logger.error(`Postmark API error in ${method}`, {
|
|
140
|
+
status,
|
|
141
|
+
errorCode: data?.ErrorCode,
|
|
142
|
+
message: data?.Message,
|
|
143
|
+
requestUrl: error.config?.url
|
|
144
|
+
});
|
|
145
|
+
throw new ExternalAPIError(`Postmark API error: ${data?.Message || error.message}`, `Service: Postmark, Method: ${method}, Status: ${status}, ErrorCode: ${data?.ErrorCode}`);
|
|
146
|
+
}
|
|
147
|
+
this.logger.error(`Unexpected error in ${method}`, {
|
|
148
|
+
error
|
|
149
|
+
});
|
|
150
|
+
throw new ExternalAPIError(`Email sending failed: ${error}`, `Service: Postmark, Method: ${method}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
//# sourceMappingURL=EmailClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/clients/EmailClient.ts"],"sourcesContent":["import axios, { type AxiosInstance } from \"axios\";\nimport { z } from \"zod\";\nimport { CommonSchemas } from \"../config/ConfigValidator.js\";\nimport { ExternalAPIError } from \"../Errors/AppError.js\";\nimport { Log } from \"../utils/Logger.js\";\n\ntype PostmarkConfig = z.infer<typeof CommonSchemas.postmark>;\n\nexport interface SendTemplateEmailRequest {\n to: string | string[];\n templateId: string | number;\n templateData: Record<string, any>;\n cc?: string | string[];\n bcc?: string | string[];\n replyTo?: string;\n tag?: string;\n metadata?: Record<string, string>;\n trackOpens?: boolean;\n trackLinks?: \"None\" | \"HtmlAndText\" | \"HtmlOnly\" | \"TextOnly\";\n}\n\nexport interface BatchTemplateEmailRequest {\n emails: Array<{\n to: string;\n templateId: string | number;\n templateData: Record<string, any>;\n tag?: string;\n metadata?: Record<string, string>;\n }>;\n}\n\nexport interface EmailResponse {\n messageId: string;\n to: string;\n submittedAt: string;\n errorCode?: number;\n message?: string;\n}\n\nexport class EmailClient {\n private static instance: EmailClient;\n private client: AxiosInstance;\n private config: PostmarkConfig;\n private logger = Log.getInstance().extend(\"email-client\");\n\n private constructor(config: PostmarkConfig) {\n this.config = config;\n this.client = axios.create({\n baseURL: \"https://api.postmarkapp.com\",\n timeout: config.POSTMARK_TIMEOUT_MS,\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n \"X-Postmark-Server-Token\": config.POSTMARK_API_KEY,\n },\n });\n }\n\n public static getInstance(): EmailClient {\n if (!EmailClient.instance) {\n const config = CommonSchemas.postmark.parse(process.env);\n EmailClient.instance = new EmailClient(config);\n }\n return EmailClient.instance;\n }\n\n public static resetInstance(): void {\n EmailClient.instance = undefined as any;\n }\n\n public async sendWithTemplate(request: SendTemplateEmailRequest): Promise<EmailResponse> {\n try {\n this.logger.info(\"Sending templated email\", {\n to: request.to,\n templateId: request.templateId,\n tag: request.tag,\n });\n\n const payload = {\n From: this.config.POSTMARK_FROM_EMAIL,\n To: Array.isArray(request.to) ? request.to.join(\",\") : request.to,\n TemplateId: request.templateId,\n TemplateModel: request.templateData,\n Cc: request.cc ? (Array.isArray(request.cc) ? request.cc.join(\",\") : request.cc) : undefined,\n Bcc: request.bcc ? (Array.isArray(request.bcc) ? request.bcc.join(\",\") : request.bcc) : undefined,\n ReplyTo: request.replyTo || this.config.POSTMARK_REPLY_TO_EMAIL,\n Tag: request.tag,\n Metadata: request.metadata,\n TrackOpens: request.trackOpens ?? true,\n TrackLinks: request.trackLinks ?? \"HtmlAndText\",\n };\n\n const response = await this.client.post(\"/email/withTemplate\", payload);\n\n this.logger.info(\"Email sent successfully\", {\n messageId: response.data.MessageID,\n to: response.data.To,\n });\n\n return {\n messageId: response.data.MessageID,\n to: response.data.To,\n submittedAt: response.data.SubmittedAt,\n errorCode: response.data.ErrorCode,\n message: response.data.Message,\n };\n } catch (error) {\n this.handleError(error, \"sendWithTemplate\");\n }\n }\n\n public async sendBatchWithTemplate(request: BatchTemplateEmailRequest): Promise<EmailResponse[]> {\n try {\n this.logger.info(\"Sending batch templated emails\", {\n count: request.emails.length,\n });\n\n const payload = {\n Messages: request.emails.map((email) => ({\n From: this.config.POSTMARK_FROM_EMAIL,\n To: email.to,\n TemplateId: email.templateId,\n TemplateModel: email.templateData,\n ReplyTo: this.config.POSTMARK_REPLY_TO_EMAIL,\n Tag: email.tag,\n Metadata: email.metadata,\n TrackOpens: true,\n TrackLinks: \"HtmlAndText\",\n })),\n };\n\n const response = await this.client.post(\"/email/batchWithTemplates\", payload);\n\n this.logger.info(\"Batch emails sent\", {\n count: response.data.length,\n });\n\n return response.data.map((item: any) => ({\n messageId: item.MessageID,\n to: item.To,\n submittedAt: item.SubmittedAt,\n errorCode: item.ErrorCode,\n message: item.Message,\n }));\n } catch (error) {\n this.handleError(error, \"sendBatchWithTemplate\");\n }\n }\n\n public async sendPasswordReset(to: string, resetToken: string, userName: string): Promise<EmailResponse> {\n return this.sendWithTemplate({\n to,\n templateId: \"password-reset\",\n templateData: {\n userName,\n resetToken,\n resetLink: `https://yourapp.com/reset/${resetToken}`,\n },\n tag: \"password-reset\",\n });\n }\n\n public async sendEmailConfirmation(to: string, confirmToken: string, userName: string): Promise<EmailResponse> {\n return this.sendWithTemplate({\n to,\n templateId: \"email-confirmation\",\n templateData: {\n userName,\n confirmToken,\n confirmLink: `https://yourapp.com/confirm/${confirmToken}`,\n },\n tag: \"email-confirmation\",\n });\n }\n\n public async sendWelcome(to: string, userName: string): Promise<EmailResponse> {\n return this.sendWithTemplate({\n to,\n templateId: \"welcome\",\n templateData: { userName },\n tag: \"welcome\",\n });\n }\n\n private handleError(error: unknown, method: string): never {\n if (axios.isAxiosError(error)) {\n const status = error.response?.status;\n const data = error.response?.data;\n\n this.logger.error(`Postmark API error in ${method}`, {\n status,\n errorCode: data?.ErrorCode,\n message: data?.Message,\n requestUrl: error.config?.url,\n });\n\n throw new ExternalAPIError(\n `Postmark API error: ${data?.Message || error.message}`,\n `Service: Postmark, Method: ${method}, Status: ${status}, ErrorCode: ${data?.ErrorCode}`\n );\n }\n\n this.logger.error(`Unexpected error in ${method}`, { error });\n throw new ExternalAPIError(\n `Email sending failed: ${error}`,\n `Service: Postmark, Method: ${method}`\n );\n }\n}\n"],"names":["axios","CommonSchemas","ExternalAPIError","Log","EmailClient","instance","client","config","logger","getInstance","extend","create","baseURL","timeout","POSTMARK_TIMEOUT_MS","headers","Accept","POSTMARK_API_KEY","postmark","parse","process","env","resetInstance","undefined","sendWithTemplate","request","info","to","templateId","tag","payload","From","POSTMARK_FROM_EMAIL","To","Array","isArray","join","TemplateId","TemplateModel","templateData","Cc","cc","Bcc","bcc","ReplyTo","replyTo","POSTMARK_REPLY_TO_EMAIL","Tag","Metadata","metadata","TrackOpens","trackOpens","TrackLinks","trackLinks","response","post","messageId","data","MessageID","submittedAt","SubmittedAt","errorCode","ErrorCode","message","Message","error","handleError","sendBatchWithTemplate","count","emails","length","Messages","map","email","item","sendPasswordReset","resetToken","userName","resetLink","sendEmailConfirmation","confirmToken","confirmLink","sendWelcome","method","isAxiosError","status","requestUrl","url"],"mappings":"AAAA,OAAOA,WAAmC,QAAQ;AAElD,SAASC,aAAa,QAAQ,+BAA+B;AAC7D,SAASC,gBAAgB,QAAQ,wBAAwB;AACzD,SAASC,GAAG,QAAQ,qBAAqB;AAmCzC,OAAO,MAAMC;IACX,OAAeC,SAAsB;IAC7BC,OAAsB;IACtBC,OAAuB;IACvBC,SAASL,IAAIM,WAAW,GAAGC,MAAM,CAAC,gBAAgB;IAE1D,YAAoBH,MAAsB,CAAE;QAC1C,IAAI,CAACA,MAAM,GAAGA;QACd,IAAI,CAACD,MAAM,GAAGN,MAAMW,MAAM,CAAC;YACzBC,SAAS;YACTC,SAASN,OAAOO,mBAAmB;YACnCC,SAAS;gBACPC,QAAQ;g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K;gBACjBC,SAASN,MAAMO;gBACfsB,YAAYrB,MAAM1D,MAAM,EAAEgF;YAC5B;YAEA,MAAM,IAAIrF,iBACR,CAAC,oBAAoB,EAAEuD,MAAMO,WAAWC,MAAMF,OAAO,EAAE,EACvD,CAAC,2BAA2B,EAAEoB,OAAO,UAAU,EAAEE,OAAO,aAAa,EAAE5B,MAAMK,WAAW;QAE5F;QAEA,IAAI,CAACtD,MAAM,CAACyD,KAAK,CAAC,CAAC,oBAAoB,EAAEkB,QAAQ,EAAE;YAAElB;QAAM;QAC3D,MAAM,IAAI/D,iBACR,CAAC,sBAAsB,EAAE+D,OAAO,EAChC,CAAC,2BAA2B,EAAEkB,QAAQ;IAE1C;AACF"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export interface NotificationPayload {
|
|
2
|
+
title: string;
|
|
3
|
+
body: string;
|
|
4
|
+
sound?: string;
|
|
5
|
+
badge?: number;
|
|
6
|
+
data?: Record<string, string>;
|
|
7
|
+
redirectPath?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class PushNotificationClient {
|
|
10
|
+
private static instance;
|
|
11
|
+
private config;
|
|
12
|
+
private logger;
|
|
13
|
+
private apnProvider;
|
|
14
|
+
private fcmAccessToken;
|
|
15
|
+
private fcmTokenExpiry;
|
|
16
|
+
private constructor();
|
|
17
|
+
static getInstance(): PushNotificationClient;
|
|
18
|
+
static resetInstance(): void;
|
|
19
|
+
shutdown(): void;
|
|
20
|
+
private getApnProvider;
|
|
21
|
+
private sendAppleNotification;
|
|
22
|
+
private getFcmAccessToken;
|
|
23
|
+
private sendAndroidNotification;
|
|
24
|
+
sendToTokens(tokens: string[], platform: "ios" | "android", notification: NotificationPayload): Promise<void>;
|
|
25
|
+
sendToUser(params: {
|
|
26
|
+
userUuid: string;
|
|
27
|
+
notification: NotificationPayload;
|
|
28
|
+
}): Promise<void>;
|
|
29
|
+
sendToUsers(params: {
|
|
30
|
+
userUuids: string[];
|
|
31
|
+
notification: NotificationPayload;
|
|
32
|
+
}): Promise<void>;
|
|
33
|
+
private calculateScheduledTime;
|
|
34
|
+
scheduleForUser(params: {
|
|
35
|
+
userUuid: string;
|
|
36
|
+
notification: NotificationPayload;
|
|
37
|
+
targetHour: number;
|
|
38
|
+
targetMinute: number;
|
|
39
|
+
}): Promise<{
|
|
40
|
+
scheduledAt: Date;
|
|
41
|
+
}>;
|
|
42
|
+
scheduleForUsers(params: {
|
|
43
|
+
userUuids: string[];
|
|
44
|
+
notification: NotificationPayload;
|
|
45
|
+
targetHour: number;
|
|
46
|
+
targetMinute: number;
|
|
47
|
+
}): Promise<Array<{
|
|
48
|
+
userUuid: string;
|
|
49
|
+
scheduledAt: Date;
|
|
50
|
+
}>>;
|
|
51
|
+
sendTemplateToUser(params: {
|
|
52
|
+
userUuid: string;
|
|
53
|
+
notificationType: string;
|
|
54
|
+
language?: string;
|
|
55
|
+
data?: Record<string, string>;
|
|
56
|
+
}): Promise<void>;
|
|
57
|
+
sendTemplateToUsers(params: {
|
|
58
|
+
userUuids: string[];
|
|
59
|
+
notificationType: string;
|
|
60
|
+
language?: string;
|
|
61
|
+
data?: Record<string, string>;
|
|
62
|
+
}): Promise<void>;
|
|
63
|
+
sendToAllUsers(params: {
|
|
64
|
+
notification: NotificationPayload;
|
|
65
|
+
batchSize?: number;
|
|
66
|
+
}): Promise<{
|
|
67
|
+
totalSent: number;
|
|
68
|
+
}>;
|
|
69
|
+
sendToGroup(params: {
|
|
70
|
+
notification: NotificationPayload;
|
|
71
|
+
group: "premium" | "free" | "trial";
|
|
72
|
+
batchSize?: number;
|
|
73
|
+
}): Promise<{
|
|
74
|
+
totalSent: number;
|
|
75
|
+
}>;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=PushNotificationClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PushNotificationClient.d.ts","sourceRoot":"","sources":["../../../src/lib/clients/PushNotificationClient.ts"],"names":[],"mappings":"AAaA,MAAM,WA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