@pulselytics/api-client 0.0.0-stage → 0.81.0

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,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Umami Software, Inc. <hello@umami.is>
4
+ Portions copyright (c) 2026 Pulselytics
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,82 @@
1
- # Temporary Holding Version
1
+ # @pulselytics/api-client
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Typed TypeScript client for the Pulse Analytics API. Every method is generated from
4
+ the project's OpenAPI contract (`public/openapi.json` in the main repository), so the client can never
5
+ drift from the server.
6
+
7
+ ```bash
8
+ pnpm add @pulselytics/api-client
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { PulseClient } from '@pulselytics/api-client';
15
+
16
+ // Local instance (the default base URL is http://localhost:3000)
17
+ const pulse = new PulseClient({ apiKey: process.env.PULSE_API_KEY });
18
+
19
+ // Remote self-hosted instance
20
+ const pulse = new PulseClient({
21
+ baseUrl: 'https://analytics.example.com/api',
22
+ token: process.env.PULSE_API_TOKEN, // API key or login token
23
+ });
24
+
25
+ const websites = await pulse.listWebsites();
26
+
27
+ const stats = await pulse.getWebsiteStats({
28
+ websiteId,
29
+ startAt: Date.now() - 7 * 24 * 60 * 60 * 1000,
30
+ endAt: Date.now(),
31
+ });
32
+
33
+ const pages = await pulse.getWebsiteMetrics({ websiteId, startAt, endAt, type: 'path', limit: 10 });
34
+ ```
35
+
36
+ Every method takes **one object** that merges path parameters, query parameters and the request
37
+ body. Method names are the OpenAPI `operationId`s; hover in your editor for the parameter and
38
+ response types, or import `OperationInput<'getWebsiteStats'>` / `OperationOutput<'…'>`.
39
+
40
+ ### Options
41
+
42
+ | Option | Description |
43
+ | --------- | ----------------------------------------------------------------------------------------------------------- |
44
+ | `baseUrl` | API root. Defaults to `http://localhost:3000`. Self-hosted: `https://your-instance/api`. |
45
+ | `token` | Bearer token: login token or self-hosted API key. |
46
+ | `apiKey` | API key (sent as `x-pulse-api-key`; also sent as a bearer token when `token` is not provided). |
47
+ | `headers` | Extra headers for every request. |
48
+ | `fetch` | Custom `fetch` (tests, other runtimes, in-process dispatch). |
49
+ | `timeout` | Per-request timeout in milliseconds. |
50
+
51
+ ### Errors
52
+
53
+ Non-2xx responses throw `PulseApiError` with `status`, `code` (`unauthorized`, `forbidden`,
54
+ `not-found`, `bad-request`, …), `message` and the parsed `body`.
55
+
56
+ ```ts
57
+ import { isPulseApiError } from '@pulselytics/api-client';
58
+
59
+ try {
60
+ await pulse.getWebsite({ websiteId });
61
+ } catch (error) {
62
+ if (isPulseApiError(error) && error.isNotFound) {
63
+ // …
64
+ }
65
+ }
66
+ ```
67
+
68
+ ### Escape hatch
69
+
70
+ `pulse.call('operationId', input)` invokes any operation by ID; `operations` exports the full
71
+ table of methods, paths and parameters.
72
+
73
+ ## Regenerating
74
+
75
+ From the Pulse Analytics repository root:
76
+
77
+ ```bash
78
+ pnpm generate:api # public/openapi.json → packages/api-client/src/generated
79
+ pnpm check:api:client # CI: fail if generated files are stale
80
+ ```
81
+
82
+ See [MIGRATION.md](./MIGRATION.md) if you are upgrading from the previous hand-written client.