|
1 | | -// Enums |
2 | | -export type MessageStatus = |
3 | | - | "created" |
4 | | - | "pending_enrichment" |
5 | | - | "enriched" |
6 | | - | "sending" |
7 | | - | "delivered" |
8 | | - | "failed"; |
9 | | - |
10 | | -export type ChannelType = |
11 | | - | "nhsapp" |
12 | | - | "email" |
13 | | - | "sms" |
14 | | - | "letter"; |
15 | | - |
16 | | -export type ChannelStatus = |
17 | | - | "created" |
18 | | - | "sending" |
19 | | - | "delivered" |
20 | | - | "failed" |
21 | | - | "skipped"; |
22 | | - |
23 | | -// Callback return schema |
| 1 | +// --- Literal sets ------------------------------------------------------------ |
| 2 | + |
| 3 | +export enum CallbackType { |
| 4 | + message = "MessageStatus", |
| 5 | + channel = "ChannelStatus" |
| 6 | +} |
| 7 | + |
| 8 | +export const MessageStatuses = [ |
| 9 | + "created", |
| 10 | + "pending_enrichment", |
| 11 | + "enriched", |
| 12 | + "sending", |
| 13 | + "delivered", |
| 14 | + "failed" |
| 15 | +] as const |
| 16 | +export type MessageStatus = typeof MessageStatuses[number]; |
| 17 | + |
| 18 | +export const ChannelTypes = ["nhsapp", "email", "sms", "letter"] as const |
| 19 | +export type ChannelType = typeof ChannelTypes[number]; |
| 20 | + |
| 21 | +export const ChannelStatuses = [ |
| 22 | + "created", |
| 23 | + "sending", |
| 24 | + "delivered", |
| 25 | + "failed", |
| 26 | + "skipped" |
| 27 | +] as const |
| 28 | +export type ChannelStatus = typeof ChannelStatuses[number]; |
| 29 | + |
| 30 | +export const CascadeTypes = ["primary", "secondary"] as const |
| 31 | +export type CascadeType = typeof CascadeTypes[number]; |
| 32 | + |
| 33 | +export const SupplierStatuses = [ |
| 34 | + "accepted", |
| 35 | + "cancelled", |
| 36 | + "delivered", |
| 37 | + "notification_attempted", |
| 38 | + "notified", |
| 39 | + "pending_virus_check", |
| 40 | + "permanent_failure", |
| 41 | + "read", |
| 42 | + "received", |
| 43 | + "rejected", |
| 44 | + "technical_failure", |
| 45 | + "temporary_failure", |
| 46 | + "unnotified", |
| 47 | + "unknown", |
| 48 | + "validation_failed" |
| 49 | +] as const |
| 50 | +export type SupplierStatus = typeof SupplierStatuses[number]; |
| 51 | + |
| 52 | +// --- Core models ------------------------------------------------------------- |
| 53 | + |
24 | 54 | export interface Channel { |
25 | | - /** The communication type of this channel */ |
26 | | - type: ChannelType; |
27 | | - /** Current status of this channel */ |
28 | | - channelStatus: ChannelStatus; |
| 55 | + readonly type: ChannelType; |
| 56 | + readonly channelStatus: ChannelStatus; |
29 | 57 | } |
30 | 58 |
|
31 | 59 | export interface RoutingPlan { |
32 | | - /** Identifier for the routing plan */ |
33 | | - id: string; |
34 | | - /** Name of the routing plan */ |
35 | | - name: string; |
36 | | - /** Specific version of the routing plan */ |
37 | | - version: string; |
38 | | - /** Creation date of the routing plan */ |
39 | | - createdDate: string; |
| 60 | + readonly id: string; |
| 61 | + readonly name: string; |
| 62 | + readonly version: string; |
| 63 | + readonly createdDate: string; |
40 | 64 | } |
41 | 65 |
|
42 | | -export interface MessageStatusAttributes { |
43 | | - /** Unique identifier for the message */ |
44 | | - messageId: string; |
45 | | - /** Original reference supplied for the message */ |
46 | | - messageReference: string; |
| 66 | +// Shared attributes across callbacks |
| 67 | +interface BaseAttributes { |
| 68 | + /** Notify ID for the message (KSUID; 27-char alphanumeric) */ |
| 69 | + readonly messageId: string; |
| 70 | + /** Original reference supplied by us for the message */ |
| 71 | + readonly messageReference: string; |
| 72 | + /** Timestamp of the callback event */ |
| 73 | + readonly timestamp: string; |
| 74 | +} |
| 75 | + |
| 76 | +export interface MessageStatusAttributes extends BaseAttributes { |
47 | 77 | /** Aggregate status across all channels */ |
48 | | - messageStatus: MessageStatus; |
49 | | - /** Extra information about the message status, if any */ |
50 | | - messageStatusDescription?: string; |
| 78 | + readonly messageStatus: MessageStatus; |
| 79 | + readonly messageStatusDescription?: string; |
51 | 80 | /** List of channels attempted for delivery */ |
52 | | - channels: Array<Channel>; |
53 | | - /** Timestamp of the callback event */ |
54 | | - timestamp: string; |
55 | | - /** Routing plan details */ |
56 | | - routingPlan: RoutingPlan; |
| 81 | + readonly channels: ReadonlyArray<Channel>; |
| 82 | + readonly routingPlan: RoutingPlan; |
57 | 83 | } |
58 | 84 |
|
59 | | -export interface MessageStatusResource { |
60 | | - /** Always "MessageStatus" */ |
61 | | - type: "MessageStatus"; |
62 | | - attributes: MessageStatusAttributes; |
63 | | - links: { |
64 | | - /** URL to retrieve the overarching message status */ |
65 | | - message: string; |
66 | | - }; |
67 | | - meta: { |
68 | | - /** Key to deduplicate retried requests */ |
69 | | - idempotencyKey: string; |
70 | | - }; |
| 85 | +export interface ChannelStatusAttributes extends BaseAttributes { |
| 86 | + readonly cascadeType?: CascadeType; |
| 87 | + readonly cascadeOrder?: number; |
| 88 | + readonly channel: ChannelType; |
| 89 | + readonly channelStatus: ChannelStatus; |
| 90 | + /** Extra information associated with the status of this channel */ |
| 91 | + readonly channelStatusDescription?: string; |
| 92 | + readonly supplierStatus?: SupplierStatus; |
| 93 | + readonly retryCount: number; |
71 | 94 | } |
72 | 95 |
|
| 96 | +// --- Generic JSON-ish resource ----------------------------------------------- |
| 97 | + |
| 98 | +interface Links { |
| 99 | + /** URL to retrieve the overarching message status */ |
| 100 | + readonly message: string; |
| 101 | +} |
| 102 | + |
| 103 | +interface Meta { |
| 104 | + /** Key to deduplicate retried requests */ |
| 105 | + readonly idempotencyKey: string; |
| 106 | +} |
| 107 | + |
| 108 | +interface Resource<CallbackType, TAttributes> { |
| 109 | + readonly type: CallbackType; |
| 110 | + readonly attributes: TAttributes; |
| 111 | + readonly links: Links; |
| 112 | + readonly meta: Meta; |
| 113 | +} |
| 114 | + |
| 115 | +// Concrete resources |
| 116 | +export type MessageStatusResource = Resource<"MessageStatus", MessageStatusAttributes>; |
| 117 | +export type ChannelStatusResource = Resource<"ChannelStatus", ChannelStatusAttributes>; |
| 118 | + |
| 119 | +// --- Responses --------------------------------------------------------------- |
| 120 | + |
73 | 121 | export interface MessageStatusResponse { |
74 | | - /** |
75 | | - * Array of MessageStatus resources. |
76 | | - * Must contain at least one element. |
77 | | - */ |
78 | | - data: Array<MessageStatusResource>; |
| 122 | + readonly data: Array<MessageStatusResource>; |
| 123 | +} |
| 124 | + |
| 125 | +export interface ChannelStatusResponse { |
| 126 | + readonly data: Array<ChannelStatusResource>; |
| 127 | +} |
| 128 | + |
| 129 | +export type CallbackResource = MessageStatusResource | ChannelStatusResource; |
| 130 | + |
| 131 | +export interface CallbackResponse { |
| 132 | + readonly data: Array<CallbackResource>; |
79 | 133 | } |
0 commit comments