Skip to content

Commit 9028d0d

Browse files
feature/customEmailProvider (#1070)
Co-authored-by: A. Craig West <[email protected]>
1 parent 4b99afd commit 9028d0d

File tree

3 files changed

+172
-14
lines changed

3 files changed

+172
-14
lines changed

src/management/__generated/managers/emails-manager.ts

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,46 @@ export class EmailsManager extends BaseAPI {
4848
}
4949

5050
/**
51-
* Update an <a href="https://auth0.com/docs/email/providers">email provider</a>.
52-
* The <code>credentials</code> object requires different properties depending on the email provider (which is specified using the <code>name</code> property):
53-
* <ul><li><code>mandrill</code> requires <code>api_key</code></li><li><code>sendgrid</code> requires <code>api_key</code></li><li><code>sparkpost</code> requires <code>api_key</code>. Optionally, set <code>region</code> to <code>eu</code> to use the SparkPost service hosted in Western Europe; set to <code>null</code> to use the SparkPost service hosted in North America. <code>eu</code> or <code>null</code> are the only valid values for <code>region</code>.</li><li><code>mailgun</code> requires <code>api_key</code> and <code>domain</code>. Optionally, set <code>region</code> to <code>eu</code> to use the Mailgun service hosted in Europe; set to <code>null</code> otherwise. <code>eu</code> or <code>null</code> are the only valid values for <code>region</code>.</li><li><code>ses</code> requires <code>accessKeyId</code>, <code>secretAccessKey</code>, and <code>region</code></li><li><code>smtp</code> requires <code>smtp_host</code>, <code>smtp_port</code>, <code>smtp_user</code>, and <code>smtp_pass</code></li></ul>Depending on the type of provider it is possible to specify <code>settings</code> object with different configuration options, which will be used when sending an email:
54-
* <ul><li><code>smtp</code> provider, <code>settings</code> may contain <code>headers</code> object. When using AWS SES SMTP host, you may provide a name of configuration set in <code>X-SES-Configuration-Set</code> header. Value must be a string.</li><li>for <code>ses</code> provider, <code>settings</code> may contain <code>message</code> object, where you can provide a name of configuration set in <code>configuration_set_name</code> property. Value must be a string.</li></ul>
51+
* Update an <a href="https://auth0.com/docs/email/providers">email provider</a>. The <code>credentials</code> object
52+
* requires different properties depending on the email provider (which is specified using the <code>name</code> property):
53+
* <ul>
54+
* <li><code>mandrill</code> requires <code>api_key</code></li>
55+
* <li><code>sendgrid</code> requires <code>api_key</code></li>
56+
* <li>
57+
* <code>sparkpost</code> requires <code>api_key</code>. Optionally, set <code>region</code> to <code>eu</code> to use
58+
* the SparkPost service hosted in Western Europe; set to <code>null</code> to use the SparkPost service hosted in
59+
* North America. <code>eu</code> or <code>null</code> are the only valid values for <code>region</code>.
60+
* </li>
61+
* <li>
62+
* <code>mailgun</code> requires <code>api_key</code> and <code>domain</code>. Optionally, set <code>region</code> to
63+
* <code>eu</code> to use the Mailgun service hosted in Europe; set to <code>null</code> otherwise. <code>eu</code> or
64+
* <code>null</code> are the only valid values for <code>region</code>.
65+
* </li>
66+
* <li><code>ses</code> requires <code>accessKeyId</code>, <code>secretAccessKey</code>, and <code>region</code></li>
67+
* <li>
68+
* <code>smtp</code> requires <code>smtp_host</code>, <code>smtp_port</code>, <code>smtp_user</code>, and
69+
* <code>smtp_pass</code>
70+
* </li>
71+
* </ul>
72+
* Depending on the type of provider it is possible to specify <code>settings</code> object with different configuration
73+
* options, which will be used when sending an email:
74+
* <ul>
75+
* <li>
76+
* <code>smtp</code> provider, <code>settings</code> may contain <code>headers</code> object.
77+
* <ul>
78+
* <li>
79+
* When using AWS SES SMTP host, you may provide a name of configuration set in
80+
* <code>X-SES-Configuration-Set</code> header. Value must be a string.
81+
* </li>
82+
* <li>
83+
* When using Sparkpost host, you may provide value for
84+
* <code>X-MSYS_API</code> header. Value must be an object.
85+
* </li>
86+
* </ul>
87+
* for <code>ses</code> provider, <code>settings</code> may contain <code>message</code> object, where you can provide
88+
* a name of configuration set in <code>configuration_set_name</code> property. Value must be a string.
89+
* </li>
90+
* </ul>
5591
*
5692
* Update the email provider
5793
*
@@ -79,10 +115,48 @@ export class EmailsManager extends BaseAPI {
79115
}
80116

81117
/**
82-
* Create an <a href="https://auth0.com/docs/email/providers">email provider</a>.
83-
* The <code>credentials</code> object requires different properties depending on the email provider (which is specified using the <code>name</code> property):
84-
* <ul><li><code>mandrill</code> requires <code>api_key</code></li><li><code>sendgrid</code> requires <code>api_key</code></li><li><code>sparkpost</code> requires <code>api_key</code>. Optionally, set <code>region</code> to <code>eu</code> to use the SparkPost service hosted in Western Europe; set to <code>null</code> to use the SparkPost service hosted in North America. <code>eu</code> or <code>null</code> are the only valid values for <code>region</code>.</li><li><code>mailgun</code> requires <code>api_key</code> and <code>domain</code>. Optionally, set <code>region</code> to <code>eu</code> to use the Mailgun service hosted in Europe; set to <code>null</code> otherwise. <code>eu</code> or <code>null</code> are the only valid values for <code>region</code>.</li><li><code>ses</code> requires <code>accessKeyId</code>, <code>secretAccessKey</code>, and <code>region</code></li><li><code>smtp</code> requires <code>smtp_host</code>, <code>smtp_port</code>, <code>smtp_user</code>, and <code>smtp_pass</code></li></ul>Depending on the type of provider it is possible to specify <code>settings</code> object with different configuration options, which will be used when sending an email:
85-
* <ul><li><code>smtp</code> provider, <code>settings</code> may contain <code>headers</code> object. When using AWS SES SMTP host, you may provide a name of configuration set in <code>X-SES-Configuration-Set</code> header. Value must be a string.</li><li>for <code>ses</code> provider, <code>settings</code> may contain <code>message</code> object, where you can provide a name of configuration set in <code>configuration_set_name</code> property. Value must be a string.</li></ul>
118+
* Create an <a href="https://auth0.com/docs/email/providers">email provider</a>. The <code>credentials</code> object
119+
* requires different properties depending on the email provider (which is specified using the <code>name</code> property):
120+
* <ul>
121+
* <li><code>mandrill</code> requires <code>api_key</code></li>
122+
* <li><code>sendgrid</code> requires <code>api_key</code></li>
123+
* <li>
124+
* <code>sparkpost</code> requires <code>api_key</code>. Optionally, set <code>region</code> to <code>eu</code> to use
125+
* the SparkPost service hosted in Western Europe; set to <code>null</code> to use the SparkPost service hosted in
126+
* North America. <code>eu</code> or <code>null</code> are the only valid values for <code>region</code>.
127+
* </li>
128+
* <li>
129+
* <code>mailgun</code> requires <code>api_key</code> and <code>domain</code>. Optionally, set <code>region</code> to
130+
* <code>eu</code> to use the Mailgun service hosted in Europe; set to <code>null</code> otherwise. <code>eu</code> or
131+
* <code>null</code> are the only valid values for <code>region</code>.
132+
* </li>
133+
* <li><code>ses</code> requires <code>accessKeyId</code>, <code>secretAccessKey</code>, and <code>region</code></li>
134+
* <li>
135+
* <code>smtp</code> requires <code>smtp_host</code>, <code>smtp_port</code>, <code>smtp_user</code>, and
136+
* <code>smtp_pass</code>
137+
* </li>
138+
* </ul>
139+
* Depending on the type of provider it is possible to specify <code>settings</code> object with different configuration
140+
* options, which will be used when sending an email:
141+
* <ul>
142+
* <li>
143+
* <code>smtp</code> provider, <code>settings</code> may contain <code>headers</code> object.
144+
* <ul>
145+
* <li>
146+
* When using AWS SES SMTP host, you may provide a name of configuration set in
147+
* <code>X-SES-Configuration-Set</code> header. Value must be a string.
148+
* </li>
149+
* <li>
150+
* When using Sparkpost host, you may provide value for
151+
* <code>X-MSYS_API</code> header. Value must be an object.
152+
* </li>
153+
* </ul>
154+
* </li>
155+
* <li>
156+
* for <code>ses</code> provider, <code>settings</code> may contain <code>message</code> object, where you can provide
157+
* a name of configuration set in <code>configuration_set_name</code> property. Value must be a string.
158+
* </li>
159+
* </ul>
86160
*
87161
* Configure the email provider
88162
*

src/management/__generated/models/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3783,7 +3783,7 @@ export type DeviceCredentialCreateTypeEnum =
37833783
*/
37843784
export interface EmailProvider {
37853785
/**
3786-
* Name of the email provider. Can be `mailgun`, `mandrill`, `sendgrid`, `ses`, `sparkpost`, `smtp`, `azure_cs`, or `ms365`.
3786+
* Name of the email provider. Can be `mailgun`, `mandrill`, `sendgrid`, `ses`, `sparkpost`, `smtp`, `azure_cs`, `ms365`, or `custom`.
37873787
*
37883788
*/
37893789
name: string;
@@ -3811,7 +3811,7 @@ export interface EmailProvider {
38113811
*/
38123812
export interface EmailProviderCreate {
38133813
/**
3814-
* Name of the email provider. Can be `mailgun`, `mandrill`, `sendgrid`, `ses`, `sparkpost`, `smtp`, `azure_cs`, or `ms365`.
3814+
* Name of the email provider. Can be `mailgun`, `mandrill`, `sendgrid`, `ses`, `sparkpost`, `smtp`, `azure_cs`, `ms365`, or `custom`.
38153815
*
38163816
*/
38173817
name: EmailProviderCreateNameEnum;
@@ -3844,6 +3844,7 @@ export const EmailProviderCreateNameEnum = {
38443844
smtp: 'smtp',
38453845
azure_cs: 'azure_cs',
38463846
ms365: 'ms365',
3847+
custom: 'custom',
38473848
} as const;
38483849
export type EmailProviderCreateNameEnum =
38493850
(typeof EmailProviderCreateNameEnum)[keyof typeof EmailProviderCreateNameEnum];
@@ -3883,7 +3884,7 @@ export interface EmailProviderCredentials {
38833884
*/
38843885
export interface EmailProviderUpdate {
38853886
/**
3886-
* Name of the email provider. Can be `mailgun`, `mandrill`, `sendgrid`, `ses`, `sparkpost`, `smtp`, `azure_cs`, or `ms365`.
3887+
* Name of the email provider. Can be `mailgun`, `mandrill`, `sendgrid`, `ses`, `sparkpost`, `smtp`, `azure_cs`, `ms365`, or `custom`.
38873888
*
38883889
*/
38893890
name?: EmailProviderUpdateNameEnum;
@@ -3916,6 +3917,7 @@ export const EmailProviderUpdateNameEnum = {
39163917
smtp: 'smtp',
39173918
azure_cs: 'azure_cs',
39183919
ms365: 'ms365',
3920+
custom: 'custom',
39193921
} as const;
39203922
export type EmailProviderUpdateNameEnum =
39213923
(typeof EmailProviderUpdateNameEnum)[keyof typeof EmailProviderUpdateNameEnum];
@@ -4629,7 +4631,7 @@ export interface GetActions200ResponseActionsInnerSupportedTriggersInnerCompatib
46294631
version: string;
46304632
}
46314633
/**
4632-
* An actions extensibility point. Acceptable values: <code>post-login, credentials-exchange, pre-user-registration, post-user-registration, post-change-password, send-phone-message, password-reset-post-challenge</code>
4634+
* An actions extensibility point. Acceptable values: <code>post-login, credentials-exchange, pre-user-registration, post-user-registration, post-change-password, send-phone-message, custom-email-provider, password-reset-post-challenge</code>
46334635
*/
46344636
export type GetActions200ResponseActionsInnerSupportedTriggersInnerId =
46354637
GetActions200ResponseActionsInnerSupportedTriggersInnerIdAnyOf;
@@ -4648,6 +4650,7 @@ export const GetActions200ResponseActionsInnerSupportedTriggersInnerIdAnyOf = {
46484650
iga_certification: 'iga-certification',
46494651
iga_fulfillment_assignment: 'iga-fulfillment-assignment',
46504652
iga_fulfillment_execution: 'iga-fulfillment-execution',
4653+
custom_email_provider: 'custom-email-provider',
46514654
password_reset_post_challenge: 'password-reset-post-challenge',
46524655
} as const;
46534656
export type GetActions200ResponseActionsInnerSupportedTriggersInnerIdAnyOf =
@@ -16404,7 +16407,7 @@ export interface GetActionsRequest {
1640416407
*/
1640516408
export interface GetBindingsRequest {
1640616409
/**
16407-
* An actions extensibility point. Acceptable values: <code>post-login, credentials-exchange, pre-user-registration, post-user-registration, post-change-password, send-phone-message, password-reset-post-challenge</code>
16410+
* An actions extensibility point. Acceptable values: <code>post-login, credentials-exchange, pre-user-registration, post-user-registration, post-change-password, send-phone-message, custom-email-provider, password-reset-post-challenge</code>
1640816411
*
1640916412
*/
1641016413
triggerId: string;
@@ -16444,7 +16447,7 @@ export interface PatchActionOperationRequest {
1644416447
*/
1644516448
export interface PatchBindingsOperationRequest {
1644616449
/**
16447-
* An actions extensibility point. Acceptable values: <code>post-login, credentials-exchange, pre-user-registration, post-user-registration, post-change-password, send-phone-message, password-reset-post-challenge</code>
16450+
* An actions extensibility point. Acceptable values: <code>post-login, credentials-exchange, pre-user-registration, post-user-registration, post-change-password, send-phone-message, custom-email-provider, password-reset-post-challenge</code>
1644816451
*
1644916452
*/
1645016453
triggerId: string;

test/management/email-provider.test.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,87 @@ describe('EmailProviderManager', () => {
248248
});
249249
});
250250

251+
describe('#configure.custom', () => {
252+
const data: PostProviderRequest = {
253+
name: PostProviderRequestNameEnum.custom,
254+
enabled: true,
255+
default_from_address: '[email protected]',
256+
credentials: {},
257+
};
258+
const response = {
259+
name: PostProviderRequestNameEnum.custom,
260+
enabled: true,
261+
default_from_address: '[email protected]',
262+
credentials: {},
263+
};
264+
let request: nock.Scope;
265+
266+
beforeEach(() => {
267+
request = nock(API_URL)
268+
.post('/emails/provider', data as any)
269+
.reply(200, response);
270+
});
271+
272+
it('should return a promise if no callback is given', (done) => {
273+
emails.configure(data).then(done.bind(null, null)).catch(done.bind(null, null));
274+
});
275+
276+
it('should pass any errors to the promise catch handler', (done) => {
277+
nock.cleanAll();
278+
279+
nock(API_URL).post('/emails/provider').reply(500, {});
280+
281+
emails.configure(data).catch((err) => {
282+
expect(err).toBeDefined();
283+
284+
done();
285+
});
286+
});
287+
288+
it('should perform a POST request to /api/v2/emails/provider', (done) => {
289+
emails.configure(data).then(() => {
290+
expect(request.isDone()).toBe(true);
291+
292+
done();
293+
});
294+
});
295+
296+
it('should pass the data in the body of the request', (done) => {
297+
emails.configure(data).then(() => {
298+
expect(request.isDone()).toBe(true);
299+
300+
done();
301+
});
302+
});
303+
304+
it('should pass the body of the response to the "then" handler', (done) => {
305+
emails.configure(data).then((provider) => {
306+
expect(provider.data.name).toBe(response.name);
307+
expect(provider.data.enabled).toBe(response.enabled);
308+
expect(provider.data.default_from_address).toBe(response.default_from_address);
309+
310+
expect(provider.data.credentials).toStrictEqual(response.credentials);
311+
312+
done();
313+
});
314+
});
315+
316+
it('should include the token in the Authorization header', (done) => {
317+
nock.cleanAll();
318+
319+
const request = nock(API_URL)
320+
.post('/emails/provider')
321+
.matchHeader('Authorization', `Bearer ${token}`)
322+
.reply(200, response);
323+
324+
emails.configure(data).then(() => {
325+
expect(request.isDone()).toBe(true);
326+
327+
done();
328+
});
329+
});
330+
});
331+
251332
describe('#update', () => {
252333
const data: PatchProviderRequest = {
253334
name: PatchProviderRequestNameEnum.smtp,

0 commit comments

Comments
 (0)