Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update kimai extension #12425

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions extensions/kimai/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Kimai Changelog

## [Update] - 2024-05-18

Added support for API token in the extension preferences.

## [Fix] - 2024-03-11

Added validation of request response data to prevent breaking the extension if the data is not valid JSON.
Expand Down
9 changes: 4 additions & 5 deletions extensions/kimai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ This [Raycast](https://raycast.com) extension lets you quickly add new time log

## Setup

![setup](media/setup.png)

To connect the extension to your Kimai instance you need to add the following settings.
To connect the extension to your Kimai instance you need to add the following settings. There are 2 way to authorize your extension `API Token` or `Email & API Password`. `API Token` is recommended and both ways are not needed.

- **Request protocol:** Protocol to be used to make API requests. If you are using local (self hosted) Kimai, set it to 'http', otherwise keep it as 'https'.
- **Kimai Domain:** The domain of your Kimai instance like `your-organization.kimai.cloud`.
- **API Token:** Recommended for use in extension. You can find it in your `API Access` settings.
- **Email:** Email you use to login into Kimai
- **API Password:** Password different from password you use to login into Kimai. You need to create it in your `API Access` settings.
- **Default time log duration (in minutes):** Duration that will be used to prepopulate duration field when adding new time log
Expand All @@ -23,5 +22,5 @@ You can find your settings by going to `https://{your-organization}.kimai.cloud/

1. Open Kimai dashboard
2. Click on your username
3. Open `Password`
4. Open `API Access`
3. Open `API Access`
4. Click on `+ Create` to create new token
Binary file removed extensions/kimai/media/setup.png
Binary file not shown.
13 changes: 10 additions & 3 deletions extensions/kimai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,24 @@
{
"name": "email",
"type": "textfield",
"required": true,
"required": false,
"title": "Email",
"description": "Your email that you use for login in Kimai"
},
{
"name": "password",
"required": false,
"type": "password",
"required": true,
"title": "API Password",
"description": "API password is different from your login password and needs to set in your profile settings"
},
{
"name": "token",
"type": "textfield",
"required": false,
"title": "API Token",
"description": "API token available in your profile settings"
},
{
"name": "duration",
"type": "textfield",
Expand Down Expand Up @@ -99,4 +106,4 @@
"pull": "npx @raycast/api@latest pull-contributions",
"publish": "npx @raycast/api@latest publish"
}
}
}
7 changes: 4 additions & 3 deletions extensions/kimai/src/libs/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ const activitySchema = z.object({
});

const fetch = async (apiPath: string, init?: RequestInit | undefined) => {
const { domain, email, password, protocol: _protocol } = getPreferences();
const { domain, email, password, protocol: _protocol, token } = getPreferences();
const protocol = _protocol || "https";

const response = await nodeFetch(`${protocol}://${domain}/api/${apiPath}`, {
...(init || {}),
headers: {
"Content-Type": "application/json",
"X-AUTH-USER": email,
"X-AUTH-TOKEN": password,
...(token ? { Authorization: `Bearer ${token}` } : {}),
...(!token && email ? { "X-AUTH-USER": email } : {}),
...(!token && password ? { "X-AUTH-TOKEN": password } : {}),
...(init?.headers || {}),
},
});
Expand Down
5 changes: 3 additions & 2 deletions extensions/kimai/src/libs/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { getPreferenceValues } from "@raycast/api";

interface Preferences {
domain: string;
password: string;
email: string;
password?: string;
email?: string;
token?: string;
protocol?: "https" | "http";
duration: string;
}
Expand Down
17 changes: 16 additions & 1 deletion extensions/kimai/src/log-time.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {
Action,
ActionPanel,
Color,
Form,
Icon,
LaunchType,
List,
PopToRootType,
Toast,
launchCommand,
Expand All @@ -27,8 +30,9 @@ interface FormValues {
const DATE_FORMAT = "YYYY-MM-DDTHH:mm:ss";

const LogTimeCommand = () => {
const { duration } = getPreferences();
const { duration, email, password, token } = getPreferences();
const initialDuration = parseInt(duration);
const validPreferences = Boolean((email && password) || token);
const { isLoading: isLoadingProjects, projects, visitItem: visitProject } = useProjects();
const { isLoading: isLoadingActivities, activities, visitItem: visitActivity } = useActivities();

Expand Down Expand Up @@ -90,6 +94,17 @@ const LogTimeCommand = () => {
},
});

if (!validPreferences) {
return (
<List>
<List.EmptyView
icon={{ source: Icon.Warning, tintColor: Color.Orange }}
title="Please set your API token or your email and password in the preferences"
/>
</List>
);
}

return (
<Form
isLoading={isLoadingProjects || isLoadingActivities}
Expand Down