Skip to content

Commit 643e89e

Browse files
committed
docs: add api-docs to the appConfig getters
1 parent 9596ff8 commit 643e89e

7 files changed

Lines changed: 261 additions & 6 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ All the applications inside the monorepo are sharing the similar Apollo-Router i
6969

7070
> Apps should not depend on apps, they can depend on packages
7171
72+
#### Configuration
73+
74+
The application and proxy configuration is done via the AppConfig -file as much as possible, so there would be a single point for all the configuration.
75+
7276
#### Shared packages
7377

7478
- [packages/eslint-config-bases](./packages/eslint-config-bases): [README](./packages/eslint-config-bases/README.md) | [CHANGELOG](./packages/eslint-config-bases/CHANGELOG.md)

apps/events-helsinki/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ Events uses a lot of the components from the HCRC-lib. For example the article a
9191
9292
There are 2 Apollo-clients in implemented: an Apollo-client for _`Headless CMS` to fetch articles and dynamic pages_ from the CMS and an Apollo-client for _`LinkedEvents` to fetch events_ from the Event-proxy. They both contains URL-fields that are targeted to an external source. Since the content is wanted to be rendered inside the Events app, the URLs needs to be transformed so that they are pointing to an internal path. An Apollo Link is a create place to do the transformation, when the URL context is known. Therefore, the URL should include a hint of the context, e.g a context path like `/articles*` or `/pages*` or a domain e.g `linkedvents.hel.fi`.
9393

94-
The transformation table is in the `AppConfig.ts`:
94+
The transformation table is in the [AppConfig.ts](./src/domain/app/AppConfig.ts) :
9595

9696
```typescript
9797
class AppConfig {
9898
// ...
9999
static get linkedEventsEventEndpoint() {
100100
return getEnvOrError(
101101
publicRuntimeConfig.linkedEvents,
102-
'LINKEDEVENTS_EVENT_ENDPOINT'
102+
"LINKEDEVENTS_EVENT_ENDPOINT"
103103
);
104104
}
105105
static get cmsArticlesContextPath() {
@@ -124,6 +124,10 @@ class AppConfig {
124124
}
125125
```
126126

127+
## Application configuration
128+
129+
The application configuration is done via the [AppConfig.ts](./src/domain/app/AppConfig.ts) as much as possible, so there would be a single point to configure it.
130+
127131
## Contact
128132

129133
City of Helsinki Slack channel _NO CHANNEL YET?_ (use #hobbieshelsinki)

apps/events-helsinki/src/domain/app/AppConfig.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,69 +7,137 @@ import { ROUTES } from '../../constants';
77
const { publicRuntimeConfig } = getConfig();
88

99
class AppConfig {
10+
/**
11+
* The base URL of the CMS.
12+
*
13+
* Example usage:
14+
* The headless CMS adds it's own domain (and possibly also the root path)
15+
* to every link that it returns through API. The cmsOrigin-getter is used
16+
* in the link manipulation so that we can remove the CMS origin from the link
17+
* inside the app.
18+
* */
1019
static get cmsOrigin() {
1120
return getEnvOrError(publicRuntimeConfig.cmsOrigin, 'CMS_ORIGIN');
1221
}
1322

23+
/**
24+
* The endpoint for the Apollo federation Router.
25+
* Can be used for example to configure the Apollo-client.
26+
* */
1427
static get federationGraphqlEndpoint() {
1528
return getEnvOrError(
1629
publicRuntimeConfig.federationRouter,
1730
'FEDERATION_ROUTER_ENDPOINT'
1831
);
1932
}
2033

34+
/**
35+
* The base URL of the LinkedEvents event-API.
36+
*
37+
* Example usage:
38+
* The headless CMS returns the LinkedEvent URLs through the API.
39+
* The linkedEventsEventEndpoint-getter is used
40+
* in the link manipulation so that we can remove the LinkedEvents origin from the link
41+
* inside the app.
42+
* */
2143
static get linkedEventsEventEndpoint() {
2244
return getEnvOrError(
2345
publicRuntimeConfig.linkedEvents,
2446
'LINKEDEVENTS_EVENT_ENDPOINT'
2547
);
2648
}
2749

50+
/**
51+
* The own origin of the app.
52+
* Can be used e.g. to configure the Headless CMS React Components -library.
53+
* */
2854
static get origin() {
2955
return getEnvOrError(
3056
process.env.NEXT_PUBLIC_APP_ORIGIN,
3157
'NEXT_PUBLIC_APP_ORIGIN'
3258
);
3359
}
3460

61+
/**
62+
* The app uses multiple domains from the Headless CMS API.
63+
* It serves posts / articles from 1 root and e.g the pages from another.
64+
* The CMS needs to be configured so, that the URI of an object it serves
65+
* contains the context. For example an URL to an article could contain
66+
* a static path `/articles` in it's pathname, so it's easily recognizible as an article URL.
67+
* The application can then use a PostQuery to fetch the related information from an external service.
68+
*/
3569
static get cmsArticlesContextPath() {
3670
return process.env.NEXT_PUBLIC_CMS_ARTICLES_CONTEXT_PATH ?? '/articles';
3771
}
3872

73+
/**
74+
* The app uses multiple domains from the Headless CMS API.
75+
* It serves posts / articles from 1 root and e.g the pages from another.
76+
* The CMS needs to be configured so, that the URI of an object it serves
77+
* contains the context. For example an URL to an page could contain
78+
* a static path `/pages` in it's pathname, so it's easily recognizible as a page URL.
79+
* The application can then use a PageQuery to fetch the related information from an external service.
80+
*/
3981
static get cmsPagesContextPath() {
4082
return process.env.NEXT_PUBLIC_CMS_PAGES_CONTEXT_PATH ?? '/pages';
4183
}
4284

85+
/** The supported LinkedEvent event types. */
4386
static get supportedEventTypes() {
4487
return [EventTypeId.General];
4588
}
4689

90+
/**
91+
* The generally used date format.
92+
* Helsinki services are recommended to follow the Finnish date and time locale -
93+
* even if the user is using some other language.
94+
* Follow these guidelines when presenting date and time in your services.
95+
* https://hds.hel.fi/foundation/guidelines/data-formats/
96+
*/
4797
static get dateFormat() {
4898
return 'dd.MM.yyyy';
4999
}
50100

101+
/**
102+
* The generally used short date time format.
103+
* Helsinki services are recommended to follow the Finnish date and time locale -
104+
* even if the user is using some other language.
105+
* Follow these guidelines when presenting date and time in your services.
106+
* https://hds.hel.fi/foundation/guidelines/data-formats/
107+
*/
51108
static get shortDatetimeFormat() {
52109
return 'dd.MM.yyyy HH:mm';
53110
}
54111

112+
/**
113+
* The generally used long date time format.
114+
* Helsinki services are recommended to follow the Finnish date and time locale -
115+
* even if the user is using some other language.
116+
* Follow these guidelines when presenting date and time in your services.
117+
* https://hds.hel.fi/foundation/guidelines/data-formats/
118+
*/
55119
static get datetimeFormat() {
56120
return 'dd.MM.yyyy HH:mm:ss';
57121
}
58122

123+
/** Should the application allow HTTP-connections? */
59124
static get allowUnauthorizedRequests() {
60125
return Boolean(
61126
parseEnvValue(process.env.NEXT_PUBLIC_ALLOW_UNAUTHORIZED_REQUESTS)
62127
);
63128
}
64129

130+
/** A global debug switch for development purposes. */
65131
static get debug() {
66132
return Boolean(parseEnvValue(process.env.NEXT_PUBLIC_DEBUG));
67133
}
68134

135+
/** A default HDS theme for the buttons. https://hds.hel.fi/foundation/design-tokens/colour. */
69136
static get defaultButtonTheme(): CommonButtonProps['theme'] {
70137
return 'default';
71138
}
72139

140+
/** A primary variant for the buttons. https://hds.hel.fi/foundation/design-tokens/colour. */
73141
static get defaultButtonVariant(): CommonButtonProps['variant'] {
74142
return 'success';
75143
}
@@ -107,6 +175,10 @@ class AppConfig {
107175
};
108176
}
109177

178+
/**
179+
* A default NextJS page revalidation time.
180+
* https://nextjs.org/docs/pages/building-your-application/data-fetching/incremental-static-regeneration#on-demand-revalidation
181+
*/
110182
static get defaultRevalidate() {
111183
const envValue = process.env.NEXT_PUBLIC_DEFAULT_ISR_REVALIDATE_SECONDS;
112184
const value = envValue ? parseEnvValue(envValue) : 60;
@@ -126,12 +198,14 @@ class AppConfig {
126198
return value;
127199
}
128200

201+
/** A feature flag for the similar events. */
129202
static get showSimilarEvents() {
130203
return Boolean(
131204
parseEnvValue(process.env.NEXT_PUBLIC_SHOW_SIMILAR_EVENTS, true)
132205
);
133206
}
134207

208+
/** A feature flag that can be used to show the enrolment status in the card details. */
135209
static get showEnrolmentStatusInCardDetails() {
136210
return Boolean(
137211
parseEnvValue(
@@ -141,6 +215,11 @@ class AppConfig {
141215
);
142216
}
143217

218+
/**
219+
* A map of URL reqriting.
220+
* Rewrite the URLs returned by the HEadless CMS
221+
* so that they can be routed and used inside the app.
222+
* */
144223
static get URLRewriteMapping() {
145224
return {
146225
[AppConfig.linkedEventsEventEndpoint]: ROUTES.EVENTS.replace(

apps/hobbies-helsinki/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ Hobbies uses a lot of the components from the HCRC-lib. For example the article
9898
9999
There are 2 Apollo-clients in implemented: an Apollo-client for _`Headless CMS` to fetch articles and dynamic pages_ from the CMS and an Apollo-client for _`LinkedEvents` to fetch events_ from the Event-proxy. They both contains URL-fields that are targeted to an external source. Since the content is wanted to be rendered inside the Hobbies app, the URLs needs to be transformed so that they are pointing to an internal path. An Apollo Link is a create place to do the transformation, when the URL context is known. Therefore, the URL should include a hint of the context, e.g a context path like `/articles*` or `/pages*` or a domain e.g `linkedvents.hel.fi`.
100100

101-
The transformation table is in the `AppConfig.ts`:
101+
The transformation table is in the [AppConfig.ts](./src/domain/app/AppConfig.ts) :
102102

103103
```typescript
104104
class AppConfig {
105105
// ...
106106
static get linkedEventsEventEndpoint() {
107107
return getEnvOrError(
108108
publicRuntimeConfig.linkedEvents,
109-
'LINKEDEVENTS_EVENT_ENDPOINT'
109+
"LINKEDEVENTS_EVENT_ENDPOINT"
110110
);
111111
}
112112
static get cmsArticlesContextPath() {
@@ -131,6 +131,10 @@ class AppConfig {
131131
}
132132
```
133133

134+
## Application configuration
135+
136+
The application configuration is done via the [AppConfig.ts](./src/domain/app/AppConfig.ts) as much as possible, so there would be a single point to configure it.
137+
134138
## Contact
135139

136140
City of Helsinki Slack channel #hobbieshelsinki

0 commit comments

Comments
 (0)