Skip to content

Commit 52c148b

Browse files
committed
Cleaning up formatting
1 parent 54c133a commit 52c148b

24 files changed

+428
-538
lines changed

src/content/docs/api-reference/1fe-server-reference.mdx

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ description: 1fe Server Reference
66
The 1fe/server package exposes a function `oneFEServer` that returns an express server instance. This reference page will list the configuration options available.
77

88
### Simple Usage Example
9+
910
```tsx
10-
import oneFEServer from '@devhub/1fe-server';
11+
import oneFEServer from "@devhub/1fe-server";
1112

1213
const app = oneFEServer({
13-
mode: 'production',
14-
environment: 'production',
15-
orgName: 'My Organization',
14+
mode: "production",
15+
environment: "production",
16+
orgName: "My Organization",
1617
configManagement: {
17-
url: 'https://my-cdn.net/production/live-configuration.json',
18-
refreshMs: 30 * 1000
18+
url: "https://my-cdn.net/production/live-configuration.json",
19+
refreshMs: 30 * 1000,
1920
},
20-
shellBundleUrl: 'https://my-cdn.net/production/shell.js',
21+
shellBundleUrl: "https://my-cdn.net/production/shell.js",
2122
});
2223

2324
app.listen(3001, () => {
@@ -33,19 +34,20 @@ What type of environment is this? The 1fe runtime will use this information to d
3334

3435
### `environment`
3536

36-
**Type**: string
37+
**Type**: `string`
3738

3839
What is the name of your environment? This is used for certain capabilities such as fetching a widget's runtime configurations.
3940

4041
### `orgName`
4142

42-
**Type**: string
43+
**Type**: `string`
4344

4445
The name of your organization. This will be used as the default page title and for the `X-Powered-By` header.
4546

4647
### `configManagement`
4748

4849
**Type**
50+
4951
```tsx
5052
type OneFEConfigManagement = {
5153
getDynamicConfigs?: () => Promise<OneFEDynamicConfigs>;
@@ -54,35 +56,34 @@ type OneFEConfigManagement = {
5456
};
5557
```
5658

57-
`**getDynamicConfigs**`: A function that returns a promise that resolves to your live configurations. This function will be called every time the server starts to hydrate the 1fe in memory cache. This will be called on an interval afterwards as defined by `refreshMs`. Use only one of this or `url` option.
58-
59-
`**url**`: The URL to fetch the live configurations from. This should be used if `getDynamicConfigs` is not provided.
60-
61-
`**refreshMs**`: The interval in milliseconds to refresh the live configurations.
59+
- `getDynamicConfigs`: A function that returns a promise that resolves to your live configurations. This function will be called every time the server starts to hydrate the 1fe in memory cache. This will be called on an interval afterwards as defined by `refreshMs`. Use only one of this or `url` option.
60+
- `url`: The URL to fetch the live configurations from. This should be used if `getDynamicConfigs` is not provided.
61+
- `refreshMs`: The interval in milliseconds to refresh the live configurations.
6262

6363
### `shellBundleUrl`
6464

65-
**Type**: string
65+
**Type**: `string`
6666

6767
The URL to fetch the shell bundle from. This should be a URL to the bundle that consumes 1fe/shell.
6868

6969
### `server`
7070

7171
**Type**
72+
7273
```tsx
7374
type OneFEServer = {
74-
playground?: boolean;
75-
knownRoutes: string[];
75+
playground?: boolean;
76+
knownRoutes: string[];
7677
};
7778
```
7879

79-
`**playground**` (optional): Whether or not to enable the playground. Defaults to false.
80-
81-
`**knownRoutes**`: An array of known routes that 1fe/server will use for plugin and 404 detection.
80+
- `playground` (optional): Whether or not to enable the playground. Defaults to false.
81+
- `knownRoutes`: An array of known routes that 1fe/server will use for plugin and 404 detection.
8282

8383
### `csp` (optional)
8484

8585
**Type**
86+
8687
```tsx
8788
type CSPPerEnvironment = {
8889
scriptSrc?: string[];
@@ -106,14 +107,5 @@ type OneFECSP = {
106107
};
107108
```
108109

109-
`**csp.defaultCSP.enforced**` (optional): Content-Security-Policy to enforce in runtime.
110-
111-
`**csp.defaultCSP.reportOnly**` (optional): report-only Content-Security-Policy.
112-
113-
114-
115-
116-
117-
118-
119-
110+
- `csp.defaultCSP.enforced` (optional): Content-Security-Policy to enforce in runtime.
111+
- `csp.defaultCSP.reportOnly` (optional): report-only Content-Security-Policy.

src/content/docs/api-reference/1fe-shell-reference.mdx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ type OneFEAuth = {
5858
};
5959
```
6060

61-
`isAuthedCallback` will be invoked by 1fe/shell when a plugin is being loaded. It should return a boolean indicating whether the user is authenticated or not.
62-
63-
`unauthedCallback` will be invoked by 1fe/shell when a plugin is being loaded and the user is not authenticated. This should always be defined if `isAuthedCallback` is defined.
61+
- `isAuthedCallback` will be invoked by 1fe/shell when a plugin is being loaded. It should return a boolean indicating whether the user is authenticated or not.
62+
- `unauthedCallback` will be invoked by 1fe/shell when a plugin is being loaded and the user is not authenticated. This should always be defined if `isAuthedCallback` is defined.
6463

6564
### `shellLogger` (optional)
6665

@@ -75,13 +74,10 @@ type OneFEShellLogger = {
7574
};
7675
```
7776

78-
`log` This will be invoked when a log is emitted from the shell.
79-
80-
`error` This will be invoked when an error is emitted from the shell.
81-
82-
`logPlatformUtilUsage` (optional): Whether or not to log the usage of platform utilities. Defaults to false.
83-
84-
`redactSensitiveData` (optional): Whether or not to redact sensitive data from the logs. Defaults to false.
77+
- `log` This will be invoked when a log is emitted from the shell.
78+
- `error` This will be invoked when an error is emitted from the shell.
79+
- `logPlatformUtilUsage` (optional): Whether or not to log the usage of platform utilities. Defaults to false.
80+
- `redactSensitiveData` (optional): Whether or not to redact sensitive data from the logs. Defaults to false.
8581

8682
### `routes` (optional)
8783

@@ -93,7 +89,7 @@ type OneFERoutes = {
9389
};
9490
```
9591

96-
`defaultRoute`: The default route to load when no route is provided. Playground will be the default route if enabled. Otherwise, this will be the default route.
92+
- `defaultRoute`: The default route to load when no route is provided. Playground will be the default route if enabled. Otherwise, this will be the default route.
9793

9894
### `components` (optional)
9995

@@ -106,6 +102,5 @@ type OneFEComponents = {
106102
};
107103
```
108104

109-
`getLoader` (optional): Custom loader component to be shown when a widget is being loaded.
110-
111-
`getError` (optional): Custom error component to be shown when in an error state (e.g a widget fails to load)
105+
- `getLoader` (optional): Custom loader component to be shown when a widget is being loaded.
106+
- `getError` (optional): Custom error component to be shown when in an error state (e.g a widget fails to load)

src/content/docs/development/Platform Utilities/Context.mdx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
title: Context
3-
description: 'Context utils API'
3+
description: "Context utils API"
44
---
55

6-
## `platform.context.self`
6+
### `platform.context.self`
77

88
Answers the question about who you are.
99

@@ -19,7 +19,7 @@ Answers the question about who you are.
1919
#### Example
2020

2121
```tsx
22-
import { platformProps } from '@1fe/shell';
22+
import { platformProps } from "@1fe/shell";
2323

2424
function MySimpleComponent(props: WidgetProps) {
2525
return (
@@ -32,16 +32,14 @@ function MySimpleComponent(props: WidgetProps) {
3232
}
3333
```
3434

35-
---
36-
37-
## `platform.context.getHost`
35+
### `platform.context.getHost`
3836

3937
Answers the question about who is hosting you.
4038

4139
This is only offered for insights and logging purposes.
4240

4341
:::danger
44-
Writing logic depending on the host is **NOT** okay. It is highly recommended to write functionality in a way that can be toggled on/off by prop-driven configuration.
42+
Writing logic depending on the host is **NOT** okay. It is highly recommended to write functionality in a way that it can be toggled on/off by prop-driven configuration.
4543

4644
It is better to write your widget in a way that it can be hosted by any widget.
4745
:::
@@ -57,7 +55,7 @@ function getHost(): {
5755
#### Example
5856

5957
```tsx
60-
import { platformProps } from '@1fe/shell';
58+
import { platformProps } from "@1fe/shell";
6159

6260
function MySimpleComponent(props: WidgetProps) {
6361
return (

src/content/docs/development/Platform Utilities/Overview.mdx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: 'Overview'
3-
iconName: 'flat-color-icons:electricity' # Icon browser at https://icon-sets.iconify.design/
4-
description: 'Utils shared and used by all Plugins & Widgets'
2+
title: "Overview"
3+
iconName: "flat-color-icons:electricity" # Icon browser at https://icon-sets.iconify.design/
4+
description: "Utils shared and used by all Plugins & Widgets"
55
sidebar:
66
order: 1
77
badge:
@@ -12,7 +12,7 @@ sidebar:
1212
### Importing 1fe Platform Utils
1313

1414
```tsx
15-
import { platformProps } from '@1fe/shell';
15+
import { platformProps } from "@1fe/shell";
1616
```
1717

1818
:::note
@@ -25,7 +25,7 @@ The above approach is also known as **shell import syntax** or **1fe contextual
2525

2626
```tsx
2727
// The 1fe shell provided the platform utils to all widgets loaded in 1fe
28-
import { PlatformPropsType, platformProps } from '@1fe/shell';
28+
import { PlatformPropsType, platformProps } from "@1fe/shell";
2929

3030
// This type is for reference and is included out of box in the widget-starter-kit
3131
interface WidgetProps {
@@ -36,7 +36,7 @@ interface WidgetProps {
3636
const MyWidget = (props: WidgetProps) => {
3737
useEffect(() => {
3838
// this is how you access all utils, use these docs for examples
39-
platformProps.utils.experience.setTitle('foo bar');
39+
platformProps.utils.experience.setTitle("foo bar");
4040
}, []);
4141

4242
return <>{/* ... */}</>;
@@ -53,9 +53,9 @@ Using the contextual injection, you can access the `platformProps` from anywhere
5353

5454
#### Why contextual injection?
5555

56-
1. No more prop drilling through the code.
57-
2. Stability of references for things like Widgets.get etc.
58-
3. No need for folks to work around by defining React contexts.
59-
4. We can now pass hooks from platformProps with a stable reference and not having to worry about react rule of hooks being voided.
60-
5. Access utils like logger etc outside of React lifecycle.
61-
6. Syntax sugar.
56+
- **No Prop Drilling**: No more prop drilling through the code.
57+
- **Stability of References**: Stability of references for things like Widgets.get etc.
58+
- **No Need for React Contexts**: No need for a shared context between widgets.
59+
- **Platform Hooks**: We can now pass hooks from platformProps with a stable reference and not having to worry about react rule of hooks being voided.
60+
- **Access Outside of React Lifecycle**: Access utils like logger etc outside of React lifecycle.
61+
- **Syntax Sugar**: The syntax is concise and easy to use.
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
title: 'Widgets'
3-
description: 'Easily load other widgets into your widget'
2+
title: "Widgets"
3+
description: "Easily load other widgets into your widget"
44
---
55

6-
## `get`
6+
### `get`
77

88
The `platformProps.utils.widget.get` function is used to load a widget inside another widget. This function has a built-in retry mechanism. If the first request for your widget fails, it will try 2 more times.
99

@@ -12,20 +12,20 @@ The `platformProps.utils.widget.get` function is used to load a widget inside an
1212
```ts
1313
function get(
1414
widgetId: string,
15-
options?: { variantId: string; Loader: React.ReactNode },
15+
options?: { variantId: string; Loader: React.ReactNode }
1616
): React.FC;
1717
```
1818

1919
### Basic usage
2020

2121
```tsx
22-
import { platformProps } from '@1fe/shell';
22+
import { platformProps } from "@1fe/shell";
2323

2424
const App = (props: WidgetProps) => {
2525
// It's REQUIRED that you invoke widgets.get at the top of your component
26-
const WidgetB = platformProps.utils.widgets.get('@namespace/widget-b');
26+
const WidgetB = platformProps.utils.widgets.get("@namespace/widget-b");
2727

28-
return <WidgetB foo='bar' />;
28+
return <WidgetB foo="bar" />;
2929
};
3030
```
3131

@@ -34,31 +34,31 @@ const App = (props: WidgetProps) => {
3434
You can replace the default by passing in a `ReactNode`. Below is an example of passing a fragment so the widget loads with no UI.
3535

3636
```tsx
37-
import { platformProps } from '@1fe/shell';
37+
import { platformProps } from "@1fe/shell";
3838

3939
const App = (props: WidgetProps) => {
4040
// It's REQUIRED that you invoke widgets.get at the top of your component
41-
const WidgetB = platformProps.utils.widgets.get('@namespace/widget-b', {
42-
Loader: {<></>},
41+
const WidgetB = platformProps.utils.widgets.get("@namespace/widget-b", {
42+
Loader: <></>,
4343
});
4444

45-
return <WidgetB foo='bar' />;
45+
return <WidgetB foo="bar" />;
4646
};
4747
```
4848

4949
### Conditional rendering
5050

5151
```tsx
52-
import { platformProps } from '@1fe/shell';
53-
import { checkIfWidgetBShouldRender } from './utils';
52+
import { platformProps } from "@1fe/shell";
53+
import { checkIfWidgetBShouldRender } from "./utils";
5454

5555
const App = (props: WidgetProps) => {
5656
// It's REQUIRED that you invoke widgets.get at the top of your component
57-
const WidgetB = platformProps.utils.widgets.get('@namespace/widget-b');
57+
const WidgetB = platformProps.utils.widgets.get("@namespace/widget-b");
5858

5959
const shouldRenderWidgetB = checkIfWidgetBShouldRender();
6060

61-
return shouldRenderWidgetB ? <WidgetB foo='bar' /> : null;
61+
return shouldRenderWidgetB ? <WidgetB foo="bar" /> : null;
6262
};
6363
```
6464

@@ -67,11 +67,11 @@ const App = (props: WidgetProps) => {
6767
While the `widgets.get` function has a built-in retry mechanism & error boundary, it is still possible for the widget to fail to load. The internal error boundary is set in place to handle errors and log them to our error tracking system, without influencing the UI or the parent error boundary. To provide a graceful fallback UI, you can use the `ErrorBoundary` component from `react-error-boundary`.
6868

6969
```tsx
70-
import { platformProps } from '@1fe/shell';
71-
import { ErrorBoundary } from 'react-error-boundary';
70+
import { platformProps } from "@1fe/shell";
71+
import { ErrorBoundary } from "react-error-boundary";
7272

7373
const ErrorFallback = ({ error, resetErrorBoundary }) => (
74-
<div role='alert'>
74+
<div role="alert">
7575
<p>Something went wrong:</p>
7676
<pre>{error.message}</pre>
7777
<button onClick={resetErrorBoundary}>Try again</button>
@@ -80,24 +80,24 @@ const ErrorFallback = ({ error, resetErrorBoundary }) => (
8080

8181
const App = (props: WidgetProps) => {
8282
// It's REQUIRED that you invoke widgets.get at the top of your component
83-
const WidgetB = platformProps.utils.widgets.get('@namespace/widget-b');
83+
const WidgetB = platformProps.utils.widgets.get("@namespace/widget-b");
8484

8585
return (
8686
<ErrorBoundary FallbackComponent={ErrorFallback}>
87-
<WidgetB foo='bar' />
87+
<WidgetB foo="bar" />
8888
</ErrorBoundary>
8989
);
9090
};
9191
```
9292

93-
## Lifecycle
93+
### Lifecycle
9494

9595
The `widgets.get` function will return a React Suspense component, which when mounted will trigger the loading of the widget. If the suspense isn't mounted, the widget will not be loaded. If the widget is already loaded, the widget will be rendered immediately.
9696

97-
## Anti-patterns
97+
### Anti-patterns
9898

9999
Due to the fact that `widgets.get` leverages React hooks internally, it is important to avoid the following anti-patterns:
100100

101-
1. Conditionally invoke widgets.get by either wrapping it inside of IF/ELSE statements, TRY/CATCH blocks or Null Coalescing operators.
102-
2. Invoke widgets.get from inside of useEffect or useCallback etc. We make a special adjustment for useMemo, yet we urge you to move away from memoizing widgets.get
103-
3. Return early before widgets.get is invoked in your React component.
101+
1. Conditionally invoke widgets.get by either wrapping it inside of IF/ELSE statements, TRY/CATCH blocks or Null Coalescing operators.
102+
2. Invoke widgets.get from inside of useEffect or useCallback etc. We make a special adjustment for useMemo, yet we urge you to move away from memoizing widgets.get
103+
3. Return early before widgets.get is invoked in your React component.

0 commit comments

Comments
 (0)