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
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/compass-connections/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,14 @@
"test-ci": "npm run test-cov",
"test-ci-electron": "npm run test-electron",
"reformat": "npm run eslint . -- --fix && npm run prettier -- --write .",
"typecheck": "echo \"TODO(COMPASS-9897): typecheck is failing in test files\" && tsc -p tsconfig-build.json --noEmit"
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@mongodb-js/compass-app-registry": "^9.4.28",
"@mongodb-js/compass-assistant": "^1.19.0",
"@mongodb-js/compass-components": "^1.59.0",
"@mongodb-js/compass-logging": "^1.7.24",
"@mongodb-js/compass-telemetry": "^1.19.3",
"@mongodb-js/compass-utils": "^0.9.22",
"@mongodb-js/connection-form": "^1.74.0",
"@mongodb-js/connection-info": "^0.23.0",
"@mongodb-js/connection-storage": "^0.62.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
import type { ConnectionInfo } from '@mongodb-js/connection-info';
import { getConnectionTitle } from '@mongodb-js/connection-info';
import ConnectionString from 'mongodb-connection-string-url';
import { isCancelError } from '@mongodb-js/compass-utils';

export function isOIDCAuth(connectionString: string): boolean {
const authMechanismString = (
Expand All @@ -25,10 +24,6 @@ export function isOIDCAuth(connectionString: string): boolean {
return authMechanismString === 'MONGODB-OIDC';
}

export function getConnectionErrorMessage(err?: any) {
return isCancelError(err) ? null : err?.message ?? null;
}

export function getConnectingStatusText(connectionInfo: ConnectionInfo) {
const connectionTitle = getConnectionTitle(connectionInfo);
const isOIDC = isOIDCAuth(connectionInfo.connectionOptions.connectionString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type ConnectionScopedAppRegistry<
Partial<Pick<ConnectionScopedAppRegistryImpl<T>, L>>;

interface EventForwarder<T extends string> {
emit(event: T, ...payload: any[]): void;
emit(event: T, ...payload: unknown[]): void;
}

export class ConnectionScopedAppRegistryImpl<T extends string>
Expand All @@ -43,7 +43,7 @@ export class ConnectionScopedAppRegistryImpl<T extends string>
* to understand how other plugins communicate with these plugins without
* relying on AppRegistry events.
*/
emit(event: T, ...payload: any[]): void {
emit(event: T, ...payload: unknown[]): void {
const connectionId = this.connectionInfoRef.current.id;
this.appRegistryEmitter(event, ...payload, { connectionId });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const mockConnections: ConnectionInfo[] = [
globalWrites: false,
rollingIndexes: false,
},
userConnectionString: 'mongodb+srv://foo',
},
},
{
Expand All @@ -52,6 +53,7 @@ const mockConnections: ConnectionInfo[] = [
globalWrites: false,
rollingIndexes: false,
},
userConnectionString: 'mongodb+srv://foo',
},
},
{
Expand All @@ -74,6 +76,7 @@ const mockConnections: ConnectionInfo[] = [
globalWrites: false,
rollingIndexes: false,
},
userConnectionString: 'mongodb+srv://foo',
},
},
{
Expand All @@ -96,6 +99,7 @@ const mockConnections: ConnectionInfo[] = [
globalWrites: false,
rollingIndexes: true,
},
userConnectionString: 'mongodb+srv://foo',
},
},
{
Expand All @@ -118,6 +122,7 @@ const mockConnections: ConnectionInfo[] = [
globalWrites: false,
rollingIndexes: true,
},
userConnectionString: 'mongodb+srv://foo',
},
},
{
Expand All @@ -140,6 +145,7 @@ const mockConnections: ConnectionInfo[] = [
globalWrites: true,
rollingIndexes: true,
},
userConnectionString: 'mongodb+srv://foo',
},
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('useConnectionsWithStatus', function () {
}
);

function getConnectionById(id) {
function getConnectionById(id: string) {
return result.current.find((conn) => {
return conn.connectionInfo.id === id;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ describe('CompassConnections store', function () {
});

it('should show device auth code modal when OIDC flow triggers the notification', async function () {
let resolveConnect;
let resolveConnect: undefined | (() => void);
const connectFn = sinon.stub().callsFake(() => {
return new Promise((resolve) => {
resolveConnect = () => resolve({});
Expand Down Expand Up @@ -278,6 +278,7 @@ describe('CompassConnections store', function () {
expect(screen.getByText('ABCabc123')).to.exist;
});

if (!resolveConnect) throw new Error('resolveConnect is not defined');
resolveConnect();

await connectPromise;
Expand Down Expand Up @@ -373,7 +374,8 @@ describe('CompassConnections store', function () {
});

// Send a heartbeat fail with an error that's not a non-retryable error code.
dataService['emit']('serverHeartbeatFailed', {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(dataService as any)['emit']('serverHeartbeatFailed', {
failure: new Error('code: 1234, Not the error we are looking for'),
});

Expand Down Expand Up @@ -413,7 +415,8 @@ describe('CompassConnections store', function () {
dataService.isConnected = () => true;

// Send a heartbeat fail with an error that's a non-retryable error code.
dataService['emit']('serverHeartbeatFailed', {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(dataService as any)['emit']('serverHeartbeatFailed', {
failure: new Error('code: 3003, reason: Insufficient permissions'),
});

Expand Down Expand Up @@ -497,10 +500,12 @@ describe('CompassConnections store', function () {
// proceeding
connectionsStore.actions.createNewConnection();

const connectionInfoId =
connectionsStore.getState().editingConnectionInfoId;
if (!connectionInfoId) throw new Error('No editingConnectionInfoId set');

const editingConnection =
connectionsStore.getState().connections.byId[
connectionsStore.getState().editingConnectionInfoId
];
connectionsStore.getState().connections.byId[connectionInfoId];

const newConnection = {
...editingConnection.info,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { connectionSupports } from './connection-supports';
import { type ConnectionInfo } from '@mongodb-js/connection-storage/provider';
import { expect } from 'chai';

const mockConnections = [
const mockConnections: ConnectionInfo[] = [
{
id: 'no-atlasMetadata',
connectionOptions: {
Expand All @@ -29,6 +29,7 @@ const mockConnections = [
globalWrites: false,
rollingIndexes: false,
},
userConnectionString: 'mongodb+srv://foo',
},
},
{
Expand All @@ -51,6 +52,7 @@ const mockConnections = [
globalWrites: false,
rollingIndexes: false,
},
userConnectionString: 'mongodb+srv://foo',
},
},
{
Expand All @@ -73,6 +75,7 @@ const mockConnections = [
globalWrites: false,
rollingIndexes: false,
},
userConnectionString: 'mongodb+srv://foo',
},
},
{
Expand All @@ -95,6 +98,7 @@ const mockConnections = [
globalWrites: false,
rollingIndexes: true,
},
userConnectionString: 'mongodb+srv://foo',
},
},
{
Expand All @@ -117,6 +121,7 @@ const mockConnections = [
globalWrites: false,
rollingIndexes: true,
},
userConnectionString: 'mongodb+srv://foo',
},
},
{
Expand All @@ -139,6 +144,7 @@ const mockConnections = [
globalWrites: true,
rollingIndexes: true,
},
userConnectionString: 'mongodb+srv://foo',
},
},
{
Expand All @@ -161,6 +167,7 @@ const mockConnections = [
globalWrites: false,
rollingIndexes: true,
},
userConnectionString: 'mongodb+srv://foo',
},
},
{
Expand All @@ -183,6 +190,7 @@ const mockConnections = [
globalWrites: false,
rollingIndexes: false,
},
userConnectionString: 'mongodb+srv://foo',
},
},
] as const;
Expand Down
14 changes: 9 additions & 5 deletions packages/compass-connections/src/utils/telemetry.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { expect } from 'chai';
import type { ConnectionInfo } from '@mongodb-js/connection-storage/renderer';
import { createIpcTrack } from '@mongodb-js/compass-telemetry';

type ErrorWithCause = Error & { cause?: ErrorWithCause };

describe('Connections telemetry', function () {
const connectionInfo: ConnectionInfo = {
id: 'TEST',
Expand Down Expand Up @@ -78,26 +80,28 @@ describe('Connections telemetry', function () {
});

it('should return an array with the error code', function () {
const error: any = new Error('Test error');
const error: Error & { code?: number } = new Error('Test error');
error.code = 123;

const result = getErrorCodeCauseChain(error);
expect(result).to.deep.equal([123]);
});

it('should return an array of error codes from the cause chain', function () {
const error: Error & { code?: number } = new Error('Test error');
const error: ErrorWithCause & { code?: number } = new Error('Test error');
error.code = 123;

// No code / codeName on error two.
const errorTwo = new Error('Test error two');
const errorTwo: ErrorWithCause = new Error('Test error two');

const errorThree: Error & { codeName?: string } = new Error(
const errorThree: ErrorWithCause & { codeName?: string } = new Error(
'Test error three'
);
errorThree.codeName = 'PINEAPPLE';

const errorFour: Error & { code?: number } = new Error('Test error four');
const errorFour: ErrorWithCause & {
code?: number;
} = new Error('Test error four');
errorFour.code = 1111;

error.cause = errorTwo;
Expand Down
Loading