Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into 1403-bump-sfmc-sdk…
Browse files Browse the repository at this point in the history
…-from-200-to-210

# Conflicts:
#	@types/lib/index.d.ts.map
#	lib/cli.js
  • Loading branch information
JoernBerkefeld committed Jul 5, 2024
2 parents 15d2763 + 04f2af5 commit a718664
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 31 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/code-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,54 @@ jobs:

- run: npm run lint

# Assuming code passes, run tests
- name: Run mcdev-tests
run: npm run test
lintandTest21:
name: lint & test w/ node v21
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 21
registry-url: https://registry.npmjs.org/

- run: npm ci --ignore-scripts

- run: npm run lint

# Assuming code passes, run tests
- name: Run mcdev-tests
run: npm run test
lintandTest22:
name: lint & test w/ node v22
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org/

- run: npm ci --ignore-scripts

- run: npm run lint

# Assuming code passes, run tests
- name: Run mcdev-tests
run: npm run test
6 changes: 3 additions & 3 deletions @types/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ declare class Mcdev {
* deletes metadata from MC instance by key
*
* @param {string} businessUnit references credentials from properties.json
* @param {string} type supported metadata type
* @param {string} customerKey Identifier of metadata
* @param {string | TypeKeyCombo} selectedTypes supported metadata type (single) or complex object
* @param {string[] | string} [keyArr] Identifier of metadata
* @returns {Promise.<boolean>} true if successful, false otherwise
*/
static deleteByKey(businessUnit: string, type: string, customerKey: string): Promise<boolean>;
static deleteByKey(businessUnit: string, selectedTypes: string | TypeKeyCombo, keyArr?: string[] | string): Promise<boolean>;
/**
* get name & key for provided id
*
Expand Down
2 changes: 1 addition & 1 deletion @types/lib/index.d.ts.map

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

12 changes: 5 additions & 7 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,18 @@ yargs(hideBin(process.argv))
.option('metadata', {
type: 'string',
alias: 'm',
group: 'Options for retrieve:',
describe:
'type or type:key or type:i:id or type:n:name to retrieve; if not provided, all metadata will be retrieved',
group: 'Options for delete:',
describe: 'type or type:key or type:i:id or type:n:name to delete',
}),
(argv) => {
Mcdev.setOptions(argv);
const typeKeyCombo = Mcdev.metadataToTypeKey(argv.metadata, ['key', 'id'], true);
const typeKeyCombo = Mcdev.metadataToTypeKey(argv.metadata, ['key', 'id']);
if ('undefined' === typeof typeKeyCombo) {
if (argv.TYPE && argv.KEY) {
Mcdev.deleteByKey(argv.BU, argv.TYPE, argv.KEY);
Mcdev.deleteByKey(argv.BU, argv.TYPE, csvToArray(argv.KEY));
}
} else {
const type = Object.keys(typeKeyCombo)[0];
Mcdev.deleteByKey(argv.BU, type, typeKeyCombo[type][0]);
Mcdev.deleteByKey(argv.BU, typeKeyCombo, null);
}
}
)
Expand Down
73 changes: 54 additions & 19 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,39 +557,74 @@ class Mcdev {
* deletes metadata from MC instance by key
*
* @param {string} businessUnit references credentials from properties.json
* @param {string} type supported metadata type
* @param {string} customerKey Identifier of metadata
* @param {string | TypeKeyCombo} selectedTypes supported metadata type (single) or complex object
* @param {string[] | string} [keyArr] Identifier of metadata
* @returns {Promise.<boolean>} true if successful, false otherwise
*/
static async deleteByKey(businessUnit, type, customerKey) {
static async deleteByKey(businessUnit, selectedTypes, keyArr) {
Util.startLogger();
Util.logger.info('mcdev:: delete');
if (!Util._isValidType(type)) {
return;
/** @typedef {string[]} */
let selectedTypesArr;
/** @typedef {TypeKeyCombo} */
let selectedTypesObj;
if ('string' === typeof keyArr) {
keyArr = [keyArr];
}
if ('string' === typeof selectedTypes) {
selectedTypesArr = [selectedTypes];
} else {
selectedTypesObj = selectedTypes;
// reset keys array because it will be overriden by values from selectedTypesObj
keyArr = null;
}
// check if types are valid
for (const selectedType of selectedTypesArr || Object.keys(selectedTypesObj)) {
if (!Util._isValidType(selectedType)) {
return;
}
}
const properties = await config.getProperties();
if (!(await config.checkProperties(properties))) {
return null;
}
const buObject = await Cli.getCredentialObject(properties, businessUnit);
if (buObject !== null) {
try {
MetadataTypeInfo[type].client = auth.getSDK(buObject);
} catch (ex) {
Util.logger.error(ex.message);
if (!buObject) {
return;
}
let client;
try {
client = auth.getSDK(buObject);
} catch (ex) {
Util.logger.error(ex.message);
return;
}
let status = true;
for (const type of selectedTypesArr || Object.keys(selectedTypesObj)) {
keyArr = selectedTypesArr ? keyArr : selectedTypesObj[type];
if (!keyArr) {
Util.logger.error(`No keys set for ${type}`);
return;
}
Util.logger.info(
Util.getGrayMsg(` - Deleting ${type} ${customerKey} on BU ${businessUnit}`)
);
try {
MetadataTypeInfo[type].properties = properties;
MetadataTypeInfo[type].buObject = buObject;
return await MetadataTypeInfo[type].deleteByKey(customerKey);
} catch (ex) {
Util.logger.errorStack(ex, ` - Deleting ${type} failed`);
for (const key of keyArr) {
MetadataTypeInfo[type].client = client;

Util.logger.info(
Util.getGrayMsg(` - Deleting ${type} ${key} on BU ${businessUnit}`)
);
try {
MetadataTypeInfo[type].properties = properties;
MetadataTypeInfo[type].buObject = buObject;
const result = await MetadataTypeInfo[type].deleteByKey(key);
status &&= result;
} catch (ex) {
Util.logger.errorStack(ex, ` - Deleting ${type} failed`);
status = false;
}
}
}

return status;
}
/**
* get name & key for provided id
Expand Down
2 changes: 1 addition & 1 deletion lib/metadataTypes/Folder.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class Folder extends MetadataType {
const response = await super.createREST(restPayload, '/email/v1/category', true);
if (response?.objectId) {
// convert the response to the same format as the SOAP response
metadataEntry.ID = response.objectId;
metadataEntry.ID = response.categoryId;
// the following is a bit of a hack to make the response look like the SOAP response; not sure if we actually need that anywhere like this --> future developers feel free to double check
const returnObject = {
Results: [
Expand Down
18 changes: 18 additions & 0 deletions test/general.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,24 @@ describe('GENERAL', () => {
);
});
});

describe('Delete --metadata ~~~', () => {
it('Should delete the item', async () => {
const argvMetadata = [
'asset:testExisting_asset',
'automation:testExisting_automation',
'journey:testExisting_journey_Quicksend/1',
'journey:testExisting_journey_Multistep/1',
];
const typeKeyCombo = handler.metadataToTypeKey(argvMetadata);
// WHEN
const isDeleted = await handler.deleteByKey('testInstance/testBU', typeKeyCombo);
// THEN
assert.equal(process.exitCode, 0, 'deleteByKey should not have thrown an error');
assert.equal(isDeleted, true, 'deleteByKey should have returned true');
return;
});
});
});

describe('without --metadata ================', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0175b971-71a3-4d8e-98ac-48121f3fbf4f
13 changes: 13 additions & 0 deletions test/type.journey.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,19 @@ describe('type: journey', () => {
assert.equal(isDeleted, true, 'should have deleted the item');
return;
});

it('Should delete 2 items with version', async () => {
// WHEN
const isDeleted = await handler.deleteByKey('testInstance/testBU', 'journey', [
'testExisting_journey_Quicksend/1',
'testExisting_journey_Multistep/1',
]);
// THEN
assert.equal(process.exitCode, 0, 'delete should not have thrown an error');

assert.equal(isDeleted, true, 'should have deleted the item');
return;
});
});

describe('ReplaceContentBlockByX ================', () => {
Expand Down

0 comments on commit a718664

Please sign in to comment.