Skip to content

Commit

Permalink
feat: Add support for self serve betas endpoints (#9386)
Browse files Browse the repository at this point in the history
Adds support for the self serve beta endpoints

Co-authored-by: Dajahi Wiley <114682940+dwiley-akamai@users.noreply.github.com>
  • Loading branch information
CodyFinn-Akamai and dwiley-akamai authored Jul 20, 2023
1 parent 40c6a91 commit 19ecd06
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/api-v4/.changeset/pr-9386-added-1689191794116.md
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))
49 changes: 49 additions & 0 deletions packages/api-v4/src/account/betas.ts
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)
);
2 changes: 2 additions & 0 deletions packages/api-v4/src/account/index.ts
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';
Expand Down
9 changes: 9 additions & 0 deletions packages/api-v4/src/account/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { APIWarning } from '../types';
import { Beta } from '../betas/types';

export interface User {
username: string;
Expand Down Expand Up @@ -454,3 +455,11 @@ export interface AccountLogin {
username: string;
status: AccountLoginStatus;
}

export interface AccountBeta extends Beta {
enrolled: string;
}

export interface EnrollInBetaPayload {
id: string;
}
32 changes: 32 additions & 0 deletions packages/api-v4/src/betas/betas.ts
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')
);
3 changes: 3 additions & 0 deletions packages/api-v4/src/betas/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './types';

export * from './betas';
8 changes: 8 additions & 0 deletions packages/api-v4/src/betas/types.ts
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;
}
2 changes: 2 additions & 0 deletions packages/api-v4/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export * from './volumes';

export * from './vpcs';

export * from './betas';

export {
baseRequest,
setToken,
Expand Down
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-9386-added-1689191860871.md
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))
14 changes: 14 additions & 0 deletions packages/manager/src/factories/betas.ts
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(),
});
1 change: 1 addition & 0 deletions packages/manager/src/factories/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './accountMaintenance';
export * from './accountOAuth';
export * from './accountPayment';
export * from './aglb';
export * from './betas';
export * from './billing';
export * from './config';
export * from './databases';
Expand Down
17 changes: 17 additions & 0 deletions packages/manager/src/mocks/serverHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import { MockData } from 'src/dev-tools/mockDataController';
import {
VLANFactory,
abuseTicketNotificationFactory,
accountBetaFactory,
accountFactory,
accountMaintenanceFactory,
accountTransferFactory,
appTokenFactory,
betaFactory,
contactFactory,
createEntrypointFactory,
createLoadbalancerFactory,
Expand Down Expand Up @@ -1353,6 +1355,21 @@ export const handlers = [
rest.delete('*/profile/tokens/:id', (req, res, ctx) => {
return res(ctx.json({}));
}),
rest.get('*/betas', (req, res, ctx) => {
return res(ctx.json(makeResourcePage(betaFactory.buildList(5))));
}),
rest.get('*/betas/:id', (req, res, ctx) => {
return res(ctx.json(betaFactory.build({ id: req.params.id })));
}),
rest.get('*/account/betas', (req, res, ctx) => {
return res(ctx.json(makeResourcePage(accountBetaFactory.buildList(5))));
}),
rest.get('*/account/betas/:id', (req, res, ctx) => {
return res(ctx.json(accountBetaFactory.build({ id: req.params.id })));
}),
rest.post('*/account/betas', (req, res, ctx) => {
return res(ctx.json({}));
}),
...entityTransfers,
...statusPage,
...databases,
Expand Down
44 changes: 44 additions & 0 deletions packages/manager/src/queries/accountBetas.ts
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']);
},
}
);
};
22 changes: 22 additions & 0 deletions packages/manager/src/queries/betas.ts
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));

0 comments on commit 19ecd06

Please sign in to comment.