alphagov / notifications-node-client

Node client for the GOV.UK Notify API
https://docs.notifications.service.gov.uk/node.html
MIT License
16 stars 12 forks source link

Types? #175

Open harryl-MoD opened 1 year ago

harryl-MoD commented 1 year ago
declare module "notifications-node-client" {
  class NotifyClient {
    constructor(apiKey: string);
    sendEmail(
      templateId: string,
      emailAddress: string,
      options: {
        personalisation: any;
        reference: string;
        emailReplyToId?: string;
      }
    ): Promise<any>;
    sendSms(
      templateId: string,
      phoneNumber: string,
      options?: NotificationSendOptions
    ): Promise<any>;
    sendLetter(
      templateId: string,
      options?: NotificationSendOptions
    ): Promise<any>;
    sendPrecompiledLetter(
      reference: string,
      pdfFile: string | Buffer,
      postage?: string
    ): Promise<any>;
    getNotificationById(notificationId: string): Promise<any>;
    getNotifications(
      templateType?: string,
      status?: string,
      reference?: string,
      olderThanId?: string
    ): Promise<any>;
    getPdfForLetterNotification(notificationId: string): Promise<Buffer>;
    getTemplateById(templateId: string): Promise<any>;
    getTemplateByIdAndVersion(
      templateId: string,
      version: number
    ): Promise<any>;
    getAllTemplates(templateType?: string): Promise<any>;
    previewTemplateById(
      templateId: string,
      personalisation?: any
    ): Promise<any>;
    getReceivedTexts(olderThan?: string): Promise<any>;
    setProxy(proxyConfig: any): void;
    prepareUpload(fileData: any, options?: FileUploadOptions): any;
  }

  export = {
    NotifyClient: NotifyClient,
  };

  export interface NotificationSendOptions {
    personalisation?: any;
    reference?: string;
    emailReplyToId?: string;
    smsSenderId?: string;
  }

  export interface FileUploadOptions {
    isCsv?: boolean;
    confirmEmailBeforeDownload?: boolean;
    retentionPeriod?: number;
  }
}

Perhaps consider publishing just types so an npm install with: npm i --save-dev @types/notifications-node-client is possible?

LeoCie commented 2 months ago

This would be useful for us too.

Currently we are using Notify for letters only, which require certain personalisation such as 3 address lines minimum. Something akin to the below:


type NotifyAddress = {
    address_line_1: string
    address_line_2: string
    address_line_3: string
    address_line_4?: string
    address_line_5?: string
    address_line_6?: string
    address_line_7?: string
}

type NotifyLetterPersonalisation =
    NotifyAddress & {
    first_name: string;
    surname: string;
}