Skip to content

Commit

Permalink
feat: support custom authorities and reserved namespace [LIBS-165] (#547
Browse files Browse the repository at this point in the history
)
  • Loading branch information
amcgee committed Apr 2, 2021
1 parent ea12423 commit fc86a55
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 12 deletions.
39 changes: 38 additions & 1 deletion cli/src/lib/generateManifest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
const { reporter } = require('@dhis2/cli-helpers-engine')
const { reporter, chalk } = require('@dhis2/cli-helpers-engine')
const fs = require('fs-extra')

const parseCustomAuthorities = authorities => {
if (!authorities) {
return undefined
}
if (
!Array.isArray(authorities) ||
!authorities.every(auth => typeof auth === 'string')
) {
reporter.warn(
`Invalid value ${chalk.bold(
authorities
)} specified for ${chalk.bold(
'customAuthorities'
)}, must be an array of strings, skipping.`
)
return undefined
}
return authorities
}
const parseDataStoreNamespace = namespace => {
if (!namespace) {
return undefined
}
if (typeof namespace !== 'string') {
reporter.warn(
`Invalid value ${chalk.bold(namespace)} specified for ${chalk.bold(
'dataStoreNamespace'
)}, must be a string, skipping.`
)
return undefined
}

return namespace
}
module.exports = (paths, config, publicUrl) => {
const manifest = {
app_hub_id: config.id,
Expand All @@ -10,13 +44,16 @@ module.exports = (paths, config, publicUrl) => {
description: config.description,
version: config.version,
core_app: config.coreApp,

launch_path: 'index.html',
default_locale: 'en',
activities: {
dhis: {
href: '*',
namespace: parseDataStoreNamespace(config.dataStoreNamespace),
},
},
authorities: parseCustomAuthorities(config.customAuthorities),
icons: {
48: 'dhis2-app-icon.png',
},
Expand Down
27 changes: 16 additions & 11 deletions docs/config/d2-config-js-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ All properties are technically optional, but it is recommended to set them expli

The following configuration properties are supported:

| Property | Type | Default | Description |
| :-----------------: | :-------: | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **type** | _string_ | **app** | Either **app** or **lib** |
| **name** | _string_ | `pkg.name` | A short, machine-readable unique name for this app |
| **title** | _string_ | `config.name` | The human-readable application title, which will appear in the HeaderBar |
| **description** | _string_ | `pkg.description` | A full-length description of the application |
| **author** | _string_ | `pkg.author` | The name of the developer to include in the DHIS2 manifest |
| **entryPoints.app** | _string_ | **./src/App** | The path to the application entrypoint (not used for libraries) |
| **entryPoints.lib** | _string_ | **./src/index** | The path to the library entrypoint (not used for applications) |
| **coreApp** | _boolean_ | **false** | **ADVANCED** If true, build an app artifact to be included as a root-level core application |
| **standalone** | _boolean_ | **false** | **ADVANCED** If true, do NOT include a static BaseURL in the production app artifact. This includes the `Server` field in the login dialog, which is usually hidden and pre-configured in production. |
| Property | Type | Default | Description |
| :--------------------: | :-------------: | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **type** | _string_ | **app** | Either **app** or **lib** |
| **name** | _string_ | `pkg.name` | A short, machine-readable unique name for this app |
| **title** | _string_ | `config.name` | The human-readable application title, which will appear in the HeaderBar |
| **description** | _string_ | `pkg.description` | A full-length description of the application |
| **author** | _string_ | `pkg.author` | The name of the developer to include in the DHIS2 manifest |
| **entryPoints.app** | _string_ | **./src/App** | The path to the application entrypoint (not used for libraries) |
| **entryPoints.lib** | _string_ | **./src/index** | The path to the library entrypoint (not used for applications) |
| **dataStoreNamespace** | _string_ | | The DataStore and UserDataStore namespace to reserve for this application. The reserved namespace **must** be suitably unique, as other apps will fail to install if they attempt to reserve the same namespace - see the [webapp manifest docs](https://docs.dhis2.org/en/develop/loading-apps.html) |
| **customAuthorities** | _Array(string)_ | | An array of custom authorities to create when installing the app, these do not provide security protections in the DHIS2 REST API but can be assigned to user roles and used to modify the interface displayed to a user - see the [webapp manifest docs](https://docs.dhis2.org/en/develop/loading-apps.html) |
| **coreApp** | _boolean_ | **false** | **ADVANCED** If true, build an app artifact to be included as a root-level core application |
| **standalone** | _boolean_ | **false** | **ADVANCED** If true, do NOT include a static BaseURL in the production app artifact. This includes the `Server` field in the login dialog, which is usually hidden and pre-configured in production. |

> _Note_: Dynamic defaults above may reference `pkg` (a property of the local `package.json` file) or `config` (another property within `d2.config.js`).
Expand All @@ -38,6 +40,9 @@ const config = {
entryPoints: {
app: './src/App',
},

dataStoreNamespace: 'my-custom-app-namespace',
customAuthorities: ['my-app-analytics-user'],
}

module.exports = config
Expand Down
3 changes: 3 additions & 0 deletions examples/simple-app/d2.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const config = {
entryPoints: {
app: './src/App.js',
},

dataStoreNamespace: 'testapp-namespace',
customAuthorities: ['testapp-authority'],
}

module.exports = config

0 comments on commit fc86a55

Please sign in to comment.