Skip to content

Commit 48f40c4

Browse files
committed
1 parent d03b8fc commit 48f40c4

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

src/management/__generated/managers/sessions-manager.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { InitOverride, ApiResponse } from '../../../lib/runtime.js';
33
import type {
44
GetSession200Response,
55
DeleteSessionRequest,
6+
RevokeSessionRequest,
67
GetSessionRequest,
78
} from '../models/index.js';
89

@@ -35,6 +36,31 @@ export class SessionsManager extends BaseAPI {
3536
return runtime.VoidApiResponse.fromResponse(response);
3637
}
3738

39+
/**
40+
* Revokes a session by ID and all associated refresh tokens.
41+
*
42+
* @throws {RequiredError}
43+
*/
44+
async revoke(
45+
requestParameters: RevokeSessionRequest,
46+
initOverrides?: InitOverride
47+
): Promise<ApiResponse<void>> {
48+
runtime.validateRequiredRequestParams(requestParameters, ['id']);
49+
50+
const response = await this.request(
51+
{
52+
path: `/sessions/{id}/revoke`.replace(
53+
'{id}',
54+
encodeURIComponent(String(requestParameters.id))
55+
),
56+
method: 'POST',
57+
},
58+
initOverrides
59+
);
60+
61+
return runtime.VoidApiResponse.fromResponse(response);
62+
}
63+
3864
/**
3965
* Retrieve session information.
4066
* Get session

src/management/__generated/models/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20741,6 +20741,16 @@ export interface DeleteSessionRequest {
2074120741
*/
2074220742
id: string;
2074320743
}
20744+
/**
20745+
*
20746+
*/
20747+
export interface RevokeSessionRequest {
20748+
/**
20749+
* ID of the session to revoke.
20750+
*
20751+
*/
20752+
id: string;
20753+
}
2074420754
/**
2074520755
*
2074620756
*/

test/management/sessions.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,54 @@ describe('SessionsManager', () => {
133133
sessions.delete({ id }).then(() => {
134134
expect(request.isDone()).toBe(true);
135135

136+
done();
137+
});
138+
});
139+
});
140+
describe('#revoke', () => {
141+
const id = '6';
142+
143+
let request: nock.Scope;
144+
145+
beforeEach(() => {
146+
request = nock(API_URL).post(`/sessions/${id}/revoke`).reply(200, {});
147+
});
148+
149+
it('should return a promise when no callback is given', (done) => {
150+
sessions.revoke({ id }).then(done.bind(null, null));
151+
});
152+
153+
it(`should perform a revoke request to /sessions/${id}/revoke`, (done) => {
154+
sessions.revoke({ id }).then(() => {
155+
expect(request.isDone()).toBe(true);
156+
157+
done();
158+
});
159+
});
160+
161+
it('should pass any errors to the promise catch handler', (done) => {
162+
nock.cleanAll();
163+
164+
nock(API_URL).post(`/sessions/${id}/revoke`).reply(500, {});
165+
166+
sessions.revoke({ id }).catch((err) => {
167+
expect(err).toBeDefined();
168+
169+
done();
170+
});
171+
});
172+
173+
it('should include the token in the authorization header', (done) => {
174+
nock.cleanAll();
175+
176+
const request = nock(API_URL)
177+
.post(`/sessions/${id}/revoke`)
178+
.matchHeader('authorization', `Bearer ${token}`)
179+
.reply(200, {});
180+
181+
sessions.revoke({ id }).then(() => {
182+
expect(request.isDone()).toBe(true);
183+
136184
done();
137185
});
138186
});

0 commit comments

Comments
 (0)