Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
golsch committed Dec 16, 2024
1 parent 94501cb commit 887d3d8
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 47 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mycore/mycore",
"version": "1.0.6",
"version": "1.0.0",
"license": "GPL-3.0",
"homepage": "https://www.mycore.de",
"repository": "https://github.com/MyCoRe-Org/mycore-js.git",
Expand Down
7 changes: 3 additions & 4 deletions src/auth/fetch-jwt.ts → src/auth/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
* along with MyCoRe. If not, see <http://www.gnu.org/licenses/>.
*/

import { createUrl } from '../common/url.ts';
import { handleError } from '../common/error.ts';
import { createUrl, handleError } from '../common/helpers.ts';

interface MCRJWTResponse {
// deno-lint-ignore camelcase
Expand All @@ -38,8 +37,8 @@ interface MCRJWTResponse {
* @throws Will throw an error if the fetch operation fails, if the server response is invalid or unexpected,
* or if the login attempt fails.
*/
export const fetchJWT = async (
baseUrl: string,
export const fetchAccessToken = async (
baseUrl: URL | string,
params?: Record<string, string>,
): Promise<string> => {
const url = createUrl(baseUrl, 'rsc/jwt', params);
Expand Down
2 changes: 1 addition & 1 deletion src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
* @module
*/

export * from './fetch-jwt.ts';
export * from './helpers.ts';
33 changes: 0 additions & 33 deletions src/common/error.ts

This file was deleted.

20 changes: 15 additions & 5 deletions src/common/url.ts → src/common/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* along with MyCoRe. If not, see <http://www.gnu.org/licenses/>.
*/

import { handleError } from './error.ts';

/**
* Creates a `URL` object by combining a base URL, a path, query parameters and a fragment.
*
Expand All @@ -30,13 +28,13 @@ import { handleError } from './error.ts';
*
* @throws Will throw an error if the `baseUrl` or `path` is invalid.
*/
const createUrl = (
export const createUrl = (
baseUrl: URL | string,
path?: string,
queryParams?: Record<string, string | number>,
fragment?: string,
): URL => {
let url;
let url: URL;
try {
url = path ? new URL(path, baseUrl) : new URL(baseUrl);
} catch (error) {
Expand All @@ -53,4 +51,16 @@ const createUrl = (
return url;
};

export { createUrl };
/**
* Handles an error by creating a new error message and throwing an error.
*
* @param message - A custom error message to prepend to the error
* @param error - The error object to handle. If the provided `error` is not an instance of `Error`, a generic message ('Unknown error') will be used
*
* @throws Always throws an `Error` with a detailed message, including the provided message and the error's message.
*/
export const handleError = (message: string, error: unknown): never => {
throw new Error(
`${message}: ${error instanceof Error ? error.message : 'Unknown error'}`,
);
};
3 changes: 1 addition & 2 deletions src/orcid/orcid-oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
* along with MyCoRe. If not, see <http://www.gnu.org/licenses/>.
*/

import { handleError } from '../common/error.ts';
import { createUrl } from '../common/url.ts';
import { createUrl, handleError } from '../common/helpers.ts';

/**
* Generates the URL for initializing the ORCID OAuth process.
Expand Down
2 changes: 1 addition & 1 deletion src/orcid/orcid-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with MyCoRe. If not, see <http://www.gnu.org/licenses/>.
*/

import { handleError } from '../common/error.ts';
import { handleError } from '../common/helpers.ts';

/**
* Interface representing the status of an ORCID user.
Expand Down

0 comments on commit 887d3d8

Please sign in to comment.