aws-sdk-js
aws-sdk-js copied to clipboard
Typescript typings for notifications
Describe the feature
Typescript types for notifications like what is shown here
If this could just be added under AWS.SNS.Types, then I could do that PR for this, but wanted a discussion first.
Use Case
Useful for assigning types to function parameters when this body type is passed along to services.
Proposed Solution
export type AwsEmailBounceNotification = {
notificationType: string;
bounce: {
bounceType: string;
bounceSubType: string;
bouncedRecipients: Array<{
emailAddress: string;
status: string;
action: string;
diagnosticCode: string
}>;
feedbackId: string;
timestamp: string;
remoteMtaIp: string;
reportingMTA: string
};
mail: {
callerIdentity: string;
commonHeaders: {
date: string;
from: Array<string>;
to: Array<string>;
messageId: string;
subject: string
};
destination: Array<string>;
headers: Array<{ name: string; value: string}>;
headersTruncated: boolean;
messageId: string;
sendingAccountId: string;
source: string;
sourceArn: string;
sourceIp: string;
timestamp: string;
}
}
Other Information
No response
Acknowledgements
- [X] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
SDK version used
2.1062.0 (serverless framework v3)
Environment details (OS name and version, etc.)
All
Hey @Landro3 thanks for opening this issue, types in V2 were added after it was written, V3 was written with type safety and should resolve this issue too. I'd be happy to take a PR for V2 if you want to take it up. Thanks
thanks @ajredniwja, do you have any suggestions for getting started, this is my first PR in the repo
Hello, I ran into this issue in the middle of a Googling rampage. I'd like to attach my SNS notification type here if it's of any help. Feel free to use it however you see it fit for your PR if it helps:
export type NotificationType = 'Bounce' | 'Complaint' | 'Delivery';
export type BounceType = 'Permanent' | 'Transient' | 'Undetermined';
export type BounceSubType = {
Permanent: 'General' | 'NoEmail' | 'Suppressed' | 'OnAccountSuppressionList';
Transient: 'General' | 'MailboxFull' | 'MessageTooLarge' | 'ContentRejected' | 'AttachmentRejected';
Undetermined: 'Undetermined';
}
export type BouncedRecipient = {
status: string;
action: string;
diagnosticCode?: string;
emailAddress: string;
}
export type SNSMessageBounce<T extends BounceType> = {
bounceType: T;
bounceSubType: BounceSubType[T];
bouncedRecipients: BouncedRecipient[];
remoteMtaIp?: string;
reportingMTA?: string;
timestamp?: string;
feedbackId?: string;
}
export type ComplainedRecipient = {
emailAddress: string;
};
export type SNSMessageComplaint = {
complainedRecipients: ComplainedRecipient[];
timestamp: string;
feedbackId: string;
complaintSubType: 'OnAccountSuppressionList' | null;
userAgent?: string;
complaintFeedbackType?: 'abuse' | 'auth-failure' | 'fraud' | 'not-spam' | 'other' | 'virus' | string;
arrivalDate?: string;
}
export type SNSMessageDelivery = {
timestamp: string;
processingTimeMillis: number;
recipients: string[];
smtpResponse: string;
reportingMTA: string;
remoteMtaIp: string;
}
export type SNSMessageMailHeader = {
name: string;
value: string;
};
export type SNSMessageMail = {
destination: string[];
headersTruncated: boolean;
timestamp: string;
messageId: string;
source: string;
sourceArn: string;
sourceIp: string;
sendingAccountId: string;
commonHeaders?: Record<string, any>;
headers?: SNSMessageMailHeader[];
}
export type SNSMessage<T extends NotificationType> = {
notificationType: T;
mail: SNSMessageMail;
bounce?: T extends 'Bounce' ? SNSMessageBounce<BounceType> : never;
complaint?: T extends 'Complaint' ? SNSMessageComplaint : never;
delivery?: T extends 'Delivery' ? SNSMessageDelivery : never;
}
I little bit changed SNSMessage type. This is better use when you parse data and guessing the type.
export type SNSMessage =
| {
notificationType: "Bounce";
mail: SNSMessageMail;
bounce: SNSMessageBounce<BounceType>;
}
| {
notificationType: "Complaint";
mail: SNSMessageMail;
complaint: SNSMessageComplaint;
}
| {
notificationType: "Delivery";
mail: SNSMessageMail;
delivery: SNSMessageDelivery;
};
Hi, sorry if I'm missing this, but where do the types for MailObject, BounceObject, ComplaintObject etc exist?