Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Planned version: **8.5.1**.

### Added
- `certificateExpiresAt` and `thumbprint` on `Credential`, plus `CredentialType.CONNECTORCERTIFICATE` and `CredentialType.ADMINCONSENTCERTIFICATE`, for Dashboard-generated certificate credentials (NYL-515).

### Fixed
- Preserve upload-session HTTP header map keys while decoding API responses (NYL-476).
- Patch vulnerable SDK tooling and example HTTP dependencies while preserving TypeDoc compatibility (NYL-471).
Expand Down
20 changes: 20 additions & 0 deletions src/models/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ export interface Credential {
* Timestamp of when the credential was updated
*/
updatedAt?: number;
/**
* The certificate expiration date as a Unix timestamp.
* Returned only when `credentialType` is `connectorcertificate` or `adminconsentcertificate`.
*/
certificateExpiresAt?: number;
/**
* The certificate thumbprint.
* Returned only when `credentialType` is `connectorcertificate` or `adminconsentcertificate`.
*/
thumbprint?: string;
}

/**
Expand Down Expand Up @@ -143,6 +153,16 @@ export enum CredentialType {
ADMINCONSENT = 'adminconsent',
SERVICEACCOUNT = 'serviceaccount',
CONNECTOR = 'connector',
/**
* Certificate-based connector credential. Created from the Nylas Dashboard only;
* returned by list/find but cannot be created through the API.
*/
CONNECTORCERTIFICATE = 'connectorcertificate',
/**
* Certificate-based admin consent credential. Created from the Nylas Dashboard only;
* returned by list/find but cannot be created through the API.
*/
ADMINCONSENTCERTIFICATE = 'adminconsentcertificate',
}

/**
Expand Down
44 changes: 44 additions & 0 deletions tests/resources/credentials.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import APIClient from '../../src/apiClient';
import { CredentialType } from '../../src/models/credentials';
import { Credentials } from '../../src/resources/credentials';
import { objKeysToCamelCase } from '../../src/utils';
jest.mock('../../src/apiClient');

describe('Credentials', () => {
Expand Down Expand Up @@ -61,6 +62,49 @@ describe('Credentials', () => {
});
});

it('should return certificate fields for certificate credentials', async () => {
// Shape of the API response after APIClient camelCases it.
const apiResponse = objKeysToCamelCase({
request_id: 'req-1',
data: {
id: 'cert-cred-id',
name: 'Dashboard cert',
credential_type: 'connectorcertificate',
certificate_expires_at: 1798761600,
thumbprint: 'A1B2C3D4E5F6',
created_at: 1763900000,
updated_at: 1763900000,
},
});
apiClient.request.mockResolvedValueOnce(apiResponse);

const { data } = await credentials.find({
provider: 'microsoft',
credentialsId: 'cert-cred-id',
});

expect(data.credentialType).toBe(CredentialType.CONNECTORCERTIFICATE);
expect(data.certificateExpiresAt).toBe(1798761600);
expect(data.thumbprint).toBe('A1B2C3D4E5F6');
});

it('should leave certificate fields undefined for other credential types', async () => {
apiClient.request.mockResolvedValueOnce(
objKeysToCamelCase({
request_id: 'req-2',
data: { id: 'sa-id', name: 'SA', credential_type: 'serviceaccount' },
})
);

const { data } = await credentials.find({
provider: 'google',
credentialsId: 'sa-id',
});

expect(data.certificateExpiresAt).toBeUndefined();
expect(data.thumbprint).toBeUndefined();
});

it('should URL encode provider and credentialsId in find', async () => {
await credentials.find({
provider: 'microsoft',
Expand Down
Loading