diff --git a/packages/api-client/src/controllers/secret.ts b/packages/api-client/src/controllers/secret.ts index 58516512..1560bd06 100644 --- a/packages/api-client/src/controllers/secret.ts +++ b/packages/api-client/src/controllers/secret.ts @@ -10,6 +10,8 @@ import { GetAllSecretsOfEnvironmentResponse, GetAllSecretsOfProjectRequest, GetAllSecretsOfProjectResponse, + GetRevisionsOfSecretRequest, + GetRevisionsOfSecretResponse, RollBackSecretRequest, RollBackSecretResponse, UpdateSecretRequest, @@ -100,4 +102,17 @@ export default class SecretController { return await parseResponse(response) } + + async getRevisionsOfSecret( + request: GetRevisionsOfSecretRequest, + headers?: Record + ): Promise> { + const url = parsePaginationUrl( + `/api/secret/${request.secretSlug}/revisions/${request.environmentSlug}`, + request + ) + const response = await this.apiClient.get(url, headers) + + return await parseResponse(response) + } } diff --git a/packages/api-client/src/controllers/variable.ts b/packages/api-client/src/controllers/variable.ts index 83a058fb..25256b10 100644 --- a/packages/api-client/src/controllers/variable.ts +++ b/packages/api-client/src/controllers/variable.ts @@ -11,6 +11,8 @@ import { GetAllVariablesOfEnvironmentResponse, GetAllVariablesOfProjectRequest, GetAllVariablesOfProjectResponse, + GetRevisionsOfVariableRequest, + GetRevisionsOfVariableResponse, RollBackVariableRequest, RollBackVariableResponse, UpdateVariableRequest, @@ -96,4 +98,17 @@ export default class VariableController { return await parseResponse(response) } + + async getRevisionsOfVariable( + request: GetRevisionsOfVariableRequest, + headers: Record + ): Promise> { + const url = parsePaginationUrl( + `/api/variable/${request.variableSlug}/revisions/${request.environmentSlug}`, + request + ) + const response = await this.apiClient.get(url, headers) + + return await parseResponse(response) + } } diff --git a/packages/api-client/src/core/pagination-parser.ts b/packages/api-client/src/core/pagination-parser.ts index c9c4307b..b25a1dd8 100644 --- a/packages/api-client/src/core/pagination-parser.ts +++ b/packages/api-client/src/core/pagination-parser.ts @@ -10,7 +10,7 @@ import { PageRequest } from '@api-client/types/index.types' */ export function parsePaginationUrl( baseUrl: string, - request: PageRequest + request: Partial ): string { let url = `${baseUrl}?` request.page && (url += `page=${request.page}&`) diff --git a/packages/api-client/src/types/environment.types.d.ts b/packages/api-client/src/types/environment.types.d.ts index d8d8a545..076ddc32 100644 --- a/packages/api-client/src/types/environment.types.d.ts +++ b/packages/api-client/src/types/environment.types.d.ts @@ -1,12 +1,6 @@ import { PageRequest, PageResponse } from './index.types' -export interface CreateEnvironmentRequest { - name: string - description?: string - projectId: string -} - -export interface CreateEnvironmentResponse { +interface Environment { id: string name: string slug: string @@ -17,57 +11,42 @@ export interface CreateEnvironmentResponse { projectId: string } -export interface UpdateEnvironmentRequest { - slug: string - name?: string +export interface CreateEnvironmentRequest { + name: string description?: string + projectId: string } -export interface UpdateEnvironmentResponse { - id: string - name: string +export interface CreateEnvironmentResponse extends Environment {} + +export interface UpdateEnvironmentRequest + extends Partial> { slug: string - description: string | null - createdAt: string - updatedAt: string - lastUpdatedById: string - projectId: string } +export interface UpdateEnvironmentResponse extends Environment {} + export interface GetEnvironmentRequest { slug: string } -export interface GetEnvironmentResponse { - id: string - name: string - slug: string - description: string | null - createdAt: string - updatedAt: string - lastUpdatedById: string - projectId: string -} +export interface GetEnvironmentResponse extends Environment {} export interface GetAllEnvironmentsOfProjectRequest extends PageRequest { projectSlug: string } export interface GetAllEnvironmentsOfProjectResponse - extends PageResponse<{ - id: string - slug: string - name: string - description: string | null - createdAt: string - updatedAt: string - lastUpdatedBy: { - id: string - name: string - email: string - profilePictureUrl: string | null + extends PageResponse< + Environment & { + lastUpdatedBy: { + id: string + name: string + email: string + profilePictureUrl: string | null + } } - }> {} + > {} export interface DeleteEnvironmentRequest { slug: string diff --git a/packages/api-client/src/types/integration.types.d.ts b/packages/api-client/src/types/integration.types.d.ts index 75b15806..035f5658 100644 --- a/packages/api-client/src/types/integration.types.d.ts +++ b/packages/api-client/src/types/integration.types.d.ts @@ -36,17 +36,8 @@ export enum EventType { INTEGRATION_UPDATED, INTEGRATION_DELETED } -export interface CreateIntegrationRequest { - workspaceSlug?: string - projectSlug?: string - name: string - type: string - notifyOn: [string] - metadata: Record - environmentSlug: string -} -export interface CreateIntegrationResponse { +interface Integration { id: string name: string slug: string @@ -60,31 +51,25 @@ export interface CreateIntegrationResponse { environmentId: string } -export interface UpdateIntegrationRequest { - integrationSlug: string +export interface CreateIntegrationRequest { workspaceSlug?: string projectSlug?: string - name?: string - type?: IntegrationType - notifyOn?: EventType[] - metadata?: Record - environmentId?: string -} - -export interface UpdateIntegrationResponse { - id: string name: string - slug: string + type: string + notifyOn: [string] metadata: Record - createdAt: string - updatedAt: string - type: IntegrationType - notifyOn: EventType[] - workspaceId: string - projectId: string - environmentId: string + environmentSlug: string } +export interface CreateIntegrationResponse extends Integration {} + +export interface UpdateIntegrationRequest + extends Partial> { + integrationSlug: string +} + +export interface UpdateIntegrationResponse extends Integration {} + export interface DeleteIntegrationResponse {} export interface DeleteIntegrationRequest { @@ -95,35 +80,10 @@ export interface GetIntegrationRequest { integrationSlug: string } -export interface GetIntegrationResponse { - id: string - name: string - slug: string - metadata: Record - createdAt: string - updatedAt: string - type: IntegrationType - notifyOn: EventType[] - workspaceId: string - projectId: string - environmentId: string -} +export interface GetIntegrationResponse extends Integration {} export interface GetAllIntegrationRequest extends PageRequest { workspaceSlug: string } -export interface GetAllIntegrationResponse - extends PageResponse<{ - id: string - name: string - slug: string - metadata: Record - createdAt: string - updatedAt: string - type: IntegrationType - notifyOn: EventType[] - workspaceId: string - projectId: string - environmentId: string - }> {} +export interface GetAllIntegrationResponse extends PageResponse {} diff --git a/packages/api-client/src/types/project.types.d.ts b/packages/api-client/src/types/project.types.d.ts index a3569205..55afb05b 100644 --- a/packages/api-client/src/types/project.types.d.ts +++ b/packages/api-client/src/types/project.types.d.ts @@ -1,15 +1,6 @@ import { PageRequest, PageResponse } from './index.types' -export interface CreateProjectRequest { - name: string - workspaceSlug: string - description?: string - storePrivateKey?: boolean - environments?: CreateEnvironment[] - accessLevel: string -} - -export interface CreateProjectResponse { +interface Project { id: string name: string slug: string @@ -28,30 +19,26 @@ export interface CreateProjectResponse { forkedFromId: string } -export interface UpdateProjectRequest { - projectSlug: string - name?: string -} - -export interface UpdateProjectResponse { - id: string +export interface CreateProjectRequest { name: string - slug: string - description: string - createdAt: string - updatedAt: string - publicKey: string - privateKey: string - storePrivateKey: boolean - isDisabled: boolean + workspaceSlug: string + description?: string + storePrivateKey?: boolean + environments?: CreateEnvironment[] accessLevel: string - pendingCreation: boolean - isForked: boolean - lastUpdatedById: string - workspaceId: string - forkedFromId: string } +export interface CreateProjectResponse extends Project {} + +export interface UpdateProjectRequest + extends Partial> { + projectSlug: string + regenerateKeyPair?: boolean + privateKey?: string +} + +export interface UpdateProjectResponse extends Project {} + export interface DeleteProjectRequest { projectSlug: string } @@ -62,24 +49,7 @@ export interface GetProjectRequest { projectSlug: string } -export interface GetProjectResponse { - id: string - name: string - slug: string - description: string - createdAt: string - updatedAt: string - publicKey: string - privateKey: string - storePrivateKey: boolean - isDisabled: boolean - accessLevel: string - pendingCreation: boolean - isForked: boolean - lastUpdatedById: string - workspaceId: string - forkedFromId: string -} +export interface GetProjectResponse extends Project {} export interface ForkProjectRequest { projectSlug: string @@ -88,24 +58,7 @@ export interface ForkProjectRequest { storePrivateKey?: boolean } -export interface ForkProjectResponse { - id: string - name: string - slug: string - description: string - createdAt: string - updatedAt: string - publicKey: string - privateKey: string - storePrivateKey: boolean - isDisabled: boolean - accessLevel: string - pendingCreation: boolean - isForked: boolean - lastUpdatedById: string - workspaceId: string - forkedFromId: string -} +export interface ForkProjectResponse extends Project {} export interface SyncProjectRequest { projectSlug: string @@ -125,44 +78,10 @@ export interface GetForkRequest extends PageRequest { workspaceSlug: string } -export interface GetForkResponse - extends PageResponse<{ - id: string - name: string - slug: string - description: string - createdAt: string - updatedAt: string - publicKey: string - privateKey: string - storePrivateKey: boolean - isDisabled: boolean - accessLevel: string - pendingCreation: boolean - isForked: boolean - lastUpdatedById: string - workspaceId: string - forkedFromId: string - }> {} +export interface GetForkResponse extends PageResponse {} export interface GetAllProjectsRequest extends PageRequest { workspaceSlug: string } -export interface GetAllProjectsResponse - extends PageResponse<{ - id: string - name: string - slug: string - description: string - createdAt: string - updatedAt: string - storePrivateKey: boolean - isDisabled: boolean - accessLevel: string - pendingCreation: boolean - isForked: boolean - lastUpdatedById: string - workspaceId: string - forkedFromId: string - }> {} +export interface GetAllProjectsResponse extends PageResponse {} diff --git a/packages/api-client/src/types/secret.types.d.ts b/packages/api-client/src/types/secret.types.d.ts index 21511a20..4d07a84d 100644 --- a/packages/api-client/src/types/secret.types.d.ts +++ b/packages/api-client/src/types/secret.types.d.ts @@ -1,19 +1,6 @@ import { PageRequest, PageResponse } from './index.types' -export interface CreateSecretRequest { - projectSlug: string - name: string - note?: string - rotateAfter?: '24' | '168' | '720' | '8760' | 'never' - entries?: [ - { - value: string - environmentSlug: string - } - ] -} - -export interface CreateSecretResponse { +interface Secret { id: string name: string slug: string @@ -28,15 +15,16 @@ export interface CreateSecretResponse { } versions: [ { - value: string + id?: string environmentId: string + value: string } ] } -export interface UpdateSecretRequest { - secretSlug: string - name?: string +export interface CreateSecretRequest { + projectSlug: string + name: string note?: string rotateAfter?: '24' | '168' | '720' | '8760' | 'never' entries?: [ @@ -47,13 +35,15 @@ export interface UpdateSecretRequest { ] } +export interface CreateSecretResponse extends Secret {} + +export interface UpdateSecretRequest + extends Partial> { + secretSlug: string +} + export interface UpdateSecretResponse { - secret: { - id: string - name: string - note: string - slug: string - } + secret: Pick updatedVersions: [ { id?: string @@ -83,16 +73,7 @@ export interface GetAllSecretsOfProjectRequest extends PageRequest { } export interface GetAllSecretsOfProjectResponse extends PageResponse<{ - secret: { - id: string - slug: string - name: string - createdAt: string - updatedAt: string - rotateAt: string - note: string | null - lastUpdatedById: string - projectId: string + secret: Omit & { lastUpdatedBy: { id: string name: string @@ -117,3 +98,18 @@ export type GetAllSecretsOfEnvironmentResponse = { value: string isPlaintext: boolean }[] + +export interface GetRevisionsOfSecretRequest extends Partial { + secretSlug: string + environmentSlug: string +} + +export interface GetRevisionsOfSecretResponse + extends PageResponse<{ + id: string + value: string + version: number + createdOn: string + createdById: string + environmentId: string + }> {} diff --git a/packages/api-client/src/types/variable.types.d.ts b/packages/api-client/src/types/variable.types.d.ts index 3c38a59f..7240b3aa 100644 --- a/packages/api-client/src/types/variable.types.d.ts +++ b/packages/api-client/src/types/variable.types.d.ts @@ -1,18 +1,6 @@ import { PageRequest, PageResponse } from './index.types' -export interface CreateVariableRequest { - projectSlug: string - name: string - note?: string - entries?: [ - { - value: string - environmentSlug: string - } - ] -} - -export interface CreateVariableResponse { +interface Variable { id: string name: string slug: string @@ -31,6 +19,21 @@ export interface CreateVariableResponse { } ] } + +export interface CreateVariableRequest { + projectSlug: string + name: string + note?: string + entries?: [ + { + value: string + environmentSlug: string + } + ] +} + +export interface CreateVariableResponse extends Variable {} + export interface UpdateVariableRequest { variableSlug: string name?: string @@ -42,12 +45,7 @@ export interface UpdateVariableRequest { ] } export interface UpdateVariableResponse { - variable: { - id: string - name: string - note: string - slug: string - } + variable: Pick updatedVersions: [ { value: string @@ -77,32 +75,26 @@ export interface GetAllVariablesOfProjectRequest extends PageRequest { } export interface GetAllVariablesOfProjectResponse - extends PageResponse<{ - variable: { - id: string - name: string - slug: string - createdAt: string - updatedAt: string - note: string | null - lastUpdatedById: string - projectId: string - lastUpdatedBy: { - id: string - name: string - } - } - values: { - environment: { - id: string - name: string + extends PageResponse< + Omit & { + variable: { + lastUpdatedBy: { + id: string + name: string + } } - value: string - version: number + values: { + environment: { + id: string + name: string + } + value: string + version: number + }[] } - }> {} + > {} -export interface GetAllVariablesOfEnvironmentRequest extends PageRequest { +export interface GetAllVariablesOfEnvironmentRequest { projectSlug: string environmentSlug: string } @@ -112,3 +104,19 @@ export type GetAllVariablesOfEnvironmentResponse = { value: string isPlaintext: boolean }[] + +export interface GetRevisionsOfVariableRequest extends Partial { + variableSlug: string + environmentSlug: string +} + +export interface GetRevisionsOfVariableResponse + extends PageResponse<{ + id: string + value: string + version: number + variableId: string + createdOn: string + createdById: string + environmentId: string + }> {} diff --git a/packages/api-client/tests/secret.spec.ts b/packages/api-client/tests/secret.spec.ts index a9b9b8ed..38cd6966 100644 --- a/packages/api-client/tests/secret.spec.ts +++ b/packages/api-client/tests/secret.spec.ts @@ -84,18 +84,7 @@ describe('Secret Controller Tests', () => { }, { 'x-e2e-user-email': email } ) - - expect(createSecretResponse.data.slug).toBeDefined() - secretSlug = createSecretResponse.data.slug - - // Fetch all secrets - const secrets = await secretController.getAllSecretsOfProject( - { projectSlug }, - { 'x-e2e-user-email': email } - ) - - expect(secrets.data.items.length).toBe(1) }) afterEach(async () => { @@ -252,4 +241,12 @@ describe('Secret Controller Tests', () => { ) expect(secrets.data.items.length).toBe(0) }) + + it('should be able to fetch revisions of a secret', async () => { + const revisions = await secretController.getRevisionsOfSecret( + { secretSlug, environmentSlug }, + { 'x-e2e-user-email': email } + ) + expect(revisions.data.items.length).toBe(1) + }) }) diff --git a/packages/api-client/tests/variable.spec.ts b/packages/api-client/tests/variable.spec.ts index b7295a4e..9d25af96 100644 --- a/packages/api-client/tests/variable.spec.ts +++ b/packages/api-client/tests/variable.spec.ts @@ -9,7 +9,7 @@ describe('Get Variable Tests', () => { const email = 'johndoe@example.com' let workspaceSlug: string | null let projectSlug: string | null - let environment: any + let environment let variableSlug: string | null beforeAll(async () => { @@ -64,8 +64,7 @@ describe('Get Variable Tests', () => { }) }) - // Create a variable - it('should create a variable', async () => { + beforeEach(async () => { const variable = await variableController.createVariable( { projectSlug, @@ -78,11 +77,50 @@ describe('Get Variable Tests', () => { 'x-e2e-user-email': email } ) - expect(variable.data.name).toBe('Variable 1') + + variableSlug = variable.data.slug + }) + + afterEach(async () => { + await variableController.deleteVariable( + { + variableSlug + }, + { + 'x-e2e-user-email': email + } + ) + }) + + // Create a variable + it('should create a variable', async () => { + const variable = await variableController.createVariable( + { + projectSlug, + name: 'Variable 2', + entries: [ + { value: 'Variable 2 value', environmentSlug: environment.slug } + ] + }, + { + 'x-e2e-user-email': email + } + ) + expect(variable.data.name).toBe('Variable 2') expect(variable.data.versions.length).toBe(1) - expect(variable.data.versions[0].value).toBe('Variable 1 value') + expect(variable.data.versions[0].value).toBe('Variable 2 value') expect(variable.data.versions[0].environmentId).toBe(environment.id) - variableSlug = variable.data.slug + + // Delete the variable + const deleteVariable = await variableController.deleteVariable( + { + variableSlug: variable.data.slug + }, + { + 'x-e2e-user-email': email + } + ) + expect(deleteVariable.success).toBe(true) }) // Update Name of the Variable @@ -98,7 +136,16 @@ describe('Get Variable Tests', () => { ) expect(updatedVariable.data.variable.name).toBe('UpdatedVariable 1') - variableSlug = updatedVariable.data.variable.slug + // Delete the variable + const deleteVariable = await variableController.deleteVariable( + { + variableSlug: updatedVariable.data.variable.slug + }, + { + 'x-e2e-user-email': email + } + ) + expect(deleteVariable.success).toBe(true) }) // Create a new version of Variable @@ -124,7 +171,21 @@ describe('Get Variable Tests', () => { // Roll back a variable it('should rollback a variable', async () => { - const rolledBackVariable: any = await variableController.rollbackVariable( + // Add a new version + await variableController.updateVariable( + { + entries: [ + { + value: '1234', + environmentSlug: environment.slug + } + ], + variableSlug + }, + { 'x-e2e-user-email': email } + ) + + const rolledBackVariable = await variableController.rollbackVariable( { variableSlug, version: 1, @@ -137,65 +198,44 @@ describe('Get Variable Tests', () => { // Get all the variables of project it('should get all variables of project', async () => { - const response: any = await variableController.getAllVariablesOfProject( + const response = await variableController.getAllVariablesOfProject( { projectSlug }, { 'x-e2e-user-email': email } ) + expect(response.data.items.length).toBe(1) const variable1 = response.data.items[0] const variable = variable1.variable const values = variable1.values expect(variable).toHaveProperty('slug') - expect(typeof variable.slug).toBe('string') expect(variable).toHaveProperty('name') - expect(typeof variable.name).toBe('string') - expect(variable).toHaveProperty('createdAt') - expect(typeof variable.createdAt).toBe('string') - expect(variable).toHaveProperty('updatedAt') - expect(typeof variable.updatedAt).toBe('string') - expect(variable).toHaveProperty('note') - expect(typeof variable.note === 'string' || variable.note === null).toBe( - true - ) - expect(variable).toHaveProperty('lastUpdatedById') - expect(typeof variable.lastUpdatedById).toBe('string') expect(variable.lastUpdatedBy).toHaveProperty('id') - expect(typeof variable.lastUpdatedBy.id).toBe('string') - expect(variable.lastUpdatedBy).toHaveProperty('name') - expect(typeof variable.lastUpdatedBy.name).toBe('string') values.forEach((value) => { expect(value).toHaveProperty('environment') expect(value.environment).toHaveProperty('id') - expect(typeof value.environment.id).toBe('string') expect(value.environment).toHaveProperty('name') - expect(typeof value.environment.name).toBe('string') - expect(value).toHaveProperty('value') - expect(typeof value.value).toBe('string') - expect(value).toHaveProperty('version') - expect(typeof value.version).toBe('number') }) }) // Get all variables for an environment it('should get all variables for an environment', async () => { - const variables: any = - await variableController.getAllVariablesOfEnvironment( - { - environmentSlug: environment.slug, - projectSlug - }, - { 'x-e2e-user-email': email } - ) + const variables = await variableController.getAllVariablesOfEnvironment( + { + environmentSlug: environment.slug, + projectSlug + }, + { 'x-e2e-user-email': email } + ) expect(variables.data.length).toBe(1) variables.data.forEach((variable) => { @@ -209,7 +249,7 @@ describe('Get Variable Tests', () => { expect(typeof variable.isPlaintext).toBe('boolean') }) const variable1 = variables.data[0] - expect(variable1.name).toBe('UpdatedVariable 1') + expect(variable1.name).toBe('Variable 1') expect(variable1.value).toBe('Variable 1 value') expect(variable1.isPlaintext).toBe(true) }) @@ -220,10 +260,18 @@ describe('Get Variable Tests', () => { { variableSlug }, { 'x-e2e-user-email': email } ) - const variables: any = await variableController.getAllVariablesOfProject( + const variables = await variableController.getAllVariablesOfProject( { projectSlug }, { 'x-e2e-user-email': email } ) expect(variables.data.items.length).toBe(0) }) + + it('should be able to fetch revisions of a secret', async () => { + const revisions = await variableController.getRevisionsOfVariable( + { variableSlug, environmentSlug: environment.slug }, + { 'x-e2e-user-email': email } + ) + expect(revisions.data.items.length).toBe(1) + }) })