@theholocron/posthog-client 1.32.0 → 1.33.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/dist/index.d.mts +58 -0
- package/dist/index.mjs +43 -0
- package/package.json +3 -3
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import "@theholocron/http-client";
|
|
2
|
+
import { ErrorSink, Logger } from "@theholocron/observability/core";
|
|
3
|
+
//#region ../../../../../src/utils.d.ts
|
|
4
|
+
interface PostHogClientOptions {
|
|
5
|
+
token: string;
|
|
6
|
+
/**
|
|
7
|
+
* PostHog host. Defaults to `https://app.posthog.com`.
|
|
8
|
+
* Use `https://eu.posthog.com` for EU cloud, or your self-hosted URL.
|
|
9
|
+
*/
|
|
10
|
+
host?: string;
|
|
11
|
+
/** Override base URL for testing. Takes precedence over `host`. */
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
/** Override fetch for testing. Defaults to globalThis.fetch. */
|
|
14
|
+
fetch?: typeof fetch;
|
|
15
|
+
/** Structured logger for request/response diagnostics. Defaults to a no-op. */
|
|
16
|
+
logger?: Logger;
|
|
17
|
+
/** Reports transport failures and unexpected 5xx. Defaults to a no-op. */
|
|
18
|
+
errors?: ErrorSink;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region ../../../../../src/users/users.d.ts
|
|
22
|
+
interface PostHogOrganization {
|
|
23
|
+
id: string;
|
|
24
|
+
slug: string;
|
|
25
|
+
name: string;
|
|
26
|
+
}
|
|
27
|
+
interface PostHogUser {
|
|
28
|
+
email: string;
|
|
29
|
+
organization: PostHogOrganization;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region ../../../../../src/projects/projects.d.ts
|
|
33
|
+
interface PostHogProject {
|
|
34
|
+
id: number;
|
|
35
|
+
name: string;
|
|
36
|
+
/** The client-side tracking token (`phc_*`). */
|
|
37
|
+
api_token: string;
|
|
38
|
+
}
|
|
39
|
+
interface PostHogProjectsResponse {
|
|
40
|
+
results: PostHogProject[];
|
|
41
|
+
}
|
|
42
|
+
interface CreatePostHogProjectInput {
|
|
43
|
+
name: string;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region ../../../../../src/index.d.ts
|
|
47
|
+
declare function createPostHogClient(opts: PostHogClientOptions): {
|
|
48
|
+
users: {
|
|
49
|
+
me: () => Promise<PostHogUser>;
|
|
50
|
+
};
|
|
51
|
+
projects: {
|
|
52
|
+
list: () => Promise<PostHogProjectsResponse>;
|
|
53
|
+
create: (input: CreatePostHogProjectInput) => Promise<PostHogProject>;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
type PostHogClient = ReturnType<typeof createPostHogClient>;
|
|
57
|
+
//#endregion
|
|
58
|
+
export { type CreatePostHogProjectInput, PostHogClient, type PostHogClientOptions, type PostHogOrganization, type PostHogProject, type PostHogProjectsResponse, type PostHogUser, createPostHogClient };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createRestClient } from "@theholocron/http-client";
|
|
2
|
+
//#region ../../../../../src/projects/projects.ts
|
|
3
|
+
function projects(rest) {
|
|
4
|
+
return {
|
|
5
|
+
/** List all projects accessible with the current token. */
|
|
6
|
+
list: () => rest.request("/api/projects/"),
|
|
7
|
+
/** Create a new project. Returns the created project including its tracking token. */
|
|
8
|
+
create: (input) => rest.request("/api/projects/", {
|
|
9
|
+
method: "POST",
|
|
10
|
+
body: input
|
|
11
|
+
})
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region ../../../../../src/users/users.ts
|
|
16
|
+
function users(rest) {
|
|
17
|
+
return {
|
|
18
|
+
/** Get the currently authenticated user. */
|
|
19
|
+
me: () => rest.request("/api/users/@me/") };
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region ../../../../../src/utils.ts
|
|
23
|
+
function createPostHogRestClient(opts) {
|
|
24
|
+
return createRestClient({
|
|
25
|
+
baseUrl: opts.baseUrl ?? opts.host ?? "https://app.posthog.com",
|
|
26
|
+
token: opts.token,
|
|
27
|
+
vendor: "PostHog",
|
|
28
|
+
fetch: opts.fetch,
|
|
29
|
+
logger: opts.logger,
|
|
30
|
+
errors: opts.errors
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region ../../../../../src/index.ts
|
|
35
|
+
function createPostHogClient(opts) {
|
|
36
|
+
const rest = createPostHogRestClient(opts);
|
|
37
|
+
return {
|
|
38
|
+
users: users(rest),
|
|
39
|
+
projects: projects(rest)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { createPostHogClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/posthog-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.33.0",
|
|
4
4
|
"description": "A TypeScript client for the PostHog management API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"posthog",
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@theholocron/observability": "^0.3.0",
|
|
36
|
-
"@theholocron/http-client": "^1.
|
|
36
|
+
"@theholocron/http-client": "^1.33.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@theholocron/cli": "5.0.0-alpha.79",
|
|
40
40
|
"@theholocron/eslint-config": "^8.4.3",
|
|
41
41
|
"@theholocron/tsconfig": "^8.2.0",
|
|
42
|
-
"@theholocron/tsdown-config": "^8.
|
|
42
|
+
"@theholocron/tsdown-config": "^8.6.1",
|
|
43
43
|
"@theholocron/vitest-config": "^8.2.0",
|
|
44
44
|
"@types/node": "^26.4.1",
|
|
45
45
|
"@vitest/coverage-v8": "^5.0.0",
|