@basetime/bldr-sfmc-sdk
Advanced tools
Comparing version 1.0.25 to 1.0.26
@@ -311,19 +311,23 @@ "use strict"; | ||
} | ||
return (resp.items.map((result) => { | ||
let objectKey = ''; | ||
switch (searchActivity) { | ||
case 'ssjs': | ||
objectKey = 'ssjsActivityId'; | ||
break; | ||
case 'sql': | ||
objectKey = 'queryDefinitionId'; | ||
break; | ||
} | ||
return { | ||
Name: result.name, | ||
[objectKey]: result[objectKey], | ||
CategoryID: result.categoryId, | ||
ModifiedDate: result.modifiedDate, | ||
}; | ||
}) || []); | ||
return ((resp && | ||
resp.items && | ||
resp.items.length && | ||
resp.items.map((result) => { | ||
let objectKey = ''; | ||
switch (searchActivity) { | ||
case 'ssjs': | ||
objectKey = 'ssjsActivityId'; | ||
break; | ||
case 'sql': | ||
objectKey = 'queryDefinitionId'; | ||
break; | ||
} | ||
return { | ||
Name: result.name, | ||
[objectKey]: result[objectKey], | ||
CategoryID: result.categoryId, | ||
ModifiedDate: result.modifiedDate, | ||
}; | ||
})) || | ||
[]); | ||
} | ||
@@ -351,6 +355,14 @@ catch (err) { | ||
const isolateFolderIds = rootFolderID && rootFolderID !== request.categoryId | ||
? buildFolderPaths.folders | ||
.map((folder) => rootFolderID !== folder.ID && folder.ID) | ||
.filter(Boolean) | ||
: buildFolderPaths.folders.map((folder) => folder.ID); | ||
? (buildFolderPaths && | ||
buildFolderPaths.folders && | ||
buildFolderPaths.folders.length && | ||
buildFolderPaths.folders | ||
.map((folder) => rootFolderID !== folder.ID && folder.ID) | ||
.filter(Boolean)) || | ||
[] | ||
: (buildFolderPaths && | ||
buildFolderPaths.folders && | ||
buildFolderPaths.folders.length && | ||
buildFolderPaths.folders.map((folder) => folder.ID)) || | ||
[]; | ||
const definitionReturn = []; | ||
@@ -357,0 +369,0 @@ for (const i in isolateFolderIds) { |
@@ -100,2 +100,4 @@ "use strict"; | ||
const formattedResponse = (response && | ||
response.items && | ||
response.items.length && | ||
response.items.map((asset) => { | ||
@@ -294,15 +296,18 @@ var _a, _b, _c; | ||
packageOut['contentBuilder'] = {}; | ||
return (packageOut['contentBuilder']['assets'] = contextAssets.map((asset) => { | ||
return { | ||
id: asset.id, | ||
bldrId: asset.bldrId, | ||
name: asset.name, | ||
assetType: asset.assetType, | ||
category: { | ||
folderPath: (asset.category && asset.category.folderPath) || | ||
asset.folderPath, | ||
}, | ||
content: (0, GetContentBuilderAssetContent_1.getContentBuilderAssetContent)(asset), | ||
}; | ||
})); | ||
return ((packageOut['contentBuilder']['assets'] = | ||
contextAssets && | ||
contextAssets.length && | ||
contextAssets.map((asset) => { | ||
return { | ||
id: asset.id, | ||
bldrId: asset.bldrId, | ||
name: asset.name, | ||
assetType: asset.assetType, | ||
category: { | ||
folderPath: (asset.category && asset.category.folderPath) || | ||
asset.folderPath, | ||
}, | ||
content: (0, GetContentBuilderAssetContent_1.getContentBuilderAssetContent)(asset), | ||
}; | ||
})) || []); | ||
}); | ||
@@ -309,0 +314,0 @@ /** |
@@ -105,3 +105,3 @@ import { SFMC_Client } from '../types/sfmc_client'; | ||
*/ | ||
gatherAssetById: (customerKey: string, complete?: boolean) => Promise<any>; | ||
gatherAssetById: (customerKey: string, complete?: boolean, shared?: boolean) => Promise<any>; | ||
} |
@@ -50,2 +50,4 @@ "use strict"; | ||
const formattedResponse = (response && | ||
response.Results && | ||
response.Results.length && | ||
response.Results.map((folder) => { | ||
@@ -100,2 +102,4 @@ return { | ||
const formattedResponse = (response && | ||
response.Results && | ||
response.Results.length && | ||
response.Results.map((dataExtension) => { | ||
@@ -142,2 +146,6 @@ return { | ||
try { | ||
const shared = request.contentType === 'shared_dataextension' ? true : false; | ||
const rootParentName = shared | ||
? 'Shared Data Extensions' | ||
: 'Data Extensions'; | ||
const folderResponse = yield this.sfmc.folder.getFoldersFromMiddle(request); | ||
@@ -150,3 +158,3 @@ const buildFolderPaths = folderResponse && | ||
folderResponse.down | ||
.map((folder) => folder.Name !== 'Data Extensions' && folder.ID) | ||
.map((folder) => folder.Name !== rootParentName && folder.ID) | ||
.filter(Boolean)) || | ||
@@ -163,3 +171,3 @@ []; | ||
const dataExtensionPayload = dataExtension && | ||
(yield this.sfmc.emailStudio.retrieveDataExtensionPayloadByName(dataExtension.Name, complete)); | ||
(yield this.sfmc.emailStudio.retrieveDataExtensionPayloadByName(dataExtension.Name, complete, shared)); | ||
formattedAssetResponse.push(dataExtensionPayload); | ||
@@ -192,3 +200,3 @@ } | ||
*/ | ||
this.gatherAssetById = (customerKey, complete = false) => __awaiter(this, void 0, void 0, function* () { | ||
this.gatherAssetById = (customerKey, complete = false, shared = false) => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
@@ -199,25 +207,34 @@ if (!customerKey) { | ||
// Accounts for LegacyIds and Content Builder AssetIds | ||
let dataExtensionPayload = yield this.sfmc.emailStudio.retrieveDataExtensionPayloadByCustomerKey(customerKey, complete); | ||
let dataExtensionPayload = yield this.sfmc.emailStudio.retrieveDataExtensionPayloadByCustomerKey(customerKey, complete, shared); | ||
const categoryId = dataExtensionPayload.category.categoryId; | ||
const dataExtensionFolderObject = yield this.sfmc.folder.getFolder({ | ||
contentType: 'dataextension', | ||
contentType: shared ? 'shared_dataextension' : 'dataextension', | ||
categoryId, | ||
}); | ||
if (dataExtensionFolderObject && | ||
!dataExtensionFolderObject.Results) { | ||
throw new Error('No Folders Found'); | ||
} | ||
let parentFolders = yield this.sfmc.folder.getParentFoldersRecursive({ | ||
contentType: 'dataextension', | ||
contentType: shared | ||
? 'shared_dataextension' | ||
: 'dataextension', | ||
categoryId, | ||
}); | ||
const folderResponse = [ | ||
const buildFolderPaths = yield (0, BuildSoapFolderObjects_1.buildFolderPathsSoap)([ | ||
...parentFolders.results, | ||
...dataExtensionFolderObject.Results, | ||
]; | ||
const buildFolderPaths = yield (0, BuildSoapFolderObjects_1.buildFolderPathsSoap)(folderResponse); | ||
const formattedFolders = buildFolderPaths.folders.map((folder) => { | ||
return { | ||
id: folder.ID, | ||
name: folder.Name, | ||
parentId: folder.ParentFolder.ID, | ||
folderPath: folder.FolderPath, | ||
}; | ||
}); | ||
]); | ||
const formattedFolders = (buildFolderPaths && | ||
buildFolderPaths.folders && | ||
buildFolderPaths.folders.length && | ||
buildFolderPaths.folders.map((folder) => { | ||
return { | ||
id: folder.ID, | ||
name: folder.Name, | ||
parentId: folder.ParentFolder.ID, | ||
folderPath: folder.FolderPath, | ||
}; | ||
})) || | ||
[]; | ||
return { | ||
@@ -229,3 +246,3 @@ folders: formattedFolders, | ||
catch (err) { | ||
return err.message; | ||
return err; | ||
} | ||
@@ -232,0 +249,0 @@ }); |
@@ -20,2 +20,3 @@ "use strict"; | ||
'Data Extensions', | ||
'Shared Data Extensions', | ||
'Query', | ||
@@ -97,2 +98,3 @@ 'Scripts', | ||
return ((folderResponse && | ||
folderResponse.length && | ||
folderResponse.map((folder) => { | ||
@@ -99,0 +101,0 @@ return { |
@@ -94,5 +94,10 @@ "use strict"; | ||
} | ||
midsArray = getAllMidsRequest.Results.map((BU) => { | ||
return BU.Client.ID; | ||
}); | ||
midsArray = | ||
(getAllMidsRequest && | ||
getAllMidsRequest.Results && | ||
getAllMidsRequest.Results.length && | ||
getAllMidsRequest.Results.map((BU) => { | ||
return BU.Client.ID; | ||
})) || | ||
[]; | ||
} | ||
@@ -99,0 +104,0 @@ for (let m in midsArray) { |
@@ -79,3 +79,3 @@ import { FieldTypes } from '../types/objects/sfmc_data_extension_assets'; | ||
*/ | ||
retrieveDataExtensionPayloadByName: (dataExtensionName: string, complete?: boolean) => Promise<{ | ||
retrieveDataExtensionPayloadByName: (dataExtensionName: string, complete?: boolean, shared?: boolean) => Promise<{ | ||
objectId: string; | ||
@@ -111,3 +111,3 @@ bldrId: string; | ||
*/ | ||
retrieveDataExtensionPayloadByCustomerKey: (customerKey: string, complete?: boolean) => Promise<{ | ||
retrieveDataExtensionPayloadByCustomerKey: (customerKey: string, complete?: boolean, shared?: boolean) => Promise<{ | ||
objectId: string; | ||
@@ -138,3 +138,3 @@ bldrId: string; | ||
} | undefined>; | ||
getDataExtensionPayload: (dataExtension: any) => Promise<{ | ||
getDataExtensionPayload: (dataExtension: any, shared?: boolean) => Promise<{ | ||
objectId: string; | ||
@@ -165,3 +165,3 @@ bldrId: string; | ||
} | undefined>; | ||
getDataExtensionPayloadComplete: (dataExtension: any) => Promise<{ | ||
getDataExtensionPayloadComplete: (dataExtension: any, shared?: boolean) => Promise<{ | ||
objectId: string; | ||
@@ -168,0 +168,0 @@ bldrId: string; |
@@ -154,3 +154,3 @@ "use strict"; | ||
*/ | ||
this.retrieveDataExtensionPayloadByName = (dataExtensionName, complete = false) => __awaiter(this, void 0, void 0, function* () { | ||
this.retrieveDataExtensionPayloadByName = (dataExtensionName, complete = false, shared = false) => __awaiter(this, void 0, void 0, function* () { | ||
const dataExtension = yield this.client.soap.retrieve('DataExtension', dataExtensionDefinition, { | ||
@@ -164,4 +164,4 @@ filter: { | ||
return complete === false | ||
? this.getDataExtensionPayload(dataExtension) | ||
: this.getDataExtensionPayloadComplete(dataExtension); | ||
? this.getDataExtensionPayload(dataExtension, shared) | ||
: this.getDataExtensionPayloadComplete(dataExtension, shared); | ||
}); | ||
@@ -173,3 +173,3 @@ /** | ||
*/ | ||
this.retrieveDataExtensionPayloadByCustomerKey = (customerKey, complete = false) => __awaiter(this, void 0, void 0, function* () { | ||
this.retrieveDataExtensionPayloadByCustomerKey = (customerKey, complete = false, shared = false) => __awaiter(this, void 0, void 0, function* () { | ||
const dataExtension = yield this.client.soap.retrieve('DataExtension', dataExtensionDefinition, { | ||
@@ -183,6 +183,6 @@ filter: { | ||
return complete === false | ||
? this.getDataExtensionPayload(dataExtension) | ||
: this.getDataExtensionPayloadComplete(dataExtension); | ||
? this.getDataExtensionPayload(dataExtension, shared) | ||
: this.getDataExtensionPayloadComplete(dataExtension, shared); | ||
}); | ||
this.getDataExtensionPayload = (dataExtension) => __awaiter(this, void 0, void 0, function* () { | ||
this.getDataExtensionPayload = (dataExtension, shared = false) => __awaiter(this, void 0, void 0, function* () { | ||
let sendableName; | ||
@@ -200,3 +200,5 @@ let RelatesOnSub; | ||
const folderPathResponse = yield this.folder.getParentFoldersRecursive({ | ||
contentType: 'dataextension', | ||
contentType: shared | ||
? 'shared_dataextension' | ||
: 'dataextension', | ||
categoryId: dataExtension.Results[0].CategoryID, | ||
@@ -206,3 +208,4 @@ }); | ||
const dataExtensionFolderObject = compiledFolderPaths.folders.find((folder) => folder.ID === dataExtension.Results[0].CategoryID); | ||
const { FolderPath } = dataExtensionFolderObject; | ||
const FolderPath = dataExtensionFolderObject && | ||
dataExtensionFolderObject.FolderPath; | ||
const dataExtensionFields = yield this.getDataExtensionFields(dataExtension.Results[0].CustomerKey); | ||
@@ -334,3 +337,3 @@ let sendable = dataExtension.Results[0].IsSendable; | ||
}); | ||
this.getDataExtensionPayloadComplete = (dataExtension) => __awaiter(this, void 0, void 0, function* () { | ||
this.getDataExtensionPayloadComplete = (dataExtension, shared = false) => __awaiter(this, void 0, void 0, function* () { | ||
let sendableName; | ||
@@ -348,3 +351,5 @@ let RelatesOnSub; | ||
const folderPathResponse = yield this.folder.getParentFoldersRecursive({ | ||
contentType: 'dataextension', | ||
contentType: shared | ||
? 'shared_dataextension' | ||
: 'dataextension', | ||
categoryId: dataExtension.Results[0].CategoryID, | ||
@@ -385,57 +390,2 @@ }); | ||
let fieldObj = dataExtensionFieldArr[a]; | ||
//Fields that need to be removed prior to creation of new DE | ||
// delete fieldObj.AttributeMaps; | ||
// delete fieldObj.CustomerKey; | ||
// delete fieldObj.ObjectID; | ||
// if (fieldObj.MaxLength == '' || fieldObj.MaxLength == 0) { | ||
// delete fieldObj.MaxLength; | ||
// } | ||
// delete fieldObj.StorageType; | ||
// delete fieldObj.DataExtension; | ||
// delete fieldObj.DataType; | ||
// delete fieldObj.IsCreatable; | ||
// delete fieldObj.IsUpdatable; | ||
// delete fieldObj.IsRetrievable; | ||
// delete fieldObj.IsQueryable; | ||
// delete fieldObj.IsFilterable; | ||
// delete fieldObj.IsPartnerProperty; | ||
// delete fieldObj.IsAccountProperty; | ||
// delete fieldObj.PartnerMap; | ||
// delete fieldObj.Markups; | ||
// delete fieldObj.Precision; | ||
// if (fieldObj.FieldType !== 'Decimal') { | ||
// delete fieldObj.Scale; | ||
// } | ||
// delete fieldObj.Label; | ||
// if (fieldObj.MinLength == '' || fieldObj.MinLength == 0) { | ||
// delete fieldObj.MinLength; | ||
// } | ||
// delete fieldObj.CreatedDate; | ||
// delete fieldObj.ModifiedDate; | ||
// delete fieldObj.ID; | ||
// delete fieldObj.IsRestrictedPicklist; | ||
// delete fieldObj.PicklistItems; | ||
// delete fieldObj.IsSendTime; | ||
// delete fieldObj.DisplayOrder; | ||
// delete fieldObj.References; | ||
// delete fieldObj.RelationshipName; | ||
// delete fieldObj.Status; | ||
// delete fieldObj.IsContextSpecific; | ||
// delete fieldObj.Client; | ||
// delete fieldObj.PartnerProperties; | ||
// const field: FieldTypes = { | ||
// partnerKey: fieldObj.PartnerKey, | ||
// name: fieldObj.Name, | ||
// defaultValue: fieldObj.DefaultValue, | ||
// maxLength: fieldObj.MaxLength, | ||
// isRequired: fieldObj.IsRequired, | ||
// ordinal: fieldObj.Ordinal, | ||
// isPrimaryKey: fieldObj.IsPrimaryKey, | ||
// fieldType: fieldObj.FieldType, | ||
// }; | ||
// if (fieldObj.FieldType === 'Decimal') { | ||
// field.scale = fieldObj.Scale; | ||
// } | ||
// await lowercaseKeys(fieldObj) | ||
// console.log({fieldObj}) | ||
const updatedFieldObj = yield (0, modifyObject_1.lowercaseKeys)(fieldObj); | ||
@@ -560,5 +510,8 @@ fieldArray.push(updatedFieldObj); | ||
this.mapFieldObj = (fields) => { | ||
const fieldsObj = fields.map((field) => { | ||
return (0, modifyObject_1.capitalizeKeys)(field); | ||
}); | ||
const fieldsObj = (fields && | ||
fields.length && | ||
fields.map((field) => { | ||
return (0, modifyObject_1.capitalizeKeys)(field); | ||
})) || | ||
[]; | ||
return fieldsObj; | ||
@@ -565,0 +518,0 @@ }; |
@@ -118,3 +118,3 @@ "use strict"; | ||
catch (err) { | ||
return (0, handleError_1.handleError)(err); | ||
return err; | ||
} | ||
@@ -184,3 +184,2 @@ }); | ||
results = [...rootFolderRequest.Results]; | ||
stopFolderId = rootFolderRequest.Results[0].ParentFolder.ID; | ||
if (rootFolderRequest.Results[0].ID === request.categoryId) { | ||
@@ -196,3 +195,3 @@ return { | ||
if (initialCategory.OverallStatus !== 'OK') { | ||
console.log(initialCategory); | ||
console.log('initial category', JSON.stringify(initialCategory, null, 2)); | ||
} | ||
@@ -210,23 +209,33 @@ if (initialCategory && | ||
} | ||
if (parentId) { | ||
do { | ||
const parentRequest = parentId && | ||
(yield this.getFolder({ | ||
contentType: request.contentType, | ||
categoryId: parentId, | ||
})); | ||
if (parentRequest && parentRequest.OverallStatus !== 'OK') { | ||
console.log(parentRequest); | ||
} | ||
if (parentRequest && | ||
parentRequest.Results && | ||
parentRequest.Results.length) { | ||
const parentResult = parentRequest.Results[0]; | ||
results.push(...parentRequest.Results); | ||
parentId = | ||
parentResult && | ||
parentResult.ParentFolder && | ||
parentResult.ParentFolder.ID; | ||
} | ||
} while (parentId !== 0); | ||
if (initialCategory && | ||
initialCategory.Results && | ||
initialCategory.Results[0] && | ||
initialCategory.Results[0].ParentFolder && | ||
initialCategory.Results[0].ParentFolder.ContentType !== | ||
'shared_items') { | ||
if (parentId) { | ||
do { | ||
const parentRequest = parentId && | ||
(yield this.getFolder({ | ||
contentType: request.contentType, | ||
categoryId: parentId, | ||
})); | ||
if (parentRequest && parentRequest.OverallStatus !== 'OK') { | ||
console.log('parentRequest', JSON.stringify(parentRequest, null, 2)); | ||
} | ||
if (parentRequest && | ||
parentRequest.Results && | ||
parentRequest.Results.length) { | ||
const parentResult = parentRequest.Results[0]; | ||
results.push(...parentRequest.Results); | ||
parentId = | ||
(parentResult && | ||
parentResult.ParentFolder && | ||
parentResult.ParentFolder.ContentType !== | ||
'shared_data' && | ||
parentResult.ParentFolder.ID) || | ||
0; | ||
} | ||
} while (parentId !== 0); | ||
} | ||
} | ||
@@ -233,0 +242,0 @@ return { |
@@ -12,2 +12,8 @@ "use strict"; | ||
{ | ||
name: 'Shared Data Extension', | ||
rootName: 'Shared Data Extensions', | ||
context: 'shared_dataextension', | ||
contentType: 'shared_dataextension', | ||
}, | ||
{ | ||
name: 'Content Builder', | ||
@@ -14,0 +20,0 @@ rootName: 'Content Builder', |
@@ -438,20 +438,24 @@ import { SFMC_SOAP_Folder } from '../../sfmc/types/objects/sfmc_soap_folders'; | ||
return ( | ||
resp.items.map((result: any) => { | ||
let objectKey: string = ''; | ||
switch (searchActivity) { | ||
case 'ssjs': | ||
objectKey = 'ssjsActivityId'; | ||
break; | ||
case 'sql': | ||
objectKey = 'queryDefinitionId'; | ||
break; | ||
} | ||
(resp && | ||
resp.items && | ||
resp.items.length && | ||
resp.items.map((result: any) => { | ||
let objectKey: string = ''; | ||
switch (searchActivity) { | ||
case 'ssjs': | ||
objectKey = 'ssjsActivityId'; | ||
break; | ||
case 'sql': | ||
objectKey = 'queryDefinitionId'; | ||
break; | ||
} | ||
return { | ||
Name: result.name, | ||
[objectKey]: result[objectKey], | ||
CategoryID: result.categoryId, | ||
ModifiedDate: result.modifiedDate, | ||
}; | ||
}) || [] | ||
return { | ||
Name: result.name, | ||
[objectKey]: result[objectKey], | ||
CategoryID: result.categoryId, | ||
ModifiedDate: result.modifiedDate, | ||
}; | ||
})) || | ||
[] | ||
); | ||
@@ -497,11 +501,19 @@ } catch (err: any) { | ||
rootFolderID && rootFolderID !== request.categoryId | ||
? buildFolderPaths.folders | ||
.map( | ||
(folder: SFMC_SOAP_Folder) => | ||
rootFolderID !== folder.ID && folder.ID | ||
) | ||
.filter(Boolean) | ||
: buildFolderPaths.folders.map( | ||
(folder: SFMC_SOAP_Folder) => folder.ID | ||
); | ||
? (buildFolderPaths && | ||
buildFolderPaths.folders && | ||
buildFolderPaths.folders.length && | ||
buildFolderPaths.folders | ||
.map( | ||
(folder: SFMC_SOAP_Folder) => | ||
rootFolderID !== folder.ID && folder.ID | ||
) | ||
.filter(Boolean)) || | ||
[] | ||
: (buildFolderPaths && | ||
buildFolderPaths.folders && | ||
buildFolderPaths.folders.length && | ||
buildFolderPaths.folders.map( | ||
(folder: SFMC_SOAP_Folder) => folder.ID | ||
)) || | ||
[]; | ||
@@ -508,0 +520,0 @@ const definitionReturn: any[] = []; |
@@ -121,2 +121,4 @@ import { SFMC_SOAP_Folder } from '../../sfmc/types/objects/sfmc_soap_folders'; | ||
(response && | ||
response.items && | ||
response.items.length && | ||
response.items.map( | ||
@@ -402,18 +404,21 @@ (asset: { | ||
packageOut['contentBuilder'] = {}; | ||
return (packageOut['contentBuilder']['assets'] = contextAssets.map( | ||
(asset: any) => { | ||
return { | ||
id: asset.id, | ||
bldrId: asset.bldrId, | ||
name: asset.name, | ||
assetType: asset.assetType, | ||
category: { | ||
folderPath: | ||
(asset.category && asset.category.folderPath) || | ||
asset.folderPath, | ||
}, | ||
content: getContentBuilderAssetContent(asset), | ||
}; | ||
} | ||
)); | ||
return ( | ||
(packageOut['contentBuilder']['assets'] = | ||
contextAssets && | ||
contextAssets.length && | ||
contextAssets.map((asset: any) => { | ||
return { | ||
id: asset.id, | ||
bldrId: asset.bldrId, | ||
name: asset.name, | ||
assetType: asset.assetType, | ||
category: { | ||
folderPath: | ||
(asset.category && asset.category.folderPath) || | ||
asset.folderPath, | ||
}, | ||
content: getContentBuilderAssetContent(asset), | ||
}; | ||
})) || [] | ||
); | ||
}; | ||
@@ -420,0 +425,0 @@ |
@@ -51,2 +51,4 @@ import { SFMC_SOAP_Folder } from '../../sfmc/types/objects/sfmc_soap_folders'; | ||
(response && | ||
response.Results && | ||
response.Results.length && | ||
response.Results.map( | ||
@@ -121,2 +123,4 @@ (folder: { | ||
(response && | ||
response.Results && | ||
response.Results.length && | ||
response.Results.map( | ||
@@ -178,2 +182,7 @@ (dataExtension: { | ||
try { | ||
const shared = | ||
request.contentType === 'shared_dataextension' ? true : false; | ||
const rootParentName = shared | ||
? 'Shared Data Extensions' | ||
: 'Data Extensions'; | ||
const folderResponse = await this.sfmc.folder.getFoldersFromMiddle( | ||
@@ -194,3 +203,3 @@ request | ||
(folder: SFMC_SOAP_Folder) => | ||
folder.Name !== 'Data Extensions' && folder.ID | ||
folder.Name !== rootParentName && folder.ID | ||
) | ||
@@ -218,3 +227,4 @@ .filter(Boolean)) || | ||
dataExtension.Name, | ||
complete | ||
complete, | ||
shared | ||
)); | ||
@@ -250,3 +260,7 @@ formattedAssetResponse.push(dataExtensionPayload); | ||
*/ | ||
gatherAssetById = async (customerKey: string, complete = false) => { | ||
gatherAssetById = async ( | ||
customerKey: string, | ||
complete = false, | ||
shared = false | ||
) => { | ||
try { | ||
@@ -261,31 +275,46 @@ if (!customerKey) { | ||
customerKey, | ||
complete | ||
complete, | ||
shared | ||
); | ||
const categoryId = dataExtensionPayload.category.categoryId; | ||
const dataExtensionFolderObject = await this.sfmc.folder.getFolder({ | ||
contentType: 'dataextension', | ||
contentType: shared ? 'shared_dataextension' : 'dataextension', | ||
categoryId, | ||
}); | ||
if ( | ||
dataExtensionFolderObject && | ||
!dataExtensionFolderObject.Results | ||
) { | ||
throw new Error('No Folders Found'); | ||
} | ||
let parentFolders = | ||
await this.sfmc.folder.getParentFoldersRecursive({ | ||
contentType: 'dataextension', | ||
contentType: shared | ||
? 'shared_dataextension' | ||
: 'dataextension', | ||
categoryId, | ||
}); | ||
const folderResponse = [ | ||
const buildFolderPaths = await buildFolderPathsSoap([ | ||
...parentFolders.results, | ||
...dataExtensionFolderObject.Results, | ||
]; | ||
const buildFolderPaths = await buildFolderPathsSoap(folderResponse); | ||
]); | ||
const formattedFolders = buildFolderPaths.folders.map((folder) => { | ||
return { | ||
id: folder.ID, | ||
name: folder.Name, | ||
parentId: folder.ParentFolder.ID, | ||
folderPath: folder.FolderPath, | ||
}; | ||
}); | ||
const formattedFolders = | ||
(buildFolderPaths && | ||
buildFolderPaths.folders && | ||
buildFolderPaths.folders.length && | ||
buildFolderPaths.folders.map((folder) => { | ||
return { | ||
id: folder.ID, | ||
name: folder.Name, | ||
parentId: folder.ParentFolder.ID, | ||
folderPath: folder.FolderPath, | ||
}; | ||
})) || | ||
[]; | ||
@@ -297,5 +326,5 @@ return { | ||
} catch (err: any) { | ||
return err.message; | ||
return err; | ||
} | ||
}; | ||
} |
@@ -0,3 +1,3 @@ | ||
import { uniqueArrayByKey } from '.'; | ||
import { SFMC_SOAP_Folder } from '../../sfmc/types/objects/sfmc_soap_folders'; | ||
import { uniqueArrayByKey } from '.'; | ||
@@ -10,2 +10,3 @@ const buildFolderPathsSoap = async (folderResponse: any[]) => { | ||
'Data Extensions', | ||
'Shared Data Extensions', | ||
'Query', | ||
@@ -120,2 +121,3 @@ 'Scripts', | ||
(folderResponse && | ||
folderResponse.length && | ||
folderResponse.map((folder: SFMC_SOAP_Folder) => { | ||
@@ -122,0 +124,0 @@ return { |
@@ -91,11 +91,16 @@ import { Client } from '../types/sfmc_client'; | ||
midsArray = getAllMidsRequest.Results.map( | ||
(BU: { | ||
Client: { | ||
ID: number; | ||
}; | ||
}) => { | ||
return BU.Client.ID; | ||
} | ||
); | ||
midsArray = | ||
(getAllMidsRequest && | ||
getAllMidsRequest.Results && | ||
getAllMidsRequest.Results.length && | ||
getAllMidsRequest.Results.map( | ||
(BU: { | ||
Client: { | ||
ID: number; | ||
}; | ||
}) => { | ||
return BU.Client.ID; | ||
} | ||
)) || | ||
[]; | ||
} | ||
@@ -102,0 +107,0 @@ |
@@ -228,3 +228,4 @@ import { guid } from '../../cli/utils'; | ||
dataExtensionName: string, | ||
complete = false | ||
complete = false, | ||
shared = false | ||
) => { | ||
@@ -244,4 +245,4 @@ const dataExtension = await this.client.soap.retrieve( | ||
return complete === false | ||
? this.getDataExtensionPayload(dataExtension) | ||
: this.getDataExtensionPayloadComplete(dataExtension); | ||
? this.getDataExtensionPayload(dataExtension, shared) | ||
: this.getDataExtensionPayloadComplete(dataExtension, shared); | ||
}; | ||
@@ -256,3 +257,4 @@ | ||
customerKey: string, | ||
complete = false | ||
complete = false, | ||
shared = false | ||
) => { | ||
@@ -272,7 +274,7 @@ const dataExtension = await this.client.soap.retrieve( | ||
return complete === false | ||
? this.getDataExtensionPayload(dataExtension) | ||
: this.getDataExtensionPayloadComplete(dataExtension); | ||
? this.getDataExtensionPayload(dataExtension, shared) | ||
: this.getDataExtensionPayloadComplete(dataExtension, shared); | ||
}; | ||
getDataExtensionPayload = async (dataExtension: any) => { | ||
getDataExtensionPayload = async (dataExtension: any, shared = false) => { | ||
let sendableName; | ||
@@ -297,3 +299,5 @@ let RelatesOnSub; | ||
await this.folder.getParentFoldersRecursive({ | ||
contentType: 'dataextension', | ||
contentType: shared | ||
? 'shared_dataextension' | ||
: 'dataextension', | ||
categoryId: dataExtension.Results[0].CategoryID, | ||
@@ -305,7 +309,11 @@ }); | ||
); | ||
const dataExtensionFolderObject = compiledFolderPaths.folders.find( | ||
(folder) => folder.ID === dataExtension.Results[0].CategoryID | ||
); | ||
const { FolderPath } = dataExtensionFolderObject; | ||
const FolderPath = | ||
dataExtensionFolderObject && | ||
dataExtensionFolderObject.FolderPath; | ||
const dataExtensionFields = await this.getDataExtensionFields( | ||
@@ -486,3 +494,6 @@ dataExtension.Results[0].CustomerKey | ||
}; | ||
getDataExtensionPayloadComplete = async (dataExtension: any) => { | ||
getDataExtensionPayloadComplete = async ( | ||
dataExtension: any, | ||
shared = false | ||
) => { | ||
let sendableName; | ||
@@ -507,3 +518,5 @@ let RelatesOnSub; | ||
await this.folder.getParentFoldersRecursive({ | ||
contentType: 'dataextension', | ||
contentType: shared | ||
? 'shared_dataextension' | ||
: 'dataextension', | ||
categoryId: dataExtension.Results[0].CategoryID, | ||
@@ -559,65 +572,2 @@ }); | ||
let fieldObj = dataExtensionFieldArr[a]; | ||
//Fields that need to be removed prior to creation of new DE | ||
// delete fieldObj.AttributeMaps; | ||
// delete fieldObj.CustomerKey; | ||
// delete fieldObj.ObjectID; | ||
// if (fieldObj.MaxLength == '' || fieldObj.MaxLength == 0) { | ||
// delete fieldObj.MaxLength; | ||
// } | ||
// delete fieldObj.StorageType; | ||
// delete fieldObj.DataExtension; | ||
// delete fieldObj.DataType; | ||
// delete fieldObj.IsCreatable; | ||
// delete fieldObj.IsUpdatable; | ||
// delete fieldObj.IsRetrievable; | ||
// delete fieldObj.IsQueryable; | ||
// delete fieldObj.IsFilterable; | ||
// delete fieldObj.IsPartnerProperty; | ||
// delete fieldObj.IsAccountProperty; | ||
// delete fieldObj.PartnerMap; | ||
// delete fieldObj.Markups; | ||
// delete fieldObj.Precision; | ||
// if (fieldObj.FieldType !== 'Decimal') { | ||
// delete fieldObj.Scale; | ||
// } | ||
// delete fieldObj.Label; | ||
// if (fieldObj.MinLength == '' || fieldObj.MinLength == 0) { | ||
// delete fieldObj.MinLength; | ||
// } | ||
// delete fieldObj.CreatedDate; | ||
// delete fieldObj.ModifiedDate; | ||
// delete fieldObj.ID; | ||
// delete fieldObj.IsRestrictedPicklist; | ||
// delete fieldObj.PicklistItems; | ||
// delete fieldObj.IsSendTime; | ||
// delete fieldObj.DisplayOrder; | ||
// delete fieldObj.References; | ||
// delete fieldObj.RelationshipName; | ||
// delete fieldObj.Status; | ||
// delete fieldObj.IsContextSpecific; | ||
// delete fieldObj.Client; | ||
// delete fieldObj.PartnerProperties; | ||
// const field: FieldTypes = { | ||
// partnerKey: fieldObj.PartnerKey, | ||
// name: fieldObj.Name, | ||
// defaultValue: fieldObj.DefaultValue, | ||
// maxLength: fieldObj.MaxLength, | ||
// isRequired: fieldObj.IsRequired, | ||
// ordinal: fieldObj.Ordinal, | ||
// isPrimaryKey: fieldObj.IsPrimaryKey, | ||
// fieldType: fieldObj.FieldType, | ||
// }; | ||
// if (fieldObj.FieldType === 'Decimal') { | ||
// field.scale = fieldObj.Scale; | ||
// } | ||
// await lowercaseKeys(fieldObj) | ||
// console.log({fieldObj}) | ||
const updatedFieldObj = await lowercaseKeys(fieldObj); | ||
@@ -846,5 +796,9 @@ fieldArray.push(updatedFieldObj); | ||
) => { | ||
const fieldsObj = fields.map((field) => { | ||
return capitalizeKeys(field); | ||
}); | ||
const fieldsObj = | ||
(fields && | ||
fields.length && | ||
fields.map((field) => { | ||
return capitalizeKeys(field); | ||
})) || | ||
[]; | ||
@@ -851,0 +805,0 @@ return fieldsObj; |
@@ -136,3 +136,3 @@ import { SFMC_SOAP_Folder } from '../types/objects/sfmc_soap_folders'; | ||
} catch (err: any) { | ||
return handleError(err); | ||
return err; | ||
} | ||
@@ -217,3 +217,2 @@ } | ||
results = [...rootFolderRequest.Results]; | ||
stopFolderId = rootFolderRequest.Results[0].ParentFolder.ID; | ||
@@ -232,3 +231,6 @@ if (rootFolderRequest.Results[0].ID === request.categoryId) { | ||
if (initialCategory.OverallStatus !== 'OK') { | ||
console.log(initialCategory); | ||
console.log( | ||
'initial category', | ||
JSON.stringify(initialCategory, null, 2) | ||
); | ||
} | ||
@@ -250,34 +252,51 @@ | ||
if (parentId) { | ||
do { | ||
const parentRequest = | ||
parentId && | ||
(await this.getFolder({ | ||
contentType: request.contentType, | ||
categoryId: parentId, | ||
})); | ||
if ( | ||
initialCategory && | ||
initialCategory.Results && | ||
initialCategory.Results[0] && | ||
initialCategory.Results[0].ParentFolder && | ||
initialCategory.Results[0].ParentFolder.ContentType !== | ||
'shared_items' | ||
) { | ||
if (parentId) { | ||
do { | ||
const parentRequest = | ||
parentId && | ||
(await this.getFolder({ | ||
contentType: request.contentType, | ||
categoryId: parentId, | ||
})); | ||
if (parentRequest && parentRequest.OverallStatus !== 'OK') { | ||
console.log(parentRequest); | ||
} | ||
if (parentRequest && parentRequest.OverallStatus !== 'OK') { | ||
console.log( | ||
'parentRequest', | ||
JSON.stringify(parentRequest, null, 2) | ||
); | ||
} | ||
if ( | ||
parentRequest && | ||
parentRequest.Results && | ||
parentRequest.Results.length | ||
) { | ||
const parentResult: { | ||
ParentFolder: { | ||
ID: number; | ||
}; | ||
} = parentRequest.Results[0]; | ||
if ( | ||
parentRequest && | ||
parentRequest.Results && | ||
parentRequest.Results.length | ||
) { | ||
const parentResult: { | ||
ParentFolder: { | ||
ID: number; | ||
ContentType: string; | ||
}; | ||
} = parentRequest.Results[0]; | ||
results.push(...parentRequest.Results); | ||
parentId = | ||
parentResult && | ||
parentResult.ParentFolder && | ||
parentResult.ParentFolder.ID; | ||
} | ||
} while (parentId !== 0); | ||
results.push(...parentRequest.Results); | ||
parentId = | ||
(parentResult && | ||
parentResult.ParentFolder && | ||
parentResult.ParentFolder.ContentType !== | ||
'shared_data' && | ||
parentResult.ParentFolder.ID) || | ||
0; | ||
} | ||
} while (parentId !== 0); | ||
} | ||
} | ||
return { | ||
@@ -284,0 +303,0 @@ results, |
@@ -11,2 +11,8 @@ import { SFMCContextMapping } from '../types/sfmc_context_mapping'; | ||
{ | ||
name: 'Shared Data Extension', | ||
rootName: 'Shared Data Extensions', | ||
context: 'shared_dataextension', | ||
contentType: 'shared_dataextension', | ||
}, | ||
{ | ||
name: 'Content Builder', | ||
@@ -13,0 +19,0 @@ rootName: 'Content Builder', |
{ | ||
"name": "@basetime/bldr-sfmc-sdk", | ||
"version": "1.0.25", | ||
"version": "1.0.26", | ||
"description": "SDK for BLDR SFMC Core Functionality", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
350771
9618