Skip to content

Commit

Permalink
feat: add user.updateLimits (#595)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MFori authored Oct 24, 2024
1 parent 2d73366 commit bf97c0f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/resource_clients/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ export class UserClient extends ResourceClient {

return undefined;
}

/**
* https://docs.apify.com/api/v2/#/reference/users/account-and-usage-limits
*/
async updateLimits(options: LimitsUpdateOptions): Promise<void> {
const requestOpts: ApifyRequestConfig = {
url: this._url('limits'),
method: 'PUT',
params: this._params(),
data: options,
};
await this.httpClient.call(requestOpts);
}
}

//
Expand Down Expand Up @@ -207,6 +220,8 @@ export interface Limits {
dataRetentionDays: number;
}

export type LimitsUpdateOptions = Pick<Limits, 'maxMonthlyUsageUsd' | 'dataRetentionDays'>

export interface Current {
monthlyUsageUsd: number;
monthlyActorComputeUnits: number;
Expand Down
1 change: 1 addition & 0 deletions test/mock_server/routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const ROUTES = [
{ id: 'get-user', method: 'GET', path: '/:userId' },
{ id: 'get-monthly-usage', method: 'GET', path: '/:userId/usage/monthly' },
{ id: 'get-limits', method: 'GET', path: '/:userId/limits' },
{ id: 'update-limits', method: 'PUT', path: '/:userId/limits' },
];

addRoutes(users, ROUTES);
Expand Down
12 changes: 12 additions & 0 deletions test/users.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,17 @@ describe('User methods', () => {
expect(browserRes).toEqual(res);
validateRequest({}, { userId });
});

test('updateLimits() works', async () => {
const userId = 'me';

const res = await client.user(userId).updateLimits({ maxMonthlyUsageUsd: 1000 });
expect(res).toBeUndefined();
validateRequest({}, { userId }, { maxMonthlyUsageUsd: 1000 });

const browserRes = await page.evaluate((id) => client.user(id).updateLimits({ maxMonthlyUsageUsd: 1000 }), userId);
expect(browserRes).toBeUndefined();
validateRequest({}, { userId }, { maxMonthlyUsageUsd: 1000 });
});
});
});

0 comments on commit bf97c0f

Please sign in to comment.