Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/eight-wombats-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': patch
'@clerk/types': patch
---

Rename the `sendCaptchaToken` to `__internal_sendCaptchaToken`.
2 changes: 1 addition & 1 deletion packages/clerk-js/src/core/auth/CaptchaHeartbeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class CaptchaHeartbeat {

try {
const params = await this.captchaChallenge.invisible({ action: 'heartbeat' });
await this.clerk.client.sendCaptchaToken(params);
await this.clerk.client.__internal_sendCaptchaToken(params);
} catch {
// Ignore unhandled errors
}
Expand Down
14 changes: 7 additions & 7 deletions packages/clerk-js/src/core/fraudProtection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('FraudProtectionService', () => {
);

const mockClientInstance = {
sendCaptchaToken: jest.fn().mockResolvedValue({}),
__internal_sendCaptchaToken: jest.fn().mockResolvedValue({}),
};

mockClient = {
Expand All @@ -55,7 +55,7 @@ describe('FraudProtectionService', () => {

// only one will need to call the captcha as the other will be blocked
expect(mockManagedInModal).toHaveBeenCalledTimes(0);
expect(mockClient.getOrCreateInstance().sendCaptchaToken).toHaveBeenCalledTimes(0);
expect(mockClient.getOrCreateInstance().__internal_sendCaptchaToken).toHaveBeenCalledTimes(0);
expect(fn1).toHaveBeenCalledTimes(1);
});

Expand All @@ -68,7 +68,7 @@ describe('FraudProtectionService', () => {
const fn1res = sut.execute(mockClerk, fn1);
expect(fn1res).rejects.toEqual(unrelatedError);
expect(mockManagedInModal).toHaveBeenCalledTimes(0);
expect(mockClient.getOrCreateInstance().sendCaptchaToken).toHaveBeenCalledTimes(0);
expect(mockClient.getOrCreateInstance().__internal_sendCaptchaToken).toHaveBeenCalledTimes(0);
expect(fn1).toHaveBeenCalledTimes(1);
});

Expand All @@ -88,7 +88,7 @@ describe('FraudProtectionService', () => {

// only one will need to call the captcha as the other will be blocked
expect(mockManagedInModal).toHaveBeenCalledTimes(1);
expect(mockClient.getOrCreateInstance().sendCaptchaToken).toHaveBeenCalledTimes(1);
expect(mockClient.getOrCreateInstance().__internal_sendCaptchaToken).toHaveBeenCalledTimes(1);
expect(fn1).toHaveBeenCalledTimes(2);
});

Expand All @@ -108,7 +108,7 @@ describe('FraudProtectionService', () => {

// captcha will only be called once
expect(mockManagedInModal).toHaveBeenCalledTimes(1);
expect(mockClient.getOrCreateInstance().sendCaptchaToken).toHaveBeenCalledTimes(1);
expect(mockClient.getOrCreateInstance().__internal_sendCaptchaToken).toHaveBeenCalledTimes(1);
// but all failed requests will be retried
expect(fn1).toHaveBeenCalledTimes(2);
expect(fn2).toHaveBeenCalledTimes(2);
Expand All @@ -135,7 +135,7 @@ describe('FraudProtectionService', () => {
await Promise.all([fn1res, fn2res]);

expect(mockManagedInModal).toHaveBeenCalledTimes(1);
expect(mockClient.getOrCreateInstance().sendCaptchaToken).toHaveBeenCalledTimes(1);
expect(mockClient.getOrCreateInstance().__internal_sendCaptchaToken).toHaveBeenCalledTimes(1);
expect(fn1).toHaveBeenCalledTimes(2);
expect(fn2).toHaveBeenCalledTimes(1);
});
Expand Down Expand Up @@ -168,7 +168,7 @@ describe('FraudProtectionService', () => {
await Promise.all([fn2res, fn3res]);

expect(mockManagedInModal).toHaveBeenCalledTimes(1);
expect(mockClient.getOrCreateInstance().sendCaptchaToken).toHaveBeenCalledTimes(1);
expect(mockClient.getOrCreateInstance().__internal_sendCaptchaToken).toHaveBeenCalledTimes(1);

expect(fn1).toHaveBeenCalledTimes(2);
expect(fn2).toHaveBeenCalledTimes(2);
Expand Down
2 changes: 1 addition & 1 deletion packages/clerk-js/src/core/fraudProtection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class FraudProtection {
try {
const captchaParams: any = await this.managedChallenge(clerk);
if (captchaParams?.captchaError !== 'modal_component_not_ready') {
await this.client.getOrCreateInstance().sendCaptchaToken(captchaParams);
await this.client.getOrCreateInstance().__internal_sendCaptchaToken(captchaParams);
this.captchaRetryCount = 0; // Reset the retry count on success
}
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion packages/clerk-js/src/core/resources/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class Client extends BaseResource implements ClientResource {
.toString();
}

public sendCaptchaToken(params: unknown): Promise<ClientResource> {
public __internal_sendCaptchaToken(params: unknown): Promise<ClientResource> {
return this._basePostBypass({ body: params, path: this.path() + '/verify' });
}

Expand Down
6 changes: 3 additions & 3 deletions packages/clerk-js/src/core/resources/__tests__/Client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createSession, createSignIn, createSignUp, createUser } from '../../tes
import { BaseResource, Client } from '../internal';

describe('Client Singleton', () => {
describe('sendCaptchaToken', () => {
describe('__internal_sendCaptchaToken', () => {
it('sends captcha token', async () => {
const user = createUser({ first_name: 'John', last_name: 'Doe', id: 'user_1' });
const session = createSession({ id: 'session_1' }, user);
Expand All @@ -24,7 +24,7 @@ describe('Client Singleton', () => {
BaseResource._baseFetch = jest.fn();

const client = Client.getOrCreateInstance().fromJSON(clientObjectJSON);
await client.sendCaptchaToken({ captcha_token: 'test_captcha_token' });
await client.__internal_sendCaptchaToken({ captcha_token: 'test_captcha_token' });
// @ts-expect-error This is a private method that we are mocking
expect(BaseResource._baseFetch).toHaveBeenCalledWith({
method: 'POST',
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('Client Singleton', () => {
BaseResource._baseFetch = jest.fn().mockResolvedValueOnce(Promise.resolve(null));

const client = Client.getOrCreateInstance().fromJSON(clientObjectJSON);
await client.sendCaptchaToken({ captcha_token: 'test_captcha_token' });
await client.__internal_sendCaptchaToken({ captcha_token: 'test_captcha_token' });
// @ts-expect-error This is a private method that we are mocking
expect(BaseResource._baseFetch).toHaveBeenCalledWith({
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export interface ClientResource extends ClerkResource {
signIn: SignInResource;
isNew: () => boolean;
create: () => Promise<ClientResource>;
sendCaptchaToken: (params: unknown) => Promise<ClientResource>;
destroy: () => Promise<void>;
removeSessions: () => Promise<ClientResource>;
clearCache: () => void;
Expand All @@ -22,6 +21,7 @@ export interface ClientResource extends ClerkResource {
cookieExpiresAt: Date | null;
createdAt: Date | null;
updatedAt: Date | null;
__internal_sendCaptchaToken: (params: unknown) => Promise<ClientResource>;
__internal_toSnapshot: () => ClientJSONSnapshot;
/**
* @deprecated Use `signedInSessions` instead
Expand Down