diff --git a/packages/api-client/src/controllers/secret/secret.ts b/packages/api-client/src/controllers/secret/secret.ts index d08a4978..c8ecd5bf 100644 --- a/packages/api-client/src/controllers/secret/secret.ts +++ b/packages/api-client/src/controllers/secret/secret.ts @@ -59,26 +59,29 @@ export default class SecretController { static async getAllSecretsOfProject( request: GetAllSecretsOfProjectRequest, headers?: Record - ): Promise { + ): Promise { let url = `/api/secret/${request.projectId}?decryptValue=true` request.page && (url += `page=${request.page}&`) request.limit && (url += `limit=${request.limit}&`) request.sort && (url += `sort=${request.sort}&`) request.order && (url += `order=${request.order}&`) request.search && (url += `search=${request.search}&`) - return this.apiClient.get(url, headers) + return this.apiClient.get(url, headers) } static async getAllSecretsOfEnvironment( request: GetAllSecretsOfEnvironmentRequest, headers?: Record - ): Promise { + ): Promise { let url = `/api/secret/${request.projectId}/${request.environmentId}` request.page && (url += `page=${request.page}&`) request.limit && (url += `limit=${request.limit}&`) request.sort && (url += `sort=${request.sort}&`) request.order && (url += `order=${request.order}&`) request.search && (url += `search=${request.search}&`) - return this.apiClient.get(url, headers) + return this.apiClient.get( + url, + headers + ) } } diff --git a/packages/api-client/src/types/secret.types.d.ts b/packages/api-client/src/types/secret.types.d.ts index 13e0dd43..033666e6 100644 --- a/packages/api-client/src/types/secret.types.d.ts +++ b/packages/api-client/src/types/secret.types.d.ts @@ -2,7 +2,7 @@ export interface CreateSecretRequest { projectId: string name: string note?: string - rotateAfter?: string + rotateAfter?: '24' | '168' | '720' | '8760' | 'never' entries?: [ { value: string @@ -35,7 +35,7 @@ export interface UpdateSecretRequest { secretId: string name?: string note?: string - rotateAfter?: string + rotateAfter?: '24' | '168' | '720' | '8760' | 'never' entries?: [ { value: string @@ -45,8 +45,18 @@ export interface UpdateSecretRequest { } export interface UpdateSecretResponse { - secret: any - updatedVersions: any + secret: { + id: string + name: string + note: string + } + updatedVersions: [ + { + id?: string + environmentId: string + value: string + } + ] } export interface DeleteSecretRequest { @@ -73,25 +83,28 @@ export interface GetAllSecretsOfProjectRequest { search?: string } export interface GetAllSecretsOfProjectResponse { - items: { + secret: { id: string name: string createdAt: string updatedAt: string - rotateAt: string | null + rotateAt: string note: string | null lastUpdatedById: string projectId: string - project: { - workspaceId: string + lastUpdatedBy: { + id: string + name: string + } + } + values: { + environment: { + id: string + name: string } - versions: [ - { - value: string - environmentId: string - } - ] - }[] + value: string + version: number + } } export interface GetAllSecretsOfEnvironmentRequest { @@ -104,23 +117,7 @@ export interface GetAllSecretsOfEnvironmentRequest { search?: string } export interface GetAllSecretsOfEnvironmentResponse { - items: { - id: string - name: string - createdAt: string - updatedAt: string - rotateAt: string | null - note: string | null - lastUpdatedById: string - projectId: string - project: { - workspaceId: string - } - versions: [ - { - value: string - environmentId: string - } - ] - }[] + name: string + value: string + isPlaintext: boolean } diff --git a/packages/api-client/tests/secret.spec.ts b/packages/api-client/tests/secret.spec.ts index dd7af751..35ad1825 100644 --- a/packages/api-client/tests/secret.spec.ts +++ b/packages/api-client/tests/secret.spec.ts @@ -117,15 +117,11 @@ describe('Get Variable tests', () => { // RollBack a Particular Version of a Secret it('should roll back a version of a secret', async () => { - try { - const rollbackSecret = await SecretController.rollbackSecret( - { secretId, environmentId: environment.id, version: 1 }, - { 'x-e2e-user-email': email } - ) - expect(rollbackSecret.count).toBe(1) - } catch (error) { - console.log(error) - } + const rollbackSecret = await SecretController.rollbackSecret( + { secretId, environmentId: environment.id, version: 1 }, + { 'x-e2e-user-email': email } + ) + expect(rollbackSecret.count).toBe(1) }) // Get all secrets of a Project @@ -147,6 +143,16 @@ describe('Get Variable tests', () => { { 'x-e2e-user-email': email } ) expect(secrets.length).toBe(1) + secrets.forEach((secret) => { + expect(secret).toHaveProperty('name') + expect(typeof secret.name).toBe('string') + + expect(secret).toHaveProperty('value') + expect(typeof secret.value).toBe('string') + + expect(secret).toHaveProperty('isPlaintext') + expect(typeof secret.isPlaintext).toBe('boolean') + }) }) // Delete a Secert from a Project