Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -19,6 +19,7 @@
},
"author": "GDS developers",
"license": "MIT",
"types": "types/index.d.ts",
"dependencies": {
"axios": "^1.7.2",
"jsonwebtoken": "^9.0.2"
Expand Down
21 changes: 21 additions & 0 deletions types/api_client.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { AxiosProxyConfig } from "axios";
import { AxiosRequestConfig } from "axios";
import axios from "axios";

export declare function get<T = any>(
path: string,
additionalOptions: AxiosRequestConfig | any
): ReturnType<typeof axios.get<T>>

export declare function post<T = any>(
path: string,
additionalOptions: AxiosRequestConfig | any
): ReturnType<typeof axios.post<T>>

export declare function setProxy(
proxyConfig: AxiosProxyConfig,
): undefined

export declare function setClient(
proxyConfig: typeof axios,
): undefined
44 changes: 44 additions & 0 deletions types/enum.d.ts
Original file line number Diff line number Diff line change
@@ -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"
79 changes: 79 additions & 0 deletions types/get.d.ts
Original file line number Diff line number Diff line change
@@ -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<typeof get<
Notification &
(EmailResponse |
TextResponse |
LetterResponse) >>

export declare function getNotifications(
templateType?: string,
status?: string,
reference?: string,
olderThanId?: string,
): ReturnType<typeof get<
{
notifications: Notification[],
links: {
current: string,
next: string
}[]
}
>>

export declare function getPdfForLetterNotification(
notificationId: string,
): ReturnType<typeof get<ArrayBuffer>>

export declare function getTemplateById(
templateId: string,
): ReturnType<typeof get<TemplateData>>

export declare function getTemplateByIdAndVersion(
templateId: string,
version: number
): ReturnType<typeof get<TemplateData>>

export declare function getAllTemplates(
templateType?: NotificationType,
): ReturnType<typeof get<{
templates: TemplateData[]
}>>

export declare function previewTemplateById(
templateId: string,
personalisation?: any,
): ReturnType<typeof get<{
id: string,
type: NotificationType,
version: number,
body: string
html: string,
subject: string,
postage?: PostageType
}>>
export declare function getReceivedTexts(
olderThan?: string,
): ReturnType<typeof get<{
received_text_messages: TextMessage[],
links: {
current: string,
next: string
}
}>>
46 changes: 46 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -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)
}
81 changes: 81 additions & 0 deletions types/interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -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
}

91 changes: 91 additions & 0 deletions types/send.d.ts
Original file line number Diff line number Diff line change
@@ -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<typeof post<{
id: string,
reference?: string,
content: {
subject: string,
body: string,
from_email: string,
one_click_unsubscribe_url: string,
},
uri: string,
template: Template
}>>

export declare function sendSms(
templateId: string,
phoneNumber: string,
options: {
personalisation?: Object,
reference?: string,
smsSendId?: string,
}
): ReturnType<typeof post<{
id: string,
reference?: string,
content: {
body: string,
from_number: string
},
uri: string,
template: Template
}>>

export declare function sendLetter(
templateId: string,
options: {
personalisation?: Object,
reference?: string
}
): ReturnType<typeof post<{
id: string,
reference?: string,
content: {
subject: string,
body: string
},
uri: string,
template: Template,
scheduled_for: string | null
}>>

export declare function sendPrecompiledLetter(
reference: string,
pdf_file: Buffer<ArrayBuffer>,
postage?: PostageType | undefined,
): ReturnType<typeof post<{
id: string,
reference: string,
postage: PostageType
}>>

export declare function prepareUpload(
fileData: Buffer<ArrayBuffer>,
options?: {
filename?: string
confirmEmailBeforeDownload?: boolean
retentionPeriod?: string
}
): {
file: string;
filename?: string;
confirm_email_before_download?: boolean;
retention_period?: boolean;
}