Skip to content

Commit de223bf

Browse files
committed
Merge branch 'main' into poc/observable-signin
2 parents c8b0689 + 607d333 commit de223bf

File tree

8 files changed

+106
-44
lines changed

8 files changed

+106
-44
lines changed

.changeset/great-windows-collect.md

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

.changeset/mean-apes-do.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+
Add JSdoc comments for user methods.

.typedoc/custom-plugin.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ function getCatchAllReplacements() {
120120
replace:
121121
'[`OrganizationInvitationPublicMetadata`](/docs/references/javascript/types/metadata#organization-invitation-public-metadata)',
122122
},
123+
{
124+
pattern: /`OrganizationMembershipPrivateMetadata`/g,
125+
replace:
126+
'[`OrganizationMembershipPrivateMetadata`](/docs/references/javascript/types/metadata#organization-membership-private-metadata)',
127+
},
128+
{
129+
pattern: /`OrganizationMembershipPublicMetadata`/g,
130+
replace:
131+
'[`OrganizationMembershipPublicMetadata`](/docs/references/javascript/types/metadata#organization-membership-public-metadata)',
132+
},
123133
{
124134
/**
125135
* By default, `@deprecated` is output with `**Deprecated**`. We want to add a full stop to it.

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,30 @@ export class User {
185185
return res;
186186
}
187187

188+
/**
189+
* The primary email address of the user.
190+
*/
188191
get primaryEmailAddress() {
189192
return this.emailAddresses.find(({ id }) => id === this.primaryEmailAddressId) ?? null;
190193
}
191194

195+
/**
196+
* The primary phone number of the user.
197+
*/
192198
get primaryPhoneNumber() {
193199
return this.phoneNumbers.find(({ id }) => id === this.primaryPhoneNumberId) ?? null;
194200
}
195201

202+
/**
203+
* The primary web3 wallet of the user.
204+
*/
196205
get primaryWeb3Wallet() {
197206
return this.web3Wallets.find(({ id }) => id === this.primaryWeb3WalletId) ?? null;
198207
}
199208

209+
/**
210+
* The full name of the user.
211+
*/
200212
get fullName() {
201213
return [this.firstName, this.lastName].join(' ').trim() || null;
202214
}
Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertType, test } from 'vitest';
1+
import { assertType, expectTypeOf, test } from 'vitest';
22

33
import type { AuthObject } from '../authObjects';
44
import type { GetAuthFn, MachineAuthObject, SessionAuthObject } from '../types';
@@ -12,57 +12,57 @@ test('infers the correct AuthObject type for each accepted token type', () => {
1212
const request = new Request('https://example.com');
1313

1414
// Session token by default
15-
assertType<SessionAuthObject>(getAuth(request));
15+
expectTypeOf(getAuth(request)).toMatchTypeOf<SessionAuthObject>();
1616

1717
// Individual token types
18-
assertType<SessionAuthObject>(getAuth(request, { acceptsToken: 'session_token' }));
19-
assertType<MachineAuthObject<'api_key'>>(getAuth(request, { acceptsToken: 'api_key' }));
20-
assertType<MachineAuthObject<'machine_token'>>(getAuth(request, { acceptsToken: 'machine_token' }));
21-
assertType<MachineAuthObject<'oauth_token'>>(getAuth(request, { acceptsToken: 'oauth_token' }));
18+
expectTypeOf(getAuth(request, { acceptsToken: 'session_token' })).toMatchTypeOf<SessionAuthObject>();
19+
expectTypeOf(getAuth(request, { acceptsToken: 'api_key' })).toMatchTypeOf<MachineAuthObject<'api_key'>>();
20+
expectTypeOf(getAuth(request, { acceptsToken: 'machine_token' })).toMatchTypeOf<MachineAuthObject<'machine_token'>>();
21+
expectTypeOf(getAuth(request, { acceptsToken: 'oauth_token' })).toMatchTypeOf<MachineAuthObject<'oauth_token'>>();
2222

2323
// Array of token types
24-
assertType<SessionAuthObject | MachineAuthObject<'machine_token'>>(
25-
getAuth(request, { acceptsToken: ['session_token', 'machine_token'] }),
26-
);
27-
assertType<MachineAuthObject<'machine_token' | 'oauth_token'>>(
28-
getAuth(request, { acceptsToken: ['machine_token', 'oauth_token'] }),
29-
);
24+
expectTypeOf(getAuth(request, { acceptsToken: ['session_token', 'machine_token'] })).toMatchTypeOf<
25+
SessionAuthObject | MachineAuthObject<'machine_token'>
26+
>();
27+
expectTypeOf(getAuth(request, { acceptsToken: ['machine_token', 'oauth_token'] })).toMatchTypeOf<
28+
MachineAuthObject<'machine_token' | 'oauth_token'>
29+
>();
3030

3131
// Any token type
32-
assertType<AuthObject>(getAuth(request, { acceptsToken: 'any' }));
32+
expectTypeOf(getAuth(request, { acceptsToken: 'any' })).toMatchTypeOf<AuthObject>();
3333
});
3434

3535
test('verifies correct properties exist for each token type', () => {
3636
const request = new Request('https://example.com');
3737

3838
// Session token should have userId
3939
const sessionAuth = getAuth(request, { acceptsToken: 'session_token' });
40-
assertType<string | null>(sessionAuth.userId);
40+
expectTypeOf(sessionAuth.userId).toMatchTypeOf<string | null>();
4141

4242
// All machine tokens should have id and subject
4343
const apiKeyAuth = getAuth(request, { acceptsToken: 'api_key' });
4444
const machineTokenAuth = getAuth(request, { acceptsToken: 'machine_token' });
4545
const oauthTokenAuth = getAuth(request, { acceptsToken: 'oauth_token' });
4646

47-
assertType<string | null>(apiKeyAuth.id);
48-
assertType<string | null>(machineTokenAuth.id);
49-
assertType<string | null>(oauthTokenAuth.id);
50-
assertType<string | null>(apiKeyAuth.subject);
51-
assertType<string | null>(machineTokenAuth.subject);
52-
assertType<string | null>(oauthTokenAuth.subject);
47+
expectTypeOf(apiKeyAuth.id).toMatchTypeOf<string | null>();
48+
expectTypeOf(machineTokenAuth.id).toMatchTypeOf<string | null>();
49+
expectTypeOf(oauthTokenAuth.id).toMatchTypeOf<string | null>();
50+
expectTypeOf(apiKeyAuth.subject).toMatchTypeOf<string | null>();
51+
expectTypeOf(machineTokenAuth.subject).toMatchTypeOf<string | null>();
52+
expectTypeOf(oauthTokenAuth.subject).toMatchTypeOf<string | null>();
5353

5454
// Only api_key and machine_token should have name and claims
55-
assertType<string | null>(apiKeyAuth.name);
56-
assertType<Record<string, any> | null>(apiKeyAuth.claims);
55+
expectTypeOf(apiKeyAuth.name).toMatchTypeOf<string | null>();
56+
expectTypeOf(apiKeyAuth.claims).toMatchTypeOf<Record<string, any> | null>();
5757

58-
assertType<string | null>(machineTokenAuth.name);
59-
assertType<Record<string, any> | null>(machineTokenAuth.claims);
58+
expectTypeOf(machineTokenAuth.name).toMatchTypeOf<string | null>();
59+
expectTypeOf(machineTokenAuth.claims).toMatchTypeOf<Record<string, any> | null>();
6060

6161
// oauth_token should NOT have name and claims
6262
// @ts-expect-error oauth_token does not have name property
63-
void oauthTokenAuth.name;
63+
assertType<string | null>(oauthTokenAuth.name);
6464
// @ts-expect-error oauth_token does not have claims property
65-
void oauthTokenAuth.claims;
65+
assertType<Record<string, any> | null>(oauthTokenAuth.claims);
6666
});
6767

6868
test('verifies discriminated union works correctly with acceptsToken: any', () => {
@@ -72,36 +72,36 @@ test('verifies discriminated union works correctly with acceptsToken: any', () =
7272

7373
if (auth.tokenType === 'session_token') {
7474
// Should be SessionAuthObject - has userId
75-
assertType<string | null>(auth.userId);
75+
expectTypeOf(auth.userId).toMatchTypeOf<string | null>();
7676
// Should NOT have machine token properties
7777
// @ts-expect-error session_token does not have id property
78-
void auth.id;
78+
assertType<string | null>(auth.id);
7979
} else if (auth.tokenType === 'api_key') {
8080
// Should be AuthenticatedMachineObject<'api_key'> - has id, name, claims
81-
assertType<string | null>(auth.id);
82-
assertType<string | null>(auth.name);
83-
assertType<Record<string, any> | null>(auth.claims);
81+
expectTypeOf(auth.id).toMatchTypeOf<string | null>();
82+
expectTypeOf(auth.name).toMatchTypeOf<string | null>();
83+
expectTypeOf(auth.claims).toMatchTypeOf<Record<string, any> | null>();
8484
// Should NOT have session token properties
8585
// @ts-expect-error api_key does not have userId property
86-
void auth.userId;
86+
assertType<string | null>(auth.userId);
8787
} else if (auth.tokenType === 'machine_token') {
8888
// Should be AuthenticatedMachineObject<'machine_token'> - has id, name, claims
89-
assertType<string | null>(auth.id);
90-
assertType<string | null>(auth.name);
91-
assertType<Record<string, any> | null>(auth.claims);
89+
expectTypeOf(auth.id).toMatchTypeOf<string | null>();
90+
expectTypeOf(auth.name).toMatchTypeOf<string | null>();
91+
expectTypeOf(auth.claims).toMatchTypeOf<Record<string, any> | null>();
9292
// Should NOT have session token properties
9393
// @ts-expect-error machine_token does not have userId property
94-
void auth.userId;
94+
assertType<string | null>(auth.userId);
9595
} else if (auth.tokenType === 'oauth_token') {
9696
// Should be AuthenticatedMachineObject<'oauth_token'> - has id but NOT name/claims
97-
assertType<string | null>(auth.id);
97+
expectTypeOf(auth.id).toMatchTypeOf<string | null>();
9898
// Should NOT have name or claims
9999
// @ts-expect-error oauth_token does not have name property
100-
void auth.name;
100+
assertType<string | null>(auth.name);
101101
// @ts-expect-error oauth_token does not have claims property
102-
void auth.claims;
102+
assertType<Record<string, any> | null>(auth.claims);
103103
// Should NOT have session token properties
104104
// @ts-expect-error oauth_token does not have userId property
105-
void auth.userId;
105+
assertType<string | null>(auth.userId);
106106
}
107107
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { expectTypeOf, test } from 'vitest';
2+
3+
import type { RequestState, TokenType } from '../../internal';
4+
import { authenticateRequest } from '../../tokens/request';
5+
6+
test('returns the correct `authenticateRequest()` return type for each accepted token type', () => {
7+
const request = new Request('https://example.com');
8+
9+
// Session token by default
10+
expectTypeOf(authenticateRequest(request)).toMatchTypeOf<Promise<RequestState>>();
11+
12+
// Individual token types
13+
expectTypeOf(authenticateRequest(request, { acceptsToken: 'session_token' })).toMatchTypeOf<
14+
Promise<RequestState<'session_token'>>
15+
>();
16+
expectTypeOf(authenticateRequest(request, { acceptsToken: 'api_key' })).toMatchTypeOf<
17+
Promise<RequestState<'api_key'>>
18+
>();
19+
expectTypeOf(authenticateRequest(request, { acceptsToken: 'machine_token' })).toMatchTypeOf<
20+
Promise<RequestState<'machine_token'>>
21+
>();
22+
expectTypeOf(authenticateRequest(request, { acceptsToken: 'oauth_token' })).toMatchTypeOf<
23+
Promise<RequestState<'oauth_token'>>
24+
>();
25+
26+
// Array of token types
27+
expectTypeOf(
28+
authenticateRequest(request, { acceptsToken: ['session_token', 'api_key', 'machine_token'] }),
29+
).toMatchTypeOf<Promise<RequestState<'session_token' | 'api_key' | 'machine_token'>>>();
30+
31+
// Any token type
32+
expectTypeOf(authenticateRequest(request, { acceptsToken: 'any' })).toMatchTypeOf<Promise<RequestState<TokenType>>>();
33+
});

packages/remix/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@
8383
"tslib": "catalog:repo"
8484
},
8585
"devDependencies": {
86-
"@remix-run/react": "^2.16.7",
87-
"@remix-run/server-runtime": "^2.16.7",
86+
"@remix-run/react": "^2.16.8",
87+
"@remix-run/server-runtime": "^2.16.8",
8888
"@types/cookie": "^0.6.0"
8989
},
9090
"peerDependencies": {

pnpm-lock.yaml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)