2017-09-25 12:17:06 +03:00
|
|
|
/**
|
|
|
|
* Parse Context
|
|
|
|
*
|
|
|
|
* Utility function, to expand strings out into objects.
|
|
|
|
* @param {Object|String} context
|
2020-03-19 18:23:10 +03:00
|
|
|
* @return {{internal: boolean, external: boolean, user: integer|null, public: boolean, api_key: Object|null}}
|
2017-09-25 12:17:06 +03:00
|
|
|
*/
|
|
|
|
module.exports = function parseContext(context) {
|
2020-04-29 18:44:27 +03:00
|
|
|
const parsed = {
|
2017-09-25 12:17:06 +03:00
|
|
|
internal: false,
|
|
|
|
external: false,
|
|
|
|
user: null,
|
2019-01-24 17:19:34 +03:00
|
|
|
api_key: null,
|
2019-01-29 21:52:05 +03:00
|
|
|
integration: null,
|
2017-09-25 12:17:06 +03:00
|
|
|
public: true
|
|
|
|
};
|
|
|
|
|
2017-09-28 16:00:52 +03:00
|
|
|
// NOTE: We use the `external` context for subscribers only at the moment.
|
2017-09-25 12:17:06 +03:00
|
|
|
if (context && (context === 'external' || context.external)) {
|
|
|
|
parsed.external = true;
|
|
|
|
parsed.public = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context && (context === 'internal' || context.internal)) {
|
|
|
|
parsed.internal = true;
|
|
|
|
parsed.public = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context && context.user) {
|
|
|
|
parsed.user = context.user;
|
|
|
|
parsed.public = false;
|
|
|
|
}
|
|
|
|
|
2019-01-24 17:19:34 +03:00
|
|
|
if (context && context.api_key) {
|
|
|
|
parsed.api_key = context.api_key;
|
2019-01-29 21:52:05 +03:00
|
|
|
parsed.integration = context.integration;
|
2019-01-24 17:19:34 +03:00
|
|
|
parsed.public = (context.api_key.type === 'content');
|
2019-01-18 14:17:12 +03:00
|
|
|
}
|
|
|
|
|
2017-09-25 12:17:06 +03:00
|
|
|
return parsed;
|
|
|
|
};
|