-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for self serve betas endpoints (#9386)
Adds support for the self serve beta endpoints Co-authored-by: Dajahi Wiley <114682940+dwiley-akamai@users.noreply.github.com>
- Loading branch information
1 parent
40c6a91
commit 19ecd06
Showing
14 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/api-v4": Added | ||
--- | ||
|
||
Support for self serve beta endpoints ([#9386](https://github.com/linode/manager/pull/9386)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { API_ROOT } from '../constants'; | ||
import Request, { | ||
setMethod, | ||
setParams, | ||
setURL, | ||
setXFilter, | ||
setData, | ||
} from '../request'; | ||
import { Filter, Params, ResourcePage } from '../types'; | ||
import { AccountBeta, EnrollInBetaPayload } from './types'; | ||
|
||
/** | ||
* getBetas | ||
* Retrieve a paginated list of betas your account is enrolled in. | ||
* | ||
*/ | ||
export const getAccountBetas = (params?: Params, filter?: Filter) => | ||
Request<ResourcePage<AccountBeta>>( | ||
setURL(`${API_ROOT}/account/betas`), | ||
setMethod('GET'), | ||
setParams(params), | ||
setXFilter(filter) | ||
); | ||
|
||
/** | ||
* getBeta | ||
* Retrieve details of a single beta your account is enrolled in. | ||
* @param betaId { string } The ID of the beta you want to be retrieved | ||
* | ||
*/ | ||
export const getAccountBeta = (betaId: string) => | ||
Request<AccountBeta>( | ||
setURL(`${API_ROOT}/account/betas/${encodeURIComponent(betaId)}`), | ||
setMethod('GET') | ||
); | ||
|
||
/** | ||
* enrollInBeta | ||
* Enrolls your account in the specified beta program. | ||
* @param data { object } | ||
* @param data.id { string } ID of the beta you want to be enrolled in. | ||
* | ||
*/ | ||
export const enrollInBeta = (data: EnrollInBetaPayload) => | ||
Request<{}>( | ||
setURL(`${API_ROOT}/account/betas`), | ||
setMethod('POST'), | ||
setData(data) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
export * from './account'; | ||
|
||
export * from './betas'; | ||
|
||
export * from './events'; | ||
|
||
export * from './invoices'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { API_ROOT } from '../constants'; | ||
import Request, { setMethod, setParams, setURL, setXFilter } from '../request'; | ||
import { Filter, Params, ResourcePage } from '../types'; | ||
import { Beta } from './types'; | ||
|
||
/** | ||
* getBetas | ||
* | ||
* Retrieve a paginated list of active beta programs. | ||
* | ||
**/ | ||
export const getBetas = (params?: Params, filter?: Filter) => | ||
Request<ResourcePage<Beta>>( | ||
setURL(`${API_ROOT}/betas`), | ||
setMethod('GET'), | ||
setParams(params), | ||
setXFilter(filter) | ||
); | ||
|
||
/** | ||
* getBeta | ||
* | ||
* Retrieve details for a single beta program. | ||
* | ||
* @param betaId { string } The ID of the beta to be retrieved | ||
* | ||
*/ | ||
export const getBeta = (betaId: string) => | ||
Request<Beta>( | ||
setURL(`${API_ROOT}/betas/${encodeURIComponent(betaId)}`), | ||
setMethod('GET') | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './types'; | ||
|
||
export * from './betas'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface Beta { | ||
label: string; | ||
started: string; | ||
id: string; | ||
ended?: string; | ||
more_info?: string; | ||
description?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Added | ||
--- | ||
|
||
Queries, server handlers, and factories for self-serve betas ([#9386](https://github.com/linode/manager/pull/9386)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Beta, AccountBeta } from '@linode/api-v4'; | ||
import * as Factory from 'factory.ts'; | ||
import { DateTime } from 'luxon'; | ||
|
||
export const betaFactory = Factory.Sync.makeFactory<Beta>({ | ||
id: Factory.each((i) => `beta-${i}`), | ||
label: Factory.each((i) => `Beta ${i}`), | ||
started: DateTime.now().toISO(), | ||
}); | ||
|
||
export const accountBetaFactory = Factory.Sync.makeFactory<AccountBeta>({ | ||
...betaFactory.build({ started: DateTime.now().minus({ days: 30 }).toISO() }), | ||
enrolled: DateTime.now().toISO(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { | ||
AccountBeta, | ||
getAccountBetas, | ||
EnrollInBetaPayload, | ||
getAccountBeta, | ||
enrollInBeta, | ||
} from '@linode/api-v4/lib/account'; | ||
import { useQuery, useQueryClient, useMutation } from 'react-query'; | ||
import { | ||
APIError, | ||
Filter, | ||
Params, | ||
ResourcePage, | ||
} from '@linode/api-v4/lib/types'; | ||
|
||
export const queryKey = 'account-betas'; | ||
|
||
export const useAccountBetasQuery = (params?: Params, filter?: Filter) => | ||
useQuery<ResourcePage<AccountBeta>, APIError[]>( | ||
[queryKey, 'paginated', params, filter], | ||
() => getAccountBetas(params, filter), | ||
{ | ||
keepPreviousData: true, | ||
} | ||
); | ||
|
||
export const useAccountBetaQuery = (id: string) => | ||
useQuery<AccountBeta, APIError[]>([queryKey, 'account-beta', id], () => | ||
getAccountBeta(id) | ||
); | ||
|
||
export const useCreateAccountBetaMutation = () => { | ||
const queryClient = useQueryClient(); | ||
return useMutation<{}, APIError[], EnrollInBetaPayload>( | ||
(data) => { | ||
return enrollInBeta(data); | ||
}, | ||
{ | ||
onSuccess() { | ||
queryClient.invalidateQueries([queryKey, 'paginated']); | ||
}, | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Beta, getBetas, getBeta } from '@linode/api-v4/lib/betas'; | ||
import { useQuery } from 'react-query'; | ||
import { | ||
APIError, | ||
Filter, | ||
Params, | ||
ResourcePage, | ||
} from '@linode/api-v4/lib/types'; | ||
|
||
export const queryKey = 'betas'; | ||
|
||
export const useBetasQuery = (params?: Params, filter?: Filter) => | ||
useQuery<ResourcePage<Beta>, APIError[]>( | ||
[queryKey, 'paginated', params, filter], | ||
() => getBetas(params, filter), | ||
{ | ||
keepPreviousData: true, | ||
} | ||
); | ||
|
||
export const useBetaQuery = (id: string) => | ||
useQuery<Beta, APIError[]>([queryKey, 'beta', id], () => getBeta(id)); |