Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: updated to use v2 feature endpoints #429

Merged
merged 9 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion oclif.manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "5.16.2",
"version": "5.17.0",
"commands": {
"authCommand": {
"id": "authCommand",
Expand Down
4 changes: 3 additions & 1 deletion src/api/apiClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios, { AxiosError } from 'axios'
import { BASE_URL } from './common'
import { createApiClient } from './zodClient'
import { createApiClient, createV2ApiClient } from './zodClient'
import { ZodIssueCode, ZodIssueOptionalMessage, ErrorMapCtx } from 'zod'

export const axiosClient = axios.create({
Expand Down Expand Up @@ -98,3 +98,5 @@ export const apiClient = createApiClient(BASE_URL, {
validate: 'request',
})
export default apiClient

export const v2ApiClient = createV2ApiClient(BASE_URL)
53 changes: 38 additions & 15 deletions src/api/features.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { AxiosError } from 'axios'
import apiClient, { axiosClient } from './apiClient'
import {
v2ApiClient as apiClient,
apiClient as apiV1Client,
axiosClient,
} from './apiClient'
import { CreateFeatureParams, Feature, UpdateFeatureParams } from './schemas'
import 'reflect-metadata'
import { buildHeaders } from './common'

const FEATURE_URL = '/v1/projects/:project/features'
const FEATURE_URL = '/v2/projects/:project/features'

export const fetchFeatures = async (
token: string,
Expand Down Expand Up @@ -69,11 +73,11 @@ export const updateFeature = async (
feature_id: string,
params: UpdateFeatureParams,
): Promise<Feature> => {
return await apiClient.patch(`${FEATURE_URL}/:key`, params, {
return await apiClient.patch(`${FEATURE_URL}/:feature`, params, {
headers: buildHeaders(token),
params: {
project: project_id,
key: feature_id,
feature: feature_id,
},
})
}
Expand All @@ -83,22 +87,36 @@ export const deleteFeature = async (
project_id: string,
key: string,
): Promise<void> => {
return apiClient.delete(`${FEATURE_URL}/:key`, undefined, {
headers: buildHeaders(token),
params: {
project: project_id,
key,
return apiV1Client.delete(
'/v1/projects/:project/features/:key',
undefined,
{
headers: buildHeaders(token),
params: {
project: project_id,
key,
},
},
})
)
}

export const fetchAllCompletedOrArchivedFeatures = async (token: string, project_id: string): Promise<Feature[]> => {
export const fetchAllCompletedOrArchivedFeatures = async (
token: string,
project_id: string,
): Promise<Feature[]> => {
const statuses = ['complete', 'archived']
const perPage = 1000
const firstPage = 1

const fetchFeaturesForStatus = async (status: string): Promise<Feature[]> => {
const url = generatePaginatedFeatureUrl(project_id, firstPage, perPage, status)
const fetchFeaturesForStatus = async (
status: string,
): Promise<Feature[]> => {
const url = generatePaginatedFeatureUrl(
project_id,
firstPage,
perPage,
status,
)
const response = await axiosClient.get(url, {
headers: buildHeaders(token),
})
Expand All @@ -108,7 +126,12 @@ export const fetchAllCompletedOrArchivedFeatures = async (token: string, project
const totalPages = Math.ceil(total / perPage)

const promises = Array.from({ length: totalPages - 1 }, (_, i) => {
const url = generatePaginatedFeatureUrl(project_id, i + 2, perPage, status)
const url = generatePaginatedFeatureUrl(
project_id,
i + 2,
perPage,
status,
)
return axiosClient.get(url, {
headers: buildHeaders(token),
})
Expand All @@ -128,7 +151,7 @@ const generatePaginatedFeatureUrl = (
project_id: string,
page: number,
perPage: number,
status: string
status: string,
): string => {
return `/v1/projects/${project_id}/features?perPage=${perPage}&page=${page}&status=${status}`
}
4 changes: 2 additions & 2 deletions src/api/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export const CreateVariableDto = schemas.CreateVariableDto
export type UpdateVariableParams = z.infer<typeof schemas.UpdateVariableDto>
export const UpdateVariableDto = schemas.UpdateVariableDto

export type CreateVariationParams = z.infer<typeof schemas.FeatureVariationDto>
export const CreateVariationDto = schemas.FeatureVariationDto
export type CreateVariationParams = z.infer<typeof schemas.CreateVariationDto>
export const CreateVariationDto = schemas.CreateVariationDto

export type UpdateVariationParams = Partial<CreateVariationParams>

Expand Down
1 change: 1 addition & 0 deletions src/api/variations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import apiClient from './apiClient'
import { CreateVariationParams, Feature, Variation } from './schemas'
import { buildHeaders } from './common'

// TODO: Update these functions to use the new v2 API client once the v2 variations endpoint is implemented
const variationsUrl = '/v1/projects/:project/features/:feature/variations'
export class UpdateVariationParams {
@IsString()
Expand Down
Loading