Skip to content
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.
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.9.3",
"version": "6.10.0-preview-workflows.3",
"description": "Node.js library for the Resend API",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
Expand Down
207 changes: 207 additions & 0 deletions src/automation-run-steps/automation-run-steps.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
import createFetchMock from 'vitest-fetch-mock';
import { Resend } from '../resend';
import {
mockErrorResponse,
mockSuccessResponse,
} from '../test-utils/mock-fetch';
import type {
GetAutomationRunStepOptions,
GetAutomationRunStepResponseSuccess,
} from './interfaces/get-automation-run-step.interface';
import type {
ListAutomationRunStepsOptions,
ListAutomationRunStepsResponseSuccess,
} from './interfaces/list-automation-run-steps.interface';

const fetchMocker = createFetchMock(vi);
fetchMocker.enableMocks();

afterEach(() => fetchMock.resetMocks());
afterAll(() => fetchMocker.disableMocks());

describe('get', () => {
it('gets a automation run step', async () => {
const options: GetAutomationRunStepOptions = {
automationId: 'wf_123',
runId: 'wr_456',
stepId: 'wrs_789',
};
const response: GetAutomationRunStepResponseSuccess = {
object: 'automation_run_step',
id: 'wrs_789',
step_id: 'step_1',
type: 'trigger',
config: { event_name: 'user.created' },
status: 'completed',
started_at: '2024-01-01T00:00:00.000Z',
completed_at: '2024-01-01T00:01:00.000Z',
created_at: '2024-01-01T00:00:00.000Z',
};

mockSuccessResponse(response, {});

const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Redact the API key literal in tests; use a non-secret dummy value instead.

(Based on your team's feedback about redacting secrets.)

View Feedback

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/automation-run-steps/automation-run-steps.spec.ts, line 43:

<comment>Redact the API key literal in tests; use a non-secret dummy value instead.

(Based on your team's feedback about redacting secrets.) </comment>

<file context>
@@ -0,0 +1,207 @@
+
+    mockSuccessResponse(response, {});
+
+    const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
+    await expect(
+      resend.automations.runs.steps.get(options),
</file context>

await expect(
resend.automations.runs.steps.get(options),
).resolves.toMatchInlineSnapshot(`
{
"data": {
"completed_at": "2024-01-01T00:01:00.000Z",
"config": {
"event_name": "user.created",
},
"created_at": "2024-01-01T00:00:00.000Z",
"id": "wrs_789",
"object": "automation_run_step",
"started_at": "2024-01-01T00:00:00.000Z",
"status": "completed",
"step_id": "step_1",
"type": "trigger",
},
"error": null,
"headers": {
"content-type": "application/json",
},
}
`);
});

it('returns error', async () => {
const options: GetAutomationRunStepOptions = {
automationId: 'wf_123',
runId: 'wr_456',
stepId: 'wrs_invalid',
};

mockErrorResponse(
{ name: 'not_found', message: 'Automation run step not found' },
{},
);

const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
const result = await resend.automations.runs.steps.get(options);
expect(result.error).not.toBeNull();
});
});

describe('list', () => {
it('lists automation run steps', async () => {
const options: ListAutomationRunStepsOptions = {
automationId: 'wf_123',
runId: 'wr_456',
};
const response: ListAutomationRunStepsResponseSuccess = {
object: 'list',
data: [
{
id: 'wrs_789',
step_id: 'step_1',
type: 'trigger',
status: 'completed',
started_at: '2024-01-01T00:00:00.000Z',
completed_at: '2024-01-01T00:01:00.000Z',
created_at: '2024-01-01T00:00:00.000Z',
},
],
has_more: false,
};

mockSuccessResponse(response, {});

const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
await expect(
resend.automations.runs.steps.list(options),
).resolves.toMatchInlineSnapshot(`
{
"data": {
"data": [
{
"completed_at": "2024-01-01T00:01:00.000Z",
"created_at": "2024-01-01T00:00:00.000Z",
"id": "wrs_789",
"started_at": "2024-01-01T00:00:00.000Z",
"status": "completed",
"step_id": "step_1",
"type": "trigger",
},
],
"has_more": false,
"object": "list",
},
"error": null,
"headers": {
"content-type": "application/json",
},
}
`);
});

it('lists automation run steps with pagination', async () => {
const options: ListAutomationRunStepsOptions = {
automationId: 'wf_123',
runId: 'wr_456',
limit: 1,
after: 'wrs_cursor',
};
const response: ListAutomationRunStepsResponseSuccess = {
object: 'list',
data: [
{
id: 'wrs_101',
step_id: 'step_2',
type: 'send_email',
status: 'running',
started_at: '2024-01-02T00:00:00.000Z',
completed_at: null,
created_at: '2024-01-02T00:00:00.000Z',
},
],
has_more: true,
};

mockSuccessResponse(response, {});

const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
await expect(
resend.automations.runs.steps.list(options),
).resolves.toMatchInlineSnapshot(`
{
"data": {
"data": [
{
"completed_at": null,
"created_at": "2024-01-02T00:00:00.000Z",
"id": "wrs_101",
"started_at": "2024-01-02T00:00:00.000Z",
"status": "running",
"step_id": "step_2",
"type": "send_email",
},
],
"has_more": true,
"object": "list",
},
"error": null,
"headers": {
"content-type": "application/json",
},
}
`);
});

it('returns error', async () => {
const options: ListAutomationRunStepsOptions = {
automationId: 'wf_invalid',
runId: 'wr_invalid',
};

mockErrorResponse(
{ name: 'not_found', message: 'Automation not found' },
{},
);

const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
const result = await resend.automations.runs.steps.list(options);
expect(result.error).not.toBeNull();
});
});
38 changes: 38 additions & 0 deletions src/automation-run-steps/automation-run-steps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { buildPaginationQuery } from '../common/utils/build-pagination-query';
import type { Resend } from '../resend';
import type {
GetAutomationRunStepOptions,
GetAutomationRunStepResponse,
GetAutomationRunStepResponseSuccess,
} from './interfaces/get-automation-run-step.interface';
import type {
ListAutomationRunStepsOptions,
ListAutomationRunStepsResponse,
ListAutomationRunStepsResponseSuccess,
} from './interfaces/list-automation-run-steps.interface';

export class AutomationRunSteps {
constructor(private readonly resend: Resend) {}

async get(
options: GetAutomationRunStepOptions,
): Promise<GetAutomationRunStepResponse> {
const data = await this.resend.get<GetAutomationRunStepResponseSuccess>(
`/automations/${options.automationId}/runs/${options.runId}/steps/${options.stepId}`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Custom agent: API Key Permission Check SDK Methods

Confirm production API keys have permission to access the new automation run steps endpoints (get/list). The rule requires this check for newly introduced SDK methods to avoid permission failures after deployment.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/automation-run-steps/automation-run-steps.ts, line 21:

<comment>Confirm production API keys have permission to access the new automation run steps endpoints (get/list). The rule requires this check for newly introduced SDK methods to avoid permission failures after deployment.</comment>

<file context>
@@ -0,0 +1,38 @@
+    options: GetAutomationRunStepOptions,
+  ): Promise<GetAutomationRunStepResponse> {
+    const data = await this.resend.get<GetAutomationRunStepResponseSuccess>(
+      `/automations/${options.automationId}/runs/${options.runId}/steps/${options.stepId}`,
+    );
+    return data;
</file context>

);
return data;
}

async list(
options: ListAutomationRunStepsOptions,
): Promise<ListAutomationRunStepsResponse> {
const queryString = buildPaginationQuery(options);
const url = queryString
? `/automations/${options.automationId}/runs/${options.runId}/steps?${queryString}`
: `/automations/${options.automationId}/runs/${options.runId}/steps`;

const data =
await this.resend.get<ListAutomationRunStepsResponseSuccess>(url);
return data;
}
}
32 changes: 32 additions & 0 deletions src/automation-run-steps/interfaces/automation-run-step.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { AutomationStepType } from '../../automations/interfaces/automation-step.interface';

export type AutomationRunStepStatus =
| 'pending'
| 'running'
| 'completed'
| 'failed'
| 'skipped'
| 'waiting';

export interface AutomationRunStep {
object: 'automation_run_step';
id: string;
step_id: string;
type: AutomationStepType;
config: Record<string, unknown>;
status: AutomationRunStepStatus;
started_at: string | null;
completed_at: string | null;
created_at: string;
}

export type AutomationRunStepItem = Pick<
AutomationRunStep,
| 'id'
| 'step_id'
| 'type'
| 'status'
| 'started_at'
| 'completed_at'
| 'created_at'
>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Response } from '../../interfaces';
import type { AutomationRunStep } from './automation-run-step';

export interface GetAutomationRunStepOptions {
automationId: string;
runId: string;
stepId: string;
}

export type GetAutomationRunStepResponseSuccess = AutomationRunStep;

export type GetAutomationRunStepResponse =
Response<GetAutomationRunStepResponseSuccess>;
3 changes: 3 additions & 0 deletions src/automation-run-steps/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './automation-run-step';
export * from './get-automation-run-step.interface';
export * from './list-automation-run-steps.interface';
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type {
PaginatedData,
PaginationOptions,
} from '../../common/interfaces/pagination-options.interface';
import type { Response } from '../../interfaces';
import type { AutomationRunStepItem } from './automation-run-step';

export type ListAutomationRunStepsOptions = PaginationOptions & {
automationId: string;
runId: string;
};

export type ListAutomationRunStepsResponseSuccess = PaginatedData<
AutomationRunStepItem[]
>;

export type ListAutomationRunStepsResponse =
Response<ListAutomationRunStepsResponseSuccess>;
Loading
Loading