From 0327cf21e5e40e291b5d2ded1626885685ce8337 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Wed, 12 Jul 2023 10:52:40 +0200 Subject: [PATCH] Add a `create` method to the `session.Client` Signed-off-by: Sebastian Martinez --- httpd-client/lib/session.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/httpd-client/lib/session.ts b/httpd-client/lib/session.ts index dbec35d28..93a1eedb2 100644 --- a/httpd-client/lib/session.ts +++ b/httpd-client/lib/session.ts @@ -1,11 +1,19 @@ import type { Fetcher, RequestOptions } from "./fetcher.js"; import type { SuccessResponse } from "./shared.js"; -import type { ZodSchema } from "zod"; +import type { ZodSchema, z } from "zod"; import { number, object, string } from "zod"; import { successResponseSchema } from "./shared.js"; +export const sessionPayloadSchema = object({ + sessionId: string(), + signature: string(), + publicKey: string(), +}); + +export type SessionPayload = z.infer; + interface Session { sessionId: string; status: string; @@ -40,6 +48,17 @@ export class Client { ); } + public async create(options?: RequestOptions): Promise { + return this.#fetcher.fetchOk( + { + method: "POST", + path: "sessions", + options, + }, + sessionSchema, + ); + } + public async update( id: string, body: {