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
12 changes: 12 additions & 0 deletions src/sso/sso.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,18 @@ describe('SSO', () => {
});
});

describe('deleteConnection', () => {
it('sends request to delete a Connection', async () => {
const mock = new MockAdapter(axios);
mock.onDelete().reply(200, {});
const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');

await workos.sso.deleteConnection('conn_123');

expect(mock.history.delete[0].url).toEqual('/connections/conn_123');
});
});

describe('getConnection', () => {
it(`requests a Connection`, async () => {
const mock = new MockAdapter(axios);
Expand Down
4 changes: 4 additions & 0 deletions src/sso/sso.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export class SSO {
return data;
}

async deleteConnection(id: string) {
await this.workos.delete(`/connections/${id}`);
}

getAuthorizationURL({
clientID,
domain,
Expand Down
34 changes: 34 additions & 0 deletions src/workos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,40 @@ export class WorkOS {
}
}

async delete(path: string, query?: any): Promise<AxiosResponse> {
try {
return await this.client.delete(path, {
params: query,
});
} catch (error) {
const { response } = error as AxiosError;

if (response) {
const { status, data, headers } = response;
const requestID = headers['X-Request-ID'];

switch (status) {
case 401: {
throw new UnauthorizedException(requestID);
}
case 422: {
const { errors } = data;

throw new UnprocessableEntityException(errors, requestID);
}
case 404: {
throw new NotFoundException(path, requestID);
}
default: {
throw new GenericServerException(status, data.message, requestID);
}
}
}

throw error;
}
}

emitWarning(warning: string) {
if (typeof process.emitWarning !== 'function') {
// tslint:disable:no-console
Expand Down