Skip to content

Commit fb4b4fa

Browse files
authored
Merge pull request #1207 from helpwave/issue/1206-Customer-API-Intgration
customer api integration
2 parents dec1fd3 + 7669dbe commit fb4b4fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2741
-1066
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515
jobs:
1616

1717
lint:
18-
runs-on: ubuntu-20.04
18+
runs-on: ubuntu-latest
1919
steps:
2020
- name: Checkout repository
2121
uses: actions/checkout@v4

.github/workflows/storybook-lib.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ on:
2525
jobs:
2626

2727
storybook:
28-
runs-on: ubuntu-20.04
28+
runs-on: ubuntu-latest
2929
steps:
3030
- name: Checkout repository
3131
uses: actions/checkout@v4

customer/.env.development

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
NEXT_PUBLIC_API_URL=https://localhost:8000
2-
NEXT_PUBLIC_OIDC_PROVIDER=http://localhost:8080/realms/myrealm
3-
NEXT_PUBLIC_CLIENT_ID=myclient
1+
NEXT_PUBLIC_API_URL=https://api.customer.helpwave.de
2+
NEXT_PUBLIC_OIDC_PROVIDER=https://id.helpwave.de/realms/main
3+
NEXT_PUBLIC_CLIENT_ID=customer.helpwave.de
44
NEXT_PUBLIC_REDIRECT_URI=http://localhost:3000/auth/callback
55
NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI=http://localhost:3000/
6+
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_51QqZfARtChvireAMzq4687T4m4TpyJvADX6IyM8A9u47lCUMMi0e2SNfxoSIDMM9DebiQCYwBa7mZRkJ50uZZjGC00hYO7FzL4

customer/.env.production

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
NEXT_PUBLIC_API_URL=https://customer.api.helpwave.de
2-
NEXT_PUBLIC_OIDC_PROVIDER=https://id.helpwave.de/realms/main/
3-
NEXT_PUBLIC_CLIENT_ID=customer-api
4-
NEXT_PUBLIC_REDIRECT_URI=https://customer.helpwave.de
5-
NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI=https://customer.helpwave.de/
1+
NEXT_PUBLIC_API_URL=https://api.customer.helpwave.de
2+
NEXT_PUBLIC_OIDC_PROVIDER=https://id.helpwave.de/realms/main
3+
NEXT_PUBLIC_CLIENT_ID=customer.helpwave.de
4+
NEXT_PUBLIC_REDIRECT_URI=https://issue-1206-customer-api-intg.customer-3de.pages.dev/auth/callback
5+
NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI=https://issue-1206-customer-api-intg.customer-3de.pages.dev/
6+
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_51QqZfARtChvireAMzq4687T4m4TpyJvADX6IyM8A9u47lCUMMi0e2SNfxoSIDMM9DebiQCYwBa7mZRkJ50uZZjGC00hYO7FzL4

customer/api/auth/authService.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { CLIENT_ID, OIDC_PROVIDER, POST_LOGOUT_REDIRECT_URI, REDIRECT_URI } from '@/api/auth/config'
3+
import { CLIENT_ID, OIDC_PROVIDER, POST_LOGOUT_REDIRECT_URI, REDIRECT_URI } from '@/api/config'
44
import type { User } from 'oidc-client-ts'
55
import { UserManager } from 'oidc-client-ts'
66

@@ -38,6 +38,10 @@ export const renewToken = async () => {
3838
return await userManager.signinSilent()
3939
}
4040

41+
export const removeUser = async () => {
42+
return await userManager.removeUser()
43+
}
44+
4145
export const restoreSession = async (): Promise<User | undefined> => {
4246
if (typeof window === 'undefined') return // Prevent SSR access
4347
const user = await userManager.getUser()
@@ -58,7 +62,6 @@ export const restoreSession = async (): Promise<User | undefined> => {
5862
return user
5963
}
6064

61-
userManager.events.addAccessTokenExpiring(async () => {
62-
console.log('Token expiring, refreshing...')
63-
await renewToken()
64-
})
65+
export const onTokenExpiringCallback = (callback: () => void) => {
66+
userManager.events.addAccessTokenExpiring(callback)
67+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
export const API_URL = process.env.NEXT_PUBLIC_API_URL
12
export const OIDC_PROVIDER = process.env.NEXT_PUBLIC_OIDC_PROVIDER
23
export const CLIENT_ID = process.env.NEXT_PUBLIC_CLIENT_ID
34
export const REDIRECT_URI = process.env.NEXT_PUBLIC_REDIRECT_URI
45
export const POST_LOGOUT_REDIRECT_URI = process.env.NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI
6+
export const STRIPE_PUBLISHABLE_KEY = process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY

customer/api/dataclasses/address.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

customer/api/dataclasses/contract.ts

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,47 @@
1-
export type Contract = {
1+
export type ContractType = 'agb_app_zum_doc_patient' | 'agb_mediquu_connect' | 'agb_app_zum_doc' |
2+
'agb_mediquu_netzmanager' | 'agb_mediquu_chat' | 'privacy_concept' | 'privacy_concept_tasks' |
3+
'avv' | 'avv_tasks' | 'nda' | 'sub' | 'tom'
4+
5+
export interface Contract {
6+
/** The unique identifier of the contract */
27
uuid: string,
8+
/** The type of contract that determines its purpose */
9+
key: ContractType,
10+
/** The version of the contract */
311
version: string,
4-
name: string,
5-
contractId: string,
12+
/** The URL at which the contract can be found as a file */
613
url: string,
7-
lastAccepted?: Date,
14+
/** The creation day of the contract */
15+
createdAt: Date,
816
}
17+
18+
/**
19+
* Converts a JSON object to a Contract object.
20+
*/
21+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
22+
const fromJson = (json: any): Contract => {
23+
return {
24+
uuid: json.uuid,
25+
key: json.key,
26+
version: json.version,
27+
url: json.url,
28+
createdAt: new Date(json.created_at),
29+
}
30+
}
31+
32+
/**
33+
* Converts a Contract object back to JSON.
34+
*/
35+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
36+
const toJson = (customer: Contract): Record<string, any> => {
37+
return {
38+
uuid: customer.uuid,
39+
key: customer.key,
40+
version: customer.version,
41+
url: customer.url,
42+
created_at: customer.createdAt.toISOString(),
43+
}
44+
}
45+
46+
47+
export const ContractHelpers = { fromJson, toJson }

customer/api/dataclasses/customer.ts

Lines changed: 115 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,123 @@
1-
import type { Address } from '@/api/dataclasses/address'
2-
import type { CustomerProduct } from '@/api/dataclasses/customer_product'
1+
import { formatString } from '@/api/util'
32

4-
export type CustomerProductExtension = { products: CustomerProduct[] }
3+
export interface CustomerCreate {
4+
name: string,
5+
email: string,
6+
phoneNumber?: string,
7+
/** Optional Website URL */
8+
websiteURL?: string,
9+
/** The street of the address */
10+
address: string,
11+
/** The house number of the address */
12+
houseNumber: string,
13+
/** The addition to the address of the person taking care of receiving mails */
14+
careOf?: string,
15+
/** The postal code of the address */
16+
postalCode: string,
17+
/** The city of the address */
18+
city: string,
19+
/** The country of the address */
20+
country: string,
21+
}
522

6-
export type Customer = {
23+
export interface Customer {
724
uuid: string,
825
name: string,
9-
creationDate: Date,
10-
address: Address,
1126
email: string,
12-
phoneNumber: string,
27+
phoneNumber?: string,
1328
/** Optional Website URL */
1429
websiteURL?: string,
15-
/** Extension that might or might not be loaded */
16-
productsExtension?: CustomerProductExtension,
30+
/** The street of the address */
31+
address: string,
32+
/** The house number of the address */
33+
houseNumber: string,
34+
/** The addition to the address of the person taking care of receiving mails */
35+
careOf?: string,
36+
/** The postal code of the address */
37+
postalCode: string,
38+
/** The city of the address */
39+
city: string,
40+
/** The country of the address */
41+
country: string,
42+
createdAt: Date,
43+
updatedAt: Date,
44+
}
45+
46+
/**
47+
* Converts a JSON object to a Customer object.
48+
*/
49+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
50+
const fromJson = (json: any): Customer => {
51+
return {
52+
uuid: json.uuid,
53+
name: json.name,
54+
email: json.email,
55+
phoneNumber: json.phone_number,
56+
websiteURL: json.website_url,
57+
address: json.address,
58+
houseNumber: json.house_number,
59+
careOf: json.care_of,
60+
postalCode: json.postal_code,
61+
city: json.city,
62+
country: json.country,
63+
createdAt: new Date(json.created_at),
64+
updatedAt: new Date(json.updated_at),
65+
}
1766
}
67+
68+
/**
69+
* Converts a Customer object back to JSON.
70+
*/
71+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
72+
const toJson = (customer: Customer): Record<string, any> => {
73+
return {
74+
uuid: customer.uuid,
75+
name: customer.name,
76+
email: customer.email,
77+
phone_number: customer.phoneNumber,
78+
website_url: customer.websiteURL,
79+
address: customer.address,
80+
house_number: customer.houseNumber,
81+
care_of: customer.careOf,
82+
postal_code: customer.postalCode,
83+
city: customer.city,
84+
country: customer.country,
85+
created_at: customer.createdAt.toISOString(),
86+
updated_at: customer.updatedAt.toISOString(),
87+
}
88+
}
89+
90+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
91+
const toJsonUpdate = (customer: Customer): Record<string, any> => {
92+
return {
93+
name: customer.name,
94+
email: customer.email,
95+
phone_number: formatString(customer.phoneNumber),
96+
website_url: formatString(customer.websiteURL),
97+
address: formatString(customer.address),
98+
house_number: formatString(customer.houseNumber),
99+
care_of: formatString(customer.careOf),
100+
postal_code: formatString(customer.postalCode),
101+
city: formatString(customer.city),
102+
country: formatString(customer.country),
103+
}
104+
}
105+
106+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
107+
const toJsonCreate = (customer: CustomerCreate): Record<string, any> => {
108+
return {
109+
name: customer.name,
110+
email: customer.email,
111+
phone_number: formatString(customer.phoneNumber),
112+
website_url: formatString(customer.websiteURL),
113+
address: formatString(customer.address),
114+
house_number: formatString(customer.houseNumber),
115+
care_of: formatString(customer.careOf),
116+
postal_code: formatString(customer.postalCode),
117+
city: formatString(customer.city),
118+
country: formatString(customer.country),
119+
}
120+
}
121+
122+
export const CustomerHelpers = { fromJson, toJson, toJsonUpdate, toJsonCreate }
123+

0 commit comments

Comments
 (0)