Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
timonson committed May 14, 2024
1 parent f505859 commit c1604cb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
10 changes: 8 additions & 2 deletions server/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { authErrorData } from "./error_data.ts";
import { getJwtFromBearer, isArray, isPresent, type Payload } from "./deps.ts";
import {
getJwtFromBearer,
isArray,
isFunction,
isPresent,
type Payload,
} from "./deps.ts";
import { type CreationInput } from "./creation.ts";
import { type AuthInput } from "./response.ts";
import { type ValidationSuccess } from "./validation.ts";
Expand Down Expand Up @@ -49,7 +55,7 @@ function processAuthData(
) {
try {
const verify = authData.verification;
if (typeof verify === "function") {
if (isFunction(verify)) {
const jwt = getJwtFromBearer(authData.headers);
const payload = await verify(jwt, authData.options);
return { validationObject, methods, options, payload };
Expand Down
3 changes: 3 additions & 0 deletions server/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export {
} from "https://dev.zaubrik.com/[email protected]/functions/mod.ts";
export {
isArray,
isFunction,
isNotNull,
isObject,
isPresent,
isString,
} from "https://dev.zaubrik.com/[email protected]/type.js";
11 changes: 0 additions & 11 deletions server/object.js

This file was deleted.

9 changes: 5 additions & 4 deletions server/response.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { createRpcResponseOrBatch } from "./creation.ts";
import { validateRequest } from "./validation.ts";
import { type JsonValue } from "../rpc_types.ts";
import {
type CryptoKeyOrUpdateInput,
isFunction,
verifyJwt,
type VerifyOptions,
} from "./deps.ts";
import { createRpcResponseOrBatch } from "./creation.ts";
import { validateRequest } from "./validation.ts";
import { type JsonValue } from "../rpc_types.ts";

export type Methods = {
// deno-lint-ignore no-explicit-any
Expand All @@ -32,7 +33,7 @@ export function ensureVerify(authInput: AuthInput): AuthInput {
const verification = authInput.verification;
return {
...authInput,
verification: typeof verification === "function"
verification: isFunction(verification)
? verification
: verifyJwt(verification),
};
Expand Down
6 changes: 3 additions & 3 deletions server/validation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isObject } from "./deps.ts";
import { isFunction, isNotNull, isObject, isString } from "./deps.ts";
import {
invalidParamsErrorData,
invalidRequestErrorData,
Expand Down Expand Up @@ -36,7 +36,7 @@ function isRpcVersion(input: unknown): input is "2.0" {
}

function isRpcMethod(input: unknown): input is string {
return typeof input === "string" && !input.startsWith("rpc.");
return isString(input) && !input.startsWith("rpc.");
}

export function isRpcParams(input: unknown): input is JsonArray | JsonObject {
Expand Down Expand Up @@ -98,7 +98,7 @@ export function validateRpcRequestObject(
id: isRpcId(decodedBody.id) ? decodedBody.id : null,
isError: true,
};
} else if (typeof methods[decodedBody.method] !== "function") {
} else if (!(isFunction(methods[decodedBody.method]))) {
return {
id: decodedBody.id,
isError: true,
Expand Down
2 changes: 1 addition & 1 deletion test_deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export {
assertEquals,
assertNotEquals,
assertThrows,
} from "https://deno.land/std@0.223.0/testing/asserts.ts";
} from "https://deno.land/std@0.224.0/testing/asserts.ts";
export { create, type Payload } from "https://deno.land/x/[email protected]/mod.ts";

0 comments on commit c1604cb

Please sign in to comment.