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

feat: create kennisbank-api server #912

Merged
merged 21 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
badf314
feat: create kennisbank-api server
AliKdhim87 Oct 1, 2024
f8d4319
build: integrate kennisbank-api into Docker
AliKdhim87 Oct 2, 2024
8a3d50c
feat: enable CORS
AliKdhim87 Oct 2, 2024
6db86fb
feat: implement openapi specification
AliKdhim87 Oct 3, 2024
2120f3b
feat: generate API interface types for kennisartikel & vac
AliKdhim87 Oct 3, 2024
5166ae6
feat: add express-openapi-validator
AliKdhim87 Oct 4, 2024
72c56db
docs: update the strapi.frameless website with kennisbank-api
AliKdhim87 Oct 7, 2024
e232a0b
docs: update root README with kennisbank-api
AliKdhim87 Oct 7, 2024
b061cb9
docs: add README file
AliKdhim87 Oct 7, 2024
aeaae4e
feat: integrate swagger-ui-express
AliKdhim87 Oct 9, 2024
5ac6b84
feat: implement objecttypes routers for kennisartikel & VAC
AliKdhim87 Oct 9, 2024
7d41c5c
refactor: refactor kennisbank-api server
AliKdhim87 Oct 9, 2024
796e229
feat: integrate kennisartikelMetadata collection into kennisbank-api
AliKdhim87 Oct 11, 2024
4f7b965
feat(pdc-dashboard): create kennisartikelMetadata
AliKdhim87 Oct 11, 2024
39a7651
test: integrate jest into kennisbank-api
AliKdhim87 Oct 16, 2024
d22a885
refactor: revert the openapi.yaml
AliKdhim87 Oct 17, 2024
c1e6d7c
refactor: inject API token into request headers
AliKdhim87 Oct 22, 2024
8d89699
refactor: refactor API_TOKEN from Bearer to TOKEN
AliKdhim87 Oct 22, 2024
f68e6cf
refactor: rename the kennisbank-api to overige-object-api
AliKdhim87 Oct 23, 2024
7328470
feat: implement pagination
AliKdhim87 Oct 24, 2024
125f9f2
refactor: rename overige-object-api to overige-objecten-api
AliKdhim87 Oct 25, 2024
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
5 changes: 5 additions & 0 deletions .changeset/khaki-bobcats-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@frameless/overige-objecten-api": major
---

Create Overige Objecten API applicatie
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ gql
**/yarn-error.log
**/.strapi-updater.json
**/generated
apps/overige-objecten-api/src/types
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: [
'./apps/overige-objecten-api/tsconfig.json',
'./apps/overige-objecten-api/tsconfig.test.json',
'./apps/kennisbank-dashboard/src/admin/tsconfig.json',
'./apps/kennisbank-dashboard/tsconfig.json',
'./apps/kennisbank-frontend/tsconfig.json',
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,8 @@ dist/
# Sitemap plugin
**/**/public/*.xml
**/**/public/*.txt

############################
# overige-objecten-api
############################
apps/overige-objecten-api/src/types
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ yarn.lock
.strapi-updater.json
generated
gql
apps/overige-objecten-api/src/types
4 changes: 3 additions & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ COPY ./apps/pdc-sc/package.json apps/pdc-sc/package.json
COPY ./apps/vth-dashboard/package.json apps/vth-dashboard/package.json
COPY ./apps/vth-frontend/package.json apps/vth-frontend/package.json
COPY ./apps/kennisbank-dashboard/package.json apps/kennisbank-dashboard/package.json
COPY ./apps/overige-objecten-api/package.json apps/overige-objecten-api/package.json
COPY ./apps/kennisbank-frontend/package.json apps/kennisbank-frontend/package.json
COPY ./packages/catalogi-data/package.json packages/catalogi-data/package.json
COPY ./packages/preview-button/package.json packages/preview-button/package.json
Expand Down Expand Up @@ -53,7 +54,8 @@ RUN npm run build --workspace @frameless/upl && \
npm run build --workspace @frameless/strapi-plugin-open-forms-embed && \
npm run build --workspace @frameless/strapi-plugin-uuid-field && \
npm run build --workspace @frameless/strapi-plugin-env-label && \
npm run build --workspace @frameless/strapi-plugin-language
npm run build --workspace @frameless/strapi-plugin-language && \
npm run build --workspace @frameless/overige-objecten-api

# Build target production #
###########################
Expand Down
90 changes: 47 additions & 43 deletions README.md

Large diffs are not rendered by default.

80 changes: 80 additions & 0 deletions apps/overige-objecten-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# overige-objecten-api

The **overige-objecten-api** is a microservice built with Node.js that maps certain PDC product fields to the **kennisartikel** and **VAC** fields.

## Features

- OpenAPI documentation.
- Request validation against **kennisartikel** and **VAC** schemas, ensuring that each field has the correct type.
- Automatic generation of TypeScript interfaces for **kennisartikel** and **VAC** schemas.
- Provides clear and descriptive error messages in JSON format when validation fails.

## Getting Started

You can run the server locally in two ways:

> Note: Before proceeding, ensure you generate an API token from the Strapi dashboard by following these steps:

1. Go to the PDC Strapi dashboard.
2. Navigate to Settings > API Tokens and select Create New API Token.
3. Allow access only to the product API by checking the boxes for find and findOne.
4. Once you've configured the permissions, click Save.

After generating the token, include it in your request headers as a Bearer token. Here's an example:

```ts
Authorization: Bearer API_TOKEN
```

### 1. Start with Docker

Ensure that you have the following environment variables in the `.pdc.prod.env` file before starting:

```shell
OVERIGE_OBJECTEN_API_PORT=4001
OVERIGE_OBJECTEN_API_CORS=http://localhost:3000 # If using multiple domains, separate them with a comma (e.g., 'http://localhost:3000, http://localhost:3001').
```

To start the service, open a terminal in the project root and run:

```shell
cd bin && bash ./deploy.sh pdc-dashboard prod up --build
```

### 2. Start without Docker

Create an .env file in the apps/overige-objecten-api directory with the following environment variables:

```shell
STRAPI_PRIVATE_URL=http://127.0.0.1:1337/
OVERIGE_OBJECTEN_API_PORT=4001
OVERIGE_OBJECTEN_API_CORS='' # Required for client-side application
```

Then, follow these steps:

1. Build the project:

```shell
yarn build

```

2. Start the PDC-dashboard server:

```shell
yarn workspace @frameless/pdc-dashboard dev

```

3. Start the overige-objecten-api server:

```shell
yarn workspace @frameless/overige-objecten-api dev

```

## API Endpoints

- Kennisartikel API: [http://localhost:4001/api/v1/objects](http://localhost:4001/api/v1/objects)
- OpenAPI specification: [http://localhost:4001/api/v1/openapi.json](http://localhost:4001/api/v1/openapi.json)
21 changes: 21 additions & 0 deletions apps/overige-objecten-api/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { Config } from 'jest';

const config: Config = {
preset: 'ts-jest',
// to obtain access to the matchers.
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
setupFilesAfterEnv: ['<rootDir>/src/tests/jest.setup.ts'],
modulePaths: ['<rootDir>'],
testEnvironment: 'node',
roots: ['<rootDir>/src'],
transform: {
'^.+\\.(ts)$': [
'ts-jest',
{
tsconfig: 'tsconfig.test.json',
},
],
},
};

export default config;
51 changes: 51 additions & 0 deletions apps/overige-objecten-api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@frameless/overige-objecten-api",
"version": "0.0.0",
"private": true,
"author": "@frameless",
"description": "Overige Objecten API for PDC",
"license": "EUPL-1.2",
"keywords": [],
"scripts": {
"prebuild": "yarn clean && yarn generate-types",
"build": "npm-run-all --parallel build:*",
"build:server": "tsc -p ./tsconfig.json",
"build:openapi": "mkdir -p dist/src/docs && cp -R src/docs/ dist/src/docs/",
"watch": "tsc -p ./tsconfig.json -w",
"start": "NODE_ENV=production node ./dist/src/server.js",
"dev": "NODE_ENV=development nodemon src/server.ts",
"clean": "rimraf dist src/types",
"generate-types": "openapi-typescript src/docs/openapi.yaml --output src/types/openapi.ts",
"test": "OVERIGE_OBJECTEN_API_PORT=3000 jest --coverage --forceExit --verbose",
"test:watch": "OVERIGE_OBJECTEN_API_PORT=3000 jest --watch"
},
"dependencies": {
"cors": "2.8.5",
"dotenv": "16.4.5",
"express": "4.21.0",
"express-openapi-validator": "5.3.7",
"js-yaml": "4.1.0",
"swagger-ui-express": "5.0.1"
},
"devDependencies": {
"@types/cors": "2.8.17",
"@types/jest": "29.5.12",
"@types/supertest": "6.0.2",
"@types/swagger-ui-express": "4.1.6",
"@types/yamljs": "0.2.34",
"jest": "29.7.0",
"nodemon": "3.1.7",
"openapi-typescript": "7.4.1",
"rimraf": "6.0.1",
"supertest": "7.0.0",
"ts-jest": "29.2.3",
"ts-node": "10.9.2",
"typescript": "5.0.4",
"jest-fetch-mock": "3.0.3"
},
"repository": {
"type": "git+ssh",
"url": "git@github.com:frameless/strapi.git",
"directory": "apps/overige-objecten-api"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
export const getStrapiKennisartikelData = () => {
return {
data: {
products: {
meta: {
pagination: {
total: 1,
page: 1,
pageSize: 10,
pageCount: 1,
},
},
data: [
{
id: '50',
attributes: {
title: 'Aansprakelijk stellen gemeente, schade melden',
slug: 'aansprakelijk-stellen-gemeente-schade-melden',
uuid: 'a9058a3e-6dd9-480c-a074-e38026bd4ffd',
locale: 'nl',
updatedAt: '2024-10-14T09:22:27.349Z',
createdAt: '2024-04-02T09:23:53.092Z',
metaTags: {
keymatch: 'schade, aansprakelijkheid',
title: 'Schade melden gemeente',
description: 'Hebt u schade door ons? Dan kunt u hier vergoeding voor vragen. ',
},
sections: [
{
id: '36',
content:
'<h2 style="text-align: start"><strong>Voorwaarden</strong></h2><ul><li><p>U kunt laten zien dat de gemeente verantwoordelijk is voor uw schade.</p></li><li><p>U hebt geen rechtsbijstandsverzekering en u bent niet verzekerd voor de schade. Denk bijvoorbeeld aan een autoverzekering, zorgverzekering, particuliere aansprakelijkheidsverzekering en telefoonverzekering. Bent u wel verzekerd? Ga dan naar uw verzekeringsmaatschappij.</p></li></ul>',
kennisartikelCategorie: 'voorwaarden',
component: 'ComponentComponentsUtrechtRichText',
},
{
id: '37',
content:
'<h2><strong>Wat stuurt u mee?</strong></h2><p>Stuur alle gevraagde bewijsstukken mee. Zo kunnen we uw aanvraag sneller en beter beoordelen.</p><ul><li><p>Foto’s van het voorwerp of de situatie die de schade veroorzaakte</p></li><li><p>Foto’s van de plek waar de schade ontstond</p></li><li><p>Foto’s van de schade</p></li><li><p>Ondertekende&nbsp;<a target="_blank" rel="noopener" href="https://www.utrecht.nl/fileadmin/uploads/documenten/9.digitaalloket/juridische-zaken/Getuigenverklaring-gemeente-Utrecht.PDF">getuigenverklaringen</a>&nbsp;(pdf, 240 kB) (alleen nodig als er getuigen waren)</p></li><li><p>Herstelofferte of reparatienota</p></li><li><p>Veroorzaakte een auto of een ander voertuig van de gemeente de schade? Dan is een compleet ingevuld Europees schadeformulier (aanrijdingsformulier) verplicht.</p></li></ul><p><span>Verder kunt u denken aan:</span></p><ul><li><p>een rapport van een schade-expert</p></li><li><p>een proces-verbaal van de politie</p></li></ul>',
kennisartikelCategorie: 'aanvraag',
component: 'ComponentComponentsUtrechtRichText',
},
{},
{
id: '38',
content: '<p>Hulp nodig bij het invullen? Bel ons dan via telefoonnummer 14 030.</p>',
kennisartikelCategorie: 'contact',
component: 'ComponentComponentsUtrechtRichText',
},
{},
{
id: '39',
content:
'<h2 style="text-align: start"><strong>Na uw melding</strong></h2><p style="text-align: start">Binnen 4 weken krijgt u een bericht. U hoort dan of wij vinden dat de gemeente aansprakelijk is voor de opgelopen schade. Of u hoort of wij hier meer tijd voor nodig hebben.</p>',
kennisartikelCategorie: null,
component: 'ComponentComponentsUtrechtRichText',
},
{
id: '40',
content:
'<h2><strong>Meer informatie</strong></h2><ul><li><p>Bent u ondernemer en hebt u winst- of inkomstenverlies door de uitvoering van het werk door de gemeente?&nbsp;<a target="_blank" rel="" href="https://www.utrecht.nl/nadeelcompensatie">Lees meer over nadeelcompensatie en vraag het aan</a></p></li><li><p>Daalt de waarde van uw woning door een veranderd bestemminsplan?&nbsp;<a target="_blank" rel="" href="https://www.utrecht.nl/planschade">Lees meer over planschade en vraag het aan</a></p></li></ul>',
kennisartikelCategorie: null,
component: 'ComponentComponentsUtrechtRichText',
},
],
kennisartikelMetadata: {
uuid: '3c1d6811-a43f-4d92-8c48-19df0a491852',
doelgroep: 'eu_burger',
productAanwezig: true,
productValtOnder: null,
afdelingen: [
{
afdelingId: 'c38039ec-3079-47d1-a13c-c16fe8277b62',
afdelingnaam: 'Demo afdeling',
},
],
verantwoordelijkeOrganisatie: {
owmsIdentifier: 'http://standaarden.overheid.nl/owms/terms/Utrecht_(gemeente)',
owmsPrefLabel: 'Gemeente Utrecht',
owmsEndDate: '2024-10-13T22:00:00.000Z',
},
upnUri: 'http://standaarden.overheid.nl/owms/terms/UPL-naam_nog_niet_beschikbaar',
},
},
},
],
},
},
};
};
4 changes: 4 additions & 0 deletions apps/overige-objecten-api/src/__mocks__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { getStrapiKennisartikelData } from './getStrapiKennisartikelData';
export { objectsResponseData } from './objectsResponseData';
export { kennisartikelObject } from './kennisartikelObject';
export { vacObject } from './vacObject';
40 changes: 40 additions & 0 deletions apps/overige-objecten-api/src/__mocks__/kennisartikelObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export const kennisartikelObject = () => ({
url: 'http://localhost:3000/api/v1/objecttypes/kennisartikel',
uuid: 'a9058a3e-6dd9-480c-a074-e38026bd4ffd',
upnUri: 'http://standaarden.overheid.nl/owms/terms/UPL-naam_nog_niet_beschikbaar',
publicatieDatum: '2024-04-02',
productAanwezig: true,
productValtOnder: null,
verantwoordelijkeOrganisatie: {
url: 'http://localhost:3000/api/v1/objecttypes/kennisartikel#verantwoordelijkeOrganisatie',
owmsIdentifier: 'http://standaarden.overheid.nl/owms/terms/Utrecht_(gemeente)',
owmsPrefLabel: 'Gemeente Utrecht',
owmsEndDate: '2024-10-13T22:00:00.000Z',
},
locaties: null,
doelgroep: 'eu-burger',
afdelingen: [
{
afdelingId: 'c38039ec-3079-47d1-a13c-c16fe8277b62',
afdelingnaam: 'Demo afdeling',
},
],
beschikbareTalen: ['nl'],
vertalingen: [
{
datumWijziging: '2024-10-14T09:22:27.349Z',
taal: 'nl',
titel: 'Aansprakelijk stellen gemeente, schade melden',
trefwoorden: [
{
trefwoord: 'schade',
},
{
trefwoord: 'aansprakelijkheid',
},
],
vereisten:
'<h2 style="text-align: start"><strong>Voorwaarden</strong></h2><ul><li><p>U kunt laten zien dat de gemeente verantwoordelijk is voor uw schade.</p></li><li><p>U hebt geen rechtsbijstandsverzekering en u bent niet verzekerd voor de schade. Denk bijvoorbeeld aan een autoverzekering, zorgverzekering, particuliere aansprakelijkheidsverzekering en telefoonverzekering. Bent u wel verzekerd? Ga dan naar uw verzekeringsmaatschappij.</p></li></ul>',
},
],
});
Loading
Loading