UNPKG

@common-creation/aws-cdk-ses-domain-identity

Version:

Constructs for provisioning and referencing domain identities which can be used in SES RuleSets and Actions Construct.

67 lines 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Record = void 0; const DEFAULT_VERIFICATION_RECORD_TTL = 1800; // 30 minutes class Record { constructor(name, type, values, ttl = DEFAULT_VERIFICATION_RECORD_TTL) { this.name = name; this.type = type; this.values = values; this.ttl = ttl; } static forIdentity(domainName, records) { return new this(`_amazonses.${domainName}.`, "TXT", new Set(records)); } static forDKIM(domainName, token) { return new this(`${token}._domainkey.${domainName}.`, "CNAME", new Set([`${token}.dkim.amazonses.com`])); } static fromResourceRecordSet(resource) { switch (resource.Type) { case "CNAME": return new this(resource.Name, resource.Type, new Set(resource.ResourceRecords.map((record) => record.Value))); case "TXT": return new this(resource.Name, resource.Type, new Set(resource.ResourceRecords.map((record) => JSON.parse(record.Value)))); default: throw new Error("Unsupported ResourceRecord Type"); } } get size() { return this.values.size; } has(value) { return this.values.has(value); } add(value) { this.values.add(value); } remove(value) { this.values.delete(value); } action(type) { const resourceRecords = this.serialize(); const payload = { Action: type, ResourceRecordSet: { Name: this.name, Type: this.type, ResourceRecords: resourceRecords, TTL: this.ttl, }, }; return payload; } serialize() { switch (this.type) { case "CNAME": return Array.from(this.values) .filter((value) => value != null && value.length > 0) .map((value) => ({ Value: value })); case "TXT": return Array.from(this.values) .filter((value) => value != null && value.length > 0) .map((value) => ({ Value: JSON.stringify(value) })); } } } exports.Record = Record; //# sourceMappingURL=record.js.map