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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "resend",
"version": "6.19.0",
"version": "6.20.0",
"description": "Node.js library for the Resend API",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
Expand Down
40 changes: 40 additions & 0 deletions src/automations/automations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
CreateAutomationOptions,
CreateAutomationResponseSuccess,
} from './interfaces/create-automation-options.interface';
import type { DuplicateAutomationResponseSuccess } from './interfaces/duplicate-automation.interface';
import type { GetAutomationResponseSuccess } from './interfaces/get-automation.interface';
import type { ListAutomationsResponseSuccess } from './interfaces/list-automation.interface';
import type { RemoveAutomationResponseSuccess } from './interfaces/remove-automation.interface';
Expand Down Expand Up @@ -529,6 +530,45 @@ describe('update', () => {
});
});

describe('duplicate', () => {
it('duplicates an automation', async () => {
const id = '71cdfe68-cf79-473a-a9d7-21f91db6a526';
const response: DuplicateAutomationResponseSuccess = {
object: 'automation',
id: 'e169aa45-1ecf-4183-9955-b1499d5701d3',
};

fetchMock.mockOnce(JSON.stringify(response), {
status: 200,
headers: {
'content-type': 'application/json',
},
});

const data = await resend.automations.duplicate(id);
expect(data).toMatchInlineSnapshot(`
{
"data": {
"id": "e169aa45-1ecf-4183-9955-b1499d5701d3",
"object": "automation",
},
"error": null,
"headers": {
"content-type": "application/json",
},
}
`);

expect(fetchMock).toHaveBeenCalledWith(
`https://api.resend.com/automations/${id}/duplicate`,
expect.objectContaining({
method: 'POST',
headers: expect.any(Headers),
}),
);
});
});

describe('stop', () => {
it('stops an automation', async () => {
const id = '71cdfe68-cf79-473a-a9d7-21f91db6a526';
Expand Down
11 changes: 11 additions & 0 deletions src/automations/automations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import type {
CreateAutomationResponse,
CreateAutomationResponseSuccess,
} from './interfaces/create-automation-options.interface';
import type {
DuplicateAutomationResponse,
DuplicateAutomationResponseSuccess,
} from './interfaces/duplicate-automation.interface';
import type {
GetAutomationResponse,
GetAutomationResponseSuccess,
Expand Down Expand Up @@ -109,6 +113,13 @@ export class Automations {
return data;
}

async duplicate(id: string): Promise<DuplicateAutomationResponse> {
const data = await this.resend.post<DuplicateAutomationResponseSuccess>(
`/automations/${id}/duplicate`,
);
return data;
}

async stop(id: string): Promise<StopAutomationResponse> {
const data = await this.resend.post<StopAutomationResponseSuccess>(
`/automations/${id}/stop`,
Expand Down
10 changes: 10 additions & 0 deletions src/automations/interfaces/duplicate-automation.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Response } from '../../interfaces';
import type { Automation } from './automation';

export interface DuplicateAutomationResponseSuccess
extends Pick<Automation, 'id'> {
object: 'automation';
}

export type DuplicateAutomationResponse =
Response<DuplicateAutomationResponseSuccess>;
1 change: 1 addition & 0 deletions src/automations/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './automation';
export * from './automation-step.interface';
export * from './create-automation-options.interface';
export * from './duplicate-automation.interface';
export * from './get-automation.interface';
export * from './list-automation.interface';
export * from './remove-automation.interface';
Expand Down
Loading