File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed
packages/auto-drive/src/api Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { ArgsWithoutPagination, ArgsWithPagination } from '../../utils/types'
2
2
import { AutoDriveApi } from '../connection'
3
3
import { PaginatedResult } from '../models/common'
4
4
import { ObjectInformation , ObjectSummary , Scope } from '../models/objects'
5
+ import { UserInfo } from '../models/user'
5
6
6
7
/**
7
8
* Retrieves the root objects based on the specified scope.
@@ -193,3 +194,21 @@ export const getObjectMetadata = async (
193
194
194
195
return response . json ( )
195
196
}
197
+
198
+ /**
199
+ * Get upload and download limits of the user
200
+ *
201
+ * @param {AutoDriveApi } api - The API instance used to send requests.
202
+ * @returns {Promise<UserInfo> } - A promise that resolves to the user info.
203
+ * @throws {Error } - Throws an error if the request fails.
204
+ */
205
+ export const getMe = async ( api : AutoDriveApi ) : Promise < UserInfo > => {
206
+ const response = await api . sendRequest ( '@me' , {
207
+ method : 'GET' ,
208
+ } )
209
+ if ( ! response . ok ) {
210
+ throw new Error ( `Failed to get limits: ${ response . statusText } ` )
211
+ }
212
+
213
+ return response . json ( )
214
+ }
Original file line number Diff line number Diff line change
1
+ export type SubscriptionGranularity = 'monthly'
2
+
3
+ export type SubscriptionInfo = {
4
+ id : string
5
+ organizationId : string
6
+ uploadLimit : number
7
+ downloadLimit : number
8
+ granularity : SubscriptionGranularity
9
+ pendingUploadCredits : number
10
+ pendingDownloadCredits : number
11
+ }
12
+
13
+ export enum UserRole {
14
+ User = 'User' ,
15
+ Admin = 'Admin' ,
16
+ }
17
+
18
+ export type User = {
19
+ oauthProvider : string
20
+ oauthUserId : string
21
+ role : UserRole
22
+ downloadCredits : number
23
+ uploadCredits : number
24
+ publicId : string
25
+ onboarded : true
26
+ }
27
+
28
+ export type UserInfo = {
29
+ user : User
30
+ subscription : SubscriptionInfo
31
+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { apiCalls } from './calls/index'
5
5
import { AutoDriveApi } from './connection'
6
6
import { GenericFile , GenericFileWithinFolder } from './models/file'
7
7
import { constructFromInput , constructZipBlobFromTreeAndPaths } from './models/folderTree'
8
+ import { SubscriptionInfo } from './models/user'
8
9
9
10
export type UploadFileOptions = {
10
11
password ?: string
@@ -375,3 +376,19 @@ export const downloadFile = async (
375
376
376
377
return iterable
377
378
}
379
+
380
+ export const getPendingCredits = async (
381
+ api : AutoDriveApi ,
382
+ ) : Promise < { upload : number ; download : number } > => {
383
+ const me = await apiCalls . getMe ( api )
384
+ return {
385
+ upload : me . subscription . pendingUploadCredits ,
386
+ download : me . subscription . pendingDownloadCredits ,
387
+ }
388
+ }
389
+
390
+ export const getSubscriptionInfo = async ( api : AutoDriveApi ) : Promise < SubscriptionInfo > => {
391
+ const me = await apiCalls . getMe ( api )
392
+
393
+ return me . subscription
394
+ }
You can’t perform that action at this time.
0 commit comments