Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task/2005 resolve locationTypeId on fileLocation #2006

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions @types/lib/metadataTypes/FileLocation.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion @types/lib/metadataTypes/FileLocation.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions @types/lib/metadataTypes/definitions/FileLocation.definition.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 43 additions & 5 deletions lib/metadataTypes/FileLocation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

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

/**
* @typedef {import('../../types/mcdev.d.js').BuObject} BuObject
Expand All @@ -20,10 +21,10 @@ import MetadataType from './MetadataType.js';
*
* @augments MetadataType
*/
class FtpLocation extends MetadataType {
class FileLocation extends MetadataType {
/**
* Retrieves Metadata of FtpLocation
* Endpoint /automation/v1/ftplocations/ return all FtpLocations
* Retrieves Metadata of FileLocation
* Endpoint /automation/v1/ftplocations/ return all FileLocations
*
* @param {string} retrieveDir Directory where retrieved metadata directory will be saved
* @param {void | string[]} [_] unused parameter
Expand All @@ -43,10 +44,47 @@ class FtpLocation extends MetadataType {
static async retrieveForCache() {
return super.retrieveREST(null, '/automation/v1/ftplocations/');
}

/**
* prepares a import definition for deployment
*
* @param {MetadataTypeItem} metadata a single importDef
* @returns {Promise.<MetadataTypeItem>} Promise
*/
static async preDeployTasks(metadata) {
if (metadata.c__locationType) {
metadata.locationTypeId = this.definition.locationTypeMapping[metadata.c__locationType];
}
return metadata;
}

/**
* manages post retrieve steps
*
* @param {MetadataTypeItem} metadata a single item
* @returns {MetadataTypeItem} parsed metadata
*/
static postRetrieveTasks(metadata) {
if (metadata.locationTypeId) {
try {
metadata.c__locationType = Util.inverseGet(
this.definition.locationTypeMapping,
metadata.locationTypeId
);
delete metadata.locationTypeId;
} catch {
Util.logger.info(
'Please report this new & unknown locationTypeId to the mcdev developer team via github: ' +
metadata.locationTypeId
);
}
}
return metadata;
}
}

// Assign definition to static attributes
import MetadataTypeDefinitions from '../MetadataTypeDefinitions.js';
FtpLocation.definition = MetadataTypeDefinitions.fileLocation;
FileLocation.definition = MetadataTypeDefinitions.fileLocation;

export default FtpLocation;
export default FileLocation;
24 changes: 22 additions & 2 deletions lib/metadataTypes/definitions/FileLocation.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ export default {
'Used for export or import of files to/from Marketing Cloud. Previously this was labeled ftpLocation.',
typeRetrieveByDefault: true,
typeName: 'File Location',
locationTypeMapping: {
'Enhanced FTP Site Import Directory': 0,
'External FTP Site': 1,
'External SFTP Site': 2,
'External FTPS Site': 3,
'Salesforce Objects and Reports': 4,
Safehouse: 5,
'Enhanced FTP Site Export Directory': 6,
'Legacy Import Directory': 8,
'Relative location under FTP Site': 9,
'Amazon Simple Storage Service': 13,
'Azure Blob Storage': 15,
'Google Cloud Storage': 16,
},
fields: {
id: {
isCreateable: false,
Expand All @@ -34,19 +48,25 @@ export default {
isCreateable: false,
isUpdateable: false,
retrieving: true,
template: false,
template: true,
},
name: {
isCreateable: false,
isUpdateable: false,
retrieving: true,
template: false,
template: true,
},
relPath: {
isCreateable: true,
isUpdateable: true,
retrieving: true,
template: true,
},
c__locationType: {
isCreateable: false,
isUpdateable: false,
retrieving: true,
template: true,
},
},
};
Loading