Skip to content

Commit 8fcb747

Browse files
committed
refactor(console): upgrade mdx packages
1 parent f2c7799 commit 8fcb747

File tree

39 files changed

+1535
-904
lines changed

39 files changed

+1535
-904
lines changed

packages/console/.parcelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"@parcel/transformer-svg-react"
77
],
88
"*.{md,mdx}": [
9-
"@parcel/transformer-mdx"
9+
"./parcel-transformer-mdx2.js"
1010
]
1111
},
1212
"compressors": {

packages/console/.parcelrc.arm64

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"@parcel/transformer-svg-react"
1111
],
1212
"*.{md,mdx}": [
13-
"@parcel/transformer-mdx"
13+
"./parcel-transformer-mdx2.js"
1414
]
1515
},
1616
"compressors": {

packages/console/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
"@logto/react": "^3.0.8",
3737
"@logto/schemas": "workspace:^1.17.0",
3838
"@logto/shared": "workspace:^3.1.1",
39-
"@mdx-js/react": "^1.6.22",
39+
"@mdx-js/mdx": "^3.0.1",
40+
"@mdx-js/react": "^3.0.1",
4041
"@monaco-editor/react": "^4.6.0",
4142
"@parcel/compressor-brotli": "2.9.3",
4243
"@parcel/compressor-gzip": "2.9.3",
4344
"@parcel/core": "2.9.3",
44-
"@parcel/transformer-mdx": "2.9.3",
4545
"@parcel/transformer-sass": "2.9.3",
4646
"@parcel/transformer-svg-react": "2.9.3",
4747
"@silverhand/eslint-config": "6.0.1",
@@ -55,8 +55,7 @@
5555
"@types/color": "^3.0.3",
5656
"@types/debug": "^4.1.7",
5757
"@types/jest": "^29.4.0",
58-
"@types/mdx": "^2.0.1",
59-
"@types/mdx-js__react": "^1.5.5",
58+
"@types/mdx": "^2.0.13",
6059
"@types/react": "^18.0.31",
6160
"@types/react-color": "^3.0.6",
6261
"@types/react-dom": "^18.0.0",
@@ -88,6 +87,7 @@
8887
"ky": "^1.2.3",
8988
"libphonenumber-js": "^1.10.51",
9089
"lint-staged": "^15.0.0",
90+
"mermaid": "^10.9.1",
9191
"nanoid": "^5.0.1",
9292
"overlayscrollbars": "^2.0.2",
9393
"overlayscrollbars-react": "^0.5.0",
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// https://github.com/parcel-bundler/parcel/pull/7922#issuecomment-1750704973
2+
3+
import { compile } from '@mdx-js/mdx';
4+
import { default as ThrowableDiagnostic } from '@parcel/diagnostic';
5+
import { Transformer } from '@parcel/plugin';
6+
7+
export default new Transformer({
8+
async transform({ asset }) {
9+
const source = await asset.getCode();
10+
11+
let codeVFile;
12+
13+
try {
14+
codeVFile = await compile(source, {
15+
development: true,
16+
jsx: true,
17+
providerImportSource: '@mdx-js/react',
18+
});
19+
} catch (error) {
20+
const { start, end } = error.position;
21+
22+
const highlight = {
23+
message: error.reason,
24+
start,
25+
end,
26+
};
27+
28+
if (!(end.line && end.column)) {
29+
highlight.end = { ...start };
30+
}
31+
32+
// Adjust for parser and reporter differences
33+
highlight.start.column -= 1;
34+
highlight.end.column -= 1;
35+
36+
throw new ThrowableDiagnostic({
37+
diagnostic: {
38+
message: 'Unable to compile MDX',
39+
codeFrames: [
40+
{
41+
filePath: asset.filePath,
42+
code: source,
43+
codeHighlights: [highlight],
44+
},
45+
],
46+
},
47+
});
48+
}
49+
50+
const code = String(codeVFile);
51+
52+
asset.type = 'jsx';
53+
asset.setCode(code);
54+
55+
return [asset];
56+
},
57+
});

packages/console/src/assets/docs/guides/api-express/README.mdx

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ To proceed, you'll need to integrate the Logto SDK into your client application.
2828

2929
You'll also need to tweak the Logto SDK configuration to inform Logto that you want to request an access token for your API in this grant. Here's an example using React:
3030

31-
<pre>
32-
<code className="language-ts">
31+
<Code className="language-ts">
3332
{`import { LogtoProvider } from '@logto/react';
3433
3534
const App = () => {
@@ -44,27 +43,23 @@ const App = () => {
4443
</LogtoProvider>
4544
);
4645
};`}
47-
</code>
48-
</pre>
46+
</Code>
4947

5048
Once a user signs in with Logto, `isAuthenticated` within the Logto SDK will become `true`:
5149

52-
<pre>
53-
<code className="language-ts">
50+
<Code className="language-ts">
5451
{`import { useLogto } from '@logto/react';
5552
5653
const Content = () => {
5754
const { isAuthenticated } = useLogto();
5855
5956
console.log(isAuthenticated); // true
6057
};`}
61-
</code>
62-
</pre>
58+
</Code>
6359

6460
Now, you can use the `getAccessToken` method to retrieve an access token for your API:
6561

66-
<pre>
67-
<code className="language-ts">
62+
<Code className="language-ts">
6863
{`const Content = () => {
6964
const { getAccessToken, isAuthenticated } = useLogto();
7065
@@ -75,13 +70,11 @@ Now, you can use the `getAccessToken` method to retrieve an access token for you
7570
}
7671
}, [isAuthenticated, getAccessToken]);
7772
};`}
78-
</code>
79-
</pre>
73+
</Code>
8074

8175
Lastly, include this access token in the `Authorization` header when making requests to your API:
8276

83-
<pre>
84-
<code className="language-ts">
77+
<Code className="language-ts">
8578
{`const Content = () => {
8679
const { getAccessToken, isAuthenticated } = useLogto();
8780
@@ -97,8 +90,7 @@ Lastly, include this access token in the `Authorization` header when making requ
9790
}
9891
}, [isAuthenticated, getAccessToken]);
9992
};`}
100-
</code>
101-
</pre>
93+
</Code>
10294

10395
</Step>
10496

@@ -150,8 +142,7 @@ const extractBearerTokenFromHeaders = ({ authorization }: IncomingHttpHeaders) =
150142

151143
Subsequently, create a middleware to verify the access token:
152144

153-
<pre>
154-
<code className="language-ts">
145+
<Code className="language-ts">
155146
{`import { createRemoteJWKSet, jwtVerify } from 'jose';
156147
157148
// Generate a JWKS using jwks_uri obtained from the Logto server
@@ -181,8 +172,7 @@ export const authMiddleware = async (req, res, next) => {
181172
182173
return next();
183174
};`}
184-
</code>
185-
</pre>
175+
</Code>
186176

187177
You can now employ this middleware to protect your API endpoints:
188178

@@ -210,17 +200,15 @@ To address this, we can employ role-based access control (RBAC). In Logto, you c
210200

211201
After defining roles and permissions, you can add the `scopes` option to the `LogtoProvider` component:
212202

213-
<pre>
214-
<code className="language-ts">
203+
<Code className="language-ts">
215204
{`<LogtoProvider
216205
config={{
217206
// ...other configurations
218207
resources: ['${props.audience}'],
219208
scopes: ['read:products', 'write:products'], // Replace with the actual scope(s)
220209
}}
221210
>`}
222-
</code>
223-
</pre>
211+
</Code>
224212

225213
Logto will then only issue an access token with the appropriate scope(s) to the user. For instance, if a user only has the `read:products` scope, the access token will solely contain that scope:
226214

packages/console/src/assets/docs/guides/api-python/README.mdx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,16 @@ All the latest public Logto Authorization Configurations can be found at <code>{
4848
e.g. You can locate the following two fields in the response body if you request the above endpoint.
4949
</p>
5050

51-
<pre>
52-
<code className="language-json">
51+
<Code className="language-json">
5352
{`{
5453
"issuer": "${appendPath(props.endpoint, '/oidc')}",
5554
"jwks_uri": "${appendPath(props.endpoint, '/oidc/jwks')}"
5655
}`}
57-
</code>
58-
</pre>
56+
</Code>
5957

6058
### Create the authorization validation decorator
6159

62-
<pre>
63-
<code className="language-python">
60+
<Code className="language-python">
6461
{`"""requires-auth.py
6562
"""
6663
@@ -105,8 +102,7 @@ def requires_auth(f):
105102
106103
return f(*args, **kwargs)
107104
return decorated`}
108-
</code>
109-
</pre>
105+
</Code>
110106

111107
<InlineNotification>
112108
For <a href="https://docs.logto.io/docs/recipes/rbac/" target="_blank" rel="noopener">🔐 RBAC</a>, scope validation is also required.

packages/console/src/assets/docs/guides/api-spring-boot/README.mdx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,22 @@ Before moving on, you will need to get an issuer and a JWKS URI to verify the is
5959

6060
An example of the response:
6161

62-
<pre>
63-
<code className="language-json">
62+
<Code className="language-json">
6463
{`{
6564
// ...
6665
"issuer": "${appendPath(props.endpoint, '/oidc')}",
6766
"jwks_uri": "${appendPath(props.endpoint, '/oidc/jwks')}"
6867
// ...
6968
}`}
70-
</code>
71-
</pre>
69+
</Code>
7270

7371
</Step>
7472

7573
<Step title="Configure application">
7674

7775
Use an `application.yml` file (instead of the default `application.properties`) to configure the server port, audience, and OAuth2 resource server.
7876

79-
<pre>
80-
<code className="language-yaml">
77+
<Code className="language-yaml">
8178
{`# path/to/project/src/main/resources/application.yaml
8279
server:
8380
port: 3000
@@ -92,8 +89,7 @@ spring:
9289
jwt:
9390
issuer-uri: ${appendPath(props.endpoint, '/oidc')}
9491
jwk-set-uri: ${appendPath(props.endpoint, '/oidc/jwks')}`}
95-
</code>
96-
</pre>
92+
</Code>
9793

9894
- `audience`: The unique API identifier of your protected API resource.
9995
- `spring.security.oauth2.resourceserver.jwt.issuer-uri`: The iss claim value and the issuer URI in the JWT issued by Logto.
@@ -277,12 +273,10 @@ gradlew.bat bootRun
277273

278274
Request your protected API with the Access Token as the Bearer token in the Authorization header, e.g. execute the `curl` command.
279275

280-
<pre>
281-
<code className="language-bash">
276+
<Code className="language-bash">
282277
{`curl --include '${appendPath(props.endpoint, '/api/profile')}' \\
283278
--header 'Authorization: Bearer <your-access-token>'`}
284-
</code>
285-
</pre>
279+
</Code>
286280

287281
If successful, you will get a response with 200 status:
288282

packages/console/src/assets/docs/guides/native-android/README.mdx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ Since the SDK needs internet access, you need to add the following permission to
5555

5656
Create a `LogtoViewModel.kt` and init `LogtoClient` in this view model:
5757

58-
<pre>
59-
<code className="language-kotlin">
58+
<Code className="language-kotlin">
6059
{`//...with other imports
6160
import io.logto.sdk.android.LogtoClient
6261
import io.logto.sdk.android.type.LogtoConfig
@@ -86,8 +85,7 @@ class LogtoViewModel(application: Application) : AndroidViewModel(application) {
8685
}
8786
}
8887
}`}
89-
</code>
90-
</pre>
88+
</Code>
9189

9290
then, create a `LogtoViewModel` for your `MainActivity.kt`:
9391

@@ -121,8 +119,7 @@ You can add the redirect URI in the following input field:
121119

122120
After the redirect URI is configured, we add a `signIn` method to your `LogtoViewModel.kt`, which will call `logtoClient.signIn` API to invoke the Logto sign-in page:
123121

124-
<pre>
125-
<code className="language-kotlin">
122+
<Code className="language-kotlin">
126123
{`//...with other imports
127124
class LogtoViewModel(application: Application) : AndroidViewModel(application) {
128125
// ...other codes
@@ -132,8 +129,7 @@ class LogtoViewModel(application: Application) : AndroidViewModel(application) {
132129
}
133130
}
134131
}`}
135-
</code>
136-
</pre>
132+
</Code>
137133

138134
Now setup on-click listener for the sign-in button in your `MainActivity.kt` to call the `signIn` method:
139135

@@ -205,8 +201,7 @@ In Logto SDK, we can use `logtoClient.isAuthenticated` to check the authenticati
205201

206202
Now, let's add a live data to `LogtoViewModel.kt` to observe the authentication status, and update the status when the user signed in or signed out:
207203

208-
<pre>
209-
<code className="language-kotlin">
204+
<Code className="language-kotlin">
210205
{`//...with other imports
211206
class LogtoViewModel(application: Application) : AndroidViewModel(application) {
212207
// ...other codes
@@ -232,8 +227,7 @@ class LogtoViewModel(application: Application) : AndroidViewModel(application) {
232227
}
233228
}
234229
}`}
235-
</code>
236-
</pre>
230+
</Code>
237231

238232
Then, we observe the `authenticated` live data in `MainActivity.kt`, when the user is signed in, we hide the sign-in button and show the sign-out button and vice versa:
239233

0 commit comments

Comments
 (0)