Skip to content

Commit feac5f3

Browse files
alexisintechclaudeSarahSoutoulJacek
authored
docs(backend,shared): Generate typedoc output for backend docs (clerk#8853)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Sarah Soutoul <sarah@clerk.dev> Co-authored-by: Jacek <jacek@clerk.dev>
1 parent 59d2456 commit feac5f3

83 files changed

Lines changed: 2463 additions & 1655 deletions

File tree

Some content is hidden

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

‎.changeset/docs-backend-typedoc.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

‎.typedoc/__tests__/__snapshots__/clerk-properties.mdx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@
1414
| <a id="proxyurl"></a> `proxyUrl` | <code>undefined \| string</code> | **Required for applications that run behind a reverse proxy**. Your Clerk app's proxy URL. Can be either a relative path (`/__clerk`) or a full URL (`https://<your-domain>/__clerk`). |
1515
| <a id="publishablekey"></a> `publishableKey` | `string` | Your Clerk [Publishable Key](!publishable-key). |
1616
| <a id="sdkmetadata"></a> `sdkMetadata` | <code>undefined \| \{ environment?: string; name: string; version: string; \}</code> | If present, contains information about the SDK that the host application is using. For example, if Clerk is loaded through `@clerk/nextjs`, this would be `{ name: '@clerk/nextjs', version: '1.0.0' }`. You don't need to set this value yourself unless you're [developing an SDK](/docs/guides/development/sdk-development/overview). |
17+
| `sdkMetadata.environment?` | `string` | Typically this will be the `NODE_ENV` that the SDK is currently running in. |
18+
| `sdkMetadata.name` | `string` | The npm package name of the SDK. |
19+
| `sdkMetadata.version` | `string` | The npm package version of the SDK. |
1720
| <a id="session"></a> `session` | <code>undefined \| null \| [SignedInSessionResource](/docs/reference/objects/session)</code> | The currently active `Session`, which is guaranteed to be one of the sessions in `Client.sessions`. If there is no active session, this field will be `null`. If the session is loading, this field will be `undefined`. |
1821
| <a id="status"></a> `status` | <code>"error" \| "degraded" \| "loading" \| "ready"</code> | The status of the `Clerk` instance. Possible values are: <ul> <li>`"error"`: Set when hotloading `clerk-js` or `Clerk.load()` failed.</li> <li>`"loading"`: Set during initialization.</li> <li>`"ready"`: Set when Clerk is fully operational.</li> <li>`"degraded"`: Set when Clerk is partially operational.</li> </ul> |
1922
| <a id="telemetry"></a> `telemetry` | <code>undefined \| \{ isDebug: boolean; isEnabled: boolean; record: void; recordLog: void; \}</code> | [Telemetry](/docs/guides/how-clerk-works/security/clerk-telemetry) configuration. |
23+
| `telemetry.isDebug` | `boolean` | If `true`, telemetry events are only logged to the console and not sent to Clerk. |
24+
| `telemetry.isEnabled` | `boolean` | Indicates whether telemetry is enabled. |
2025
| <a id="uiversion"></a> `uiVersion` | <code>undefined \| string</code> | The version of `@clerk/ui` that is currently loaded, or `undefined` if the prebuilt UI has not been loaded yet. |
2126
| <a id="user"></a> `user` | <code>undefined \| null \| [UserResource](/docs/reference/objects/user)</code> | A shortcut to `Session.user` which holds the currently active `User` object. If the session is `null` or `undefined`, the user field will match. |
2227
| <a id="version"></a> `version` | <code>undefined \| string</code> | The Clerk SDK version number. |

‎.typedoc/__tests__/__snapshots__/sign-in-future-resource-methods-email-link.mdx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
| Property | Type | Description |
55
| ------ | ------ | ------ |
66
| `verification` | <code>null \| \{ createdSessionId: string; status: "expired" \| "failed" \| "verified" \| "client_mismatch"; verifiedFromTheSameClient: boolean; \}</code> | The verification status of the email link. This property is populated by reading query parameters from the URL after the user visits the email link. Returns `null` if no verification status is available. |
7+
| `verification.createdSessionId` | `string` | The ID of the session that was created upon completion of the current sign-in. |
8+
| `verification.status` | <code>"expired" \| "failed" \| "verified" \| "client_mismatch"</code> | The verification status. |
9+
| `verification.verifiedFromTheSameClient` | `boolean` | Whether the verification was from the same client. |

‎.typedoc/__tests__/file-structure.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,48 @@ describe('Typedoc output', () => {
4848

4949
expect(nestedFolders).toMatchInlineSnapshot(`
5050
[
51+
"backend/agent-task-api",
52+
"backend/agent-task-api/methods",
53+
"backend/allowlist-identifier-api",
54+
"backend/allowlist-identifier-api/methods",
55+
"backend/api-keys-api",
56+
"backend/api-keys-api/methods",
57+
"backend/billing-api",
58+
"backend/billing-api/methods",
59+
"backend/client-api",
60+
"backend/client-api/methods",
61+
"backend/domain-api",
62+
"backend/domain-api/methods",
63+
"backend/email-address-api",
64+
"backend/email-address-api/methods",
65+
"backend/enterprise-connection-api",
66+
"backend/enterprise-connection-api/methods",
67+
"backend/instance-api",
68+
"backend/instance-api/methods",
69+
"backend/invitation-api",
70+
"backend/invitation-api/methods",
71+
"backend/m2-m-token-api",
72+
"backend/m2-m-token-api/methods",
73+
"backend/machine-api",
74+
"backend/machine-api/methods",
75+
"backend/o-auth-applications-api",
76+
"backend/o-auth-applications-api/methods",
77+
"backend/organization-api",
78+
"backend/organization-api/methods",
79+
"backend/phone-number-api",
80+
"backend/phone-number-api/methods",
81+
"backend/redirect-url-api",
82+
"backend/redirect-url-api/methods",
83+
"backend/session-api",
84+
"backend/session-api/methods",
85+
"backend/sign-in-token-api",
86+
"backend/sign-in-token-api/methods",
87+
"backend/testing-token-api",
88+
"backend/testing-token-api/methods",
89+
"backend/user-api",
90+
"backend/user-api/methods",
91+
"backend/waitlist-entry-api",
92+
"backend/waitlist-entry-api/methods",
5193
"react/legacy",
5294
"shared/api-key-resource",
5395
"shared/api-key-resource/methods",

‎.typedoc/custom-plugin.mjs‎

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @ts-check - Enable TypeScript checks for safer MDX post-processing and link rewriting
2-
import { Converter } from 'typedoc';
2+
import { Converter, DeclarationReflection, ReflectionKind, ReflectionType, RendererEvent } from 'typedoc';
33
import { MarkdownPageEvent } from 'typedoc-plugin-markdown';
44

55
/**
@@ -75,6 +75,7 @@ const LINK_REPLACEMENTS = [
7575
['o-auth-consent-info', '/docs/reference/types/oauth-consent-info'],
7676
['o-auth-consent-scope', '/docs/reference/types/oauth-consent-scope'],
7777
['o-auth-strategy', '/docs/reference/types/sso#o-auth-strategy'],
78+
['o-auth-provider', '/docs/reference/types/sso#o-auth-provider'],
7879
['session', '/docs/reference/backend/types/backend-session'],
7980
['session-activity', '/docs/reference/backend/types/backend-session-activity'],
8081
['organization', '/docs/reference/backend/types/backend-organization'],
@@ -101,6 +102,7 @@ const LINK_REPLACEMENTS = [
101102
['confirm-checkout-params', '/docs/reference/types/billing-checkout-resource#parameters'],
102103
['billing-payment-method-resource', '/docs/reference/types/billing-payment-method-resource'],
103104
['billing-payer-resource', '/docs/reference/types/billing-payer-resource'],
105+
['billing-plan-price', '/docs/reference/types/billing-plan-price'],
104106
['billing-plan-resource', '/docs/reference/types/billing-plan-resource'],
105107
['billing-plan-unit-price', '/docs/reference/types/billing-plan-unit-price'],
106108
['billing-plan-unit-price-tier', '/docs/reference/types/billing-plan-unit-price-tier'],
@@ -130,6 +132,10 @@ const LINK_REPLACEMENTS = [
130132
['session-task', '/docs/reference/types/session-task'],
131133
['public-user-data', '/docs/reference/types/public-user-data'],
132134
['session-status', '/docs/reference/types/session-status'],
135+
[
136+
'create-organization-invitation-params',
137+
'/docs/reference/backend/organization/create-organization-invitation#create-organization-invitation-params',
138+
],
133139
['create-organization-domain-params', '#create-organization-domain-params'],
134140
['organization-domain-verification', '/docs/reference/types/organization-domain-resource'],
135141
];
@@ -215,6 +221,10 @@ function getCatchAllReplacements() {
215221
pattern: /(?<![\[\w`#])`?LocalizationResource`?(?![\]\w`])/g,
216222
replace: '[LocalizationResource](/docs/guides/customizing-clerk/localization)',
217223
},
224+
{
225+
pattern: /(?<![\[\w`#])`?Machine`?(?![\]\w`])/g,
226+
replace: '[Machine](/docs/reference/backend/types/backend-machine)',
227+
},
218228
{
219229
pattern: /(?<![\[\w`#])`?PasskeyResource`?(?![\]\w`])/g,
220230
replace: '[PasskeyResource](/docs/reference/types/passkey-resource)',
@@ -293,6 +303,10 @@ function getCatchAllReplacements() {
293303
pattern: /(?<![\[\w`#])`?OAuthStrategy`?(?![\]\w`])/g,
294304
replace: '[OAuthStrategy](/docs/reference/types/sso#o-auth-strategy)',
295305
},
306+
{
307+
pattern: /(?<![\[\w`#])`?OAuthProvider`?(?![\]\w`])/g,
308+
replace: '[OAuthProvider](/docs/reference/types/sso#o-auth-provider)',
309+
},
296310
{
297311
pattern: /(?<![\[\w`#])`?OrganizationResource`?(?![\]\w`])/g,
298312
replace: '[OrganizationResource](/docs/reference/objects/organization)',
@@ -468,6 +482,33 @@ export function applyCatchAllMdReplacements(contents) {
468482
.join('\n');
469483
}
470484

485+
/**
486+
* Walk a typedoc Type and return a flat list of property declarations to render as a merged table. Used by the `@expandProperties` flattener below to handle three shapes:
487+
* - intersection types: walk each constituent
488+
* - inline object literals (ReflectionType): take its declaration.children
489+
* - named references (ReferenceType): take the target's children plus any properties contributed via type arguments, which captures the `Foo<{ ... }>` instantiation pattern where typedoc otherwise loses the generic parameter at the alias boundary.
490+
*
491+
* @param {import('typedoc').SomeType | undefined} type
492+
* @param {Map<string, import('typedoc').Reflection>} reflectionsByName lookup for cross-package refs whose `.reflection` is not linked
493+
* @returns {import('typedoc').DeclarationReflection[]}
494+
*/
495+
function collectPropertiesFromType(type, reflectionsByName) {
496+
if (!type) return [];
497+
if (type.type === 'reflection') {
498+
return type.declaration?.children ?? [];
499+
}
500+
if (type.type === 'intersection') {
501+
return type.types.flatMap(t => collectPropertiesFromType(t, reflectionsByName));
502+
}
503+
if (type.type === 'reference') {
504+
const target = type.reflection ?? reflectionsByName.get(type.name);
505+
const targetChildren = target?.children ?? [];
506+
const argChildren = (type.typeArguments ?? []).flatMap(t => collectPropertiesFromType(t, reflectionsByName));
507+
return [...targetChildren, ...argChildren];
508+
}
509+
return [];
510+
}
511+
471512
/**
472513
* @param {import('typedoc-plugin-markdown').MarkdownApplication} app
473514
*/
@@ -483,6 +524,49 @@ export function load(app) {
483524
}
484525
});
485526

527+
/**
528+
* Flatten the `Foo<{...}>` generic-instantiation pattern into a single merged properties table when `Foo` opts in via `@expandProperties`. typedoc-plugin-markdown would otherwise render an empty page for these aliases because the resolved type is a `ReferenceType` with no inline declaration — see `member.declaration.js` in the plugin, which only walks `IntersectionType` sub-types and has no branch for top-level `ReferenceType`.
529+
*
530+
* Runs at `RendererEvent.BEGIN` rather than `EVENT_RESOLVE_END` because the resolve hook fires per package, and cross-package references (e.g. `@clerk/backend` types referencing `ClerkPaginationRequest` from `@clerk/shared`) only link up after typedoc merges packages.
531+
*
532+
* The opt-in tag lives on the wrapper type so we never accidentally flatten unrelated generic aliases (e.g. `SignInErrors = Errors<SignInFields>`).
533+
*/
534+
app.renderer.on(RendererEvent.BEGIN, event => {
535+
const all = Object.values(event.project.reflections);
536+
const reflectionsByName = new Map();
537+
for (const r of all) {
538+
if (r.name && !reflectionsByName.has(r.name)) reflectionsByName.set(r.name, r);
539+
}
540+
const expandable = new Set();
541+
for (const r of all) {
542+
if (r.comment?.modifierTags?.has('@expandProperties')) {
543+
expandable.add(r);
544+
r.comment.modifierTags.delete('@expandProperties');
545+
}
546+
}
547+
for (const reflection of all) {
548+
if (
549+
reflection.kindOf?.(ReflectionKind.TypeAlias) &&
550+
reflection.type?.type === 'reference' &&
551+
Array.isArray(reflection.type.typeArguments) &&
552+
reflection.type.typeArguments.length > 0
553+
) {
554+
const target = reflection.type.reflection ?? reflectionsByName.get(reflection.type.name);
555+
if (!target || !expandable.has(target)) continue;
556+
const merged = collectPropertiesFromType(reflection.type, reflectionsByName);
557+
if (merged.length > 0) {
558+
// typedoc's package-level `sort: 'alphabetical'` is applied during conversion, before
559+
// our synthetic merge runs. Sort here to match the alphabetical ordering used by
560+
// every other table in the docs.
561+
merged.sort((a, b) => a.name.localeCompare(b.name));
562+
const decl = new DeclarationReflection('__type', ReflectionKind.TypeLiteral, reflection);
563+
decl.children = merged;
564+
reflection.type = new ReflectionType(decl);
565+
}
566+
}
567+
}
568+
});
569+
486570
app.renderer.on(MarkdownPageEvent.END, output => {
487571
const fileName = output.url.split('/').pop();
488572

0 commit comments

Comments
 (0)