diff --git a/package.json b/package.json index fb0fbcee5..6a11af50d 100644 --- a/package.json +++ b/package.json @@ -134,6 +134,7 @@ "redirect_uri", "request_uri", "response_type", + "source_url", "success_description", "token_type" ] diff --git a/packages/endpoint-posts/includes/endpoint-posts-syndicate.njk b/packages/endpoint-posts/includes/endpoint-posts-syndicate.njk index bd13eab3d..46e190213 100644 --- a/packages/endpoint-posts/includes/endpoint-posts-syndicate.njk +++ b/packages/endpoint-posts/includes/endpoint-posts-syndicate.njk @@ -6,14 +6,14 @@ }) | indent(2) }} {{ input({ - name: "redirectUri", + name: "syndication[redirect_uri]", type: "hidden", value: redirectUri }) | indent(2) }} {{ button({ classes: "button--secondary button--small", - name: "url", + name: "syndication[source_url]", value: post.url, icon: "syndicate", text: __("posts.post.syndicate") diff --git a/packages/endpoint-syndicate/README.md b/packages/endpoint-syndicate/README.md index fca0319ae..b81210baa 100644 --- a/packages/endpoint-syndicate/README.md +++ b/packages/endpoint-syndicate/README.md @@ -28,4 +28,4 @@ Add `@indiekit/endpoint-syndicate` to your list of plug-ins, specifying options ## Supported endpoint queries - Access token (required): `/syndicate?token=XXXXXXX` -- URL to syndicate: `/syndicate?token=XXXXXXX&url=https%3A%2F%2Fwebsite.example%2Fposts%2F1` +- URL to syndicate: `/syndicate?token=XXXXXXX&source_url=https%3A%2F%2Fwebsite.example%2Fposts%2F1` diff --git a/packages/endpoint-syndicate/lib/controllers/syndicate.js b/packages/endpoint-syndicate/lib/controllers/syndicate.js index d5d383f65..8a8215926 100644 --- a/packages/endpoint-syndicate/lib/controllers/syndicate.js +++ b/packages/endpoint-syndicate/lib/controllers/syndicate.js @@ -7,8 +7,10 @@ export const syndicateController = { try { const { application, publication } = request.app.locals; const token = request.query.token || request.body.token; - const url = request.query.url || request.body.url; - const redirectUri = request.query.redirectUri || request.body.redirectUri; + const sourceUrl = + request.query.source_url || request.body.syndication?.source_url; + const redirectUri = + request.query.redirect_uri || request.body.syndication?.redirect_uri; if (!application.hasDatabase) { throw IndiekitError.notImplemented( @@ -26,12 +28,12 @@ export const syndicateController = { } // Get post data - const postData = await getPostData(publication, url); + const postData = await getPostData(publication, sourceUrl); - if (!postData && url) { + if (!postData && sourceUrl) { return response.json({ success: "OK", - success_description: `No post record available for ${url}`, + success_description: `No post record available for ${sourceUrl}`, }); } diff --git a/packages/endpoint-syndicate/tests/integration/200-no-post-record-for-url.js b/packages/endpoint-syndicate/tests/integration/200-no-post-record-for-url.js index 748bcb4d4..ee2acc768 100644 --- a/packages/endpoint-syndicate/tests/integration/200-no-post-record-for-url.js +++ b/packages/endpoint-syndicate/tests/integration/200-no-post-record-for-url.js @@ -12,7 +12,7 @@ test("Returns no post record for URL", async (t) => { .post("/syndicate") .auth(testToken(), { type: "bearer" }) .set("accept", "application/json") - .query({ url: "https://website.example/notes/foobar/" }); + .query({ source_url: "https://website.example/notes/foobar/" }); t.is(result.status, 200); t.is( diff --git a/packages/endpoint-syndicate/tests/integration/200-syndicates-url-for-target.js b/packages/endpoint-syndicate/tests/integration/200-syndicates-url-for-target.js index 5787fca22..4d0eb5c00 100644 --- a/packages/endpoint-syndicate/tests/integration/200-syndicates-url-for-target.js +++ b/packages/endpoint-syndicate/tests/integration/200-syndicates-url-for-target.js @@ -29,7 +29,7 @@ test("Syndicates a URL", async (t) => { const result = await request .post("/syndicate") .set("accept", "application/json") - .query({ url: "https://website.example/notes/foobar/" }) + .query({ source_url: "https://website.example/notes/foobar/" }) .query({ token: testToken() }); t.is(result.status, 200); diff --git a/packages/endpoint-syndicate/tests/integration/200-syndicates-url-for-targets-one-fail.js b/packages/endpoint-syndicate/tests/integration/200-syndicates-url-for-targets-one-fail.js index c471654f4..aade8e25c 100644 --- a/packages/endpoint-syndicate/tests/integration/200-syndicates-url-for-targets-one-fail.js +++ b/packages/endpoint-syndicate/tests/integration/200-syndicates-url-for-targets-one-fail.js @@ -41,7 +41,7 @@ test("Syndicates a URL", async (t) => { const result = await request .post("/syndicate") .set("accept", "application/json") - .query({ url: "https://website.example/notes/foobar/" }) + .query({ source_url: "https://website.example/notes/foobar/" }) .query({ token: testToken() }); t.is(result.status, 200); diff --git a/packages/endpoint-syndicate/tests/integration/200-syndicates-url-for-targets.js b/packages/endpoint-syndicate/tests/integration/200-syndicates-url-for-targets.js index fe479a7ad..168857755 100644 --- a/packages/endpoint-syndicate/tests/integration/200-syndicates-url-for-targets.js +++ b/packages/endpoint-syndicate/tests/integration/200-syndicates-url-for-targets.js @@ -48,7 +48,7 @@ test("Syndicates a URL", async (t) => { const result = await request .post("/syndicate") .set("accept", "application/json") - .query({ url: "https://website.example/notes/foobar/" }) + .query({ source_url: "https://website.example/notes/foobar/" }) .query({ token: testToken() }); t.is(result.status, 200); diff --git a/packages/endpoint-syndicate/tests/integration/200-target-error.js b/packages/endpoint-syndicate/tests/integration/200-target-error.js index 7da9327ed..1e5225c82 100644 --- a/packages/endpoint-syndicate/tests/integration/200-target-error.js +++ b/packages/endpoint-syndicate/tests/integration/200-target-error.js @@ -29,7 +29,7 @@ test("Returns 500 error syndicating URL", async (t) => { const result = await request .post("/syndicate") .set("accept", "application/json") - .query({ url: "https://website.example/notes/foobar/" }) + .query({ source_url: "https://website.example/notes/foobar/" }) .query({ token: testToken() }); t.is(result.status, 200); diff --git a/packages/endpoint-syndicate/tests/integration/302-syndicates-url-for-target-redirect.js b/packages/endpoint-syndicate/tests/integration/302-syndicates-url-for-target-redirect.js index 52bd94da6..6e68575db 100644 --- a/packages/endpoint-syndicate/tests/integration/302-syndicates-url-for-target-redirect.js +++ b/packages/endpoint-syndicate/tests/integration/302-syndicates-url-for-target-redirect.js @@ -29,8 +29,12 @@ test("Syndicates a URL", async (t) => { const result = await request .post("/syndicate") .set("accept", "application/json") - .send({ url: "https://website.example/notes/foobar/" }) - .send({ redirectUri: "/posts/12345" }) + .send({ + syndication: { + url: "https://website.example/notes/foobar/", + redirect_uri: "/posts/12345", + }, + }) .send({ token: testToken() }); t.is(result.status, 302);