@knpkv/clockify-api-client 0.3.0 → 1.0.1
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.
- package/CHANGELOG.md +29 -0
- package/README.md +92 -80
- package/dist/ClockifyApiClient.d.ts +44 -45
- package/dist/ClockifyApiClient.d.ts.map +1 -1
- package/dist/ClockifyApiClient.js +52 -121
- package/dist/ClockifyApiClient.js.map +1 -1
- package/dist/generated/ClockifyApi.d.ts +14432 -0
- package/dist/generated/ClockifyApi.d.ts.map +1 -0
- package/dist/generated/ClockifyApi.js +1239 -0
- package/dist/generated/ClockifyApi.js.map +1 -0
- package/dist/index.d.ts +4 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/package.json +15 -21
- package/scripts/regenerate.ts +182 -201
- package/scripts/tsconfig.json +13 -0
- package/src/ClockifyApiClient.ts +125 -226
- package/src/generated/ClockifyApi.ts +3020 -0
- package/src/index.ts +10 -14
- package/test/ClockifyApiClient.test.ts +195 -0
- package/vitest.config.ts +7 -0
- package/.specs/VERSION +0 -1
- package/.specs/clockify-v1.json +0 -31670
- package/.specs/clockify-v1.patch.json +0 -48
- package/dist/ClockifyApiError.d.ts +0 -11
- package/dist/ClockifyApiError.d.ts.map +0 -1
- package/dist/ClockifyApiError.js +0 -14
- package/dist/ClockifyApiError.js.map +0 -1
- package/dist/OpenApiFetchClient.d.ts +0 -55
- package/dist/OpenApiFetchClient.d.ts.map +0 -1
- package/dist/OpenApiFetchClient.js +0 -63
- package/dist/OpenApiFetchClient.js.map +0 -1
- package/dist/generated/index.d.ts +0 -2
- package/dist/generated/index.d.ts.map +0 -1
- package/dist/generated/index.js +0 -2
- package/dist/generated/index.js.map +0 -1
- package/dist/generated/schema.d.ts +0 -16204
- package/src/ClockifyApiError.ts +0 -17
- package/src/OpenApiFetchClient.ts +0 -92
- package/src/generated/index.ts +0 -1
- package/src/generated/schema.d.ts +0 -16204
- package/tsconfig.tsbuildinfo +0 -1
package/src/ClockifyApiError.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tagged error for Clockify API failures.
|
|
3
|
-
*
|
|
4
|
-
* **Mental model**
|
|
5
|
-
*
|
|
6
|
-
* - **Catch by tag**: `Effect.catchTag("ClockifyApiError", ...)` handles all API errors.
|
|
7
|
-
* The `status` field distinguishes HTTP errors (>0) from network errors (0).
|
|
8
|
-
*
|
|
9
|
-
* @module
|
|
10
|
-
*/
|
|
11
|
-
import * as Data from "effect/Data"
|
|
12
|
-
|
|
13
|
-
export class ClockifyApiError extends Data.TaggedError("ClockifyApiError")<{
|
|
14
|
-
readonly status: number
|
|
15
|
-
readonly message: string
|
|
16
|
-
readonly cause?: unknown
|
|
17
|
-
}> {}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic Effect wrapper for openapi-fetch clients.
|
|
3
|
-
*
|
|
4
|
-
* Exposes a type-safe `Client<Paths>` and a `toEffect` helper that wraps
|
|
5
|
-
* any `Promise<FetchResponse>` in Effect with error mapping.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* const page = yield* toEffect(client.GET("/pages/{id}", {
|
|
10
|
-
* params: { path: { id: 123 } }
|
|
11
|
-
* }))
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* @module
|
|
15
|
-
*/
|
|
16
|
-
import * as Data from "effect/Data"
|
|
17
|
-
import * as Effect from "effect/Effect"
|
|
18
|
-
import createClient, { type Client, type FetchResponse } from "openapi-fetch"
|
|
19
|
-
import type { MediaType } from "openapi-typescript-helpers"
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Error from openapi-fetch operations.
|
|
23
|
-
*
|
|
24
|
-
* @category Errors
|
|
25
|
-
*/
|
|
26
|
-
export class FetchClientError extends Data.TaggedError("FetchClientError")<{
|
|
27
|
-
readonly error: unknown
|
|
28
|
-
readonly status: number
|
|
29
|
-
readonly message: string
|
|
30
|
-
}> {}
|
|
31
|
-
|
|
32
|
-
/** Extract success `data` from a FetchResponse discriminated union. */
|
|
33
|
-
export type SuccessData<T> = T extends { data: infer D; error?: undefined } ? D
|
|
34
|
-
: T extends { data?: infer D } ? NonNullable<D>
|
|
35
|
-
: never
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Wrap an openapi-fetch `Promise<FetchResponse>` in Effect.
|
|
39
|
-
*
|
|
40
|
-
* Extracts `data` on success, maps errors to `FetchClientError`.
|
|
41
|
-
* Fully type-safe — path/body constraints come from the `Client<Paths>` call site.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```typescript
|
|
45
|
-
* const page = yield* toEffect(client.GET("/pages/{id}", { params: { path: { id: 123 } } }))
|
|
46
|
-
* ```
|
|
47
|
-
*
|
|
48
|
-
* @category Utilities
|
|
49
|
-
*/
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- matches FetchResponse generic constraint
|
|
51
|
-
export const toEffect = <T extends Record<string | number, any>, O, M extends MediaType>(
|
|
52
|
-
promise: Promise<FetchResponse<T, O, M>>
|
|
53
|
-
): Effect.Effect<SuccessData<FetchResponse<T, O, M>>, FetchClientError> =>
|
|
54
|
-
Effect.tryPromise({
|
|
55
|
-
try: () =>
|
|
56
|
-
promise.then(({ data, error, response }) => {
|
|
57
|
-
if (error !== undefined || !response.ok) {
|
|
58
|
-
throw { error, status: response.status }
|
|
59
|
-
}
|
|
60
|
-
return data as SuccessData<FetchResponse<T, O, M>>
|
|
61
|
-
}),
|
|
62
|
-
catch: (e) =>
|
|
63
|
-
new FetchClientError({
|
|
64
|
-
error: (e as Record<string, unknown>).error ?? e,
|
|
65
|
-
status: ((e as Record<string, unknown>).status as number | undefined) ?? 0,
|
|
66
|
-
message: typeof (e as Record<string, unknown>).error === "string"
|
|
67
|
-
? (e as Record<string, unknown>).error as string
|
|
68
|
-
: JSON.stringify((e as Record<string, unknown>).error ?? e)
|
|
69
|
-
})
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* openapi-fetch client paired with the `toEffect` helper.
|
|
74
|
-
*
|
|
75
|
-
* @category Client
|
|
76
|
-
*/
|
|
77
|
-
export interface OpenApiFetchClient<Paths extends {}> {
|
|
78
|
-
/** Type-safe openapi-fetch client. Use with `toEffect()` to get Effect. */
|
|
79
|
-
readonly client: Client<Paths, "application/json">
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Create an openapi-fetch client with auth headers pre-configured.
|
|
84
|
-
*
|
|
85
|
-
* @category Constructors
|
|
86
|
-
*/
|
|
87
|
-
export const makeOpenApiFetchClient = <Paths extends {}>(
|
|
88
|
-
baseUrl: string,
|
|
89
|
-
headers: Record<string, string>
|
|
90
|
-
): OpenApiFetchClient<Paths> => ({
|
|
91
|
-
client: createClient<Paths, "application/json">({ baseUrl, headers })
|
|
92
|
-
})
|
package/src/generated/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type { paths, components, operations } from "./schema.js"
|