How to use zod - 8 common examples

To help you get started, we’ve selected a few zod examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github molenzwiebel / Mimic / rift / src / web.ts View on Github external
app.post("/v1/conduit/register", async (req, res) => {
    // Check that they provided a public key.
    if (!z.object({
        pubkey: z.string()
    }).check(req.body)) {
        return res.status(400).json({
            ok: false,
            error: "Invalid request."
        });
    }

    // Generate a new unique code.
    const code = await db.generateCode(req.body.pubkey);
    console.log("[+] New Conduit registered. Code: " + code);

    // Sign a JWT for the machine and return it.
    res.json({
        ok: true,
        token: tokens.createConnectionToken(code)
    });
github molenzwiebel / Mimic / rift / src / web.ts View on Github external
app.post("/v1/notifications/register", async (req, res) => {
    if (!z.object({
        uuid: z.string(),
        platform: z.string(),
        token: z.string().nullable()
    }).check(req.body) || !NOTIFICATION_PLATFORMS.includes(req.body.platform)) {
        return res.status(400).json({
            ok: false,
            error: "Invalid request."
        });
    }

    console.log(`[+] Updated notification token for ${req.body.uuid} to '${req.body.token}'`);
    await db.registerOrUpdateDeviceNotifications(req.body.uuid, req.body.platform as NotificationPlatform, req.body.token);

    return res.json({
        ok: true
    });
});
github molenzwiebel / Mimic / rift / src / web.ts View on Github external
app.post("/v1/notifications/respond", async (req, res) => {
    if (!z.object({
        token: z.string(),
        response: z.string()
    }).check(req.query)) {
        return res.status(400).json({
            ok: false,
            error: "Invalid request."
        });
    }

    const token = await tokens.verifyInstantResponseToken(req.query.token);
    if (!token) {
        return res.status(400).json({
            ok: false,
            error: "Invalid token."
        });
    }

    console.log("[+] Got response " + req.query.response + " for computer " + token.code);
github molenzwiebel / Mimic / rift / src / web.ts View on Github external
app.post("/v1/notifications/register", async (req, res) => {
    if (!z.object({
        uuid: z.string(),
        platform: z.string(),
        token: z.string().nullable()
    }).check(req.body) || !NOTIFICATION_PLATFORMS.includes(req.body.platform)) {
        return res.status(400).json({
            ok: false,
            error: "Invalid request."
        });
    }

    console.log(`[+] Updated notification token for ${req.body.uuid} to '${req.body.token}'`);
    await db.registerOrUpdateDeviceNotifications(req.body.uuid, req.body.platform as NotificationPlatform, req.body.token);

    return res.json({
        ok: true
    });
});
github molenzwiebel / Mimic / rift / src / web.ts View on Github external
app.post("/v1/notifications/subscribe", async (req, res) => {
    if (!z.object({
        uuid: z.string(),
        token: z.string(),
        type: z.string()
    }).check(req.body) || !NOTIFICATION_TYPES.includes(req.body.type)) {
        return res.status(400).json({
            ok: false,
            error: "Invalid request."
        });
    }

    const code = await tokens.verifyPushNotificationToken(req.body.token);
    if (!code) return res.status(403).json({
        ok: false,
        error: "Invalid token."
    });

    console.log(`[+] Device ${req.body.uuid} subscribed to ${req.body.type} notifications.`);
    await db.subscribeDeviceNotifications(req.body.uuid, code, req.body.type as NotificationType);
github molenzwiebel / Mimic / rift / src / web.ts View on Github external
app.post("/v1/notifications/register", async (req, res) => {
    if (!z.object({
        uuid: z.string(),
        platform: z.string(),
        token: z.string().nullable()
    }).check(req.body) || !NOTIFICATION_PLATFORMS.includes(req.body.platform)) {
        return res.status(400).json({
            ok: false,
            error: "Invalid request."
        });
    }

    console.log(`[+] Updated notification token for ${req.body.uuid} to '${req.body.token}'`);
    await db.registerOrUpdateDeviceNotifications(req.body.uuid, req.body.platform as NotificationPlatform, req.body.token);

    return res.json({
        ok: true
    });
});
github molenzwiebel / Mimic / rift / src / web.ts View on Github external
app.post("/v1/notifications/respond", async (req, res) => {
    if (!z.object({
        token: z.string(),
        response: z.string()
    }).check(req.query)) {
        return res.status(400).json({
            ok: false,
            error: "Invalid request."
        });
    }

    const token = await tokens.verifyInstantResponseToken(req.query.token);
    if (!token) {
        return res.status(400).json({
            ok: false,
            error: "Invalid token."
        });
    }
github molenzwiebel / Mimic / rift / src / web.ts View on Github external
app.post("/v1/notifications/subscribe", async (req, res) => {
    if (!z.object({
        uuid: z.string(),
        token: z.string(),
        type: z.string()
    }).check(req.body) || !NOTIFICATION_TYPES.includes(req.body.type)) {
        return res.status(400).json({
            ok: false,
            error: "Invalid request."
        });
    }

    const code = await tokens.verifyPushNotificationToken(req.body.token);
    if (!code) return res.status(403).json({
        ok: false,
        error: "Invalid token."
    });

zod

TypeScript-first schema declaration and validation library with static type inference

MIT
Latest version published 7 months ago

Package Health Score

93 / 100
Full package analysis

Popular zod functions