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

Add support for the detect provider endpoint #548

Open
wants to merge 3 commits into
base: v6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

### Unreleased
* Add support for the detect provider endpoint

### 6.11.1 / 2024-02-09
* Fix issue where Graph events were returning 400 on update
* Make comment param in rsvp optional
Expand Down
44 changes: 44 additions & 0 deletions src/models/detect-provider-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Model from './model';
import Attributes, { Attribute } from './attributes';

export type DetectProviderResponseProperties = {
authName: string;
emailAddress: string;
detected: boolean;
providerName?: string;
isImap?: boolean;
};

export default class DetectProviderResponse extends Model
implements DetectProviderResponseProperties {
authName = '';
emailAddress = '';
detected = false;

Check warning on line 16 in src/models/detect-provider-response.ts

View check run for this annotation

Codecov / codecov/patch

src/models/detect-provider-response.ts#L14-L16

Added lines #L14 - L16 were not covered by tests
provider?: string;
isImap?: boolean;
static attributes: Record<string, Attribute> = {
authName: Attributes.String({
modelKey: 'authName',
jsonKey: 'auth_name',
}),
emailAddress: Attributes.String({
modelKey: 'emailAddress',
jsonKey: 'email_address',
}),
detected: Attributes.Boolean({
modelKey: 'detected',
}),
provider: Attributes.String({
modelKey: 'provider',
}),
isImap: Attributes.Boolean({
modelKey: 'isImap',
jsonKey: 'is_imap',
}),
};

constructor(props?: DetectProviderResponseProperties) {

Check warning on line 40 in src/models/detect-provider-response.ts

View check run for this annotation

Codecov / codecov/patch

src/models/detect-provider-response.ts#L40

Added line #L40 was not covered by tests
super();
this.initAttributes(props);

Check warning on line 42 in src/models/detect-provider-response.ts

View check run for this annotation

Codecov / codecov/patch

src/models/detect-provider-response.ts#L42

Added line #L42 was not covered by tests
}
}
25 changes: 25 additions & 0 deletions src/nylas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ApplicationDetailsProperties,
} from './models/application-details';
import LoggingInterface from './models/LoggingInterface';
import DetectProviderResponse from './models/detect-provider-response';

class Nylas {
static clientId = '';
Expand Down Expand Up @@ -212,6 +213,30 @@
return url;
}

/**
* Detect the provider for a given email address
* @param email The email address you want to check
* @return The response from the API containing the provider, if found
*/
static detectProvider(email: string): Promise<DetectProviderResponse> {
const connection = new NylasConnection(null, { clientId: this.clientId });

Check warning on line 222 in src/nylas.ts

View check run for this annotation

Codecov / codecov/patch

src/nylas.ts#L222

Added line #L222 was not covered by tests

return connection

Check warning on line 224 in src/nylas.ts

View check run for this annotation

Codecov / codecov/patch

src/nylas.ts#L224

Added line #L224 was not covered by tests
.request({
method: 'POST',
path: '/connect/detect-provider',
body: {
client_id: this.clientId,
client_secret: this.clientSecret,
email_address: email,
},
})
.then(res => {
return new DetectProviderResponse().fromJSON(res);

Check warning on line 235 in src/nylas.ts

View check run for this annotation

Codecov / codecov/patch

src/nylas.ts#L234-L235

Added lines #L234 - L235 were not covered by tests
})
.catch(err => Promise.reject(err));

Check warning on line 237 in src/nylas.ts

View check run for this annotation

Codecov / codecov/patch

src/nylas.ts#L237

Added line #L237 was not covered by tests
}

/**
* Revoke a single access token
* @param accessToken The access token to revoke
Expand Down