Skip to content

Commit

Permalink
Merge pull request #1267 from Accenture/feature/1266-add-support-for-…
Browse files Browse the repository at this point in the history
…sendclassification-createupdatedelete-and-resolve-deliveryprofile-and-senderprofile

Feature/1266 add support for sendClassification create/update/delete and resolve deliveryProfile and senderProfile
  • Loading branch information
JoernBerkefeld authored Apr 15, 2024
2 parents 38bb2c6 + 83ef7b6 commit 7730620
Show file tree
Hide file tree
Showing 18 changed files with 619 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/metadataTypes/ImportFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class ImportFile extends MetadataType {
* prepares a import definition for deployment
*
* @param {MetadataTypeItem} metadata a single importDef
* @returns {Promise} Promise
* @returns {Promise.<MetadataTypeItem>} Promise
*/
static async preDeployTasks(metadata) {
const fileLocation = cache.getByKey('fileLocation', metadata.source.r__fileLocation_name);
Expand Down
103 changes: 103 additions & 0 deletions lib/metadataTypes/SendClassification.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

import MetadataType from './MetadataType.js';
import { Util } from '../util/util.js';
import cache from '../util/cache.js';

/**
* @typedef {import('../../types/mcdev.d.js').BuObject} BuObject
Expand Down Expand Up @@ -44,6 +46,107 @@ class SendClassification extends MetadataType {
}
return super.retrieveSOAP(retrieveDir, requestParams, key);
}
/**
* Updates a single item
*
* @param {MetadataTypeItem} metadataItem a single item
* @returns {Promise} Promise
*/
static update(metadataItem) {
return super.updateSOAP(metadataItem);
}

/**
* Creates a single item
*
* @param {MetadataTypeItem} metadataItem a single item
* @returns {Promise} Promise
*/
static create(metadataItem) {
return super.createSOAP(metadataItem);
}

/**
* Delete a metadata item from the specified business unit
*
* @param {string} customerKey Identifier of data extension
* @returns {Promise.<boolean>} deletion success status
*/
static deleteByKey(customerKey) {
return super.deleteByKeySOAP(customerKey);
}
/**
* prepares a import definition for deployment
*
* @param {MetadataTypeItem} metadata a single importDef
* @returns {Promise.<MetadataTypeItem>} Promise
*/
static async preDeployTasks(metadata) {
metadata.SendClassificationType =
this.definition.sendClassificationTypeMapping[metadata.c__classification];
delete metadata.c__classification;

metadata.SenderProfile = {
CustomerKey: cache.searchForField(
'senderProfile',
metadata.r__senderProfile_CustomerKey,
'CustomerKey',
'CustomerKey'
),
};
delete metadata.r__senderProfile_CustomerKey;

metadata.DeliveryProfile = {
CustomerKey: cache.searchForField(
'deliveryProfile',
metadata.r__deliveryProfile_key,
'key',
'key'
),
};
delete metadata.r__deliveryProfile_key;

return metadata;
}

/**
* manages post retrieve steps
*
* @param {MetadataTypeItem} metadata a single item
* @returns {MetadataTypeItem} parsed metadata
*/
static postRetrieveTasks(metadata) {
metadata.c__classification = Util.inverseGet(
this.definition.sendClassificationTypeMapping,
metadata.SendClassificationType
);
delete metadata.SendClassificationType;

try {
metadata.r__senderProfile_CustomerKey = cache.searchForField(
'senderProfile',
metadata.SenderProfile.CustomerKey,
'CustomerKey',
'CustomerKey'
);
delete metadata.SenderProfile;
} catch (ex) {
Util.logger.warn(` - ${this.definition.type} ${metadata.CustomerKey}: ${ex.message}`);
}
try {
metadata.r__deliveryProfile_key = cache.searchForField(
'deliveryProfile',
metadata.DeliveryProfile.CustomerKey,
'key',
'key'
);
delete metadata.DeliveryProfile;
} catch (ex) {
Util.logger.warn(` - ${this.definition.type} ${metadata.CustomerKey}: ${ex.message}`);
}

return metadata;
}
}

// Assign definition to static attributes
Expand Down
2 changes: 1 addition & 1 deletion lib/metadataTypes/SenderProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SenderProfile extends MetadataType {
* @param {string} [key] customer key of single item to retrieve
* @returns {Promise.<MetadataTypeMapObj>} Promise of metadata
*/
static retrieve(retrieveDir, _, __, key) {
static async retrieve(retrieveDir, _, __, key) {
/** @type {SoapRequestParams} */
let requestParams;
if (key) {
Expand Down
77 changes: 58 additions & 19 deletions lib/metadataTypes/definitions/SendClassification.definition.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/sendclassification.html
export default {
bodyIteratorField: 'Results',
dependencies: [],
dependencies: ['senderProfile', 'deliveryProfile'],
filter: {},
hasExtended: false,
idField: 'ObjectID',
Expand All @@ -18,6 +18,10 @@ export default {
'Lets admins define Delivery Profile, Sender Profile and CAN-SPAM for an email job in a central location.',
typeRetrieveByDefault: false,
typeName: 'Send Classification',
sendClassificationTypeMapping: {
Commercial: 'Marketing',
Transactional: 'Operational',
},
fields: {
'Client.ID': {
isCreateable: false,
Expand All @@ -28,38 +32,38 @@ export default {
CreatedDate: {
isCreateable: false,
isUpdateable: false,
retrieving: false,
retrieving: true,
template: false,
},
ModifiedDate: {
isCreateable: false,
isUpdateable: false,
retrieving: false,
retrieving: true,
template: false,
},
CustomerKey: {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: false,
template: true,
},
ObjectID: {
isCreateable: false,
isUpdateable: false,
isUpdateable: true,
retrieving: true,
template: false,
},
Name: {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: false,
template: true,
},
Description: {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: false,
template: true,
},
PartnerKey: {
isCreateable: false,
Expand All @@ -75,40 +79,75 @@ export default {
},

ArchiveEmail: {
isCreateable: false,
isUpdateable: false,
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
DeliveryProfile: {
'DeliveryProfile.CustomerKey': {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
'DeliveryProfile.PartnerKey': {
isCreateable: false,
isUpdateable: false,
retrieving: false,
template: false,
},
HonorPublicationListOptOutsForTransactionalSends: {
'DeliveryProfile.ObjectID': {
isCreateable: false,
isUpdateable: false,
retrieving: false,
template: false,
},
SendClassificationType: {
HonorPublicationListOptOutsForTransactionalSends: {
/* not supported */
isCreateable: false,
isUpdateable: false,
retrieving: false,
template: false,
},
SendClassificationType: {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
'SenderProfile.CustomerKey': {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
SenderProfile: {
'SenderProfile.PartnerKey': {
isCreateable: false,
isUpdateable: false,
retrieving: false,
template: false,
},
'SenderProfile.ObjectID': {
isCreateable: false,
isUpdateable: false,
retrieving: false,
template: false,
},
SendPriority: {
/* not supported */
isCreateable: false,
isUpdateable: false,
retrieving: false,
template: false,
},
c__classification: {
skipValidation: true,
},
r__deliveryProfile_key: {
skipValidation: true,
},
r__senderProfile_CustomerKey: {
skipValidation: true,
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"CustomerKey": "testExisting_sendClassification",
"Name": "testExisting_sendClassification",
"Description": "updated on deploy",
"c__classification": "Commercial",
"r__senderProfile_CustomerKey": "testExisting_senderProfile",
"r__deliveryProfile_key": "Default"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"CustomerKey": "testNew_sendClassification",
"Name": "testNew_sendClassification",
"Description": "created on deploy",
"c__classification": "Commercial",
"r__senderProfile_CustomerKey": "testExisting_senderProfile",
"r__deliveryProfile_key": "Default"
}
8 changes: 8 additions & 0 deletions test/resources/9999999/sendClassification/build-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"CustomerKey": "testTemplated_sendClassification",
"Description": "",
"Name": "testTemplated_sendClassification",
"c__classification": "Commercial",
"r__deliveryProfile_key": "Default",
"r__senderProfile_CustomerKey": "testTemplated_senderProfile"
}
51 changes: 51 additions & 0 deletions test/resources/9999999/sendClassification/create-response.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soap:Header>
<wsa:Action>CreateResponse</wsa:Action>
<wsa:MessageID>urn:uuid:bb642235-9021-414c-8f0e-31d693a573e8</wsa:MessageID>
<wsa:RelatesTo>urn:uuid:b49d6c14-33d7-4ba8-8aea-0fe3282fdbfd</wsa:RelatesTo>
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
<wsse:Security>
<wsu:Timestamp wsu:Id="Timestamp-3e603e14-dc4c-4733-be8a-e2d8d3e205cb">
<wsu:Created>2024-04-15T21:38:02Z</wsu:Created>
<wsu:Expires>2024-04-15T21:43:02Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</soap:Header>
<soap:Body>
<CreateResponse xmlns="http://exacttarget.com/wsdl/partnerAPI">
<Results>
<StatusCode>OK</StatusCode>
<StatusMessage>SendClassification created</StatusMessage>
<OrdinalID>0</OrdinalID>
<NewID>0</NewID>
<NewObjectID>07cf2a6e-70fb-ee11-a5c8-5cba2c6fc270</NewObjectID>
<Object xsi:type="SendClassification">
<PartnerKey xsi:nil="true" />
<ObjectID>07cf2a6e-70fb-ee11-a5c8-5cba2c6fc270</ObjectID>
<CustomerKey>testNew_sendClassification</CustomerKey>
<SendClassificationType>Operational</SendClassificationType>
<Name>testNew_sendClassification</Name>
<Description>created on deploy</Description>
<SenderProfile>
<PartnerKey xsi:nil="true" />
<ObjectID xsi:nil="true" />
<CustomerKey>testExisting_senderProfile</CustomerKey>
</SenderProfile>
<DeliveryProfile>
<PartnerKey xsi:nil="true" />
<ObjectID xsi:nil="true" />
<CustomerKey>Default</CustomerKey>
</DeliveryProfile>
</Object>
</Results>
<RequestID>d5f798f9-02eb-4b76-a4b4-90cfee939ce2</RequestID>
<OverallStatus>OK</OverallStatus>
</CreateResponse>
</soap:Body>
</soap:Envelope>
Loading

0 comments on commit 7730620

Please sign in to comment.