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/294 task run checkproperties on config load #324

Draft
wants to merge 19 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 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
50 changes: 31 additions & 19 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4398,7 +4398,7 @@ CLI entry for SFMC DevTools
* [.isTrue(attrValue)](#Util.isTrue) ⇒ <code>boolean</code>
* [.isFalse(attrValue)](#Util.isFalse) ⇒ <code>boolean</code>
* [._isValidType(selectedType)](#Util._isValidType) ⇒ <code>boolean</code>
* [.getRetrieveTypeChoices()](#Util.getRetrieveTypeChoices) ⇒ <code>Array.&lt;string&gt;</code>
* [.getRetrieveTypeChoices()](#Util.getRetrieveTypeChoices) ⇒ <code>Array.&lt;TYPE.SupportedMetadataTypes&gt;</code>
* [.metadataLogger(level, type, method, payload, [source])](#Util.metadataLogger) ⇒ <code>void</code>
* [.replaceByObject(str, obj)](#Util.replaceByObject) ⇒ <code>string</code> \| <code>object</code>
* [.inverseGet(objs, val)](#Util.inverseGet) ⇒ <code>string</code>
Expand Down Expand Up @@ -4523,15 +4523,15 @@ helper for retrieve, retrieveAsTemplate and deploy

| Param | Type | Description |
| --- | --- | --- |
| selectedType | <code>string</code> | type or type-subtype |
| selectedType | <code>TYPE.SupportedMetadataTypes</code> | type or type-subtype |

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

### Util.getRetrieveTypeChoices() ⇒ <code>Array.&lt;string&gt;</code>
### Util.getRetrieveTypeChoices() ⇒ <code>Array.&lt;TYPE.SupportedMetadataTypes&gt;</code>
helper for getDefaultProperties()

**Kind**: static method of [<code>Util</code>](#Util)
**Returns**: <code>Array.&lt;string&gt;</code> - type choices
**Returns**: <code>Array.&lt;TYPE.SupportedMetadataTypes&gt;</code> - type choices
<a name="Util.metadataLogger"></a>

### Util.metadataLogger(level, type, method, payload, [source]) ⇒ <code>void</code>
Expand Down Expand Up @@ -4842,7 +4842,6 @@ this keeps the config automatically upgradable when we add new subtypes or chang
shows metadata type descriptions

**Kind**: static method of [<code>Cli</code>](#Cli)
**Returns**: <code>void</code> - -
<a name="config"></a>

## config
Expand All @@ -4851,43 +4850,56 @@ Central class for loading and validating properties from config and auth
**Kind**: global constant

* [config](#config)
* [.getProperties([silent])](#config.getProperties) ⇒ <code>object</code>
* [.checkProperties(properties, [silent])](#config.checkProperties) ⇒ <code>Promise.&lt;(boolean\|Array.&lt;string&gt;)&gt;</code>
* [.getDefaultProperties()](#config.getDefaultProperties) ⇒ <code>object</code>
* [.getProperties([skipChecks])](#config.getProperties) ⇒ <code>object</code>
* [.checkProperties(properties, [skipCredentialValidation])](#config.checkProperties) ⇒ <code>Promise.&lt;(boolean\|Array.&lt;string&gt;)&gt;</code>
* [.getDefaultProperties()](#config.getDefaultProperties) ⇒ <code>TYPE.Mcdevrc</code>
* [.getProblems(properties, [defaultProps], [skipCredentialValidation])](#config.getProblems) ⇒ <code>Promise.&lt;{missingFields: Array.&lt;string&gt;, errorMsgs: Array.&lt;string&gt;, solutionSet: Set.&lt;string&gt;}&gt;</code>

<a name="config.getProperties"></a>

### config.getProperties([silent]) ⇒ <code>object</code>
### config.getProperties([skipChecks]) ⇒ <code>object</code>
loads central properties from config file

**Kind**: static method of [<code>config</code>](#config)
**Returns**: <code>object</code> - central properties object

| Param | Type | Description |
| --- | --- | --- |
| [silent] | <code>boolean</code> | omit throwing errors and print messages; assuming not silent if not set |
| [skipChecks] | <code>boolean</code> | omit throwing errors and print messages |

<a name="config.checkProperties"></a>

### config.checkProperties(properties, [silent]) ⇒ <code>Promise.&lt;(boolean\|Array.&lt;string&gt;)&gt;</code>
### config.checkProperties(properties, [skipCredentialValidation]) ⇒ <code>Promise.&lt;(boolean\|Array.&lt;string&gt;)&gt;</code>
check if the config file is correctly formatted and has values

**Kind**: static method of [<code>config</code>](#config)
**Returns**: <code>Promise.&lt;(boolean\|Array.&lt;string&gt;)&gt;</code> - file structure ok OR list of fields to be fixed

| Param | Type | Description |
| --- | --- | --- |
| properties | <code>object</code> | javascript object in .mcdevrc.json |
| [silent] | <code>boolean</code> | set to true for internal use w/o cli output |
| properties | <code>TYPE.Mcdevrc</code> | javascript object in .mcdevrc.json |
| [skipCredentialValidation] | <code>boolean</code> | set to true for internal use w/o cli output |

<a name="config.getDefaultProperties"></a>

### config.getDefaultProperties() ⇒ <code>object</code>
### config.getDefaultProperties() ⇒ <code>TYPE.Mcdevrc</code>
defines how the properties.json should look like
used for creating a template and for checking if variables are set

**Kind**: static method of [<code>config</code>](#config)
**Returns**: <code>object</code> - default properties
**Returns**: <code>TYPE.Mcdevrc</code> - default properties
<a name="config.getProblems"></a>

### config.getProblems(properties, [defaultProps], [skipCredentialValidation]) ⇒ <code>Promise.&lt;{missingFields: Array.&lt;string&gt;, errorMsgs: Array.&lt;string&gt;, solutionSet: Set.&lt;string&gt;}&gt;</code>
**Kind**: static method of [<code>config</code>](#config)
**Returns**: <code>Promise.&lt;{missingFields: Array.&lt;string&gt;, errorMsgs: Array.&lt;string&gt;, solutionSet: Set.&lt;string&gt;}&gt;</code> - -

| Param | Type | Description |
| --- | --- | --- |
| properties | <code>TYPE.Mcdevrc</code> | javascript object in .mcdevrc.json |
| [defaultProps] | <code>TYPE.Mcdevrc</code> | default properties |
| [skipCredentialValidation] | <code>boolean</code> | used by init.config.js>fixMcdevConfig() to auto-fix the config file |

<a name="DevOps"></a>

## DevOps
Expand Down Expand Up @@ -6151,7 +6163,7 @@ Util that contains logger and simple util methods
* [.isTrue(attrValue)](#Util.isTrue) ⇒ <code>boolean</code>
* [.isFalse(attrValue)](#Util.isFalse) ⇒ <code>boolean</code>
* [._isValidType(selectedType)](#Util._isValidType) ⇒ <code>boolean</code>
* [.getRetrieveTypeChoices()](#Util.getRetrieveTypeChoices) ⇒ <code>Array.&lt;string&gt;</code>
* [.getRetrieveTypeChoices()](#Util.getRetrieveTypeChoices) ⇒ <code>Array.&lt;TYPE.SupportedMetadataTypes&gt;</code>
* [.metadataLogger(level, type, method, payload, [source])](#Util.metadataLogger) ⇒ <code>void</code>
* [.replaceByObject(str, obj)](#Util.replaceByObject) ⇒ <code>string</code> \| <code>object</code>
* [.inverseGet(objs, val)](#Util.inverseGet) ⇒ <code>string</code>
Expand Down Expand Up @@ -6276,15 +6288,15 @@ helper for retrieve, retrieveAsTemplate and deploy

| Param | Type | Description |
| --- | --- | --- |
| selectedType | <code>string</code> | type or type-subtype |
| selectedType | <code>TYPE.SupportedMetadataTypes</code> | type or type-subtype |

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

### Util.getRetrieveTypeChoices() ⇒ <code>Array.&lt;string&gt;</code>
### Util.getRetrieveTypeChoices() ⇒ <code>Array.&lt;TYPE.SupportedMetadataTypes&gt;</code>
helper for getDefaultProperties()

**Kind**: static method of [<code>Util</code>](#Util)
**Returns**: <code>Array.&lt;string&gt;</code> - type choices
**Returns**: <code>Array.&lt;TYPE.SupportedMetadataTypes&gt;</code> - type choices
<a name="Util.metadataLogger"></a>

### Util.metadataLogger(level, type, method, payload, [source]) ⇒ <code>void</code>
Expand Down
1 change: 0 additions & 1 deletion lib/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ saved
* @returns {Promise.<TYPE.MultiMetadataTypeList>} -
*/
static async buildTemplate(businessUnit, selectedType, keyArr, market) {
Util.logger.info('mcdev:: Build Definition from Template');
const properties = await config.getProperties();
DougMidgley marked this conversation as resolved.
Show resolved Hide resolved
if (!Util._isValidType(selectedType)) {
return;
Expand Down
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Mcdev {
* @returns {Promise.<TYPE.DeltaPkgItem[]>} list of changed items
*/
static async createDeltaPkg(argv) {
Util.logger.info('Create Delta Package ::');
Mcdev.setSkipInteraction(argv.skipInteraction);
const properties = await config.getProperties();
DougMidgley marked this conversation as resolved.
Show resolved Hide resolved
// get source market and source BU from config
Expand Down Expand Up @@ -481,6 +482,7 @@ class Mcdev {
* @returns {Promise.<TYPE.MultiMetadataTypeList>} -
*/
static async buildTemplate(businessUnit, selectedType, keyArr, market) {
Util.logger.info('mcdev:: Build Definition from Template');
return Builder.buildTemplate(businessUnit, selectedType, keyArr, market);
}
/**
Expand Down
68 changes: 35 additions & 33 deletions lib/util/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,40 @@ const credentialStore = new Conf({ configName: 'sessions', clearInvalidConfig: t
const initializedSDKs = {};
let authfile;

module.exports = {
/**
* Returns an SDK instance to be used for API calls
*
* @param {string} sessionKey key for specific BU
* @param {TYPE.AuthObject} authObject credentials for specific BU
* @returns {SDK} auth object
*/
function setupSDK(sessionKey, authObject) {
return new SDK(authObject, {
eventHandlers: {
onLoop: (type, req) => {
Util.logger.info(
`- Requesting next batch (currently ${req.Results.length} records)`
);
},
onRefresh: (authObject) => {
authObject.scope = authObject.scope.split(' '); // Scope is usually not an array, but we enforce conversion here for simplicity
credentialStore.set(sessionKey, authObject);
},
onConnectionError: (ex, remainingAttempts) => {
Util.logger.warn(
`- Connection problem (Code: ${ex.code}). Retrying ${remainingAttempts} time${
remainingAttempts > 1 ? 's' : ''
}`
);
Util.logger.errorStack(ex);
},
},
requestAttempts: 4,
retryOnConnectionError: true,
});
}

const Auth = {
/**
* For each business unit, set up base credentials to be used.
*
Expand Down Expand Up @@ -81,35 +114,4 @@ module.exports = {
Util.logger.info(`Auth sessions cleared`);
},
};
/**
* Returns an SDK instance to be used for API calls
*
* @param {string} sessionKey key for specific BU
* @param {TYPE.AuthObject} authObject credentials for specific BU
* @returns {SDK} auth object
*/

const setupSDK = (sessionKey, authObject) =>
new SDK(authObject, {
eventHandlers: {
onLoop: (type, req) => {
Util.logger.info(
`- Requesting next batch (currently ${req.Results.length} records)`
);
},
onRefresh: (authObject) => {
authObject.scope = authObject.scope.split(' '); // Scope is usually not an array, but we enforce conversion here for simplicity
credentialStore.set(sessionKey, authObject);
},
onConnectionError: (ex, remainingAttempts) => {
Util.logger.warn(
`- Connection problem (Code: ${ex.code}). Retrying ${remainingAttempts} time${
remainingAttempts > 1 ? 's' : ''
}`
);
Util.logger.errorStack(ex);
},
},
requestAttempts: 4,
retryOnConnectionError: true,
});
module.exports = Auth;
2 changes: 1 addition & 1 deletion lib/util/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Cli = {
async initMcdevConfig(skipInteraction) {
Util.logger.info('-- Initialising server connection --');
Util.logger.info('Please enter a name for your "Installed Package" credentials:');
const propertiesTemplate = Util.getDefaultProperties();
const propertiesTemplate = config.getDefaultProperties();
delete propertiesTemplate.credentials.default;

// wait for the interaction to finish or else an outer await will run before this is done
Expand Down
Loading