@theholocron/holocron-plugin-posthog 5.0.0-alpha.278 → 5.0.0-alpha.279

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 CHANGED
@@ -1,25 +1,32 @@
1
1
  import { Analytics, AuthError, PluginToken, ResolveTokenInput, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess } from "@theholocron/cli";
2
2
  import { PostHogClient, PostHogClient as PostHogClient$1, PostHogClientOptions, PostHogProject, PostHogProjectsResponse, PostHogUser, createPostHogClient } from "@theholocron/posthog-client";
3
+ /** Resolves the PostHog personal API key from `--token`, `HOLOCRON_POSTHOG_TOKEN`, `POSTHOG_PERSONAL_API_KEY` or the keyring, and throws an `AuthError` when none is set. */
3
4
  export declare const resolveToken: import("@theholocron/cli").TokenResolver;
4
5
  /** Every token this plugin takes, for `holocron doctor tokens`. */
5
6
  export declare const tokens: PluginToken[];
7
+ /** Options for the PostHog `analytics` capability. */
6
8
  interface PostHogAnalyticsOptions {
7
9
  /** PostHog instance host — pushed as NEXT_PUBLIC_POSTHOG_HOST. Default: https://app.posthog.com */
8
10
  host?: string;
9
11
  }
12
+ /** The `analytics` capability for PostHog: finds or creates a project and reports its API token. */
10
13
  export declare class PostHogAnalytics implements Analytics {
11
14
  private readonly client;
12
15
  private readonly opts;
16
+ /** The capability key, always `analytics`. */
13
17
  readonly key: "analytics";
18
+ /** The provider name, `posthog`. */
14
19
  readonly providerName = "posthog";
15
20
  constructor(client: () => PostHogClient$1, opts: PostHogAnalyticsOptions);
16
21
  describe(): Promise<{
17
22
  provider: string;
18
23
  envKeys: string[];
19
24
  }>;
25
+ /** Returns the organization slug of the user the token belongs to. */
20
26
  whoami(): Promise<{
21
27
  org: string;
22
28
  }>;
29
+ /** Returns the API token of the project called `name`, creating the project when it does not exist yet; `alreadyExists` says which happened. */
23
30
  ensureProject(name: string): Promise<{
24
31
  token: string;
25
32
  alreadyExists: boolean;
@@ -32,7 +39,9 @@ interface VerifyTokenOptions {
32
39
  baseUrl?: string;
33
40
  fetch?: typeof fetch;
34
41
  }
42
+ /** Checks a PostHog personal API key by fetching the current user; the success subject is `email @ organization slug`, the failure carries the error message. */
35
43
  export declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult$1>;
44
+ /** Options for the PostHog plugin: token resolution, the instance host and test overrides. */
36
45
  export interface PostHogPluginOptions extends ResolveTokenInput, PostHogAnalyticsOptions {
37
46
  /**
38
47
  * PostHog instance host. Defaults to US cloud.
@@ -42,14 +51,21 @@ export interface PostHogPluginOptions extends ResolveTokenInput, PostHogAnalytic
42
51
  host?: string;
43
52
  /** Override base URL for tests (takes precedence over host). */
44
53
  baseUrl?: string;
54
+ /** Override `fetch` for tests. */
45
55
  fetch?: typeof fetch;
46
56
  }
57
+ /** What the plugin's capabilities share: the options and a lazily built client. */
47
58
  export interface PluginContext {
59
+ /** The options the plugin was created with. */
48
60
  options: PostHogPluginOptions;
61
+ /** Builds the PostHog client on first call and reuses it; the token is resolved then, not at plugin load. */
49
62
  client: () => PostHogClient$1;
50
63
  }
64
+ /** Creates the shared context for the given options; no token is resolved until `client()` is first called. */
51
65
  export declare function createContext(options?: PostHogPluginOptions): PluginContext;
66
+ /** Builds the `analytics` capability from a plugin context. */
52
67
  export declare function analytics(ctx: PluginContext): Analytics;
68
+ /** Creates the PostHog plugin: a `connection` probe and the `analytics` capability. */
53
69
  export declare function createPlugin(options?: PostHogPluginOptions): {
54
70
  name: string;
55
71
  probes: {
@@ -59,5 +75,6 @@ export declare function createPlugin(options?: PostHogPluginOptions): {
59
75
  analytics: () => Analytics;
60
76
  };
61
77
  };
78
+ /** One-line hint shown by `holocron auth set posthog` when no token is given or the token is rejected. */
62
79
  export declare const AUTH_HINT: string;
63
80
  export { AuthError, type PostHogAnalyticsOptions, type PostHogClient, type PostHogClientOptions, type PostHogProject, type PostHogProjectsResponse, type PostHogUser, type ResolveTokenInput, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, createPostHogClient };
package/dist/index.mjs CHANGED
@@ -2,6 +2,7 @@ import { AuthError, connectionProbe, createResolveToken } from "@theholocron/cli
2
2
  import { createPostHogClient, createPostHogClient as createPostHogClient$1 } from "@theholocron/posthog-client";
3
3
  import { errorMessage } from "@theholocron/misc-utils";
4
4
  // src/auth.ts
5
+ /** Resolves the PostHog personal API key from `--token`, `HOLOCRON_POSTHOG_TOKEN`, `POSTHOG_PERSONAL_API_KEY` or the keyring, and throws an `AuthError` when none is set. */
5
6
  const resolveToken = createResolveToken({
6
7
  envName: "HOLOCRON_POSTHOG_TOKEN",
7
8
  vendorEnvName: "POSTHOG_PERSONAL_API_KEY",
@@ -11,10 +12,13 @@ const resolveToken = createResolveToken({
11
12
  /** Every token this plugin takes, for `holocron doctor tokens`. */
12
13
  const tokens = [resolveToken.token];
13
14
  // src/capabilities/analytics.ts
15
+ /** The `analytics` capability for PostHog: finds or creates a project and reports its API token. */
14
16
  var PostHogAnalytics = class {
15
17
  client;
16
18
  opts;
19
+ /** The capability key, always `analytics`. */
17
20
  key = "analytics";
21
+ /** The provider name, `posthog`. */
18
22
  providerName = "posthog";
19
23
  constructor(client, opts) {
20
24
  this.client = client;
@@ -26,9 +30,11 @@ var PostHogAnalytics = class {
26
30
  envKeys: ["NEXT_PUBLIC_POSTHOG_KEY", "NEXT_PUBLIC_POSTHOG_HOST"]
27
31
  };
28
32
  }
33
+ /** Returns the organization slug of the user the token belongs to. */
29
34
  async whoami() {
30
35
  return { org: (await this.client().users.me()).organization.slug };
31
36
  }
37
+ /** Returns the API token of the project called `name`, creating the project when it does not exist yet; `alreadyExists` says which happened. */
32
38
  async ensureProject(name) {
33
39
  const { results } = await this.client().projects.list();
34
40
  const found = results.find((p) => p.name === name);
@@ -47,6 +53,7 @@ var PostHogAnalytics = class {
47
53
  }
48
54
  };
49
55
  // src/verify-token.ts
56
+ /** Checks a PostHog personal API key by fetching the current user; the success subject is `email @ organization slug`, the failure carries the error message. */
50
57
  async function verifyToken(token, opts = {}) {
51
58
  const client = createPostHogClient$1({
52
59
  token,
@@ -68,6 +75,7 @@ async function verifyToken(token, opts = {}) {
68
75
  }
69
76
  }
70
77
  // src/index.ts
78
+ /** Creates the shared context for the given options; no token is resolved until `client()` is first called. */
71
79
  function createContext(options = {}) {
72
80
  let client;
73
81
  return {
@@ -80,9 +88,11 @@ function createContext(options = {}) {
80
88
  })
81
89
  };
82
90
  }
91
+ /** Builds the `analytics` capability from a plugin context. */
83
92
  function analytics(ctx) {
84
93
  return new PostHogAnalytics(ctx.client, { host: ctx.options.host });
85
94
  }
95
+ /** Creates the PostHog plugin: a `connection` probe and the `analytics` capability. */
86
96
  function createPlugin(options = {}) {
87
97
  const ctx = createContext(options);
88
98
  return {
@@ -101,5 +111,6 @@ function createPlugin(options = {}) {
101
111
  capabilities: { analytics: () => analytics(ctx) }
102
112
  };
103
113
  }
114
+ /** One-line hint shown by `holocron auth set posthog` when no token is given or the token is rejected. */
104
115
  const AUTH_HINT = "create a personal API key at https://app.posthog.com/settings/user/api-keys (not the project API key — that is the client-side phc_* tracking token), then run: holocron auth set posthog <phx_KEY>";
105
116
  export { AUTH_HINT, AuthError, PostHogAnalytics, analytics, createContext, createPlugin, createPostHogClient, resolveToken, tokens, verifyToken };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-posthog",
3
- "version": "5.0.0-alpha.278",
3
+ "version": "5.0.0-alpha.279",
4
4
  "description": "Holocron plugin for PostHog. Implements the analytics capability — project provisioning and tracking token retrieval.",
5
5
  "keywords": [
6
6
  "analytics",
@@ -44,17 +44,17 @@
44
44
  "tsx": "4.23.15",
45
45
  "typescript": "^5.9.3",
46
46
  "vitest": "^5.0.5",
47
- "@theholocron/cli": "5.0.0-alpha.278",
48
- "@theholocron/eslint-config": "^8.9.0-alpha.4",
49
- "@theholocron/http-client": "^1.58.0-alpha.3",
50
47
  "@theholocron/misc-utils": "^1.16.1-alpha.3",
48
+ "@theholocron/cli": "5.0.0-alpha.279",
49
+ "@theholocron/tsdown-config": "^8.9.0-alpha.4",
51
50
  "@theholocron/tsconfig": "^8.9.0-alpha.4",
52
51
  "@theholocron/vitest-config": "^8.9.0-alpha.4",
53
- "@theholocron/tsdown-config": "^8.9.0-alpha.4"
52
+ "@theholocron/http-client": "^1.58.0-alpha.3",
53
+ "@theholocron/eslint-config": "^8.9.0-alpha.4"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@theholocron/misc-utils": "^1.16.0",
57
- "@theholocron/cli": "5.0.0-alpha.278"
57
+ "@theholocron/cli": "5.0.0-alpha.279"
58
58
  },
59
59
  "engines": {
60
60
  "node": ">=22"