diff --git a/cli/src/lib/generateManifest.js b/cli/src/lib/generateManifest.js index bd4337b91..c54a7a269 100644 --- a/cli/src/lib/generateManifest.js +++ b/cli/src/lib/generateManifest.js @@ -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, @@ -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', }, diff --git a/docs/config/d2-config-js-reference.md b/docs/config/d2-config-js-reference.md index 416f904ae..0b9ff4b04 100644 --- a/docs/config/d2-config-js-reference.md +++ b/docs/config/d2-config-js-reference.md @@ -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`). @@ -38,6 +40,9 @@ const config = { entryPoints: { app: './src/App', }, + + dataStoreNamespace: 'my-custom-app-namespace', + customAuthorities: ['my-app-analytics-user'], } module.exports = config diff --git a/examples/simple-app/d2.config.js b/examples/simple-app/d2.config.js index 5ed877ea5..2118a4489 100644 --- a/examples/simple-app/d2.config.js +++ b/examples/simple-app/d2.config.js @@ -9,6 +9,9 @@ const config = { entryPoints: { app: './src/App.js', }, + + dataStoreNamespace: 'testapp-namespace', + customAuthorities: ['testapp-authority'], } module.exports = config