Skip to content

Commit bf97c0f

Browse files
authored
feat: add user.updateLimits (#595)
Resolves #329 - add `updateLimits` function to `UserClient`, which does `PUT: /v2/users/:userId/limits` Api docs PR here: apify/openapi#103 Endpoint is already implemented, only api docs and client was missing
1 parent 2d73366 commit bf97c0f

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/resource_clients/user.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ export class UserClient extends ResourceClient {
6464

6565
return undefined;
6666
}
67+
68+
/**
69+
* https://docs.apify.com/api/v2/#/reference/users/account-and-usage-limits
70+
*/
71+
async updateLimits(options: LimitsUpdateOptions): Promise<void> {
72+
const requestOpts: ApifyRequestConfig = {
73+
url: this._url('limits'),
74+
method: 'PUT',
75+
params: this._params(),
76+
data: options,
77+
};
78+
await this.httpClient.call(requestOpts);
79+
}
6780
}
6881

6982
//
@@ -207,6 +220,8 @@ export interface Limits {
207220
dataRetentionDays: number;
208221
}
209222

223+
export type LimitsUpdateOptions = Pick<Limits, 'maxMonthlyUsageUsd' | 'dataRetentionDays'>
224+
210225
export interface Current {
211226
monthlyUsageUsd: number;
212227
monthlyActorComputeUnits: number;

test/mock_server/routes/users.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const ROUTES = [
88
{ id: 'get-user', method: 'GET', path: '/:userId' },
99
{ id: 'get-monthly-usage', method: 'GET', path: '/:userId/usage/monthly' },
1010
{ id: 'get-limits', method: 'GET', path: '/:userId/limits' },
11+
{ id: 'update-limits', method: 'PUT', path: '/:userId/limits' },
1112
];
1213

1314
addRoutes(users, ROUTES);

test/users.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,17 @@ describe('User methods', () => {
8282
expect(browserRes).toEqual(res);
8383
validateRequest({}, { userId });
8484
});
85+
86+
test('updateLimits() works', async () => {
87+
const userId = 'me';
88+
89+
const res = await client.user(userId).updateLimits({ maxMonthlyUsageUsd: 1000 });
90+
expect(res).toBeUndefined();
91+
validateRequest({}, { userId }, { maxMonthlyUsageUsd: 1000 });
92+
93+
const browserRes = await page.evaluate((id) => client.user(id).updateLimits({ maxMonthlyUsageUsd: 1000 }), userId);
94+
expect(browserRes).toBeUndefined();
95+
validateRequest({}, { userId }, { maxMonthlyUsageUsd: 1000 });
96+
});
8597
});
8698
});

0 commit comments

Comments
 (0)