From 5b9a7493bf8cc3af7e4fb2931ff87f2c38b72a27 Mon Sep 17 00:00:00 2001 From: Adam Shea Date: Tue, 9 Dec 2025 11:10:14 +0000 Subject: [PATCH 1/2] add types --- package.json | 1 + types/api_client.d.ts | 21 ++++++++++ types/enum.d.ts | 44 +++++++++++++++++++++ types/get.d.ts | 79 +++++++++++++++++++++++++++++++++++++ types/index.d.ts | 46 ++++++++++++++++++++++ types/interfaces.d.ts | 81 ++++++++++++++++++++++++++++++++++++++ types/send.d.ts | 91 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 363 insertions(+) create mode 100644 types/api_client.d.ts create mode 100644 types/enum.d.ts create mode 100644 types/get.d.ts create mode 100644 types/index.d.ts create mode 100644 types/interfaces.d.ts create mode 100644 types/send.d.ts diff --git a/package.json b/package.json index d586236..e2f3190 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ }, "author": "GDS developers", "license": "MIT", + "types": "types/index.d.ts", "dependencies": { "axios": "^1.7.2", "jsonwebtoken": "^9.0.2" diff --git a/types/api_client.d.ts b/types/api_client.d.ts new file mode 100644 index 0000000..cf1f50f --- /dev/null +++ b/types/api_client.d.ts @@ -0,0 +1,21 @@ +import { AxiosProxyConfig } from "axios"; +import { AxiosRequestConfig } from "axios"; +import axios from "axios"; + +export declare function get( + path: string, + additionalOptions: AxiosRequestConfig | any +): ReturnType> + +export declare function post( + path: string, + additionalOptions: AxiosRequestConfig | any +): ReturnType> + +export declare function setProxy( + proxyConfig: AxiosProxyConfig, +): undefined + +export declare function setClient( + proxyConfig: typeof axios, +): undefined diff --git a/types/enum.d.ts b/types/enum.d.ts new file mode 100644 index 0000000..576df8f --- /dev/null +++ b/types/enum.d.ts @@ -0,0 +1,44 @@ +export type PostageType = + "first" | + "second" | + "economy" + +export type EmailStatus = + "created" | + "sending" | + "delivered" | + "permanent-failure" | + "temporary-failure" | + "technical-failure" + +export type TextStatus = + "created" | + "sending" | + "pending" | + "sent" | + "delivered" | + "permanent-failure" | + "temporary-failure" | + "technical-failure" + +export type LetterStatus = + "accepted" | + "received" | + "cancelled" | + "technical-failure" | + "permanent-failure" + +export type PrecompLetterStatus = + "accepted" | + "received" | + "cancelled" | + "pending-virus-check" | + "virus-scan-failed" | + "validation-failed" | + "technical-failure" | + "permanent-failure" + +export type NotificationType = + "sms" | + "letter" | + "email" diff --git a/types/get.d.ts b/types/get.d.ts new file mode 100644 index 0000000..4ba1588 --- /dev/null +++ b/types/get.d.ts @@ -0,0 +1,79 @@ +import type { get } from "./api_client.d.ts" + +import type { + Notification, + EmailResponse, + TextResponse, + LetterResponse, + TextMessage, + TemplateData +} from "./interfaces.d.ts" + +import type { + PostageType, + NotificationType, +} from "./enum.d.ts" + +export declare function getNotificationById( + notificationId: string, +): ReturnType> + +export declare function getNotifications( + templateType?: string, + status?: string, + reference?: string, + olderThanId?: string, +): ReturnType> + +export declare function getPdfForLetterNotification( + notificationId: string, +): ReturnType> + +export declare function getTemplateById( + templateId: string, +): ReturnType> + +export declare function getTemplateByIdAndVersion( + templateId: string, + version: number +): ReturnType> + +export declare function getAllTemplates( + templateType?: NotificationType, +): ReturnType> + +export declare function previewTemplateById( + templateId: string, + personalisation?: any, +): ReturnType> +export declare function getReceivedTexts( + olderThan?: string, +): ReturnType> diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..401195c --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,46 @@ +import type { + setClient, + setProxy +} from "./api_client.d.ts" +import type { + getNotificationById, + getNotifications, + getPdfForLetterNotification, + getTemplateById, + getTemplateByIdAndVersion, + getAllTemplates, + previewTemplateById, + getReceivedTexts, +} from "./get.d.ts" + +import type { + sendEmail, + sendSms, + sendLetter, + sendPrecompiledLetter, + prepareUpload +} from "./send.d.ts" + +export declare class NotifyClient { + getNotificationById: typeof getNotificationById + getNotifications: typeof getNotifications + getPdfForLetterNotification: typeof getPdfForLetterNotification + getTemplateById: typeof getTemplateById + getTemplateByIdAndVersion: typeof getTemplateByIdAndVersion + getAllTemplates: typeof getAllTemplates + previewTemplateById: typeof previewTemplateById + getReceivedTexts: typeof getReceivedTexts + + sendEmail: typeof sendEmail + sendSms: typeof sendSms + sendLetter: typeof sendLetter + sendPrecompiledLetter: typeof sendPrecompiledLetter + prepareUpload: typeof prepareUpload + + setClient: typeof setClient + setProxy: typeof setProxy + + constructor(urlBase: string, serviceId: string, apiKeyId: string) + constructor(urlBase: string, apiKeyId: string) + constructor(apiKeyId: string) +} diff --git a/types/interfaces.d.ts b/types/interfaces.d.ts new file mode 100644 index 0000000..2434691 --- /dev/null +++ b/types/interfaces.d.ts @@ -0,0 +1,81 @@ +import type { + PostageType, + NotificationType, + TextStatus, + PrecompLetterStatus, + EmailStatus, + LetterStatus +} from "./enum.d.ts" + +export interface EmailResponse { + email_address: string + subject: string, +} + +export interface TextResponse { + phone_number: string +} + +export interface LetterResponse { + line_1: string, + line_2: string, + line_3: string, + line_4?: string, + line_5?: string, + line_6?: string, + line_7?: string + postage: PostageType +} + +export interface LetterCost { + billable_sheets_of_paper?: number, + postage?: "first" | "second" | "europe" | "rest-of-world" +} + +export interface SmsCost { + billable_sms_fragments?: number, + international_rate_multiplier?: number, + sms_rate?: number, +} + +export interface Notification { + id: string, + reference?: string, + type: NotificationType, + status: TextStatus | PrecompLetterStatus | EmailStatus | LetterStatus, + template: Template, + body: string, + created_at: string, + created_by_name?: string, + sent_at?: string, + completed_at?: string, + scheduled_for?: string, + one_click_unsubscribe?: string, + is_cost_data_ready: boolean, + cost_in_pounds?: number, + cost_details?: LetterCost | SmsCost +} + + +export interface TemplateData { + id: string, + name: string, + type: NotificationType, + created_at: string, + updated_at: string, + version: number, + created_by: string, + subject: string, + body: string, + letter_contact_block?: string +} + +interface TextMessage { + id: string, + user_number: string, + notify_number: string, + created_at: string, + service_id: string, + content: string +} + diff --git a/types/send.d.ts b/types/send.d.ts new file mode 100644 index 0000000..b9e399e --- /dev/null +++ b/types/send.d.ts @@ -0,0 +1,91 @@ +import type { post } from "./api_client.d.ts" +import type { PostageType } from "./enum.d.ts" + +interface Template { + id: string, + version: number, + uri: string +} + +export declare function sendEmail( + templateId: string, + emailAddress: string, + options: { + personalisation?: Object, + reference?: string, + emailReplyToId?: string, + oneClickUnsubscribeURL?: string, + } +): ReturnType> + +export declare function sendSms( + templateId: string, + phoneNumber: string, + options: { + personalisation?: Object, + reference?: string, + smsSendId?: string, + } +): ReturnType> + +export declare function sendLetter( + templateId: string, + options: { + personalisation?: Object, + reference?: string + } +): ReturnType> + +export declare function sendPrecompiledLetter( + reference: string, + pdf_file: Buffer, + postage?: PostageType | undefined, +): ReturnType> + +export declare function prepareUpload( + fileData: Buffer, + options?: { + filename?: string + confirmEmailBeforeDownload?: boolean + retentionPeriod?: string + } +): { + file: string; + filename?: string; + confirm_email_before_download?: boolean; + retention_period?: boolean; +} From 3f402afea9b29276f4131037af7a4f41bdd2817f Mon Sep 17 00:00:00 2001 From: Adam Shea Date: Tue, 9 Dec 2025 11:11:48 +0000 Subject: [PATCH 2/2] bump minor version change --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e2f3190..2ea5549 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "notifications-node-client", - "version": "8.2.1", + "version": "8.3.0", "homepage": "https://docs.notifications.service.gov.uk/node.html", "repository": { "type": "git",