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 internal/events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@
"typecheck": "tsc --noEmit"
},
"types": "dist/index.d.ts",
"version": "1.0.13"
"version": "1.0.14"
}
22 changes: 22 additions & 0 deletions internal/events/src/events/__tests__/event-envelope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,5 +364,27 @@ describe("EventEnvelope schema validation", () => {
const result = $EnvelopeNoPrefix.safeParse(envelope);
expect(result.success).toBe(false);
});

it("should accept subject with non uuid resource id", () => {
const envelope = {
...baseLetterEnvelope,
subject: "letter-origin/letter-rendering/letter/Some_Letter_12345",
};

const result = $EnvelopeWithPrefix.safeParse(envelope);
expect(result.error).toBeUndefined();
expect(result.success).toBe(true);
});

it("should accept subject with multi sub path resource id", () => {
const envelope = {
...baseLetterEnvelope,
subject: "letter-origin/letter-rendering/letter/a/B/c/123",
};

const result = $EnvelopeWithPrefix.safeParse(envelope);
expect(result.error).toBeUndefined();
expect(result.success).toBe(true);
});
});
});
7 changes: 5 additions & 2 deletions internal/events/src/events/event-envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export function EventEnvelope<TData extends z.ZodTypeAny>(

source: z
.string()
// eslint-disable-next-line security/detect-unsafe-regex
.regex(/^\/data-plane\/supplier-api(?:\/.*)?$/)
.meta({
title: "Event Source",
Expand All @@ -90,8 +91,10 @@ export function EventEnvelope<TData extends z.ZodTypeAny>(

subject: z
.string()

.regex(new RegExp(`^${subjectPrefixRegex}${resourceName}/[a-z0-9-]+$`))
.regex(
// eslint-disable-next-line security/detect-non-literal-regexp
new RegExp(`^${subjectPrefixRegex}${resourceName}/[^/]+(?:/.*)?$`),
)
.meta({
title: "Event Subject",
description:
Expand Down
Loading