@nekm/svelte-core 1.7.11 → 1.7.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
- import type { ProtectConfig } from "./contracts.ts";
1
+ import type { ProtectConfig } from "./contracts.js";
2
+ import { type JWTVerifyGetKey } from "jose";
2
3
  export declare function getRedirectUri(origin: string, path: string): string;
3
- export declare function jwtVerifyIdToken(config: ProtectConfig, jwks: unknown, idToken: string): Promise<import("jose").JWTPayload>;
4
- export declare function jwtVerifyAccessToken(config: ProtectConfig, jwks: unknown, accessToken: string): Promise<import("jose").JWTPayload>;
4
+ export declare function jwtVerifyIdToken(config: ProtectConfig, jwks: JWTVerifyGetKey, idToken: string): Promise<import("jose").JWTPayload>;
5
+ export declare function jwtVerifyAccessToken(config: ProtectConfig, jwks: JWTVerifyGetKey, accessToken: string): Promise<import("jose").JWTPayload>;
@@ -3,18 +3,16 @@ import { jwtVerify } from "jose";
3
3
  export function getRedirectUri(origin, path) {
4
4
  return `${strTrimEnd(origin, "/")}/${path}`;
5
5
  }
6
- export async function jwtVerifyIdToken(config, jwks, idToken) {
7
- const { payload } = await jwtVerify(idToken,
8
- // @ts-expect-error It's OK.
9
- jwks, {
6
+ export function jwtVerifyIdToken(config, jwks, idToken) {
7
+ return jwtVerifyToken(jwks, {
10
8
  issuer: config.oauth.issuer,
11
9
  audience: config.oauth.clientId,
12
- });
13
- return payload;
10
+ }, idToken);
11
+ }
12
+ export function jwtVerifyAccessToken(config, jwks, accessToken) {
13
+ return jwtVerifyToken(jwks, { issuer: config.oauth.issuer }, accessToken);
14
14
  }
15
- export async function jwtVerifyAccessToken(config, jwks, accessToken) {
16
- const { payload } = await jwtVerify(accessToken,
17
- // @ts-expect-error It's OK.
18
- jwks, { issuer: config.oauth.issuer });
15
+ async function jwtVerifyToken(jwks, options, token) {
16
+ const { payload } = await jwtVerify(token, jwks, options);
19
17
  return payload;
20
18
  }
@@ -1,7 +1,7 @@
1
1
  import { error, redirect } from "@sveltejs/kit";
2
2
  import { ROUTE_PATH_LOGIN } from "./routes/login.js";
3
3
  import { ROUTE_PATH_LOGOUT } from "./routes/logout.js";
4
- import { routeCreate } from "./routes/routes.ts";
4
+ import { routeCreate } from "./routes/routes.js";
5
5
  export const PROTECT_LOGIN = "/" + ROUTE_PATH_LOGIN;
6
6
  export const PROTECT_LOGOUT = "/" + ROUTE_PATH_LOGOUT;
7
7
  export function protect(config) {
@@ -1,3 +1,3 @@
1
- import type { RouteFactory } from "./routes.ts";
1
+ import type { RouteFactory } from "./routes.js";
2
2
  export declare const ROUTE_PATH_LOGIN = "_auth/login";
3
3
  export declare const routeLoginFactory: RouteFactory;
@@ -1,3 +1,3 @@
1
- import type { RouteFactory } from "./routes.ts";
1
+ import type { RouteFactory } from "./routes.js";
2
2
  export declare const ROUTE_PATH_LOGOUT = "_auth/logout";
3
3
  export declare const routeLogoutFactory: RouteFactory;
@@ -1,3 +1,3 @@
1
- import type { RouteFactory } from "./routes.ts";
1
+ import type { RouteFactory } from "./routes.js";
2
2
  export declare const ROUTE_PATH_REDIRECT_LOGIN = "_auth/redirect/login";
3
3
  export declare const routeRedirectLoginFactory: RouteFactory;
@@ -20,13 +20,16 @@ export const routeRedirectLoginFactory = (config) => {
20
20
  redirect_uri: getRedirectUri(origin, ROUTE_PATH_REDIRECT_LOGIN),
21
21
  }).toString(),
22
22
  });
23
+ if (!response.ok) {
24
+ const error = await response.text();
25
+ throw new Error(`Token exchange failed: ${error}`);
26
+ }
23
27
  return await response.json();
24
28
  }
25
29
  return {
26
30
  path: ROUTE_PATH_REDIRECT_LOGIN,
27
31
  async handle({ event }) {
28
32
  const state = event.url.searchParams.get("state") ?? undefined;
29
- ;
30
33
  const stateSession = await config.session.stateGet(event);
31
34
  if (state !== stateSession) {
32
35
  throw new Error("State do not match");
@@ -1,3 +1,3 @@
1
- import type { RouteFactory } from "./routes.ts";
1
+ import type { RouteFactory } from "./routes.js";
2
2
  export declare const ROUTE_PATH_REDIRECT_LOGOUT = "_auth/redirect/logout";
3
3
  export declare const routeRedirectLogoutFactory: RouteFactory;
@@ -1,5 +1,5 @@
1
1
  import type { Handle } from "@sveltejs/kit";
2
- import type { ProtectConfig } from "../contracts.ts";
2
+ import type { ProtectConfig } from "../contracts.js";
3
3
  export interface Route {
4
4
  readonly path: string;
5
5
  readonly handle: Handle;
@@ -1,7 +1,7 @@
1
- import { routeLoginFactory } from "./login.ts";
2
- import { routeLogoutFactory } from "./logout.ts";
3
- import { routeRedirectLogoutFactory } from "./redirect-logout.ts";
4
- import { routeRedirectLoginFactory } from "./redirect-login.ts";
1
+ import { routeLoginFactory } from "./login.js";
2
+ import { routeLogoutFactory } from "./logout.js";
3
+ import { routeRedirectLogoutFactory } from "./redirect-logout.js";
4
+ import { routeRedirectLoginFactory } from "./redirect-login.js";
5
5
  const routeFactories = Object.freeze([
6
6
  routeLoginFactory,
7
7
  routeLogoutFactory,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@nekm/svelte-core",
3
3
  "description": "Code I find myself re-writing over-and-over, Svelte edition.",
4
4
  "license": "MIT",
5
- "version": "1.7.11",
5
+ "version": "1.7.15",
6
6
  "scripts": {
7
7
  "dev": "vite dev",
8
8
  "build": "vite build && npm run prepack",