Skip to content

Commit 795d09a

Browse files
authored
chore(backend): Add JSDoc comments to resources (#6049)
1 parent e0d6fbe commit 795d09a

36 files changed

+934
-23
lines changed

.changeset/true-bears-divide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/backend': patch
3+
---
4+
5+
Improve JSDoc comments

.typedoc/__tests__/__snapshots__/file-structure.test.ts.snap

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ exports[`Typedoc output > should have a deliberate file structure 1`] = `
77
"types/active-session-resource.mdx",
88
"types/check-authorization-fn.mdx",
99
"types/check-authorization-from-session-claims.mdx",
10+
"types/check-authorization-params-from-session-claims.mdx",
1011
"types/check-authorization-with-custom-permissions.mdx",
1112
"types/clerk-api-error.mdx",
1213
"types/clerk-host-router.mdx",
@@ -46,10 +47,13 @@ exports[`Typedoc output > should have a deliberate file structure 1`] = `
4647
"types/pending-session-resource.mdx",
4748
"types/record-to-path.mdx",
4849
"types/redirect-options.mdx",
50+
"types/reverification-config.mdx",
4951
"types/saml-strategy.mdx",
5052
"types/sdk-metadata.mdx",
5153
"types/session-resource.mdx",
5254
"types/session-status-claim.mdx",
55+
"types/session-verification-level.mdx",
56+
"types/session-verification-types.mdx",
5357
"types/set-active-params.mdx",
5458
"types/set-active.mdx",
5559
"types/sign-in-resource.mdx",
@@ -140,10 +144,36 @@ exports[`Typedoc output > should have a deliberate file structure 1`] = `
140144
"clerk-react/use-sign-in.mdx",
141145
"clerk-react/use-sign-up.mdx",
142146
"clerk-react/use-user.mdx",
147+
"backend/allowlist-identifier.mdx",
148+
"backend/auth-object.mdx",
149+
"backend/authenticate-request-options.mdx",
150+
"backend/client.mdx",
151+
"backend/email-address.mdx",
152+
"backend/external-account.mdx",
153+
"backend/identification-link.mdx",
154+
"backend/invitation-status.mdx",
155+
"backend/invitation.mdx",
156+
"backend/organization-invitation-status.mdx",
157+
"backend/organization-invitation.mdx",
158+
"backend/organization-membership-public-user-data.mdx",
159+
"backend/organization-membership.mdx",
160+
"backend/organization-sync-target.mdx",
161+
"backend/organization.mdx",
162+
"backend/paginated-resource-response.mdx",
163+
"backend/phone-number.mdx",
164+
"backend/public-organization-data-json.mdx",
165+
"backend/redirect-url.mdx",
166+
"backend/saml-account.mdx",
167+
"backend/saml-connection.mdx",
168+
"backend/session-activity.mdx",
169+
"backend/session.mdx",
170+
"backend/user.mdx",
171+
"backend/verification.mdx",
143172
"backend/verify-machine-auth-token.mdx",
144173
"backend/verify-token-options.mdx",
145174
"backend/verify-token.mdx",
146175
"backend/verify-webhook-options.mdx",
147176
"backend/verify-webhook.mdx",
177+
"backend/web3-wallet.mdx",
148178
]
149179
`;

.typedoc/custom-plugin.mjs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ const FILES_WITHOUT_HEADINGS = [
1515
'use-organization-list-return.mdx',
1616
'use-organization-list-params.mdx',
1717
'create-organization-params.mdx',
18+
'authenticate-request-options.mdx',
19+
'verify-token-options.mdx',
20+
'public-organization-data-json.mdx',
21+
'organization-membership-public-user-data.mdx',
1822
];
1923

2024
/**
@@ -36,6 +40,18 @@ const LINK_REPLACEMENTS = [
3640
['organization-domain-resource', '/docs/references/javascript/types/organization-domain'],
3741
['organization-invitation-resource', '/docs/references/javascript/types/organization-invitation'],
3842
['organization-membership-request-resource', '/docs/references/javascript/types/organization-membership-request'],
43+
['session', '/docs/references/backend/types/backend-session'],
44+
['session-activity', '/docs/references/backend/types/backend-session-activity'],
45+
['organization', '/docs/references/backend/types/backend-organization'],
46+
['public-organization-data-json', '#public-organization-data-json'],
47+
['organization-membership-public-user-data', '#organization-membership-public-user-data'],
48+
['identification-link', '/docs/references/backend/types/backend-identification-link'],
49+
['verification', '/docs/references/backend/types/backend-verification'],
50+
['email-address', '/docs/references/backend/types/backend-email-address'],
51+
['external-account', '/docs/references/backend/types/backend-external-account'],
52+
['phone-number', '/docs/references/backend/types/backend-phone-number'],
53+
['saml-account', '/docs/references/backend/types/backend-saml-account'],
54+
['web3-wallet', '/docs/references/backend/types/backend-web3-wallet'],
3955
];
4056

4157
/**
@@ -84,6 +100,25 @@ function getCatchAllReplacements() {
84100
pattern: /\| `SignInResource` \|/,
85101
replace: '| [SignInResource](/docs/references/javascript/sign-in) |',
86102
},
103+
{
104+
pattern: /`OrganizationPrivateMetadata`/g,
105+
replace:
106+
'[`OrganizationPrivateMetadata`](/docs/references/javascript/types/metadata#organization-private-metadata)',
107+
},
108+
{
109+
pattern: /OrganizationPublicMetadata/g,
110+
replace: '[OrganizationPublicMetadata](/docs/references/javascript/types/metadata#organization-public-metadata)',
111+
},
112+
{
113+
pattern: /`OrganizationInvitationPrivateMetadata`/g,
114+
replace:
115+
'[`OrganizationInvitationPrivateMetadata`](/docs/references/javascript/types/metadata#organization-invitation-private-metadata)',
116+
},
117+
{
118+
pattern: /`OrganizationInvitationPublicMetadata`/g,
119+
replace:
120+
'[`OrganizationInvitationPublicMetadata`](/docs/references/javascript/types/metadata#organization-invitation-public-metadata)',
121+
},
87122
{
88123
/**
89124
* By default, `@deprecated` is output with `**Deprecated**`. We want to add a full stop to it.
@@ -105,6 +140,15 @@ function getCatchAllReplacements() {
105140
pattern: /\*\*Example\*\* `([^`]+)`/g,
106141
replace: 'Example: `$1`.',
107142
},
143+
{
144+
/**
145+
* By default, multiple `@example` are output with "**Examples** `value1` `value2`". We want to capture the values and place them inside "Examples: `value1`, `value2`."
146+
*/
147+
pattern: /\*\*Examples\*\* ((?:`[^`]+`)(?: `[^`]+`)*)/g,
148+
replace: (/** @type {string} */ _match, /** @type {string} */ capturedGroup) => {
149+
return `Examples: ${capturedGroup.split(' ').join(', ')}.`;
150+
},
151+
},
108152
];
109153
}
110154

@@ -126,6 +170,7 @@ export function load(app) {
126170

127171
for (const { pattern, replace } of catchAllReplacements) {
128172
if (output.contents) {
173+
// @ts-ignore - Mixture of string and function replacements
129174
output.contents = output.contents.replace(pattern, replace);
130175
}
131176
}

.typedoc/custom-theme.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ ${tabs}
319319

320320
return `<code>${output}</code>`;
321321
},
322+
/**
323+
* Hide "Extends" and "Extended by" sections
324+
*/
325+
hierarchy: () => '',
322326
};
323327
}
324328
}

packages/backend/src/api/resources/AllowlistIdentifier.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
11
import type { AllowlistIdentifierType } from './Enums';
22
import type { AllowlistIdentifierJSON } from './JSON';
33

4+
/**
5+
* The Backend `AllowlistIdentifier` object represents an identifier that has been added to the allowlist of your application. The Backend `AllowlistIdentifier` object is used in the [Backend API](https://clerk.com/docs/reference/backend-api/tag/Allow-list-Block-list#operation/ListAllowlistIdentifiers) and is not directly accessible from the Frontend API.
6+
*/
47
export class AllowlistIdentifier {
58
constructor(
9+
/**
10+
* A unique ID for the allowlist identifier.
11+
*/
612
readonly id: string,
13+
/**
14+
* The [identifier](https://clerk.com/docs/authentication/configuration/sign-up-sign-in-options#identifiers) that was added to the allowlist.
15+
*/
716
readonly identifier: string,
17+
/**
18+
* The type of the allowlist identifier.
19+
*/
820
readonly identifierType: AllowlistIdentifierType,
21+
/**
22+
* The date when the allowlist identifier was first created.
23+
*/
924
readonly createdAt: number,
25+
/**
26+
* The date when the allowlist identifier was last updated.
27+
*/
1028
readonly updatedAt: number,
29+
/**
30+
* The ID of the instance that this allowlist identifier belongs to.
31+
*/
1132
readonly instanceId?: string,
33+
/**
34+
* The ID of the invitation sent to the identifier.
35+
*/
1236
readonly invitationId?: string,
1337
) {}
1438

packages/backend/src/api/resources/Client.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,42 @@
11
import type { ClientJSON } from './JSON';
22
import { Session } from './Session';
33

4+
/**
5+
* The Backend `Client` object is similar to the [`Client`](https://clerk.com/docs/references/javascript/client) object as it holds information about the authenticated sessions in the current device. However, the Backend `Client` object is different from the `Client` object in that it is used in the [Backend API](https://clerk.com/docs/reference/backend-api/tag/Clients#operation/GetClient) and is not directly accessible from the Frontend API.
6+
*/
47
export class Client {
58
constructor(
9+
/**
10+
* The unique identifier for the `Client`.
11+
*/
612
readonly id: string,
13+
/**
14+
* An array of [Session](https://clerk.com/docs/references/backend/types/backend-session){{ target: '_blank' }} IDs associated with the `Client`.
15+
*/
716
readonly sessionIds: string[],
17+
/**
18+
* An array of [Session](https://clerk.com/docs/references/backend/types/backend-session){{ target: '_blank' }} objects associated with the `Client`.
19+
*/
820
readonly sessions: Session[],
21+
/**
22+
* The ID of the [`SignIn`](https://clerk.com/docs/references/javascript/sign-in){{ target: '_blank' }}.
23+
*/
924
readonly signInId: string | null,
25+
/**
26+
* The ID of the [`SignUp`](https://clerk.com/docs/references/javascript/sign-up){{ target: '_blank' }}.
27+
*/
1028
readonly signUpId: string | null,
29+
/**
30+
* The ID of the last active [Session](https://clerk.com/docs/references/backend/types/backend-session).
31+
*/
1132
readonly lastActiveSessionId: string | null,
33+
/**
34+
* The date when the `Client` was first created.
35+
*/
1236
readonly createdAt: number,
37+
/**
38+
* The date when the `Client` was last updated.
39+
*/
1340
readonly updatedAt: number,
1441
) {}
1542

packages/backend/src/api/resources/Deserializer.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,27 @@ import { ObjectType } from './JSON';
3939
import { WaitlistEntry } from './WaitlistEntry';
4040

4141
type ResourceResponse<T> = {
42+
/**
43+
* An array that contains the fetched data.
44+
*/
4245
data: T;
4346
};
4447

48+
/**
49+
* An interface that describes the response of a method that returns a paginated list of resources.
50+
*
51+
* If the promise resolves, you will get back the [properties](#properties) listed below. `data` will be an array of the resource type you requested. You can use the `totalCount` property to determine how many total items exist remotely.
52+
*
53+
* Some methods that return this type allow pagination with the `limit` and `offset` parameters, in which case the first 10 items will be returned by default. For methods such as [`getAllowlistIdentifierList()`](https://clerk.com/docs/references/backend/allowlist/get-allowlist-identifier-list), which do not take a `limit` or `offset`, all items will be returned.
54+
*
55+
* If the promise is rejected, you will receive a `ClerkAPIResponseError` or network error.
56+
*
57+
* @interface
58+
*/
4559
export type PaginatedResourceResponse<T> = ResourceResponse<T> & {
60+
/**
61+
* The total count of data that exist remotely.
62+
*/
4663
totalCount: number;
4764
};
4865

packages/backend/src/api/resources/EmailAddress.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,30 @@ import { IdentificationLink } from './IdentificationLink';
22
import type { EmailAddressJSON } from './JSON';
33
import { Verification } from './Verification';
44

5+
/**
6+
* The Backend `EmailAddress` object is a model around an email address. Email addresses are one of the [identifiers](https://clerk.com/docs/authentication/configuration/sign-up-sign-in-options#identifiers) used to provide identification for users.
7+
*
8+
* Email addresses must be **verified** to ensure that they are assigned to their rightful owners. The `EmailAddress` object holds all necessary state around the verification process.
9+
*
10+
* For implementation examples for adding and verifying email addresses, see the [email link custom flow](https://clerk.com/docs/custom-flows/email-links) and [email code custom flow](https://clerk.com/docs/custom-flows/add-email) guides.
11+
*/
512
export class EmailAddress {
613
constructor(
14+
/**
15+
* The unique identifier for the email address.
16+
*/
717
readonly id: string,
18+
/**
19+
* The value of the email address.
20+
*/
821
readonly emailAddress: string,
22+
/**
23+
* An object holding information on the verification of the email address.
24+
*/
925
readonly verification: Verification | null,
26+
/**
27+
* An array of objects containing information about any identifications that might be linked to the email address.
28+
*/
1029
readonly linkedTo: IdentificationLink[],
1130
) {}
1231

packages/backend/src/api/resources/Enums.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export type OAuthProvider =
2121

2222
export type OAuthStrategy = `oauth_${OAuthProvider}`;
2323

24+
/**
25+
* @inline
26+
*/
2427
export type OrganizationInvitationStatus = 'pending' | 'accepted' | 'revoked' | 'expired';
2528

2629
export type OrganizationDomainVerificationStatus = 'unverified' | 'verified';
@@ -35,6 +38,9 @@ export type SignInStatus = 'needs_identifier' | 'needs_factor_one' | 'needs_fact
3538

3639
export type SignUpVerificationNextAction = 'needs_prepare' | 'needs_attempt' | '';
3740

41+
/**
42+
* @inline
43+
*/
3844
export type InvitationStatus = 'pending' | 'accepted' | 'revoked' | 'expired';
3945

4046
export const DomainsEnrollmentModes = {
@@ -51,8 +57,17 @@ export const ActorTokenStatus = {
5157
} as const;
5258
export type ActorTokenStatus = (typeof ActorTokenStatus)[keyof typeof ActorTokenStatus];
5359

60+
/**
61+
* @inline
62+
*/
5463
export type AllowlistIdentifierType = 'email_address' | 'phone_number' | 'web3_wallet';
5564

65+
/**
66+
* @inline
67+
*/
5668
export type BlocklistIdentifierType = AllowlistIdentifierType;
5769

70+
/**
71+
* @inline
72+
*/
5873
export type WaitlistEntryStatus = 'pending' | 'invited' | 'completed' | 'rejected';

0 commit comments

Comments
 (0)