Skip to content
Open
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
2 changes: 2 additions & 0 deletions .changeset/electron-single-tsconfig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
36 changes: 14 additions & 22 deletions packages/electron/src/main/__tests__/create-clerk-bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ const windowSender = { mainFrame, getType: () => 'window' };
const mainFrameEvent = { sender: windowSender, senderFrame: mainFrame } as unknown as Electron.IpcMainInvokeEvent;
const subframeEvent = { sender: windowSender, senderFrame: {} } as unknown as Electron.IpcMainInvokeEvent;

function getAppListener<T extends (...args: never[]) => void>(event: string): T | undefined {
return (vi.mocked(app.on).mock.calls as unknown as Array<[string, T]>).find(
([registered]) => registered === event,
)?.[1];
Comment thread
Ephem marked this conversation as resolved.
}

describe('createClerkBridge', () => {
const missingStorage = {} as Parameters<typeof createClerkBridge>[0];
const storage: TokenStorage = {
Expand Down Expand Up @@ -145,7 +151,6 @@ describe('createClerkBridge', () => {
host: 'renderer',
scheme: 'my-app',
privileges: {
allowExtensions: true,
allowServiceWorkers: true,
bypassCSP: true,
codeCache: true,
Expand All @@ -157,7 +162,6 @@ describe('createClerkBridge', () => {
{
scheme: 'my-app',
privileges: {
allowExtensions: true,
allowServiceWorkers: true,
bypassCSP: true,
codeCache: true,
Expand Down Expand Up @@ -590,12 +594,9 @@ describe('createClerkBridge', () => {
return channel === OAUTH_TRANSPORT_CHANNELS.open;
})?.[1];
const openPromise = openHandler?.(mainFrameEvent, 'https://accounts.example.com/oauth');
const openUrlListener = vi.mocked(app.on).mock.calls.find(([event]) => event === 'open-url')?.[1] as (
event: Electron.Event,
url: string,
) => void;
const openUrlListener = getAppListener<(event: Electron.Event, url: string) => void>('open-url');

openUrlListener({ preventDefault: vi.fn() } as unknown as Electron.Event, 'my-app://renderer/?code=123');
openUrlListener?.({ preventDefault: vi.fn() } as unknown as Electron.Event, 'my-app://renderer/?code=123');

await expect(openPromise).resolves.toEqual({ callbackUrl: 'my-app://renderer/?code=123' });
expect(shell.openExternal).toHaveBeenCalledWith('https://accounts.example.com/oauth');
Expand All @@ -615,12 +616,9 @@ describe('createClerkBridge', () => {
return channel === OAUTH_TRANSPORT_CHANNELS.open;
})?.[1];
const openPromise = openHandler?.(mainFrameEvent, 'https://accounts.example.com/oauth');
const secondInstanceListener = vi.mocked(app.on).mock.calls.find(([event]) => event === 'second-instance')?.[1] as (
event: Electron.Event,
argv: string[],
) => void;
const secondInstanceListener = getAppListener<(event: Electron.Event, argv: string[]) => void>('second-instance');

secondInstanceListener({} as Electron.Event, [
secondInstanceListener?.({} as Electron.Event, [
'/opt/MyApp/my-app',
'--enable-features=UseOzonePlatform',
'my-app://renderer/?code=123',
Expand All @@ -647,12 +645,9 @@ describe('createClerkBridge', () => {
return channel === OAUTH_TRANSPORT_CHANNELS.open;
})?.[1];
const openPromise = openHandler?.(mainFrameEvent, 'https://accounts.example.com/oauth');
const secondInstanceListener = vi.mocked(app.on).mock.calls.find(([event]) => event === 'second-instance')?.[1] as (
event: Electron.Event,
argv: string[],
) => void;
const secondInstanceListener = getAppListener<(event: Electron.Event, argv: string[]) => void>('second-instance');

secondInstanceListener({} as Electron.Event, ['/opt/MyApp/my-app', 'my-app://renderer/?code=123']);
secondInstanceListener?.({} as Electron.Event, ['/opt/MyApp/my-app', 'my-app://renderer/?code=123']);

await expect(openPromise).resolves.toEqual({ callbackUrl: 'my-app://renderer/?code=123' });
expect(rendererWindow.restore).toHaveBeenCalledOnce();
Expand All @@ -676,13 +671,10 @@ describe('createClerkBridge', () => {
return channel === OAUTH_TRANSPORT_CHANNELS.open;
})?.[1];
const openPromise = openHandler?.(mainFrameEvent, 'https://accounts.example.com/oauth');
const secondInstanceListener = vi.mocked(app.on).mock.calls.find(([event]) => event === 'second-instance')?.[1] as (
event: Electron.Event,
argv: string[],
) => void;
const secondInstanceListener = getAppListener<(event: Electron.Event, argv: string[]) => void>('second-instance');

rendererWindow.isDestroyed.mockReturnValue(true);
secondInstanceListener({} as Electron.Event, ['/opt/MyApp/my-app', 'my-app://renderer/?code=123']);
secondInstanceListener?.({} as Electron.Event, ['/opt/MyApp/my-app', 'my-app://renderer/?code=123']);

await expect(openPromise).resolves.toEqual({ callbackUrl: 'my-app://renderer/?code=123' });
expect(rendererWindow.focus).not.toHaveBeenCalled();
Expand Down
30 changes: 16 additions & 14 deletions packages/electron/src/passkeys/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { webAuthnCreateCredential, webAuthnGetCredential } from '@clerk/shared/internal/clerk-js/passkeys';
import type {
PublicKeyCredentialCreationOptionsWithoutExtensions,
PublicKeyCredentialRequestOptionsWithoutExtensions,
} from '@clerk/shared/types';
import { isWebAuthnAutofillSupported } from '@clerk/shared/webauthn';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

Expand All @@ -22,7 +26,7 @@ vi.mock('@clerk/shared/webauthn', () => ({

const HELLO_B64URL = 'aGVsbG8';

const creationOptions = () =>
const creationOptions = (): PublicKeyCredentialCreationOptionsWithoutExtensions =>
({
rp: { id: 'example.com', name: 'Example' },
user: { id: new Uint8Array([1]).buffer, name: 'jdoe', displayName: 'J Doe' },
Expand All @@ -37,28 +41,26 @@ const creationOptions = () =>
},
attestation: 'none',
excludeCredentials: [],
}) as never;
}) as PublicKeyCredentialCreationOptionsWithoutExtensions;
Comment thread
Ephem marked this conversation as resolved.

const requestOptions = () =>
const requestOptions = (): PublicKeyCredentialRequestOptionsWithoutExtensions =>
({
challenge: new Uint8Array([1, 2, 3]).buffer,
rpId: 'example.com',
timeout: 60_000,
userVerification: 'required',
allowCredentials: [],
}) as never;
}) as PublicKeyCredentialRequestOptionsWithoutExtensions;

const creationOptionsForRpId = (rpId: string) =>
({
...creationOptions(),
rp: { id: rpId, name: 'Example' },
}) as never;
const creationOptionsForRpId = (rpId: string): PublicKeyCredentialCreationOptionsWithoutExtensions => ({
...creationOptions(),
rp: { id: rpId, name: 'Example' },
});

const requestOptionsForRpId = (rpId: string) =>
({
...requestOptions(),
rpId,
}) as never;
const requestOptionsForRpId = (rpId: string): PublicKeyCredentialRequestOptionsWithoutExtensions => ({
...requestOptions(),
rpId,
});

const registrationJSON = {
id: HELLO_B64URL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ describe('Electron ClerkProvider', () => {
tokenCache.getToken.mockResolvedValue('client-jwt');
renderToStaticMarkup(<ClerkProvider publishableKey='pk_test_before_request'>App</ClerkProvider>);

const request = {
const request: { credentials?: RequestCredentials; headers: Headers; url: URL } = {
headers: new Headers(),
url: new URL('https://api.clerk.test/v1/client'),
};
Expand Down
18 changes: 0 additions & 18 deletions packages/electron/tsconfig.base.json

This file was deleted.

19 changes: 15 additions & 4 deletions packages/electron/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"target": "ES2019",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "preserve",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"declaration": true,
"declarationDir": "dist/types",
"declarationMap": true,
"emitDeclarationOnly": true,
"rootDir": "./src"
},
"include": ["src"],
"exclude": ["src/**/__tests__/**"],
"references": [{ "path": "./tsconfig.test.json" }]
"include": ["src"]
}
13 changes: 0 additions & 13 deletions packages/electron/tsconfig.test.json

This file was deleted.

Loading