inkwire-receiver-core 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,6 +34,18 @@ it("rejects bad auth with 401", async () => {
34
34
  expect(r.status).toBe(401);
35
35
  expect(r.body.error.code).toBe("unauthorized");
36
36
  });
37
+ it("dedupes a 255-char slug without exceeding the length cap", async () => {
38
+ const longTitle = "a".repeat(300);
39
+ const first = await handlePost({ authHeader: auth, apiKeys: keys, store,
40
+ rawBody: { external_id: "long-1", title: longTitle, markdown: "x" } });
41
+ const second = await handlePost({ authHeader: auth, apiKeys: keys, store,
42
+ rawBody: { external_id: "long-2", title: longTitle, markdown: "x" } });
43
+ const firstSlug = first.body.slug;
44
+ const secondSlug = second.body.slug;
45
+ expect(firstSlug.length).toBe(255);
46
+ expect(secondSlug.length).toBeLessThanOrEqual(255);
47
+ expect(secondSlug).not.toBe(firstSlug);
48
+ });
37
49
  it("409 on explicit slug owned by a different external_id", async () => {
38
50
  await handlePost({ authHeader: auth, apiKeys: keys, store,
39
51
  rawBody: { external_id: "owner", title: "O", markdown: "x", slug: "taken" } });
package/dist/handle.js CHANGED
@@ -41,9 +41,12 @@ export async function handlePost(input) {
41
41
  return { status: e.httpStatus, headers: HEADERS, body: { error: { code: e.code, message: e.message } } };
42
42
  }
43
43
  }
44
+ const MAX_SLUG_LENGTH = 255;
44
45
  async function dedupeSlug(store, key, base) {
45
46
  let slug = base, n = 1;
46
- while (await store.findBySlug(key, slug))
47
- slug = `${base}-${++n}`;
47
+ while (await store.findBySlug(key, slug)) {
48
+ const suffix = `-${++n}`;
49
+ slug = base.slice(0, MAX_SLUG_LENGTH - suffix.length) + suffix;
50
+ }
48
51
  return slug;
49
52
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "inkwire-receiver-core", "version": "0.1.0", "type": "module",
2
+ "name": "inkwire-receiver-core", "version": "0.1.1", "type": "module",
3
3
  "description": "Shared TS core (validate, render, sanitize, upsert) for building an Inkwire receiver.",
4
4
  "license": "MIT",
5
5
  "repository": { "type": "git", "url": "git+https://github.com/etugrand/inkwire.git", "directory": "inkwire/receivers/core-ts" },