|
| 1 | +/** |
| 2 | + * Metadata for an embedded message. |
| 3 | + */ |
| 4 | +export class IterableEmbeddedMessageMetadata { |
| 5 | + /** The ID for the embedded message */ |
| 6 | + readonly messageId: string; |
| 7 | + /** The placement ID for the embedded message */ |
| 8 | + readonly placementId: number; |
| 9 | + /** The campaign ID for the embedded message */ |
| 10 | + readonly campaignId?: number; |
| 11 | + /** Whether the embedded message is a proof */ |
| 12 | + readonly isProof: boolean; |
| 13 | + |
| 14 | + /** |
| 15 | + * Constructs an instance of IterableEmbeddedMessageMetadata. |
| 16 | + * |
| 17 | + * @param messageId - The ID for the embedded message. |
| 18 | + * @param placementId - The placement ID for the embedded message. |
| 19 | + * @param campaignId - The campaign ID for the embedded message. |
| 20 | + * @param isProof - Whether the embedded message is a proof. |
| 21 | + */ |
| 22 | + constructor( |
| 23 | + messageId: string, |
| 24 | + placementId: number, |
| 25 | + campaignId: number | undefined, |
| 26 | + isProof: boolean = false |
| 27 | + ) { |
| 28 | + this.messageId = messageId; |
| 29 | + this.placementId = placementId; |
| 30 | + this.campaignId = campaignId; |
| 31 | + this.isProof = isProof; |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Creates an instance of `IterableEmbeddedMessageMetadata` from a dictionary object. |
| 36 | + * |
| 37 | + * @param dict - The dictionary objectcontaining the metadata properties. |
| 38 | + * This corresponds to the properties in {@link IterableEmbeddedMessageMetadata} |
| 39 | + * |
| 40 | + * @returns A new instance of `IterableEmbeddedMessageMetadata` with the provided properties. |
| 41 | + */ |
| 42 | + static fromDict( |
| 43 | + dict: Partial<EmbeddedMessageMetadataDict> |
| 44 | + ): IterableEmbeddedMessageMetadata { |
| 45 | + if (!dict.messageId || !dict.placementId) { |
| 46 | + throw new Error('messageId and placementId are required'); |
| 47 | + } |
| 48 | + return new IterableEmbeddedMessageMetadata( |
| 49 | + dict.messageId, |
| 50 | + dict.placementId, |
| 51 | + dict.campaignId, |
| 52 | + dict.isProof |
| 53 | + ); |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +/** |
| 58 | + * An interface defining the dictionary object containing the metadata properties for an embedded message. |
| 59 | + */ |
| 60 | +export interface EmbeddedMessageMetadataDict { |
| 61 | + messageId: string; |
| 62 | + placementId: number; |
| 63 | + campaignId?: number; |
| 64 | + isProof?: boolean; |
| 65 | +} |
0 commit comments