@logto/sveltekit 0.1.0 → 0.2.2

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,2 +1,3 @@
1
- /// <reference types="jest" />
2
- export declare const redirect: jest.Mock<any, any, any>;
1
+ import { type redirect as originalRedirect } from '@sveltejs/kit';
2
+ import { type Mock } from 'vitest';
3
+ export declare const redirect: Mock<Parameters<typeof originalRedirect>, ReturnType<typeof originalRedirect>>;
@@ -1 +1,2 @@
1
- export const redirect = jest.fn();
1
+ import { vi } from 'vitest';
2
+ export const redirect = vi.fn();
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import LogtoClient, { type LogtoConfig, type CookieConfig } from '@logto/node';
2
2
  import { type Handle, type RequestEvent } from '@sveltejs/kit';
3
- export type { IdTokenClaims, LogtoErrorCode, LogtoConfig, LogtoClientErrorCode, Storage, StorageKey, InteractionMode, ClientAdapter, JwtVerifier, UserInfoResponse, } from '@logto/node';
4
- export { LogtoError, LogtoRequestError, LogtoClientError, OidcError, Prompt, ReservedScope, ReservedResource, UserScope, organizationUrnPrefix, buildOrganizationUrn, getOrganizationIdFromUrn, PersistKey, StandardLogtoClient, default as LogtoClient, } from '@logto/node';
3
+ export type { IdTokenClaims, LogtoErrorCode, LogtoConfig, LogtoClientErrorCode, Storage, StorageKey, InteractionMode, ClientAdapter, JwtVerifier, UserInfoResponse, CookieConfig, } from '@logto/node';
4
+ export { LogtoError, LogtoRequestError, LogtoClientError, OidcError, Prompt, ReservedScope, ReservedResource, UserScope, organizationUrnPrefix, buildOrganizationUrn, getOrganizationIdFromUrn, PersistKey, CookieStorage, StandardLogtoClient, default as LogtoClient, } from '@logto/node';
5
5
  export type HookConfig = {
6
6
  /**
7
7
  * The error response factory when an error occurs during the callback. If not provided, a 400
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import LogtoClient, { CookieStorage } from '@logto/node';
2
- import { redirect } from '@sveltejs/kit';
3
- export { LogtoError, LogtoRequestError, LogtoClientError, OidcError, Prompt, ReservedScope, ReservedResource, UserScope, organizationUrnPrefix, buildOrganizationUrn, getOrganizationIdFromUrn, PersistKey, StandardLogtoClient, default as LogtoClient, } from '@logto/node';
2
+ import { redirect, isRedirect } from '@sveltejs/kit';
3
+ export { LogtoError, LogtoRequestError, LogtoClientError, OidcError, Prompt, ReservedScope, ReservedResource, UserScope, organizationUrnPrefix, buildOrganizationUrn, getOrganizationIdFromUrn, PersistKey, CookieStorage, StandardLogtoClient, default as LogtoClient, } from '@logto/node';
4
4
  /**
5
5
  * The factory to create a SvelteKit hook to handle Logto authentication. The hook will
6
6
  * initialize the `LogtoClient` instance and add it to the `locals` of the request event. It will
@@ -74,8 +74,12 @@ export const handleLogto = (config, cookieConfig, hookConfig) => {
74
74
  await logtoClient.handleSignInCallback(event.url.href);
75
75
  }
76
76
  catch (error) {
77
+ if (isRedirect(error)) {
78
+ // eslint-disable-next-line @typescript-eslint/no-throw-literal -- SvelteKit's convention
79
+ throw error;
80
+ }
77
81
  return (onCallbackError?.(error) ??
78
- new Response(`Error: ${error instanceof Error ? error.message : String(error)}`, {
82
+ new Response(`Error: ${error instanceof Error ? error.message : JSON.stringify(error, undefined, 2)}`, {
79
83
  status: 400,
80
84
  }));
81
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/sveltekit",
3
- "version": "0.1.0",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",
@@ -25,15 +25,14 @@
25
25
  "@silverhand/ts-config": "^5.0.0",
26
26
  "@sveltejs/kit": "^2.0.0",
27
27
  "@swc/core": "^1.4.2",
28
- "@swc/jest": "^0.2.24",
29
28
  "@types/cookie": "^0.6.0",
30
- "@types/jest": "^29.5.12",
31
29
  "@types/node": "^20.11.19",
30
+ "@vitest/coverage-v8": "^1.4.0",
32
31
  "eslint": "^8.44.0",
33
- "jest": "^29.5.0",
34
32
  "lint-staged": "^15.0.0",
35
33
  "prettier": "^3.0.0",
36
- "typescript": "^5.3.3"
34
+ "typescript": "^5.3.3",
35
+ "vitest": "^1.3.1"
37
36
  },
38
37
  "eslintConfig": {
39
38
  "extends": "@silverhand"
@@ -46,7 +45,7 @@
46
45
  "@sveltejs/kit": "^2.0.0"
47
46
  },
48
47
  "dependencies": {
49
- "@logto/node": "^2.4.0"
48
+ "@logto/node": "^2.4.1"
50
49
  },
51
50
  "scripts": {
52
51
  "dev:tsc": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
@@ -54,6 +53,7 @@
54
53
  "check": "tsc --noEmit",
55
54
  "build": "rm -rf lib/ && tsc -p tsconfig.build.json",
56
55
  "lint": "eslint --ext .ts src",
57
- "test": "jest"
56
+ "test": "vitest src",
57
+ "test:coverage": "vitest src --coverage"
58
58
  }
59
59
  }