@praxium/sdk 0.2.4 → 0.2.9

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Praxium Platform
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # @praxium/sdk
2
+
3
+ Official TypeScript SDK for the Praxium platform API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @praxium/sdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { createTenantClient } from '@praxium/sdk'
15
+
16
+ const client = createTenantClient({
17
+ baseUrl: 'https://api.example.com',
18
+ })
19
+ ```
20
+
21
+ ## Next.js Revalidation
22
+
23
+ Optional utilities for ISR cache revalidation (requires `next` as peer dependency):
24
+
25
+ ```typescript
26
+ import { revalidatePublicPages } from '@praxium/sdk/revalidation'
27
+ ```
28
+
29
+ ## Development
30
+
31
+ ```bash
32
+ npm run generate # Regenerate client from OpenAPI spec
33
+ npm run build # Build dist/
34
+ npm run test # Run tests
35
+ npm run typecheck # Type-check without emitting
36
+ ```
37
+
38
+ ## Publishing
39
+
40
+ This package is dual-published:
41
+
42
+ - **GitLab Package Registry** (internal) — via `CI_JOB_TOKEN`
43
+ - **npm public registry** — via [OIDC Trusted Publishing](https://docs.npmjs.com/trusted-publishers/) (no stored secrets)
44
+
45
+ Versioning: `0.2.<commit-count>` — deterministic from git history.
46
+
47
+ ## License
48
+
49
+ [MIT](LICENSE)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@praxium/sdk",
3
- "version": "0.2.4",
4
- "description": "TypeScript SDK for Praxium public tenant API — auto-generated from OpenAPI spec",
3
+ "version": "0.2.9",
4
+ "description": "Official TypeScript SDK for the Praxium platform API",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
@@ -14,8 +14,7 @@
14
14
  }
15
15
  },
16
16
  "files": [
17
- "dist",
18
- "src"
17
+ "dist"
19
18
  ],
20
19
  "scripts": {
21
20
  "generate": "openapi-ts",
@@ -45,12 +44,13 @@
45
44
  "praxium",
46
45
  "sdk",
47
46
  "openapi",
48
- "physiotherapy",
47
+ "practice-management",
49
48
  "tenant-api"
50
49
  ],
51
- "license": "UNLICENSED",
50
+ "license": "MIT",
51
+ "homepage": "https://praxium.nl",
52
52
  "repository": {
53
53
  "type": "git",
54
- "url": "https://gitlab.com/praxium_platform/core/sdk.git"
54
+ "url": "git+https://gitlab.com/praxium_platform/core/sdk.git"
55
55
  }
56
56
  }
package/src/errors.ts DELETED
@@ -1,126 +0,0 @@
1
- /**
2
- * Typed error hierarchy for the Praxium SDK.
3
- *
4
- * Every method on `TenantClient` throws one of these errors when the
5
- * API returns a non-2xx response. Consumers can catch a specific
6
- * subclass (e.g. `PraxiumNotFoundError`) or the base `PraxiumError`.
7
- *
8
- * @example
9
- * ```ts
10
- * try {
11
- * const hours = await client.getOpeningHours()
12
- * } catch (err) {
13
- * if (err instanceof PraxiumNotFoundError) {
14
- * // tenant slug is invalid
15
- * }
16
- * }
17
- * ```
18
- */
19
-
20
- import type { ApiError } from './generated/types.gen'
21
-
22
- /** Validation error detail from the API */
23
- export type ValidationDetail = NonNullable<ApiError['details']>[number]
24
-
25
- // ─── Base Error ──────────────────────────────────────────────────────
26
-
27
- /**
28
- * Base error for all Praxium API failures.
29
- *
30
- * Properties mirror the `ApiError` response body from the platform:
31
- * - `status` — HTTP status code
32
- * - `errorCode` — Machine-readable code (e.g. `'TENANT_NOT_FOUND'`)
33
- * - `message` — Human-readable explanation
34
- * - `details` — Optional validation error details (400 responses only)
35
- */
36
- export class PraxiumError extends Error {
37
- override name: string
38
-
39
- constructor(
40
- public readonly status: number,
41
- public readonly errorCode: string,
42
- message: string,
43
- public readonly details?: ApiError['details']
44
- ) {
45
- super(message)
46
- this.name = 'PraxiumError'
47
- // Restore prototype chain broken by extending built-ins
48
- Object.setPrototypeOf(this, new.target.prototype)
49
- }
50
- }
51
-
52
- // ─── 400 Validation ──────────────────────────────────────────────────
53
-
54
- /** Thrown when the server rejects the request body (HTTP 400). */
55
- export class PraxiumValidationError extends PraxiumError {
56
- constructor(
57
- errorCode: string,
58
- message: string,
59
- details?: ApiError['details']
60
- ) {
61
- super(400, errorCode, message, details)
62
- this.name = 'PraxiumValidationError'
63
- }
64
- }
65
-
66
- // ─── 401 Authentication ──────────────────────────────────────────────
67
-
68
- /** Thrown when the API key is missing or invalid (HTTP 401). */
69
- export class PraxiumAuthError extends PraxiumError {
70
- constructor(errorCode: string, message: string) {
71
- super(401, errorCode, message)
72
- this.name = 'PraxiumAuthError'
73
- }
74
- }
75
-
76
- // ─── 403 Forbidden ───────────────────────────────────────────────────
77
-
78
- /** Thrown when the API key does not match the requested tenant (HTTP 403). */
79
- export class PraxiumForbiddenError extends PraxiumError {
80
- constructor(errorCode: string, message: string) {
81
- super(403, errorCode, message)
82
- this.name = 'PraxiumForbiddenError'
83
- }
84
- }
85
-
86
- // ─── 404 Not Found ───────────────────────────────────────────────────
87
-
88
- /** Thrown when the tenant is not found or inactive (HTTP 404). */
89
- export class PraxiumNotFoundError extends PraxiumError {
90
- constructor(errorCode: string, message: string) {
91
- super(404, errorCode, message)
92
- this.name = 'PraxiumNotFoundError'
93
- }
94
- }
95
-
96
- // ─── 429 Rate Limit ──────────────────────────────────────────────────
97
-
98
- /** Thrown when the rate limit is exceeded (HTTP 429). */
99
- export class PraxiumRateLimitError extends PraxiumError {
100
- constructor(errorCode: string, message: string) {
101
- super(429, errorCode, message)
102
- this.name = 'PraxiumRateLimitError'
103
- }
104
- }
105
-
106
- // ─── Status → Error Mapping ──────────────────────────────────────────
107
-
108
- /**
109
- * Map of HTTP status codes to their corresponding PraxiumError subclass.
110
- * Used internally by `unwrapOrThrow` to construct the correct error.
111
- * @internal Not part of the public SDK API — do not re-export from index.ts
112
- */
113
- export const STATUS_ERROR_MAP: Record<
114
- number,
115
- new (
116
- errorCode: string,
117
- message: string,
118
- details?: ApiError['details']
119
- ) => PraxiumError
120
- > = {
121
- 400: PraxiumValidationError,
122
- 401: PraxiumAuthError,
123
- 403: PraxiumForbiddenError,
124
- 404: PraxiumNotFoundError,
125
- 429: PraxiumRateLimitError,
126
- }
@@ -1,288 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
-
3
- import { createSseClient } from '../core/serverSentEvents.gen';
4
- import type { HttpMethod } from '../core/types.gen';
5
- import { getValidRequestBody } from '../core/utils.gen';
6
- import type { Client, Config, RequestOptions, ResolvedRequestOptions } from './types.gen';
7
- import {
8
- buildUrl,
9
- createConfig,
10
- createInterceptors,
11
- getParseAs,
12
- mergeConfigs,
13
- mergeHeaders,
14
- setAuthParams,
15
- } from './utils.gen';
16
-
17
- type ReqInit = Omit<RequestInit, 'body' | 'headers'> & {
18
- body?: any;
19
- headers: ReturnType<typeof mergeHeaders>;
20
- };
21
-
22
- export const createClient = (config: Config = {}): Client => {
23
- let _config = mergeConfigs(createConfig(), config);
24
-
25
- const getConfig = (): Config => ({ ..._config });
26
-
27
- const setConfig = (config: Config): Config => {
28
- _config = mergeConfigs(_config, config);
29
- return getConfig();
30
- };
31
-
32
- const interceptors = createInterceptors<Request, Response, unknown, ResolvedRequestOptions>();
33
-
34
- const beforeRequest = async (options: RequestOptions) => {
35
- const opts = {
36
- ..._config,
37
- ...options,
38
- fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
39
- headers: mergeHeaders(_config.headers, options.headers),
40
- serializedBody: undefined,
41
- };
42
-
43
- if (opts.security) {
44
- await setAuthParams({
45
- ...opts,
46
- security: opts.security,
47
- });
48
- }
49
-
50
- if (opts.requestValidator) {
51
- await opts.requestValidator(opts);
52
- }
53
-
54
- if (opts.body !== undefined && opts.bodySerializer) {
55
- opts.serializedBody = opts.bodySerializer(opts.body);
56
- }
57
-
58
- // remove Content-Type header if body is empty to avoid sending invalid requests
59
- if (opts.body === undefined || opts.serializedBody === '') {
60
- opts.headers.delete('Content-Type');
61
- }
62
-
63
- const url = buildUrl(opts);
64
-
65
- return { opts, url };
66
- };
67
-
68
- const request: Client['request'] = async (options) => {
69
- // @ts-expect-error
70
- const { opts, url } = await beforeRequest(options);
71
- const requestInit: ReqInit = {
72
- redirect: 'follow',
73
- ...opts,
74
- body: getValidRequestBody(opts),
75
- };
76
-
77
- let request = new Request(url, requestInit);
78
-
79
- for (const fn of interceptors.request.fns) {
80
- if (fn) {
81
- request = await fn(request, opts);
82
- }
83
- }
84
-
85
- // fetch must be assigned here, otherwise it would throw the error:
86
- // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
87
- const _fetch = opts.fetch!;
88
- let response: Response;
89
-
90
- try {
91
- response = await _fetch(request);
92
- } catch (error) {
93
- // Handle fetch exceptions (AbortError, network errors, etc.)
94
- let finalError = error;
95
-
96
- for (const fn of interceptors.error.fns) {
97
- if (fn) {
98
- finalError = (await fn(error, undefined as any, request, opts)) as unknown;
99
- }
100
- }
101
-
102
- finalError = finalError || ({} as unknown);
103
-
104
- if (opts.throwOnError) {
105
- throw finalError;
106
- }
107
-
108
- // Return error response
109
- return opts.responseStyle === 'data'
110
- ? undefined
111
- : {
112
- error: finalError,
113
- request,
114
- response: undefined as any,
115
- };
116
- }
117
-
118
- for (const fn of interceptors.response.fns) {
119
- if (fn) {
120
- response = await fn(response, request, opts);
121
- }
122
- }
123
-
124
- const result = {
125
- request,
126
- response,
127
- };
128
-
129
- if (response.ok) {
130
- const parseAs =
131
- (opts.parseAs === 'auto'
132
- ? getParseAs(response.headers.get('Content-Type'))
133
- : opts.parseAs) ?? 'json';
134
-
135
- if (response.status === 204 || response.headers.get('Content-Length') === '0') {
136
- let emptyData: any;
137
- switch (parseAs) {
138
- case 'arrayBuffer':
139
- case 'blob':
140
- case 'text':
141
- emptyData = await response[parseAs]();
142
- break;
143
- case 'formData':
144
- emptyData = new FormData();
145
- break;
146
- case 'stream':
147
- emptyData = response.body;
148
- break;
149
- case 'json':
150
- default:
151
- emptyData = {};
152
- break;
153
- }
154
- return opts.responseStyle === 'data'
155
- ? emptyData
156
- : {
157
- data: emptyData,
158
- ...result,
159
- };
160
- }
161
-
162
- let data: any;
163
- switch (parseAs) {
164
- case 'arrayBuffer':
165
- case 'blob':
166
- case 'formData':
167
- case 'text':
168
- data = await response[parseAs]();
169
- break;
170
- case 'json': {
171
- // Some servers return 200 with no Content-Length and empty body.
172
- // response.json() would throw; read as text and parse if non-empty.
173
- const text = await response.text();
174
- data = text ? JSON.parse(text) : {};
175
- break;
176
- }
177
- case 'stream':
178
- return opts.responseStyle === 'data'
179
- ? response.body
180
- : {
181
- data: response.body,
182
- ...result,
183
- };
184
- }
185
-
186
- if (parseAs === 'json') {
187
- if (opts.responseValidator) {
188
- await opts.responseValidator(data);
189
- }
190
-
191
- if (opts.responseTransformer) {
192
- data = await opts.responseTransformer(data);
193
- }
194
- }
195
-
196
- return opts.responseStyle === 'data'
197
- ? data
198
- : {
199
- data,
200
- ...result,
201
- };
202
- }
203
-
204
- const textError = await response.text();
205
- let jsonError: unknown;
206
-
207
- try {
208
- jsonError = JSON.parse(textError);
209
- } catch {
210
- // noop
211
- }
212
-
213
- const error = jsonError ?? textError;
214
- let finalError = error;
215
-
216
- for (const fn of interceptors.error.fns) {
217
- if (fn) {
218
- finalError = (await fn(error, response, request, opts)) as string;
219
- }
220
- }
221
-
222
- finalError = finalError || ({} as string);
223
-
224
- if (opts.throwOnError) {
225
- throw finalError;
226
- }
227
-
228
- // TODO: we probably want to return error and improve types
229
- return opts.responseStyle === 'data'
230
- ? undefined
231
- : {
232
- error: finalError,
233
- ...result,
234
- };
235
- };
236
-
237
- const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
238
- request({ ...options, method });
239
-
240
- const makeSseFn = (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
241
- const { opts, url } = await beforeRequest(options);
242
- return createSseClient({
243
- ...opts,
244
- body: opts.body as BodyInit | null | undefined,
245
- headers: opts.headers as unknown as Record<string, string>,
246
- method,
247
- onRequest: async (url, init) => {
248
- let request = new Request(url, init);
249
- for (const fn of interceptors.request.fns) {
250
- if (fn) {
251
- request = await fn(request, opts);
252
- }
253
- }
254
- return request;
255
- },
256
- serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined,
257
- url,
258
- });
259
- };
260
-
261
- return {
262
- buildUrl,
263
- connect: makeMethodFn('CONNECT'),
264
- delete: makeMethodFn('DELETE'),
265
- get: makeMethodFn('GET'),
266
- getConfig,
267
- head: makeMethodFn('HEAD'),
268
- interceptors,
269
- options: makeMethodFn('OPTIONS'),
270
- patch: makeMethodFn('PATCH'),
271
- post: makeMethodFn('POST'),
272
- put: makeMethodFn('PUT'),
273
- request,
274
- setConfig,
275
- sse: {
276
- connect: makeSseFn('CONNECT'),
277
- delete: makeSseFn('DELETE'),
278
- get: makeSseFn('GET'),
279
- head: makeSseFn('HEAD'),
280
- options: makeSseFn('OPTIONS'),
281
- patch: makeSseFn('PATCH'),
282
- post: makeSseFn('POST'),
283
- put: makeSseFn('PUT'),
284
- trace: makeSseFn('TRACE'),
285
- },
286
- trace: makeMethodFn('TRACE'),
287
- } as Client;
288
- };
@@ -1,25 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
-
3
- export type { Auth } from '../core/auth.gen';
4
- export type { QuerySerializerOptions } from '../core/bodySerializer.gen';
5
- export {
6
- formDataBodySerializer,
7
- jsonBodySerializer,
8
- urlSearchParamsBodySerializer,
9
- } from '../core/bodySerializer.gen';
10
- export { buildClientParams } from '../core/params.gen';
11
- export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
12
- export { createClient } from './client.gen';
13
- export type {
14
- Client,
15
- ClientOptions,
16
- Config,
17
- CreateClientConfig,
18
- Options,
19
- RequestOptions,
20
- RequestResult,
21
- ResolvedRequestOptions,
22
- ResponseStyle,
23
- TDataShape,
24
- } from './types.gen';
25
- export { createConfig, mergeHeaders } from './utils.gen';