From 759425bbaceb8e96608aaf2def7ced424061a3ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ko=C5=82odziejczak?= <31549762+mrl5@users.noreply.github.com> Date: Sat, 22 Oct 2022 14:04:38 +0200 Subject: [PATCH] feat(deno-client): improve docs by extending function signatures (#791) > as a windmill script developer I want to know what type/data structure is returned from the windmill sdk --- deno-client/mod.ts | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/deno-client/mod.ts b/deno-client/mod.ts index 19f5a3b5fa..f89d50d4bf 100644 --- a/deno-client/mod.ts +++ b/deno-client/mod.ts @@ -138,7 +138,18 @@ export async function databaseUrlFromResource(path: string): Promise { } -export async function genNounceAndHmac(workspace: string, jobId: string) { +export interface NonceAndHmac { + nonce: number; + signature: string; +} + +/** + * Get HMAC and nonce needed for approval script + * @param workspace workspace name + * @param jobId + * @returns HMAC and nonce needed to authorize approval script actions + */ +export async function genNounceAndHmac(workspace: string, jobId: string): Promise { const nonce = Math.floor(Math.random() * 4294967295); const sig = await fetch(Deno.env.get("WM_BASE_URL") + `/api/w/${workspace}/jobs/job_signature/${jobId}/${nonce}?token=${Deno.env.get("WM_TOKEN")}`) @@ -148,7 +159,17 @@ export async function genNounceAndHmac(workspace: string, jobId: string) { }; } -export async function getResumeEndpoints() { +export interface ResumeEndpoints { + approvalPage: string; + resume: string; + cancel: string; +} + +/** + * Get URLs needed for approval script + * @returns approval page UI URL, resume and cancel API URLs for approval script + */ +export async function getResumeEndpoints(): Promise { const workspace = getWorkspace() const { nonce, signature } = await genNounceAndHmac( @@ -158,7 +179,7 @@ export async function getResumeEndpoints() { const url_prefix = Deno.env.get("WM_BASE_URL") + `/api/w/${workspace}/jobs/`; - function getResumeUrl(op: string) { + function getResumeUrl(op: string): string { return url_prefix + `${op}/${Deno.env.get("WM_JOB_ID")}/${nonce}/${signature}`; } @@ -170,7 +191,6 @@ export async function getResumeEndpoints() { }; } - export function base64ToUint8Array(data: string): Uint8Array { return Uint8Array.from(atob(data), c => c.charCodeAt(0)) } @@ -225,4 +245,4 @@ export function uint8ArrayToBase64(arrayBuffer: Uint8Array): string { } return base64 -} \ No newline at end of file +}