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 .secretlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{
"name": "credential in URL query string",
"patterns": [
"/[?&](?:token|api[_-]?key|access[_-]?token|auth[_-]?token|client[_-]?secret|secret|password)=(?<CREDENTIAL>(?!p\\.)[^&\\s\"'<>]{16,})/i"
"/[?&](?:token|api[_-]?key|access[_-]?token|auth[_-]?token|client[_-]?secret|secret|password)=(?<CREDENTIAL>(?!p\\.|\\$\\{)[^&\\s\"'<>]{16,})/i"
]
},
{
Expand Down
43 changes: 43 additions & 0 deletions ghost/core/core/server/api/endpoints/automations.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,49 @@ const controller = {
}
},

read: {
headers: {
cacheInvalidate: false
},
data: [
'id'
],
permissions: true,
query(frame) {
// TODO: NY-1265 - replace this static payload with persisted automation data.
return {
id: frame.data.id,
slug: 'member-welcome-email-free',
name: 'Welcome email',
status: 'active',
created_at: '2026-05-05T00:00:00.000Z',
updated_at: '2026-05-05T00:00:00.000Z',
actions: [{
id: '67f3f3f3f3f3f3f3f3f3f3f4',
type: 'wait',
data: {
wait_hours: 24
}
}, {
id: '67f3f3f3f3f3f3f3f3f3f3f5',
type: 'send email',
data: {
email_subject: 'Welcome!',
email_lexical: '{"root":{"children":[]}}',
email_sender_name: null,
email_sender_email: null,
email_sender_reply_to: null,
email_design_setting_id: '680000000000000000000001'
}
}],
edges: [{
source_action_id: '67f3f3f3f3f3f3f3f3f3f3f4',
target_action_id: '67f3f3f3f3f3f3f3f3f3f3f5'
}]
};
Comment on lines +37 to +66
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@troyciesco this is sort of a guess of what you'd need on the frontend, feel free to adjust it as needed

}
},

poll: {
statusCode: 204,
headers: {
Expand Down
1 change: 1 addition & 0 deletions ghost/core/core/server/web/api/endpoints/admin/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ module.exports = function apiRoutes() {

// ## Automations
router.get('/automations', mw.authAdminApi, http(api.automations.browse));
router.get('/automations/:id', mw.authAdminApi, http(api.automations.read));
router.put('/automations/poll', mw.authAdminApiWithUrl, http(api.automations.poll));

// ## Automated Emails
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,58 @@ Object {
"x-powered-by": "Express",
}
`;

exports[`Automations API read returns a placeholder automation for the requested id 1: [body] 1`] = `
Object {
"automations": Array [
Object {
"actions": Array [
Object {
"data": Object {
"wait_hours": 24,
},
"id": "67f3f3f3f3f3f3f3f3f3f3f4",
"type": "wait",
},
Object {
"data": Object {
"email_design_setting_id": "680000000000000000000001",
"email_lexical": "{\\"root\\":{\\"children\\":[]}}",
"email_sender_email": null,
"email_sender_name": null,
"email_sender_reply_to": null,
"email_subject": "Welcome!",
},
"id": "67f3f3f3f3f3f3f3f3f3f3f5",
"type": "send email",
},
],
"created_at": "2026-05-05T00:00:00.000Z",
"edges": Array [
Object {
"source_action_id": "67f3f3f3f3f3f3f3f3f3f3f4",
"target_action_id": "67f3f3f3f3f3f3f3f3f3f3f5",
},
],
"id": "67f3f3f3f3f3f3f3f3f3f3f3",
"name": "Welcome email",
"slug": "member-welcome-email-free",
"status": "active",
"updated_at": "2026-05-05T00:00:00.000Z",
},
],
}
`;

exports[`Automations API read returns a placeholder automation for the requested id 2: [headers] 1`] = `
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "666",
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
"vary": "Accept-Version, Origin, Accept-Encoding",
"x-powered-by": "Express",
}
`;
16 changes: 16 additions & 0 deletions ghost/core/test/e2e-api/admin/automations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ describe('Automations API', function () {
});
});

describe('read', function () {
it('returns a placeholder automation for the requested id', async function () {
const automationId = '67f3f3f3f3f3f3f3f3f3f3f3';

await agent
.get(`automations/${automationId}`)
.expectStatus(200)
.expect(cacheInvalidateHeaderNotSet())
.matchBodySnapshot()
.matchHeaderSnapshot({
'content-version': anyContentVersion,
etag: anyEtag
});
});
});

describe('poll', function () {
/** @type {sinon.SinonStub} */
let dispatchStub;
Expand Down
41 changes: 41 additions & 0 deletions ghost/core/test/unit/api/endpoints/automations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,47 @@ describe('Automations controller', function () {
});
});

describe('read', function () {
it('returns a placeholder automation for the requested id', function () {
const result = automationsController.read.query({
data: {
id: '67f3f3f3f3f3f3f3f3f3f3f3'
}
});

assert.deepEqual(result, {
id: '67f3f3f3f3f3f3f3f3f3f3f3',
slug: 'member-welcome-email-free',
name: 'Welcome email',
status: 'active',
created_at: '2026-05-05T00:00:00.000Z',
updated_at: '2026-05-05T00:00:00.000Z',
actions: [{
id: '67f3f3f3f3f3f3f3f3f3f3f4',
type: 'wait',
data: {
wait_hours: 24
}
}, {
id: '67f3f3f3f3f3f3f3f3f3f3f5',
type: 'send email',
data: {
email_subject: 'Welcome!',
email_lexical: '{"root":{"children":[]}}',
email_sender_name: null,
email_sender_email: null,
email_sender_reply_to: null,
email_design_setting_id: '680000000000000000000001'
}
}],
edges: [{
source_action_id: '67f3f3f3f3f3f3f3f3f3f3f4',
target_action_id: '67f3f3f3f3f3f3f3f3f3f3f5'
}]
});
});
});

describe('poll', function () {
it('dispatches a StartAutomationsPollEvent', function () {
const result = automationsController.poll.query({});
Expand Down
Loading