Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b61bb65

Browse files
committed
fix(domains): fix bulkCreateLoginLinks response types
1 parent aeb2773 commit b61bb65

File tree

4 files changed

+37
-33
lines changed

4 files changed

+37
-33
lines changed

docs/modules/domains.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ const { results } = await mailchannels.domains.bulkCreateLoginLinks([
513513
**Bulk Create Login Links type declarations**
514514

515515
<<< @/snippets/domains-bulk-create-login-link-result.ts
516-
<<< @/snippets/domains-bulk-create-login-link.ts
516+
<<< @/snippets/domains-bulk-create-login-links.ts
517517
<<< @/snippets/domains-bulk-create-login-links-response.ts
518518
</details>
519519

src/modules/domains.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { DomainsBulkProvisionOptions, DomainsBulkProvisionResponse, Domains
77
import type { DomainsListOptions, DomainsListResponse } from "../types/domains/list";
88
import type { DomainsCreateLoginLinkResponse } from "../types/domains/create-login-link";
99
import type { DomainsDownstreamAddress, DomainsListDownstreamAddressesOptions, DomainsListDownstreamAddressesResponse } from "../types/domains/downstream-addresses";
10-
import type { DomainsBulkCreateLoginLink, DomainsBulkCreateLoginLinksResponse } from "../types/domains/bulk-create-login-links";
10+
import type { DomainsBulkCreateLoginLinks, DomainsBulkCreateLoginLinksResponse } from "../types/domains/bulk-create-login-links";
1111
import { ErrorCode, getStatusError } from "../utils/errors";
1212

1313
export class Domains {
@@ -486,7 +486,7 @@ export class Domains {
486486
* ```
487487
*/
488488
async bulkCreateLoginLinks (domains: string[]): Promise<DomainsBulkCreateLoginLinksResponse> {
489-
const data: DomainsBulkCreateLoginLinksResponse = { results: [], error: null };
489+
const data: DomainsBulkCreateLoginLinksResponse = { results: null, error: null };
490490

491491
if (!domains || !domains.length) {
492492
data.error = "No domains provided.";
@@ -498,7 +498,7 @@ export class Domains {
498498
return data;
499499
}
500500

501-
const response = await this.mailchannels.post<DomainsBulkCreateLoginLink[]>("/inbound/v1/domains/batch/login-link", {
501+
const response = await this.mailchannels.post<DomainsBulkCreateLoginLinks>("/inbound/v1/domains/batch/login-link", {
502502
body: {
503503
domains: domains.map(domain => ({ domain }))
504504
},
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { Optional } from "../internal";
2+
13
interface DomainsBulkCreateLoginLinkResult {
24
/**
35
* The domain the request was for.
@@ -8,19 +10,18 @@ interface DomainsBulkCreateLoginLinkResult {
810
* More information about the result of creating the login link.
911
*/
1012
comment?: string;
13+
/**
14+
* If a user browses to this URL, they will be automatically logged in as a domain admin.
15+
*/
16+
loginLink: string;
1117
}
1218

13-
export interface DomainsBulkCreateLoginLink {
14-
successes: DomainsBulkCreateLoginLinkResult & {
15-
/**
16-
* If a user browses to this URL, they will be automatically logged in as a domain admin.
17-
*/
18-
loginLink: string;
19-
}[];
20-
errors: DomainsBulkCreateLoginLinkResult[];
19+
export interface DomainsBulkCreateLoginLinks {
20+
successes: DomainsBulkCreateLoginLinkResult[];
21+
errors: Omit<DomainsBulkCreateLoginLinkResult, "loginLink">[];
2122
}
2223

2324
export interface DomainsBulkCreateLoginLinksResponse {
24-
results: DomainsCreateLoginLink[];
25+
results: DomainsBulkCreateLoginLinks | null;
2526
error: string | null;
2627
}

test/domains.test.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { DomainsData, DomainsProvisionOptions } from "../src/types/domains/
55
import { ErrorCode } from "../src/utils/errors";
66
import type { ListEntryOptions } from "../src/types/lists/entry";
77
import type { DomainsAddListEntryApiResponse } from "../src/types/domains/internal";
8+
import type { DomainsBulkCreateLoginLinksResponse } from "../src/types/domains/bulk-create-login-links";
89

910
const fake = {
1011
provision: {
@@ -88,23 +89,25 @@ const fake = {
8889
]
8990
},
9091
bulkCreateLoginLinksResponse: {
91-
successes: [
92-
{
93-
domain: "example1.com",
94-
code: 200,
95-
comment: "string",
96-
loginLink: "string"
97-
}
98-
],
99-
errors: [
100-
{
101-
domain: "example2.com",
102-
code: 400,
103-
comment: "string",
104-
loginLink: "string"
105-
}
106-
]
107-
}
92+
results: {
93+
successes: [
94+
{
95+
domain: "example1.com",
96+
code: 200,
97+
comment: "string",
98+
loginLink: "string"
99+
}
100+
],
101+
errors: [
102+
{
103+
domain: "example2.com",
104+
code: 400,
105+
comment: "string"
106+
}
107+
]
108+
},
109+
error: null
110+
} satisfies DomainsBulkCreateLoginLinksResponse
108111
};
109112

110113
describe("provision", () => {
@@ -744,7 +747,7 @@ describe("bulkCreateLoginLinks", () => {
744747
const { results, error } = await domains.bulkCreateLoginLinks([]);
745748

746749
expect(error).toBe("No domains provided.");
747-
expect(results).toEqual([]);
750+
expect(results).toBeNull();
748751
expect(mockClient.post).not.toHaveBeenCalled();
749752
});
750753

@@ -757,7 +760,7 @@ describe("bulkCreateLoginLinks", () => {
757760
const { results, error } = await domains.bulkCreateLoginLinks(new Array(1001).fill("example.com"));
758761

759762
expect(error).toBe("The maximum number of domains to create login links for is 1000.");
760-
expect(results).toEqual([]);
763+
expect(results).toBeNull();
761764
expect(mockClient.post).not.toHaveBeenCalled();
762765
});
763766

@@ -776,7 +779,7 @@ describe("bulkCreateLoginLinks", () => {
776779
]);
777780

778781
expect(error).toBeTruthy();
779-
expect(results).toEqual([]);
782+
expect(results).toBeNull();
780783
expect(mockClient.post).toHaveBeenCalled();
781784
});
782785
});

0 commit comments

Comments
 (0)