Skip to content

Commit

Permalink
#557: add support for transactionalEmail
Browse files Browse the repository at this point in the history
add/update/retrieve/delete
  • Loading branch information
JoernBerkefeld committed Nov 22, 2022
1 parent 728bd1f commit a55512b
Show file tree
Hide file tree
Showing 6 changed files with 317 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ The following metadata types are currently supported:
| Mobile Connect Code | `mobileCode` | Yes | No | No | - | Mobile Connect Shore or Long Codes used for sending. First 50 per BU are retrieved |
| Mobile Connect Keyword | `mobileKeyword` | Yes | Yes | Yes | - | Mobile Connect keywords configured within the Business UNit. First 50 per BU are retrieved |
| Role | `role` | Yes | Yes | Yes (`bt`) | Yes | User Roles define groups that are used to grant users access to SFMC systems. |
| Transactional Email | `transactionalEmail` | Yes | Yes | Yes | Yes | Lets you send immediate Email messages via API events |
| Transactional SMS | `transactionalSMS` | Yes | Yes | Yes | Yes | Lets you send immediate SMS messages via API events |
| Triggered Send | `triggeredSendDefinition` | Yes | Yes | Yes (`bt`) | Yes | **DEPRECATED**: Sends emails via API or DataExtension Event. |
| User | `accountUser` | Yes | in backlog | - | - | Users and Installed Packages including their assigned Roles, BUs and personal permissions |
Expand Down Expand Up @@ -774,6 +775,7 @@ Currently supported types:
| Data Extension Field | `dataExtensionField` |
| Email Send Definition | `Email Send Definition` |
| List | `list` |
| Transactional Email | `transactionalEmail` |
| Transactional SMS | `transactionalSMS` |
| Triggered Send | `triggeredSendDefinition` |
Expand Down
79 changes: 79 additions & 0 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ Provides default functionality that can be overwritten by child metadata type cl
<dt><a href="#SetDefinition">SetDefinition</a> ⇐ <code><a href="#MetadataType">MetadataType</a></code></dt>
<dd><p>SetDefinition MetadataType</p>
</dd>
<dt><a href="#TransactionalEmail">TransactionalEmail</a> ⇐ <code><a href="#MetadataType">MetadataType</a></code></dt>
<dd><p>TransactionalEmail MetadataType</p>
</dd>
<dt><a href="#TransactionalSMS">TransactionalSMS</a> ⇐ <code><a href="#MetadataType">MetadataType</a></code></dt>
<dd><p>TransactionalSMS MetadataType</p>
</dd>
Expand Down Expand Up @@ -4357,6 +4360,82 @@ Retrieves Metadata of schema set definitions for caching.

**Kind**: static method of [<code>SetDefinition</code>](#SetDefinition)
**Returns**: <code>Promise.&lt;TYPE.MetadataTypeMapObj&gt;</code> - Promise
<a name="TransactionalEmail"></a>

## TransactionalEmail ⇐ [<code>MetadataType</code>](#MetadataType)
TransactionalEmail MetadataType

**Kind**: global class
**Extends**: [<code>MetadataType</code>](#MetadataType)

* [TransactionalEmail](#TransactionalEmail)[<code>MetadataType</code>](#MetadataType)
* [.retrieve(retrieveDir, [_], [__], [___], [key])](#TransactionalEmail.retrieve) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMapObj&gt;</code>
* [.retrieveForCache()](#TransactionalEmail.retrieveForCache) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMapObj&gt;</code>
* [.update(metadata)](#TransactionalEmail.update) ⇒ <code>Promise</code>
* [.create(metadata)](#TransactionalEmail.create) ⇒ <code>Promise</code>
* [.deleteByKey(buObject, key)](#TransactionalEmail.deleteByKey) ⇒ <code>Promise.&lt;boolean&gt;</code>

<a name="TransactionalEmail.retrieve"></a>

### TransactionalEmail.retrieve(retrieveDir, [_], [__], [___], [key]) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMapObj&gt;</code>
Retrieves Metadata of Mobile Keywords
Endpoint /legacy/v1/beta/mobile/code/ return all Mobile Codes with all details.

**Kind**: static method of [<code>TransactionalEmail</code>](#TransactionalEmail)
**Returns**: <code>Promise.&lt;TYPE.MetadataTypeMapObj&gt;</code> - Promise of metadata

| Param | Type | Description |
| --- | --- | --- |
| retrieveDir | <code>string</code> | Directory where retrieved metadata directory will be saved |
| [_] | <code>void</code> | unused parameter |
| [__] | <code>void</code> | unused parameter |
| [___] | <code>void</code> | unused parameter |
| [key] | <code>string</code> | customer key of single item to retrieve |

<a name="TransactionalEmail.retrieveForCache"></a>

### TransactionalEmail.retrieveForCache() ⇒ <code>Promise.&lt;TYPE.MetadataTypeMapObj&gt;</code>
Retrieves event definition metadata for caching

**Kind**: static method of [<code>TransactionalEmail</code>](#TransactionalEmail)
**Returns**: <code>Promise.&lt;TYPE.MetadataTypeMapObj&gt;</code> - Promise of metadata
<a name="TransactionalEmail.update"></a>

### TransactionalEmail.update(metadata) ⇒ <code>Promise</code>
Updates a single item

**Kind**: static method of [<code>TransactionalEmail</code>](#TransactionalEmail)
**Returns**: <code>Promise</code> - Promise

| Param | Type | Description |
| --- | --- | --- |
| metadata | <code>TYPE.MetadataTypeItem</code> | a single item |

<a name="TransactionalEmail.create"></a>

### TransactionalEmail.create(metadata) ⇒ <code>Promise</code>
Creates a single item

**Kind**: static method of [<code>TransactionalEmail</code>](#TransactionalEmail)
**Returns**: <code>Promise</code> - Promise

| Param | Type | Description |
| --- | --- | --- |
| metadata | <code>TYPE.MetadataTypeItem</code> | a single item |

<a name="TransactionalEmail.deleteByKey"></a>

### TransactionalEmail.deleteByKey(buObject, key) ⇒ <code>Promise.&lt;boolean&gt;</code>
Delete a metadata item from the specified business unit

**Kind**: static method of [<code>TransactionalEmail</code>](#TransactionalEmail)
**Returns**: <code>Promise.&lt;boolean&gt;</code> - deletion success status

| Param | Type | Description |
| --- | --- | --- |
| buObject | <code>TYPE.BuObject</code> | references credentials |
| key | <code>string</code> | Identifier of item |

<a name="TransactionalSMS"></a>

## TransactionalSMS ⇐ [<code>MetadataType</code>](#MetadataType)
Expand Down
1 change: 1 addition & 0 deletions lib/MetadataTypeDefinitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const MetadataTypeDefinitions = {
role: require('./metadataTypes/definitions/Role.definition'),
script: require('./metadataTypes/definitions/Script.definition'),
setDefinition: require('./metadataTypes/definitions/SetDefinition.definition'),
transactionalEmail: require('./metadataTypes/definitions/TransactionalEmail.definition'),
transactionalSMS: require('./metadataTypes/definitions/TransactionalSMS.definition'),
triggeredSendDefinition: require('./metadataTypes/definitions/TriggeredSendDefinition.definition'),
};
Expand Down
1 change: 1 addition & 0 deletions lib/MetadataTypeInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const MetadataTypeInfo = {
role: require('./metadataTypes/Role'),
script: require('./metadataTypes/Script'),
setDefinition: require('./metadataTypes/SetDefinition'),
transactionalEmail: require('./metadataTypes/TransactionalEmail'),
transactionalSMS: require('./metadataTypes/TransactionalSMS'),
triggeredSendDefinition: require('./metadataTypes/TriggeredSendDefinition'),
};
Expand Down
101 changes: 101 additions & 0 deletions lib/metadataTypes/TransactionalEmail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
'use strict';

const TYPE = require('../../types/mcdev.d');
const MetadataType = require('./MetadataType');
const Util = require('../util/util');

/**
* TransactionalEmail MetadataType
*
* @augments MetadataType
*/
class TransactionalEmail extends MetadataType {
/**
* Retrieves Metadata of Mobile Keywords
* Endpoint /legacy/v1/beta/mobile/code/ return all Mobile Codes with all details.
*
* @param {string} retrieveDir Directory where retrieved metadata directory will be saved
* @param {void} [_] unused parameter
* @param {void} [__] unused parameter
* @param {void} [___] unused parameter
* @param {string} [key] customer key of single item to retrieve
* @returns {Promise.<TYPE.MetadataTypeMapObj>} Promise of metadata
*/
static async retrieve(retrieveDir, _, __, ___, key) {
let keyList;
const baseUri = '/messaging/v1/email/definitions/';
if (!key) {
// Retrieve all
const response = this.definition.restPagination
? await this.client.rest.getBulk(baseUri)
: await this.client.rest.get(baseUri);
keyList = Object.keys(this.parseResponseBody(response));
} else {
// Retrieve single
keyList = [key];
}

// get all sms with additional details not given by the list endpoint
const details = keyList
? await Promise.all(keyList.map((key) => this.client.rest.get(baseUri + (key || ''))))
: [];

const parsed = this.parseResponseBody({ definitions: details });

// * retrieveDir is mandatory in this method as it is not used for caching (there is a seperate method for that)
const savedMetadata = await this.saveResults(parsed, retrieveDir, null, null);
Util.logger.info(
`Downloaded: ${this.definition.type} (${Object.keys(savedMetadata).length})`
);

return { metadata: savedMetadata, type: this.definition.type };
}

/**
* Retrieves event definition metadata for caching
*
* @returns {Promise.<TYPE.MetadataTypeMapObj>} Promise of metadata
*/
static retrieveForCache() {
return super.retrieveREST(null, '/messaging/v1/email/definitions/');
}
/**
* Updates a single item
*
* @param {TYPE.MetadataTypeItem} metadata a single item
* @returns {Promise} Promise
*/
static update(metadata) {
return super.updateREST(metadata, '/messaging/v1/email/definitions');
}

/**
* Creates a single item
*
* @param {TYPE.MetadataTypeItem} metadata a single item
* @returns {Promise} Promise
*/
static create(metadata) {
return super.createREST(metadata, '/messaging/v1/email/definitions');
}
/**
* Delete a metadata item from the specified business unit
*
* @param {TYPE.BuObject} buObject references credentials
* @param {string} key Identifier of item
* @returns {Promise.<boolean>} deletion success status
*/
static deleteByKey(buObject, key) {
return super.deleteByKeyREST(
buObject,
'/messaging/v1/email/definitions/' + key,
key,
false
);
}
}

// Assign definition to static attributes
TransactionalEmail.definition = require('../MetadataTypeDefinitions').transactionalEmail;

module.exports = TransactionalEmail;
133 changes: 133 additions & 0 deletions lib/metadataTypes/definitions/TransactionalEmail.definition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
module.exports = {
bodyIteratorField: 'definitions',
dependencies: [],
hasExtended: false,
idField: 'definitionId',
keyField: 'definitionKey',
nameField: 'name',
createdDateField: 'createdDate',
createdNameField: null,
lastmodDateField: 'modifiedDate',
lastmodNameField: null,
restPagination: false,
type: 'transactionalEmail',
typeDescription: 'Lets you send immediate Email messages via API events',
typeRetrieveByDefault: true,
typeName: 'Transactional Email',
fields: {
name: {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
definitionKey: {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
description: {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
requestId: {
isCreateable: false,
isUpdateable: false,
retrieving: false,
template: false,
},
definitionId: {
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
status: {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: false,
},
createdDate: {
isCreateable: false,
isUpdateable: false,
retrieving: true,
template: false,
},
modifiedDate: {
isCreateable: false,
isUpdateable: false,
retrieving: true,
template: false,
},
classification: {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
'content.customerKey': {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
'subscriptions.dataExtension': {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
'subscriptions.list': {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
'subscriptions.autoAddSubscriber': {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
'subscriptions.updateSubscriber': {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
'options.trackLinks': {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
'options.cc': {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
'options.bcc': {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
journey: {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
'journey.interactionKey': {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
},
};

0 comments on commit a55512b

Please sign in to comment.