fix: address demo mock review
This commit is contained in:
1 parent
135611bb50
commit
d8eec36d98
13 files changed
+32
-12
No files matched your search
@@ -20,6 +20,12 @@ const noteIdInput = z.object({
|
|||||||
|
|
||||||
const logger = createLogger({ module: "anchorNotesRouter" });
|
const logger = createLogger({ module: "anchorNotesRouter" });
|
||||||
|
|
||||||
|
const assertMockNoteExists = (noteId: string) => {
|
||||||
|
if (noteId === mockWidgetData.anchorNote.id) return;
|
||||||
|
|
||||||
|
throw new TRPCError({ code: "NOT_FOUND", message: "Note not found" });
|
||||||
|
};
|
||||||
|
|
||||||
const isJsonDeltaString = (value: string) => {
|
const isJsonDeltaString = (value: string) => {
|
||||||
try {
|
try {
|
||||||
const parsed: unknown = JSON.parse(value);
|
const parsed: unknown = JSON.parse(value);
|
||||||
@@ -70,7 +76,10 @@ export const anchorNotesRouter = createTRPCRouter({
|
|||||||
.concat(createOneIntegrationMiddleware("query", "anchor", "mock"))
|
.concat(createOneIntegrationMiddleware("query", "anchor", "mock"))
|
||||||
.input(noteIdInput)
|
.input(noteIdInput)
|
||||||
.query(async ({ ctx, input }) => {
|
.query(async ({ ctx, input }) => {
|
||||||
if (ctx.integration.kind === "mock") return mockWidgetData.anchorNote;
|
if (ctx.integration.kind === "mock") {
|
||||||
|
assertMockNoteExists(input.noteId);
|
||||||
|
return mockWidgetData.anchorNote;
|
||||||
|
}
|
||||||
|
|
||||||
const handler = anchorNoteRequestHandler.handler(
|
const handler = anchorNoteRequestHandler.handler(
|
||||||
{ ...ctx.integration, kind: "anchor" },
|
{ ...ctx.integration, kind: "anchor" },
|
||||||
@@ -90,6 +99,7 @@ export const anchorNotesRouter = createTRPCRouter({
|
|||||||
input.content !== undefined && normalizedContent !== undefined && input.content !== normalizedContent;
|
input.content !== undefined && normalizedContent !== undefined && input.content !== normalizedContent;
|
||||||
|
|
||||||
if (ctx.integration.kind === "mock") {
|
if (ctx.integration.kind === "mock") {
|
||||||
|
assertMockNoteExists(input.noteId);
|
||||||
return {
|
return {
|
||||||
...mockWidgetData.anchorNote,
|
...mockWidgetData.anchorNote,
|
||||||
...(input.title !== undefined ? { title: input.title } : {}),
|
...(input.title !== undefined ? { title: input.title } : {}),
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export const archiveTeamWarriorRouter = createTRPCRouter({
|
|||||||
.concat(createOneIntegrationMiddleware("query", "archiveTeamWarrior", "mock"))
|
.concat(createOneIntegrationMiddleware("query", "archiveTeamWarrior", "mock"))
|
||||||
.query(async ({ ctx }) => {
|
.query(async ({ ctx }) => {
|
||||||
if (ctx.integration.kind === "mock") {
|
if (ctx.integration.kind === "mock") {
|
||||||
return { status: mockWidgetData.archiveTeamWarrior, updatedAt: new Date() };
|
return { status: mockWidgetData.archiveTeamWarrior, updatedAt: new Date(mockWidgetData.timestamp) };
|
||||||
}
|
}
|
||||||
|
|
||||||
const handler = archiveTeamWarriorRequestHandler.handler({ ...ctx.integration, kind: "archiveTeamWarrior" }, {});
|
const handler = archiveTeamWarriorRequestHandler.handler({ ...ctx.integration, kind: "archiveTeamWarrior" }, {});
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export const coolifyRouter = createTRPCRouter({
|
|||||||
integrationName: integration.name,
|
integrationName: integration.name,
|
||||||
integrationUrl: integration.url,
|
integrationUrl: integration.url,
|
||||||
instanceInfo: mockWidgetData.coolify,
|
instanceInfo: mockWidgetData.coolify,
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(mockWidgetData.timestamp),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,12 @@ const queryFirewall = <TSummary>(
|
|||||||
async (integration): Promise<FirewallResult<TSummary>> => {
|
async (integration): Promise<FirewallResult<TSummary>> => {
|
||||||
if (integration.kind === "mock") {
|
if (integration.kind === "mock") {
|
||||||
return {
|
return {
|
||||||
integration: { id: integration.id, name: integration.name, kind: integration.kind, updatedAt: new Date() },
|
integration: {
|
||||||
|
id: integration.id,
|
||||||
|
name: integration.name,
|
||||||
|
kind: integration.kind,
|
||||||
|
updatedAt: new Date(mockWidgetData.timestamp),
|
||||||
|
},
|
||||||
summary: getMockData(),
|
summary: getMockData(),
|
||||||
error: undefined,
|
error: undefined,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export const speedtestTrackerRouter = createTRPCRouter({
|
|||||||
integrationName: integration.name,
|
integrationName: integration.name,
|
||||||
integrationUrl: integration.url,
|
integrationUrl: integration.url,
|
||||||
dashboard: mockWidgetData.speedtestTracker,
|
dashboard: mockWidgetData.speedtestTracker,
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(mockWidgetData.timestamp),
|
||||||
error: undefined,
|
error: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export const tracearrRouter = createTRPCRouter({
|
|||||||
integrationName: integration.name,
|
integrationName: integration.name,
|
||||||
integrationUrl: integration.url,
|
integrationUrl: integration.url,
|
||||||
dashboard: mockWidgetData.tracearr,
|
dashboard: mockWidgetData.tracearr,
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(mockWidgetData.timestamp),
|
||||||
error: undefined,
|
error: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export const traefikRouter = createTRPCRouter({
|
|||||||
integrationName: integration.name,
|
integrationName: integration.name,
|
||||||
integrationUrl: integration.url,
|
integrationUrl: integration.url,
|
||||||
dashboard: mockWidgetData.traefik,
|
dashboard: mockWidgetData.traefik,
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(mockWidgetData.timestamp),
|
||||||
error: undefined,
|
error: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ export const umamiRouter = createTRPCRouter({
|
|||||||
integrationName: integration.name,
|
integrationName: integration.name,
|
||||||
integrationUrl: integration.url,
|
integrationUrl: integration.url,
|
||||||
visitorStats: { ...mockWidgetData.umamiVisitorStats, timeFrame: input.timeFrame },
|
visitorStats: { ...mockWidgetData.umamiVisitorStats, timeFrame: input.timeFrame },
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(mockWidgetData.timestamp),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const innerHandler = umamiRequestHandler.handler(
|
const innerHandler = umamiRequestHandler.handler(
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export const uptimeKumaRouter = createTRPCRouter({
|
|||||||
integrationName: integration.name,
|
integrationName: integration.name,
|
||||||
integrationUrl: integration.url,
|
integrationUrl: integration.url,
|
||||||
dashboard: mockWidgetData.uptimeKuma,
|
dashboard: mockWidgetData.uptimeKuma,
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(mockWidgetData.timestamp),
|
||||||
error: undefined,
|
error: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export const vpnRouter = createTRPCRouter({
|
|||||||
id: integration.id,
|
id: integration.id,
|
||||||
name: integration.name,
|
name: integration.name,
|
||||||
kind: integration.kind,
|
kind: integration.kind,
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(mockWidgetData.timestamp),
|
||||||
},
|
},
|
||||||
summary: mockWidgetData.vpn,
|
summary: mockWidgetData.vpn,
|
||||||
error: undefined,
|
error: undefined,
|
||||||
|
|||||||
@@ -10,12 +10,14 @@ export const wudRouter = createTRPCRouter({
|
|||||||
mcp: {
|
mcp: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
description:
|
description:
|
||||||
"Returns monitored-container counts and available updates from a What's Up Docker integration. REQUIRED: integrationId from integration_all. The caller needs query permission for that integration.",
|
"Returns monitored-container counts and available updates from a What's Up Docker integration, or mock statistics from a mock integration. REQUIRED: integrationId from integration_all. The caller needs query permission for that integration.",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.concat(createOneIntegrationMiddleware("query", "wud", "mock"))
|
.concat(createOneIntegrationMiddleware("query", "wud", "mock"))
|
||||||
.query(async ({ ctx }) => {
|
.query(async ({ ctx }) => {
|
||||||
if (ctx.integration.kind === "mock") return { stats: mockWidgetData.wud, updatedAt: new Date() };
|
if (ctx.integration.kind === "mock") {
|
||||||
|
return { stats: mockWidgetData.wud, updatedAt: new Date(mockWidgetData.timestamp) };
|
||||||
|
}
|
||||||
const handler = wudStatsRequestHandler.handler({ ...ctx.integration, kind: "wud" }, {});
|
const handler = wudStatsRequestHandler.handler({ ...ctx.integration, kind: "wud" }, {});
|
||||||
const { data, timestamp } = await handler.getDataAsync();
|
const { data, timestamp } = await handler.getDataAsync();
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ const anchorNote: AnchorNote = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const mockWidgetData = {
|
export const mockWidgetData = {
|
||||||
|
timestamp: demoTimestamp,
|
||||||
anchorNote,
|
anchorNote,
|
||||||
anchorNotes: [
|
anchorNotes: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ describe("iframe policy", () => {
|
|||||||
it("accepts HTTP URLs and same-origin paths", () => {
|
it("accepts HTTP URLs and same-origin paths", () => {
|
||||||
expect(isSupportedProtocol("https://example.com")).toBe(true);
|
expect(isSupportedProtocol("https://example.com")).toBe(true);
|
||||||
expect(isSupportedProtocol("/api/demo-assets/overview")).toBe(true);
|
expect(isSupportedProtocol("/api/demo-assets/overview")).toBe(true);
|
||||||
|
expect(isSupportedProtocol("//evil.example")).toBe(false);
|
||||||
|
expect(isSupportedProtocol("/\\evil.example")).toBe(false);
|
||||||
expect(isSupportedProtocol("javascript:alert(1)")).toBe(false);
|
expect(isSupportedProtocol("javascript:alert(1)")).toBe(false);
|
||||||
expect(isSupportedProtocol("not a url")).toBe(false);
|
expect(isSupportedProtocol("not a url")).toBe(false);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user