-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#557: add support for transactionalEmail
add/update/retrieve/delete
- Loading branch information
1 parent
728bd1f
commit a55512b
Showing
6 changed files
with
317 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
133
lib/metadataTypes/definitions/TransactionalEmail.definition.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}, | ||
}; |