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

Feature/1025 add schedule and deploy --schedule for automations #1026

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
94 changes: 88 additions & 6 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ Provides default functionality that can be overwritten by child metadata type cl
<dt><a href="#Automation.">Automation.(metadataMap, key)</a> ⇒ <code>Promise.&lt;object&gt;</code></dt>
<dd><p>helper for <a href="#Automation.execute">execute</a></p>
</dd>
<dt><a href="#Automation.">Automation.(metadataEntry)</a> ⇒ <code>Promise.&lt;object&gt;</code></dt>
<dd><p>helper for <a href="#Automation.execute">execute</a></p>
</dd>
<dt><a href="#Automation.">Automation.(metadata)</a> ⇒ <code>Promise.&lt;object&gt;</code></dt>
<dd><p>helper for <a href="#Automation.pause">pause</a></p>
</dd>
Expand Down Expand Up @@ -516,6 +519,7 @@ main class
* [.buildDefinition(businessUnit, selectedType, name, market)](#Mcdev.buildDefinition) ⇒ <code>Promise.&lt;void&gt;</code>
* [.buildDefinitionBulk(listName, type, name)](#Mcdev.buildDefinitionBulk) ⇒ <code>Promise.&lt;void&gt;</code>
* [.getFilesToCommit(businessUnit, selectedType, keyArr)](#Mcdev.getFilesToCommit) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
* [.schedule(businessUnit, [selectedType], [keys])](#Mcdev.schedule) ⇒ <code>Promise.&lt;boolean&gt;</code>
* [.execute(businessUnit, [selectedType], [keys])](#Mcdev.execute) ⇒ <code>Promise.&lt;boolean&gt;</code>
* [.pause(businessUnit, [selectedType], [keys])](#Mcdev.pause) ⇒ <code>Promise.&lt;boolean&gt;</code>

Expand Down Expand Up @@ -770,6 +774,20 @@ Build a specific metadata file based on a template using a list of bu-market com
| selectedType | <code>string</code> | supported metadata type |
| keyArr | <code>Array.&lt;string&gt;</code> | customerkey of the metadata |

<a name="Mcdev.schedule"></a>

### Mcdev.schedule(businessUnit, [selectedType], [keys]) ⇒ <code>Promise.&lt;boolean&gt;</code>
Schedule an item (shortcut for execute --schedule)

**Kind**: static method of [<code>Mcdev</code>](#Mcdev)
**Returns**: <code>Promise.&lt;boolean&gt;</code> - true if all started successfully, false if not

| Param | Type | Description |
| --- | --- | --- |
| businessUnit | <code>string</code> | name of BU |
| [selectedType] | <code>TYPE.SupportedMetadataTypes</code> | limit to given metadata types |
| [keys] | <code>Array.&lt;string&gt;</code> | customerkey of the metadata |

<a name="Mcdev.execute"></a>

### Mcdev.execute(businessUnit, [selectedType], [keys]) ⇒ <code>Promise.&lt;boolean&gt;</code>
Expand Down Expand Up @@ -1339,6 +1357,7 @@ Automation MetadataType
* [.retrieveAsTemplate(templateDir, name, templateVariables)](#Automation.retrieveAsTemplate) ⇒ <code>Promise.&lt;TYPE.AutomationItemObj&gt;</code>
* [.postRetrieveTasks(metadata)](#Automation.postRetrieveTasks) ⇒ <code>TYPE.AutomationItem</code> \| <code>void</code>
* [.execute(keyArr)](#Automation.execute) ⇒ <code>Promise.&lt;boolean&gt;</code>
* [.getErrorsREST(ex)](#Automation.getErrorsREST) ⇒ <code>Array.&lt;string&gt;</code> \| <code>void</code>
* [.pause(keyArr)](#Automation.pause) ⇒ <code>Promise.&lt;boolean&gt;</code>
* [.deploy(metadata, targetBU, retrieveDir)](#Automation.deploy) ⇒ <code>Promise.&lt;TYPE.AutomationMap&gt;</code>
* [.create(metadata)](#Automation.create) ⇒ <code>Promise</code>
Expand Down Expand Up @@ -1422,6 +1441,18 @@ a function to start query execution via API
| --- | --- | --- |
| keyArr | <code>Array.&lt;string&gt;</code> | customerkey of the metadata |

<a name="Automation.getErrorsREST"></a>

### Automation.getErrorsREST(ex) ⇒ <code>Array.&lt;string&gt;</code> \| <code>void</code>
Standardizes a check for multiple messages but adds query specific filters to error texts

**Kind**: static method of [<code>Automation</code>](#Automation)
**Returns**: <code>Array.&lt;string&gt;</code> \| <code>void</code> - formatted Error Message

| Param | Type | Description |
| --- | --- | --- |
| ex | <code>object</code> | response payload from REST API |

<a name="Automation.pause"></a>

### Automation.pause(keyArr) ⇒ <code>Promise.&lt;boolean&gt;</code>
Expand Down Expand Up @@ -3311,6 +3342,7 @@ Provides default functionality that can be overwritten by child metadata type cl
* [.retrieveSOAP(retrieveDir, [requestParams], [singleRetrieve], [additionalFields])](#MetadataType.retrieveSOAP) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMapObj&gt;</code>
* [.retrieveREST(retrieveDir, uri, [templateVariables], [singleRetrieve])](#MetadataType.retrieveREST) ⇒ <code>Promise.&lt;{metadata: (TYPE.MetadataTypeMap\|TYPE.MetadataTypeItem), type: string}&gt;</code>
* [.executeREST(uri, key)](#MetadataType.executeREST) ⇒ <code>Promise.&lt;string&gt;</code>
* [.executeSOAP([metadataEntry])](#MetadataType.executeSOAP) ⇒ <code>Promise.&lt;object&gt;</code>
* [.runDocumentOnRetrieve([singleRetrieve], metadataMap)](#MetadataType.runDocumentOnRetrieve) ⇒ <code>Promise.&lt;void&gt;</code>
* [.parseResponseBody(body, [singleRetrieve])](#MetadataType.parseResponseBody) ⇒ <code>TYPE.MetadataTypeMap</code>
* [.deleteFieldByDefinition(metadataEntry, fieldPath, definitionProperty, origin)](#MetadataType.deleteFieldByDefinition) ⇒ <code>void</code>
Expand All @@ -3328,7 +3360,7 @@ Provides default functionality that can be overwritten by child metadata type cl
* [.findSubType(templateDir, templateName)](#MetadataType.findSubType) ⇒ <code>Promise.&lt;string&gt;</code>
* [.readSecondaryFolder(templateDir, typeDirArr, templateName, fileName, ex)](#MetadataType.readSecondaryFolder) ⇒ <code>object</code>
* [.buildDefinition(templateDir, targetDir, templateName, variables)](#MetadataType.buildDefinition) ⇒ <code>Promise.&lt;TYPE.MetadataTypeMapObj&gt;</code>
* [.checkForErrors(ex)](#MetadataType.checkForErrors) ⇒ <code>Array.&lt;string&gt;</code> \| <code>void</code>
* [.getErrorsREST(ex)](#MetadataType.getErrorsREST) ⇒ <code>Array.&lt;string&gt;</code> \| <code>void</code>
* [.document([metadata], [isDeploy])](#MetadataType.document) ⇒ <code>void</code>
* [.deleteByKey(customerKey)](#MetadataType.deleteByKey) ⇒ <code>boolean</code>
* [.postDeleteTasks(customerKey, [additionalExtensions])](#MetadataType.postDeleteTasks) ⇒ <code>Promise.&lt;void&gt;</code>
Expand Down Expand Up @@ -3799,6 +3831,18 @@ Used to execute a query/automation etc.
| uri | <code>string</code> | REST endpoint where the POST request should be sent |
| key | <code>string</code> | item key |

<a name="MetadataType.executeSOAP"></a>

### MetadataType.executeSOAP([metadataEntry]) ⇒ <code>Promise.&lt;object&gt;</code>
Used to execute a query/automation etc.

**Kind**: static method of [<code>MetadataType</code>](#MetadataType)
**Returns**: <code>Promise.&lt;object&gt;</code> - api response

| Param | Type | Description |
| --- | --- | --- |
| [metadataEntry] | <code>TYPE.MetadataTypeItem</code> | single metadata entry |

<a name="MetadataType.runDocumentOnRetrieve"></a>

### MetadataType.runDocumentOnRetrieve([singleRetrieve], metadataMap) ⇒ <code>Promise.&lt;void&gt;</code>
Expand Down Expand Up @@ -4037,9 +4081,9 @@ parsing is required (for example scripts & queries)
| templateName | <code>string</code> | name of the metadata file |
| variables | <code>TYPE.TemplateMap</code> | variables to be replaced in the metadata |

<a name="MetadataType.checkForErrors"></a>
<a name="MetadataType.getErrorsREST"></a>

### MetadataType.checkForErrors(ex) ⇒ <code>Array.&lt;string&gt;</code> \| <code>void</code>
### MetadataType.getErrorsREST(ex) ⇒ <code>Array.&lt;string&gt;</code> \| <code>void</code>
Standardizes a check for multiple messages

**Kind**: static method of [<code>MetadataType</code>](#MetadataType)
Expand Down Expand Up @@ -4725,7 +4769,7 @@ Query MetadataType
* [.buildDefinitionForNested(templateDir, targetDir, metadata, templateVariables, templateName)](#Query.buildDefinitionForNested) ⇒ <code>Promise.&lt;Array.&lt;Array.&lt;string&gt;&gt;&gt;</code>
* [.buildTemplateForNested(templateDir, targetDir, metadata, templateVariables, templateName)](#Query.buildTemplateForNested) ⇒ <code>Promise.&lt;Array.&lt;Array.&lt;string&gt;&gt;&gt;</code>
* [.getFilesToCommit(keyArr)](#Query.getFilesToCommit) ⇒ <code>Array.&lt;string&gt;</code>
* [.checkForErrors(ex)](#Query.checkForErrors) ⇒ <code>Array.&lt;string&gt;</code> \| <code>void</code>
* [.getErrorsREST(ex)](#Query.getErrorsREST) ⇒ <code>Array.&lt;string&gt;</code> \| <code>void</code>
* [.deleteByKey(customerKey)](#Query.deleteByKey) ⇒ <code>boolean</code>
* [.postDeleteTasks(customerKey)](#Query.postDeleteTasks) ⇒ <code>void</code>
* [.postDeployTasks(upsertResults)](#Query.postDeployTasks)
Expand Down Expand Up @@ -4892,9 +4936,9 @@ additionally, the documentation for dataExtension and automation should be retur
| --- | --- | --- |
| keyArr | <code>Array.&lt;string&gt;</code> | customerkey of the metadata |

<a name="Query.checkForErrors"></a>
<a name="Query.getErrorsREST"></a>

### Query.checkForErrors(ex) ⇒ <code>Array.&lt;string&gt;</code> \| <code>void</code>
### Query.getErrorsREST(ex) ⇒ <code>Array.&lt;string&gt;</code> \| <code>void</code>
Standardizes a check for multiple messages but adds query specific filters to error texts

**Kind**: static method of [<code>Query</code>](#Query)
Expand Down Expand Up @@ -5995,6 +6039,7 @@ CLI entry for SFMC DevTools
* [.getSsjs(code)](#Util.getSsjs) ⇒ <code>string</code>
* [.stringLike(testString, search)](#Util.stringLike) ⇒ <code>boolean</code>
* [.fieldsLike(metadata, [filters])](#Util.fieldsLike) ⇒ <code>boolean</code>
* [.capitalizeFirstLetter(str)](#Util.capitalizeFirstLetter) ⇒ <code>string</code>

<a name="Util.skipInteraction"></a>

Expand Down Expand Up @@ -6377,6 +6422,18 @@ returns true if no LIKE filter is defined or if all filters match
| metadata | <code>TYPE.MetadataTypeItem</code> | a single metadata item |
| [filters] | <code>object</code> | only used in recursive calls |

<a name="Util.capitalizeFirstLetter"></a>

### Util.capitalizeFirstLetter(str) ⇒ <code>string</code>
helper used by SOAP methods to ensure the type always uses an upper-cased first letter

**Kind**: static method of [<code>Util</code>](#Util)
**Returns**: <code>string</code> - str with first letter capitalized

| Param | Type | Description |
| --- | --- | --- |
| str | <code>string</code> | string to capitalize |

<a name="MetadataTypeDefinitions"></a>

## MetadataTypeDefinitions
Expand Down Expand Up @@ -7913,6 +7970,7 @@ Util that contains logger and simple util methods
* [.getSsjs(code)](#Util.getSsjs) ⇒ <code>string</code>
* [.stringLike(testString, search)](#Util.stringLike) ⇒ <code>boolean</code>
* [.fieldsLike(metadata, [filters])](#Util.fieldsLike) ⇒ <code>boolean</code>
* [.capitalizeFirstLetter(str)](#Util.capitalizeFirstLetter) ⇒ <code>string</code>

<a name="Util.skipInteraction"></a>

Expand Down Expand Up @@ -8295,6 +8353,18 @@ returns true if no LIKE filter is defined or if all filters match
| metadata | <code>TYPE.MetadataTypeItem</code> | a single metadata item |
| [filters] | <code>object</code> | only used in recursive calls |

<a name="Util.capitalizeFirstLetter"></a>

### Util.capitalizeFirstLetter(str) ⇒ <code>string</code>
helper used by SOAP methods to ensure the type always uses an upper-cased first letter

**Kind**: static method of [<code>Util</code>](#Util)
**Returns**: <code>string</code> - str with first letter capitalized

| Param | Type | Description |
| --- | --- | --- |
| str | <code>string</code> | string to capitalize |

<a name="csvToArray"></a>

## csvToArray(csv) ⇒ <code>Array.&lt;string&gt;</code>
Expand Down Expand Up @@ -8378,6 +8448,18 @@ helper for [execute](#Automation.execute)

<a name="Automation."></a>

## Automation.(metadataEntry) ⇒ <code>Promise.&lt;object&gt;</code>
helper for [execute](#Automation.execute)

**Kind**: global function
**Returns**: <code>Promise.&lt;object&gt;</code> - Returns the result of the API call

| Param | Type | Description |
| --- | --- | --- |
| metadataEntry | <code>TYPE.AutomationItem</code> | metadata object |

<a name="Automation."></a>

## Automation.(metadata) ⇒ <code>Promise.&lt;object&gt;</code>
helper for [pause](#Automation.pause)

Expand Down
46 changes: 45 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ yargs
.option('execute', {
type: 'boolean',
group: 'Options for deploy:',
describe: 'optional for query: runs execute after deploy',
describe:
'optional: executes item after deploy; this will run the item once immediately',
})
.option('schedule', {
type: 'boolean',
group: 'Options for deploy:',
describe:
'optionally start existing schedule instead of running item once immediately (only works for automations)',
});
},
handler: (argv) => {
Expand Down Expand Up @@ -430,6 +437,12 @@ yargs
group: 'Options for execute:',
describe:
'filter metadata components (can include % as wildcard or _ for a single character)',
})
.option('schedule', {
type: 'boolean',
group: 'Options for execute:',
describe:
'optionally start existing schedule instead of running item once immediately (only works for automations)',
});
},
handler: (argv) => {
Expand All @@ -438,6 +451,37 @@ yargs
Mcdev.execute(argv.BU, argv.TYPE, csvToArray(argv.KEY));
},
})
.command({
command: 'schedule <BU> <TYPE> [KEY]',
aliases: ['sched'],
desc: 'starts the predefined schedule of the item (shortcut for running execute --schedule)',
builder: (yargs) => {
yargs
.positional('BU', {
type: 'string',
describe: 'the business unit where to start an item',
})
.positional('TYPE', {
type: 'string',
describe: 'metadata type',
})
.positional('KEY', {
type: 'string',
describe: 'key(s) of the metadata component(s)',
})
.option('like', {
type: 'string',
group: 'Options for execute:',
describe:
'filter metadata components (can include % as wildcard or _ for a single character)',
});
},
handler: (argv) => {
Mcdev.setOptions(argv);
// ! do not allow multiple types to be passed in here via csvToArray
Mcdev.schedule(argv.BU, argv.TYPE, csvToArray(argv.KEY));
},
})
.command({
command: 'pause <BU> <TYPE> [KEY]',
aliases: ['p', 'stop'],
Expand Down
15 changes: 14 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ class Mcdev {
'changeKeyField',
'changeKeyValue',
'commitHistory',
'execute',
'filter',
'fromRetrieve',
'json',
'like',
'noLogFile',
'refresh',
'execute',
'schedule',
'skipInteraction',
];
for (const option of knownOptions) {
Expand Down Expand Up @@ -728,6 +729,18 @@ class Mcdev {
return DevOps.getFilesToCommit(properties, buObject, selectedType, keyArr);
}
}
/**
* Schedule an item (shortcut for execute --schedule)
*
* @param {string} businessUnit name of BU
* @param {TYPE.SupportedMetadataTypes} [selectedType] limit to given metadata types
* @param {string[]} [keys] customerkey of the metadata
* @returns {Promise.<boolean>} true if all started successfully, false if not
*/
static async schedule(businessUnit, selectedType, keys) {
this.setOptions({ schedule: true });
return this.#runMethod('execute', businessUnit, selectedType, keys);
}
/**
* Start/execute an item
*
Expand Down
Loading