Skip to content

Commit

Permalink
Merge pull request #236 from RBND-studio/dev
Browse files Browse the repository at this point in the history
Merge dev
  • Loading branch information
VojtechVidra committed Apr 10, 2024
2 parents 29f5950 + 9d3b5f2 commit f54df2c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const FlowPreviewDialog: FC<Props> = ({ flow }) => {
label="Start url"
type="url"
{...register("url")}
required
placeholder="https://example.com/about"
/>
</DialogContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export const FlowEditForm: FC<Props> = ({ flow, organizationId }) => {
if (res.error) return;
reset(data, { keepValues: true });
toast.success(t.toasts.updateFlowSuccess);
if (event) router.push(backLink);
const calledProgramatically = !event;
if (!calledProgramatically) router.push(backLink);
router.refresh();
},
[backLink, flow.id, reset, router, send],
Expand Down
9 changes: 9 additions & 0 deletions apps/backend/src/lib/uuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ export const UUIDParam = (name: string): ParameterDecorator =>

export const UUIDQuery = (name: string): ParameterDecorator =>
Query(name, new ParseUUIDPipe({ version: "4" }));

export const isUUID = async (value: string): Promise<boolean> => {
try {
await new ParseUUIDPipe({ version: "4" }).transform(value, { type: "custom" });
return true;
} catch {
return false;
}
};
14 changes: 11 additions & 3 deletions apps/backend/src/sdk/sdk.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ beforeEach(async () => {

describe("Get css", () => {
beforeEach(() => {
db.query.projects.findFirst.mockReturnValue({ css_vars: "vars", css_template: "template" });
db.query.projects.findFirst.mockReturnValue({
css_vars: "body { color: red; }",
css_template: "body { color: blue; }",
});
});
it("should throw without projectId", async () => {
await expect(sdkController.getCss("", "latest")).rejects.toThrow("Not Found");
Expand All @@ -56,7 +59,7 @@ describe("Get css", () => {
await expect(sdkController.getCss("projectId", "latest")).rejects.toThrow("Not Found");
});
it("should return css", async () => {
await expect(sdkController.getCss("projectId", "latest")).resolves.toEqual("vars\ntemplate");
await expect(sdkController.getCss("projectId", "latest")).resolves.toEqual("body{color:#00f}");
});
});

Expand Down Expand Up @@ -133,7 +136,7 @@ describe("Create event", () => {
userHash: "d",
flowHash: "e",
stepHash: "f",
projectId: "g",
projectId: "882b69bd-d73e-454d-8042-44d0720c6ea4",
sdkVersion: "0.0.0",
location: "/",
type: "startFlow",
Expand All @@ -149,6 +152,11 @@ describe("Create event", () => {
lemonSqueezyService.createUsageRecord.mockResolvedValue({});
organizationUsageService.getIsOrganizationLimitReachedByProject.mockResolvedValue(false);
});
it("should throw with non uuid projectId", async () => {
await expect(
sdkController.createEvent("origin", { ...createEventDto, projectId: "my-id" }),
).rejects.toThrow("Bad Request");
});
it("should throw with not allowed origin", async () => {
dbPermissionService.isAllowedOrigin.mockRejectedValue(new Error());
await expect(sdkController.createEvent("origin", createEventDto)).rejects.toThrow();
Expand Down
3 changes: 3 additions & 0 deletions apps/backend/src/sdk/sdk.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { DatabaseService } from "../database/database.service";
import { DbPermissionService } from "../db-permission/db-permission.service";
import { LemonSqueezyService } from "../lemon-squeezy/lemon-squeezy.service";
import { getDefaultCssMinTemplate, getDefaultCssMinVars } from "../lib/css";
import { isUUID } from "../lib/uuid";
import { OrganizationUsageService } from "../organization-usage/organization-usage.service";
import type { CreateEventDto, CreateEventResponseDto, GetSdkFlowsDto } from "./sdk.dto";

Expand Down Expand Up @@ -220,6 +221,8 @@ export class SdkService {
requestOrigin: string;
}): Promise<CreateEventResponseDto> {
const projectId = event.projectId;
if (!(await isUUID(projectId))) throw new BadRequestException();

await this.dbPermissionService.isAllowedOrigin({ projectId, requestOrigin });

const existingFlow = await this.databaseService.db.query.flows.findFirst({
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const Dialog: FC<Props> = ({ open, onOpenChange, trigger, children, maxWi
})}
/>
<RadixDialog.Content
onSubmit={(e) => e.stopPropagation()}
className={css({
backgroundColor: "bg",
// TODO: come up with a systematic way for dialog widths
Expand Down

0 comments on commit f54df2c

Please sign in to comment.