Skip to content

Commit

Permalink
chore: updated to use v2 feature endpoints (#429)
Browse files Browse the repository at this point in the history
* chore: updated to use v2 feature endpoints

* chore: fixed feature create test for v2

* chore: fixed features get

* chore: moved mockfeatures to test utils

* chore: fixed feature update tests

* chore: fixed variables create tests

* chore: fixed variations test

* chore: fix associating variable to existing feature

* chore: fix associating new variable with feature
  • Loading branch information
jsalaber authored Sep 9, 2024
1 parent 774801f commit 3e4b376
Show file tree
Hide file tree
Showing 23 changed files with 579 additions and 284 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ $ npm install -g @devcycle/cli
$ dvc COMMAND
running command...
$ dvc (--version)
@devcycle/cli/5.17.0 linux-x64 node-v20.10.0
@devcycle/cli/5.17.0 darwin-arm64 node-v18.17.0
$ dvc --help [COMMAND]
USAGE
$ dvc COMMAND
Expand Down
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

0 comments on commit 3e4b376

Please sign in to comment.