Skip to content

Commit 01e4825

Browse files
TypeScript Client + Client Example (#271)
* feat typescript api client * add ui api to clients * fix npm package README.md urls not absolute --------- Co-authored-by: Tim Berthold <75306992+tmberthold@users.noreply.github.com>
1 parent 601ec76 commit 01e4825

40 files changed

+6686
-2
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.scss text diff=css
66
*.htm text diff=html
77
*.html text diff=html
8+
*.properties text eol=lf
89

910
# Exclude files from exporting
1011
.gitattributes export-ignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: TypeScript API Client Library
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
release:
7+
types: [ published ]
8+
pull_request:
9+
branches: [ main ]
10+
11+
jobs:
12+
build-and-publish-npm-package:
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 30
15+
permissions:
16+
contents: read
17+
packages: write
18+
19+
steps:
20+
- uses: FranzDiebold/github-env-vars-action@v2
21+
- uses: actions/checkout@v3
22+
- uses: actions/setup-java@v3
23+
with:
24+
distribution: 'temurin'
25+
java-version: '17'
26+
cache: 'gradle'
27+
- uses: actions/setup-node@v3
28+
with:
29+
node-version: 16
30+
cache: 'npm'
31+
registry-url: 'https://registry.npmjs.org'
32+
cache-dependency-path: ./extensions/wrapper/client-ts/package-lock.json
33+
- name: Generate openapi.yaml & Client Code
34+
run: |
35+
./gradlew :extensions:wrapper:wrapper:clean :extensions:wrapper:wrapper:build -x test --no-daemon
36+
- name: Decide Package Version
37+
working-directory: ./extensions/wrapper/client-ts
38+
run: |
39+
# We re-use the maven module version
40+
VERSION=$(cat ../../../gradle.properties | sed -n "s/^sovityEdcExtensionsVersion=\(.*\)$/\1/p")
41+
42+
# We add the date in milis as "pre-release" version to ensure re-running the pipeline does not fail
43+
# due to a version already existing
44+
DATE_IN_UTC_MILIS="$(date +%s%3N)"
45+
if [[ "$VERSION" == *-SNAPSHOT ]]; then
46+
VERSION="$VERSION.$DATE_IN_UTC_MILIS"
47+
else
48+
VERSION="$VERSION-$DATE_IN_UTC_MILIS"
49+
fi
50+
51+
# Updates package.json
52+
npm version $VERSION
53+
- name: NPM Package Dist Tag
54+
run: |
55+
if [ "${{ startsWith(github.ref, 'refs/tags/') }}" == "true" ]; then
56+
# Only releases will build with the latest tag
57+
# Other tags will be ignored for default npm installs
58+
DIST_TAG=latest
59+
elif [ "$CI_REF_NAME" = "refs/heads/main" ]; then
60+
# The next tag is a common tag used for unstable versions
61+
DIST_TAG=next
62+
else
63+
# Branches and PRs will be built under special tags
64+
DIST_TAG=$CI_REF_SLUG
65+
fi
66+
echo "DIST_TAG=$DIST_TAG" >> $GITHUB_ENV
67+
- name: Build NPM Library
68+
working-directory: ./extensions/wrapper/client-ts
69+
run: |
70+
npm ci && npm run build
71+
- name: Publish NPM Library
72+
working-directory: ./extensions/wrapper/client-ts
73+
run: |
74+
npm set //registry.npmjs.org/:_authToken $NODE_AUTH_TOKEN
75+
npm set //registry.npmjs.org/:username $NODE_USER
76+
npm publish --access public --tag "${{ env.DIST_TAG }}"
77+
env:
78+
NODE_USER: richardtreier-sovity
79+
NODE_AUTH_TOKEN: ${{ secrets.SOVITY_EDC_CLIENT_NPM_AUTH }}

extensions/wrapper/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ contains multiple components:
2323
- EDC UI
2424
- Use Cases
2525
- Further APIs
26+
- An [EDC Extension](./wrapper) serving the implementations
2627
- Auto generated
2728
- [Java API Client](./client)
2829
- [TypeScript API Client](./client-ts)

extensions/wrapper/client-example/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ From the root folder of this repository execute the following:
2626
# Use WSL or Git Bash
2727

2828
# Build Dev EDC
29-
docker build -f "connector/Dockerfile" -t "edc-dev-for-api-wrapper" --build-arg BUILD_ARGS="-Pdev-edc" .
29+
docker build -f "connector/Dockerfile" -t "edc-dev-for-api-wrapper" --build-arg BUILD_ARGS="-Pdmgmt-api-key" .
3030

3131
# Fetch up-to-date UI
3232
docker compose -f docker-compose-dev.yaml pull
3333

3434
# Launch Dev EDCs
35-
EDC_IMAGE=edc-dev-for-api-wrapper EDC_UI_ACTIVE_PROFILE=sovity-open-source docker compose -f docker-compose-dev.yaml up --scale postgresql=0 --scale postgresql2=0 -d
35+
DEV_EDC_IMAGE=edc-dev-for-api-wrapper EDC_UI_ACTIVE_PROFILE=sovity-open-source docker compose -f docker-compose-dev.yaml up --scale postgresql=0 --scale postgresql2=0 -d
3636

3737
# Launch Quarkus Application
3838
./gradlew :extensions:wrapper:client-example:quarkusDev
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
node_modules
3+
/build
4+
/.svelte-kit
5+
/package
6+
.env
7+
.env.*
8+
!.env.example
9+
vite.config.js.timestamp-*
10+
vite.config.ts.timestamp-*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.DS_Store
2+
node_modules
3+
/build
4+
/.svelte-kit
5+
/package
6+
.env
7+
.env.*
8+
!.env.example
9+
10+
# Ignore files for PNPM, NPM and YARN
11+
pnpm-lock.yaml
12+
package-lock.json
13+
yarn.lock
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"useTabs": false,
3+
"tabWidth": 2,
4+
"singleQuote": true,
5+
"trailingComma": "none",
6+
"printWidth": 100,
7+
"plugins": ["prettier-plugin-svelte"],
8+
"pluginSearchDirs": ["."],
9+
"overrides": [
10+
{
11+
"files": "*.svelte",
12+
"options": {
13+
"parser": "svelte"
14+
}
15+
}
16+
]
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<!-- PROJECT LOGO -->
2+
<br />
3+
<div align="center">
4+
<a href="https://github.com/sovity/edc-extensions">
5+
<img src="https://raw.githubusercontent.com/sovity/edc-ui/main/src/assets/images/sovity_logo.svg" alt="Logo" width="300">
6+
</a>
7+
8+
<h3 align="center">EDC-Connector Extension:<br />API Wrapper &amp; API Client:<br />TypeScript API Client Example</h3>
9+
10+
<p align="center">
11+
<a href="https://github.com/sovity/edc-extensions/issues/new?template=bug_report.md">Report Bug</a>
12+
·
13+
<a href="https://github.com/sovity/edc-extensions/issues/new?template=feature_request.md">Request Feature</a>
14+
</p>
15+
</div>
16+
17+
## About this component
18+
19+
Example Project that consumes the TypeScript API Client Library.
20+
21+
The dependency itself is not part of the package.json as it is expected to be built and linked via `npm link`.
22+
23+
## Getting Started
24+
25+
From the root folder of this repository execute the following:
26+
27+
```shell script
28+
# Use WSL or Git Bash
29+
30+
# Build Dev EDC
31+
docker build -f "connector/Dockerfile" -t "edc-dev-for-api-wrapper" --build-arg BUILD_ARGS="-Pdmgmt-api-key" .
32+
33+
# Fetch up-to-date UI
34+
docker compose -f docker-compose-dev.yaml pull
35+
36+
# Launch Dev EDCs
37+
DEV_EDC_IMAGE=edc-dev-for-api-wrapper EDC_UI_ACTIVE_PROFILE=sovity-open-source docker compose -f docker-compose-dev.yaml up --scale postgresql=0 --scale postgresql2=0 -d
38+
39+
# Generate OpenAPI & TypeScript Code
40+
./gradlew :extensions:wrapper:wrapper:clean :extensions:wrapper:wrapper:build
41+
42+
# Build Client Library
43+
(cd extensions/wrapper/client-ts && npm install && npm run build)
44+
45+
# Run Example Project
46+
(cd extensions/wrapper/client-ts-example && npm install && npm link ../client-ts && npm run dev)
47+
48+
# Shut down Dev EDCs
49+
docker compose -f docker-compose-dev.yaml down -t 1
50+
```
51+
52+
## License
53+
54+
Apache License 2.0 - see [LICENSE](../../LICENSE)
55+
56+
## Contact
57+
58+
sovity GmbH - contact@sovity.de

0 commit comments

Comments
 (0)