-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Generate the HTML * Bringing elementary packages to the core * Prepared for exposing packages as shared deps * Realigned and improved * Use default import map and favicon * Bring api and error-handling to core * Enhanced FHIR * Incldued fihr typings * Renamed to config * Renamed module-config to config * Improved sync * Finished debugging * Enhanced local settings * Refinement * Alignment * Final alignment of basis * Merged with latest changes * Prettified * Prepare for openmrs run command * Changed version number * Reordered deps * Removed prepublishOnly script * Updated dep version * Rewired postcss * Improved webpack * Use submodule for running * Adjusted for deployment; only need to publish app shell * Added backend parameter * Updated with importmap flag * Changed to better i18n backend see #14 * Review comments * Review comments * Warn if importmap seems wrong * Prettified
- Loading branch information
1 parent
1a228ce
commit cbddc8a
Showing
215 changed files
with
12,066 additions
and
1,743 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,4 +67,5 @@ dist | |
*.iml | ||
.idea/ | ||
|
||
docs/ | ||
docs/ | ||
storybook-static |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
dist/ | ||
README.md | ||
docs/ | ||
docs/ | ||
*.svg | ||
*.ico | ||
*.ejs | ||
packages/esm-styleguide/src/**/*.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,46 @@ | ||
# OpenMRS Frontend Core | ||
|
||
This is a [Lerna](https://lerna.js.org/) project containing the core | ||
packages for the OpenMRS Frontend. These packages handle the | ||
"cross-cutting concerns" described in the | ||
[Domain Decomposition](https://wiki.openmrs.org/display/projects/MFE+Domain+Decomposition) | ||
document. | ||
This is a [Lerna](https://lerna.js.org/) project containing the core packages for the OpenMRS Frontend. These packages handle the "cross-cutting concerns" described in the [Domain Decomposition](https://wiki.openmrs.org/display/projects/MFE+Domain+Decomposition) document. | ||
|
||
- [@openmrs/esm-api](packages/esm-api) | ||
- [@openmrs/esm-app-shell](packages/esm-app-shell) | ||
- [@openmrs/esm-config](packages/esm-config) | ||
- [@openmrs/esm-error-handling](packages/esm-error-handling) | ||
- [@openmrs/esm-extension-manager](packages/esm-extension-manager) | ||
- [@openmrs/esm-styleguide](packages/esm-styleguide) | ||
|
||
## Getting Started | ||
|
||
To install and setup the repository just use the following command: | ||
|
||
```sh | ||
npx lerna bootstrap | ||
``` | ||
|
||
For working with the app shell you don't need to have the repository cloned. You can also just use the `run-openmrs` directly. | ||
|
||
```sh | ||
npx run-openmrs | ||
``` | ||
npm install -g lerna | ||
npm install | ||
lerna bootstrap | ||
|
||
This is a command line utility for running (or building) the app shell in isolation. In particular, it deals with everything that touches the development, distribution, and deployment of an app shell. | ||
|
||
## Possibilities | ||
|
||
The new architecture offers a couple of interesting possibilities. We go into them one by one. | ||
|
||
### Proxying OpenMRS Backends | ||
|
||
We can now proxy *any* backend. For instance, using the backend of the demo instance we just run: | ||
|
||
```sh | ||
npx run-openmrs debug --backend https://demo.openmrs.org/ | ||
``` | ||
|
||
There are a couple of interesting public instances: | ||
|
||
```sh | ||
https://qa-refapp.openmrs.org/ | ||
https://demo.openmrs.org/ | ||
https://openmrs-spa.org/ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
# openmrs-esm-api | ||
|
||
An [OpenMRS Microfrontend](https://wiki.openmrs.org/display/projects/Frontend+-+SPA+and+Microfrontends). | ||
|
||
## What is this? | ||
|
||
openmrs-esm-api is an [in-browser javascript module](https://github.com/openmrs/openmrs-rfc-frontend/blob/master/text/0002-modules.md) that exports functions that interact with the OpenMRS API. | ||
|
||
## How do I use it? | ||
|
||
```js | ||
import { openmrsFetch, openmrsObservableFetch, getCurrentUser, fhir } from '@openmrs/esm-api'; | ||
openmrsFetch('/ws/rest/v1/session').then(response => { | ||
console.log(response.data.authenticated) | ||
} | ||
``` | ||
## Contributing / Development | ||
[Instructions for local development](https://wiki.openmrs.org/display/projects/Setup+local+development+environment+for+OpenMRS+SPA) | ||
## API | ||
The following functions are exported from the @openmrs/esm-api module: | ||
## openmrsFetch(url, init): Promise | ||
The openmrsFetch function is a wrapper around the [browser's built-in fetch function](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch), with extra handling for OpenMRS-specific API behaviors, such as request headers, authentication, authorization, and the API urls. | ||
##### Arguments | ||
1. url (required): A string url to make the request to. Note that the openmrs base url (by default "/openmrs") will be automatically prepended to the URL, so there is no need to include it. | ||
2. init (optional): A [fetch init object](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Syntax). Note that the `body` property does not need to be JSON.stringify()'ed because openmrsFetch will do that for you. | ||
##### Return value | ||
A [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that resolves with a [Response object](https://developer.mozilla.org/en-US/docs/Web/API/Response). Note that the openmrs version of the Response object has already downloaded the HTTP response body as json, and has an additional `data` property with the HTTP response json as a javascript object. | ||
### Example | ||
```js | ||
import { openmrsFetch } from '@openmrs/esm-api' | ||
const abortController = new AbortController(); | ||
openmrsFetch('/ws/rest/v1/session', {signal: abortController.signal}) | ||
.then(response => { | ||
console.log(response.data.authenticated) | ||
}) | ||
.catch(err => { | ||
console.error(err.status); | ||
}) | ||
abortController.abort(); | ||
openmrsFetch('/ws/rest/v1/session', { | ||
method: 'POST', | ||
body: { | ||
username: 'hi', | ||
password: 'there', | ||
} | ||
}) | ||
``` | ||
### Cancellation | ||
To cancel a network request, use an [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort). It is best practice to cancel your network requests when the user navigates away from a page while the request is pending request, to free up memory and network resources and to prevent race conditions. | ||
## openmrsObservableFetch(url, init): Observable | ||
The openmrsObservableFetch function is a wrapper around openmrsFetch that returns an [Observable](https://rxjs-dev.firebaseapp.com/guide/observable) instead of a promise. It exists in case using an Observable is preferred or more convenient than a promise. | ||
##### Arguments | ||
The arguments to openmrsObservableFetch are exactly the same as the arguments to openmrsFetch. | ||
##### Return value | ||
An Observable that produces exactly one Response object. The response object is exactly the same as for openmrsFetch. | ||
### Example | ||
```js | ||
import { openmrsObservableFetch } from '@openmrs/esm-api' | ||
const subscription = openmrsObservableFetch('/ws/rest/v1/session').subscribe( | ||
response => console.log(response.data), | ||
err => {throw err}, | ||
() => console.log('finished') | ||
) | ||
subscription.unsubscribe() | ||
``` | ||
### Cancellation | ||
To cancel the network request, simply call `subscription.unsubscribe();` | ||
## fhir | ||
The `fhir` object is [an instance of fhir.js](https://github.com/FHIR/fhir.js) that can be used to call FHIR-compliant OpenMRS APIs. See [the docs for fhir.js](https://github.com/FHIR/fhir.js) for more info and example usage. | ||
## getCurrentUser(): Observable | ||
The getCurrentUser function returns an observable that produces **zero or more values, over time**. It will produce zero values by default if the user is not logged in. And it will provide a first value when the logged in user is fetched from the server. Subsequent values will be produced whenever the user object is updated. | ||
###### Arguments | ||
1. options (optional): An object with includeAuthStatus boolean property that defaults to false. When includeAuthStatus is set to true, the entire response object from the API will be provided. When includeAuthStatus is set to false, only the user property of the response object will be provided. | ||
###### Return value | ||
An Observable that produces zero or more values (as described above). The values produced will be a user object (if includeAuthStatus is set to false) or an object with a session and authenticated property (if includeAuthStatus is set to true). | ||
### Example | ||
```js | ||
import { getCurrentUser } from '@openmrs/esm-api' | ||
const subscription = getCurrentUser().subscribe( | ||
user => console.log(user) | ||
) | ||
subscription.unsubscribe() | ||
getCurrentUser({includeAuthStatus: true}).subscribe( | ||
data => console.log(data.authenticated) | ||
) | ||
``` | ||
### Be sure to unsubscribe when your component unmounts | ||
Otherwise your code will continue getting updates to the user object even after the UI component is gone from the screen. This is a memory leak and source of bugs. | ||
## refetchCurrentUser(): Observable | ||
The refetchCurrentUser function causes a network request to redownload the user. All subscribers to the current user will be notified of the new users once the new version of the user object is downloaded. | ||
###### Arguments | ||
None | ||
###### Return value | ||
An observable exactly the same as if you had called `getCurrentUser()`. | ||
#### Example | ||
```js | ||
import { refetchCurrentUser } from '@openmrs/esm-api' | ||
refetchCurrentUser() | ||
``` |
2 changes: 2 additions & 0 deletions
2
packages/esm-api/__mocks__/openmrs-esm-error-handling.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export function createErrorHandler() {} | ||
export function reportError() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const defineConfigSchema = jest.fn(); | ||
|
||
export const getConfig = jest | ||
.fn() | ||
.mockResolvedValue({ redirectAuthFailure: { enabled: false } }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const navigateToUrl = jest.fn(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
transform: { | ||
"^.+\\.tsx?$": "babel-jest", | ||
}, | ||
moduleNameMapper: { | ||
"lodash-es": "lodash", | ||
"@openmrs/esm-error-handling": | ||
"<rootDir>/__mocks__/openmrs-esm-error-handling.mock.ts", | ||
"@openmrs/esm-config": | ||
"<rootDir>/__mocks__/openmrs-esm-module-config.mock.ts", | ||
"single-spa": "<rootDir>/__mocks__/single-spa.mock.ts", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"name": "@openmrs/esm-api", | ||
"version": "3.1.0", | ||
"license": "MPL-2.0", | ||
"description": "The javascript module for interacting with the OpenMRS API", | ||
"browser": "dist/openmrs-esm-api.js", | ||
"main": "src/index.ts", | ||
"source": true, | ||
"scripts": { | ||
"test": "jest --config jest.config.js --passWithNoTests", | ||
"build": "webpack --mode=production", | ||
"typescript": "tsc", | ||
"lint": "eslint src --ext ts,tsx" | ||
}, | ||
"directories": { | ||
"lib": "dist", | ||
"src": "src" | ||
}, | ||
"browserslist": [ | ||
"extends browserslist-config-openmrs" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/openmrs/openmrs-esm-core.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/openmrs/openmrs-esm-core/issues" | ||
}, | ||
"homepage": "https://github.com/openmrs/openmrs-esm-core#readme", | ||
"dependencies": { | ||
"fhir.js": "0.0.22", | ||
"lodash-es": "^4.17.15", | ||
"systemjs-webpack-interop": "^2.1.2", | ||
"unistore": "^3.5.2" | ||
}, | ||
"peerDependencies": { | ||
"@openmrs/esm-config": "*", | ||
"@openmrs/esm-error-handling": "*", | ||
"react": "16.x", | ||
"single-spa": "4.x" | ||
}, | ||
"devDependencies": { | ||
"@openmrs/esm-config": "^0.3.0", | ||
"@openmrs/esm-error-handling": "^1.3.0", | ||
"@types/fhir": "0.0.31", | ||
"@types/react": "^16.9.46", | ||
"react": "^16.13.1", | ||
"rxjs": "^6.5.3", | ||
"single-spa": "^4.4.1" | ||
} | ||
} |
Oops, something went wrong.