@radjay/kit-analytics 0.0.2 → 0.0.3

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/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # @radjay/kit-analytics
2
+
3
+ CLI tool for pulling newsletter data from [Kit.com](https://kit.com) via the Kit API v4.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install -g @radjay/kit-analytics
9
+ ```
10
+
11
+ ## Configuration
12
+
13
+ Provide your Kit API key via any of these methods (in priority order):
14
+
15
+ 1. `--api-key` flag
16
+ 2. `--api-key-cmd` flag (shell command, e.g. `--api-key-cmd "op read ..."`)
17
+ 3. `KIT_API_KEY` environment variable
18
+ 4. `.env` file in the current directory
19
+ 5. `~/.config/kit-analytics/config.json` (`api_key` field)
20
+
21
+ ## Commands
22
+
23
+ | Command | Description |
24
+ |---|---|
25
+ | `account` | Display account info (name, plan, subscriber count) |
26
+ | `subscribers` | List subscribers with filtering by status, tag, date range |
27
+ | `broadcasts` | List sent emails with stats (open rate, click rate, etc.) |
28
+ | `tags` | List all tags with subscriber counts |
29
+ | `forms` | List all forms with subscriber counts |
30
+ | `sequences` | List all sequences with subscriber counts |
31
+
32
+ ## Examples
33
+
34
+ ```bash
35
+ # Verify setup
36
+ kit-analytics account
37
+
38
+ # Active subscribers added this month
39
+ kit-analytics subscribers --status active --since 2025-02-01
40
+
41
+ # Broadcast performance
42
+ kit-analytics broadcasts --limit 10
43
+
44
+ # JSON output
45
+ kit-analytics tags --format json
46
+ ```
47
+
48
+ ## Global Options
49
+
50
+ - `--api-key <key>` — Kit API key
51
+ - `--api-key-cmd <cmd>` — shell command to retrieve API key
52
+ - `--format <json|table>` — output format (default: `table`)
53
+ - `--help` — show help
package/dist/api.d.ts CHANGED
@@ -42,6 +42,27 @@ export interface Broadcast {
42
42
  send_at?: string | null;
43
43
  description?: string | null;
44
44
  }
45
+ export interface BroadcastDetail {
46
+ id: number;
47
+ publication_id: number;
48
+ created_at: string;
49
+ subject: string;
50
+ preview_text: string | null;
51
+ description: string | null;
52
+ content: string | null;
53
+ public: boolean;
54
+ published_at: string | null;
55
+ send_at: string | null;
56
+ thumbnail_alt: string | null;
57
+ thumbnail_url: string | null;
58
+ public_url: string | null;
59
+ email_address: string | null;
60
+ email_template: {
61
+ id: number;
62
+ name: string;
63
+ } | null;
64
+ subscriber_filter: unknown[];
65
+ }
45
66
  export interface Tag {
46
67
  id: number;
47
68
  name: string;
@@ -87,6 +108,9 @@ export declare class KitClient {
87
108
  broadcasts: Broadcast[];
88
109
  pagination: Pagination;
89
110
  }>;
111
+ getBroadcast(id: number): Promise<{
112
+ broadcast: BroadcastDetail;
113
+ }>;
90
114
  getBroadcastStats(id: number): Promise<{
91
115
  broadcast: {
92
116
  id: number;
package/dist/api.js CHANGED
@@ -57,6 +57,9 @@ class KitClient {
57
57
  params["after"] = opts.cursor;
58
58
  return this.request("/broadcasts", params);
59
59
  }
60
+ async getBroadcast(id) {
61
+ return this.request(`/broadcasts/${id}`);
62
+ }
60
63
  async getBroadcastStats(id) {
61
64
  return this.request(`/broadcasts/${id}/stats`);
62
65
  }
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare function broadcastCommand(): Command;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.broadcastCommand = broadcastCommand;
4
+ const commander_1 = require("commander");
5
+ const formatter_js_1 = require("../formatter.js");
6
+ function broadcastCommand() {
7
+ return new commander_1.Command("broadcast")
8
+ .description("Get a single broadcast by ID (includes HTML content)")
9
+ .argument("<id>", "Broadcast ID")
10
+ .option("--content-only", "Output only the HTML content")
11
+ .action(async function (id) {
12
+ const client = this.opts()["__client"];
13
+ const format = this.opts()["__format"];
14
+ const opts = this.opts();
15
+ const res = await client.getBroadcast(Number(id));
16
+ const b = res.broadcast;
17
+ if (opts.contentOnly) {
18
+ console.log(b.content ?? "");
19
+ return;
20
+ }
21
+ if (format === "json") {
22
+ console.log(JSON.stringify(b, null, 2));
23
+ return;
24
+ }
25
+ (0, formatter_js_1.output)({
26
+ id: b.id,
27
+ subject: b.subject,
28
+ preview_text: b.preview_text ?? "",
29
+ email_address: b.email_address ?? "",
30
+ email_template: b.email_template?.name ?? "",
31
+ public: b.public,
32
+ public_url: b.public_url ?? "",
33
+ published_at: b.published_at ?? "",
34
+ send_at: b.send_at ?? "",
35
+ created_at: b.created_at,
36
+ }, format);
37
+ if (b.content) {
38
+ console.log("\n--- Content ---\n");
39
+ console.log(b.content);
40
+ }
41
+ });
42
+ }
package/dist/index.js CHANGED
@@ -2,9 +2,11 @@
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const commander_1 = require("commander");
5
+ const resolve_key_1 = require("@radjay/resolve-key");
5
6
  const api_js_1 = require("./api.js");
6
7
  const account_js_1 = require("./commands/account.js");
7
8
  const subscribers_js_1 = require("./commands/subscribers.js");
9
+ const broadcast_js_1 = require("./commands/broadcast.js");
8
10
  const broadcasts_js_1 = require("./commands/broadcasts.js");
9
11
  const tags_js_1 = require("./commands/tags.js");
10
12
  const forms_js_1 = require("./commands/forms.js");
@@ -15,12 +17,20 @@ program
15
17
  .description("Pull Kit.com newsletter analytics via Kit API v4")
16
18
  .version("0.0.2")
17
19
  .option("--api-key <key>", "Kit API key (overrides KIT_API_KEY env var)")
20
+ .option("--api-key-cmd <cmd>", "Shell command that outputs the API key")
18
21
  .option("--format <format>", "Output format: json or table", "table");
19
22
  program.hook("preAction", () => {
20
23
  const opts = program.opts();
21
- const apiKey = opts.apiKey || process.env["KIT_API_KEY"];
24
+ const apiKey = (0, resolve_key_1.resolveKey)({
25
+ flag: opts.apiKey,
26
+ keyCmd: opts.apiKeyCmd,
27
+ envVar: "KIT_API_KEY",
28
+ appName: "kit-analytics",
29
+ });
22
30
  if (!apiKey) {
23
- console.error("Error: Kit API key is required. Set KIT_API_KEY env var or pass --api-key.");
31
+ console.error("Error: Kit API key is required.\n" +
32
+ " Set KIT_API_KEY env var, pass --api-key, use --api-key-cmd,\n" +
33
+ " add it to a .env file, or save it in ~/.config/kit-analytics/config.json.");
24
34
  process.exit(1);
25
35
  }
26
36
  const client = new api_js_1.KitClient({ apiKey });
@@ -34,6 +44,7 @@ program.hook("preAction", () => {
34
44
  // Register commands — each command pulls client/format from its own opts
35
45
  program.addCommand((0, account_js_1.accountCommand)());
36
46
  program.addCommand((0, subscribers_js_1.subscribersCommand)());
47
+ program.addCommand((0, broadcast_js_1.broadcastCommand)());
37
48
  program.addCommand((0, broadcasts_js_1.broadcastsCommand)());
38
49
  program.addCommand((0, tags_js_1.tagsCommand)());
39
50
  program.addCommand((0, forms_js_1.formsCommand)());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radjay/kit-analytics",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "CLI tool to pull Kit.com newsletter analytics via Kit API v4",
5
5
  "bin": {
6
6
  "kit-analytics": "./dist/index.js"
@@ -11,6 +11,7 @@
11
11
  "clean": "rm -rf dist"
12
12
  },
13
13
  "dependencies": {
14
+ "@radjay/resolve-key": "workspace:*",
14
15
  "commander": "^13.1.0"
15
16
  },
16
17
  "devDependencies": {