@chirpie/sdk 0.1.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.
@@ -0,0 +1,135 @@
1
+ interface ApiPost {
2
+ id: string;
3
+ account_id: string;
4
+ text: string;
5
+ media_urls: string[] | null;
6
+ platform_post_id: string | null;
7
+ status: "draft" | "scheduled" | "publishing" | "published" | "failed" | "deleted";
8
+ scheduled_at: string | null;
9
+ published_at: string | null;
10
+ thread_id: string | null;
11
+ thread_order: number | null;
12
+ created_at: string;
13
+ }
14
+ interface ApiThread {
15
+ id: string;
16
+ account_id: string;
17
+ posts: ApiPost[];
18
+ status: "draft" | "scheduled" | "publishing" | "published" | "failed";
19
+ scheduled_at: string | null;
20
+ created_at: string;
21
+ }
22
+ interface ApiAccount {
23
+ id: string;
24
+ x_user_id: string;
25
+ x_username: string;
26
+ x_display_name: string | null;
27
+ x_profile_image_url: string | null;
28
+ is_active: boolean;
29
+ created_at: string;
30
+ }
31
+ interface ApiAnalytics {
32
+ post_id: string;
33
+ impressions: number;
34
+ likes: number;
35
+ retweets: number;
36
+ replies: number;
37
+ quotes: number;
38
+ bookmarks: number;
39
+ clicks: number;
40
+ fetched_at: string;
41
+ }
42
+ interface ApiKeyInfo {
43
+ id: string;
44
+ name: string;
45
+ key_prefix: string;
46
+ last_used_at: string | null;
47
+ created_at: string;
48
+ revoked: boolean;
49
+ }
50
+ interface CreatePostInput {
51
+ account_id: string;
52
+ text: string;
53
+ media_urls?: string[];
54
+ schedule_at?: string;
55
+ }
56
+ interface CreateThreadInput {
57
+ account_id: string;
58
+ posts: {
59
+ text: string;
60
+ media_urls?: string[];
61
+ }[];
62
+ schedule_at?: string;
63
+ }
64
+ interface ListPostsOptions {
65
+ status?: string;
66
+ account_id?: string;
67
+ limit?: number;
68
+ offset?: number;
69
+ }
70
+
71
+ interface ChirpieClientOptions {
72
+ apiKey: string;
73
+ baseUrl?: string;
74
+ }
75
+ declare class ChirpieClient {
76
+ private apiKey;
77
+ private baseUrl;
78
+ constructor(options: ChirpieClientOptions);
79
+ private request;
80
+ createPost(input: CreatePostInput): Promise<ApiPost>;
81
+ listPosts(options?: ListPostsOptions): Promise<ApiPost[]>;
82
+ getPost(id: string): Promise<ApiPost>;
83
+ deletePost(id: string): Promise<{
84
+ id: string;
85
+ deleted: boolean;
86
+ }>;
87
+ createThread(input: CreateThreadInput): Promise<ApiThread>;
88
+ listAccounts(): Promise<ApiAccount[]>;
89
+ connectAccount(): Promise<{
90
+ authorization_url: string;
91
+ }>;
92
+ createKey(name?: string): Promise<{
93
+ key: string;
94
+ prefix: string;
95
+ name: string;
96
+ }>;
97
+ listKeys(): Promise<ApiKeyInfo[]>;
98
+ revokeKey(id: string): Promise<{
99
+ id: string;
100
+ revoked: boolean;
101
+ }>;
102
+ getPostAnalytics(postId: string): Promise<ApiAnalytics>;
103
+ }
104
+
105
+ declare class ChirpieError extends Error {
106
+ constructor(message: string);
107
+ }
108
+ declare class ChirpieApiError extends ChirpieError {
109
+ code: string;
110
+ status: number;
111
+ constructor(code: string, message: string, status: number);
112
+ }
113
+
114
+ interface ChirpieConfig {
115
+ api_key: string;
116
+ base_url: string;
117
+ }
118
+ /**
119
+ * Get stored config. Env var CHIRPIE_API_KEY takes precedence.
120
+ */
121
+ declare function getConfig(): ChirpieConfig | null;
122
+ /**
123
+ * Save config to ~/.chirpie/config.json with 0600 permissions.
124
+ */
125
+ declare function saveConfig(apiKey: string, baseUrl?: string): void;
126
+ /**
127
+ * Delete stored config.
128
+ */
129
+ declare function deleteConfig(): boolean;
130
+ /**
131
+ * Get config or throw with a helpful message.
132
+ */
133
+ declare function requireConfig(): ChirpieConfig;
134
+
135
+ export { type ApiAccount, type ApiAnalytics, type ApiKeyInfo, type ApiPost, type ApiThread, ChirpieApiError, ChirpieClient, type ChirpieClientOptions, type ChirpieConfig, ChirpieError, type CreatePostInput, type CreateThreadInput, type ListPostsOptions, deleteConfig, getConfig, requireConfig, saveConfig };
@@ -0,0 +1,135 @@
1
+ interface ApiPost {
2
+ id: string;
3
+ account_id: string;
4
+ text: string;
5
+ media_urls: string[] | null;
6
+ platform_post_id: string | null;
7
+ status: "draft" | "scheduled" | "publishing" | "published" | "failed" | "deleted";
8
+ scheduled_at: string | null;
9
+ published_at: string | null;
10
+ thread_id: string | null;
11
+ thread_order: number | null;
12
+ created_at: string;
13
+ }
14
+ interface ApiThread {
15
+ id: string;
16
+ account_id: string;
17
+ posts: ApiPost[];
18
+ status: "draft" | "scheduled" | "publishing" | "published" | "failed";
19
+ scheduled_at: string | null;
20
+ created_at: string;
21
+ }
22
+ interface ApiAccount {
23
+ id: string;
24
+ x_user_id: string;
25
+ x_username: string;
26
+ x_display_name: string | null;
27
+ x_profile_image_url: string | null;
28
+ is_active: boolean;
29
+ created_at: string;
30
+ }
31
+ interface ApiAnalytics {
32
+ post_id: string;
33
+ impressions: number;
34
+ likes: number;
35
+ retweets: number;
36
+ replies: number;
37
+ quotes: number;
38
+ bookmarks: number;
39
+ clicks: number;
40
+ fetched_at: string;
41
+ }
42
+ interface ApiKeyInfo {
43
+ id: string;
44
+ name: string;
45
+ key_prefix: string;
46
+ last_used_at: string | null;
47
+ created_at: string;
48
+ revoked: boolean;
49
+ }
50
+ interface CreatePostInput {
51
+ account_id: string;
52
+ text: string;
53
+ media_urls?: string[];
54
+ schedule_at?: string;
55
+ }
56
+ interface CreateThreadInput {
57
+ account_id: string;
58
+ posts: {
59
+ text: string;
60
+ media_urls?: string[];
61
+ }[];
62
+ schedule_at?: string;
63
+ }
64
+ interface ListPostsOptions {
65
+ status?: string;
66
+ account_id?: string;
67
+ limit?: number;
68
+ offset?: number;
69
+ }
70
+
71
+ interface ChirpieClientOptions {
72
+ apiKey: string;
73
+ baseUrl?: string;
74
+ }
75
+ declare class ChirpieClient {
76
+ private apiKey;
77
+ private baseUrl;
78
+ constructor(options: ChirpieClientOptions);
79
+ private request;
80
+ createPost(input: CreatePostInput): Promise<ApiPost>;
81
+ listPosts(options?: ListPostsOptions): Promise<ApiPost[]>;
82
+ getPost(id: string): Promise<ApiPost>;
83
+ deletePost(id: string): Promise<{
84
+ id: string;
85
+ deleted: boolean;
86
+ }>;
87
+ createThread(input: CreateThreadInput): Promise<ApiThread>;
88
+ listAccounts(): Promise<ApiAccount[]>;
89
+ connectAccount(): Promise<{
90
+ authorization_url: string;
91
+ }>;
92
+ createKey(name?: string): Promise<{
93
+ key: string;
94
+ prefix: string;
95
+ name: string;
96
+ }>;
97
+ listKeys(): Promise<ApiKeyInfo[]>;
98
+ revokeKey(id: string): Promise<{
99
+ id: string;
100
+ revoked: boolean;
101
+ }>;
102
+ getPostAnalytics(postId: string): Promise<ApiAnalytics>;
103
+ }
104
+
105
+ declare class ChirpieError extends Error {
106
+ constructor(message: string);
107
+ }
108
+ declare class ChirpieApiError extends ChirpieError {
109
+ code: string;
110
+ status: number;
111
+ constructor(code: string, message: string, status: number);
112
+ }
113
+
114
+ interface ChirpieConfig {
115
+ api_key: string;
116
+ base_url: string;
117
+ }
118
+ /**
119
+ * Get stored config. Env var CHIRPIE_API_KEY takes precedence.
120
+ */
121
+ declare function getConfig(): ChirpieConfig | null;
122
+ /**
123
+ * Save config to ~/.chirpie/config.json with 0600 permissions.
124
+ */
125
+ declare function saveConfig(apiKey: string, baseUrl?: string): void;
126
+ /**
127
+ * Delete stored config.
128
+ */
129
+ declare function deleteConfig(): boolean;
130
+ /**
131
+ * Get config or throw with a helpful message.
132
+ */
133
+ declare function requireConfig(): ChirpieConfig;
134
+
135
+ export { type ApiAccount, type ApiAnalytics, type ApiKeyInfo, type ApiPost, type ApiThread, ChirpieApiError, ChirpieClient, type ChirpieClientOptions, type ChirpieConfig, ChirpieError, type CreatePostInput, type CreateThreadInput, type ListPostsOptions, deleteConfig, getConfig, requireConfig, saveConfig };
package/dist/index.js ADDED
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ ChirpieApiError: () => ChirpieApiError,
24
+ ChirpieClient: () => ChirpieClient,
25
+ ChirpieError: () => ChirpieError,
26
+ deleteConfig: () => deleteConfig,
27
+ getConfig: () => getConfig,
28
+ requireConfig: () => requireConfig,
29
+ saveConfig: () => saveConfig
30
+ });
31
+ module.exports = __toCommonJS(index_exports);
32
+
33
+ // src/errors.ts
34
+ var ChirpieError = class extends Error {
35
+ constructor(message) {
36
+ super(message);
37
+ this.name = "ChirpieError";
38
+ }
39
+ };
40
+ var ChirpieApiError = class extends ChirpieError {
41
+ code;
42
+ status;
43
+ constructor(code, message, status) {
44
+ super(message);
45
+ this.name = "ChirpieApiError";
46
+ this.code = code;
47
+ this.status = status;
48
+ }
49
+ };
50
+
51
+ // src/client.ts
52
+ var ChirpieClient = class {
53
+ apiKey;
54
+ baseUrl;
55
+ constructor(options) {
56
+ if (!options.apiKey) {
57
+ throw new ChirpieError("API key is required");
58
+ }
59
+ this.apiKey = options.apiKey;
60
+ this.baseUrl = (options.baseUrl ?? "https://chirpie.ai").replace(/\/$/, "");
61
+ }
62
+ async request(method, path, body) {
63
+ const url = `${this.baseUrl}/api/v1${path}`;
64
+ const headers = {
65
+ Authorization: `Bearer ${this.apiKey}`,
66
+ "Content-Type": "application/json"
67
+ };
68
+ const res = await fetch(url, {
69
+ method,
70
+ headers,
71
+ body: body ? JSON.stringify(body) : void 0
72
+ });
73
+ const json = await res.json();
74
+ if (!res.ok) {
75
+ const err = json.error ?? { code: "unknown", message: "Request failed" };
76
+ throw new ChirpieApiError(err.code, err.message, res.status);
77
+ }
78
+ return json.data;
79
+ }
80
+ // Posts
81
+ async createPost(input) {
82
+ return this.request("POST", "/posts", input);
83
+ }
84
+ async listPosts(options) {
85
+ const params = new URLSearchParams();
86
+ if (options?.status) params.set("status", options.status);
87
+ if (options?.account_id) params.set("account_id", options.account_id);
88
+ if (options?.limit) params.set("limit", String(options.limit));
89
+ if (options?.offset) params.set("offset", String(options.offset));
90
+ const qs = params.toString();
91
+ return this.request("GET", `/posts${qs ? `?${qs}` : ""}`);
92
+ }
93
+ async getPost(id) {
94
+ return this.request("GET", `/posts/${id}`);
95
+ }
96
+ async deletePost(id) {
97
+ return this.request("DELETE", `/posts/${id}`);
98
+ }
99
+ // Threads
100
+ async createThread(input) {
101
+ return this.request("POST", "/threads", input);
102
+ }
103
+ // Accounts
104
+ async listAccounts() {
105
+ return this.request("GET", "/accounts");
106
+ }
107
+ async connectAccount() {
108
+ return this.request("POST", "/accounts");
109
+ }
110
+ // Keys
111
+ async createKey(name) {
112
+ return this.request(
113
+ "POST",
114
+ "/keys",
115
+ name ? { name } : void 0
116
+ );
117
+ }
118
+ async listKeys() {
119
+ return this.request("GET", "/keys");
120
+ }
121
+ async revokeKey(id) {
122
+ return this.request(
123
+ "DELETE",
124
+ `/keys?id=${id}`
125
+ );
126
+ }
127
+ // Analytics
128
+ async getPostAnalytics(postId) {
129
+ return this.request("GET", `/analytics/posts/${postId}`);
130
+ }
131
+ };
132
+
133
+ // src/config.ts
134
+ var import_fs = require("fs");
135
+ var import_path = require("path");
136
+ var import_os = require("os");
137
+ var CONFIG_DIR = (0, import_path.join)((0, import_os.homedir)(), ".chirpie");
138
+ var CONFIG_FILE = (0, import_path.join)(CONFIG_DIR, "config.json");
139
+ function getConfig() {
140
+ const envKey = process.env.CHIRPIE_API_KEY;
141
+ if (envKey) {
142
+ return {
143
+ api_key: envKey,
144
+ base_url: process.env.CHIRPIE_BASE_URL ?? "https://chirpie.ai"
145
+ };
146
+ }
147
+ if (!(0, import_fs.existsSync)(CONFIG_FILE)) return null;
148
+ try {
149
+ return JSON.parse((0, import_fs.readFileSync)(CONFIG_FILE, "utf-8"));
150
+ } catch {
151
+ return null;
152
+ }
153
+ }
154
+ function saveConfig(apiKey, baseUrl) {
155
+ (0, import_fs.mkdirSync)(CONFIG_DIR, { recursive: true });
156
+ const config = {
157
+ api_key: apiKey,
158
+ base_url: baseUrl ?? "https://chirpie.ai"
159
+ };
160
+ (0, import_fs.writeFileSync)(CONFIG_FILE, JSON.stringify(config, null, 2));
161
+ (0, import_fs.chmodSync)(CONFIG_FILE, 384);
162
+ }
163
+ function deleteConfig() {
164
+ if ((0, import_fs.existsSync)(CONFIG_FILE)) {
165
+ (0, import_fs.unlinkSync)(CONFIG_FILE);
166
+ return true;
167
+ }
168
+ return false;
169
+ }
170
+ function requireConfig() {
171
+ const config = getConfig();
172
+ if (!config) {
173
+ throw new Error(
174
+ "Not authenticated. Run `chirpie login` or set CHIRPIE_API_KEY environment variable."
175
+ );
176
+ }
177
+ return config;
178
+ }
179
+ // Annotate the CommonJS export names for ESM import in node:
180
+ 0 && (module.exports = {
181
+ ChirpieApiError,
182
+ ChirpieClient,
183
+ ChirpieError,
184
+ deleteConfig,
185
+ getConfig,
186
+ requireConfig,
187
+ saveConfig
188
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,155 @@
1
+ // src/errors.ts
2
+ var ChirpieError = class extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "ChirpieError";
6
+ }
7
+ };
8
+ var ChirpieApiError = class extends ChirpieError {
9
+ code;
10
+ status;
11
+ constructor(code, message, status) {
12
+ super(message);
13
+ this.name = "ChirpieApiError";
14
+ this.code = code;
15
+ this.status = status;
16
+ }
17
+ };
18
+
19
+ // src/client.ts
20
+ var ChirpieClient = class {
21
+ apiKey;
22
+ baseUrl;
23
+ constructor(options) {
24
+ if (!options.apiKey) {
25
+ throw new ChirpieError("API key is required");
26
+ }
27
+ this.apiKey = options.apiKey;
28
+ this.baseUrl = (options.baseUrl ?? "https://chirpie.ai").replace(/\/$/, "");
29
+ }
30
+ async request(method, path, body) {
31
+ const url = `${this.baseUrl}/api/v1${path}`;
32
+ const headers = {
33
+ Authorization: `Bearer ${this.apiKey}`,
34
+ "Content-Type": "application/json"
35
+ };
36
+ const res = await fetch(url, {
37
+ method,
38
+ headers,
39
+ body: body ? JSON.stringify(body) : void 0
40
+ });
41
+ const json = await res.json();
42
+ if (!res.ok) {
43
+ const err = json.error ?? { code: "unknown", message: "Request failed" };
44
+ throw new ChirpieApiError(err.code, err.message, res.status);
45
+ }
46
+ return json.data;
47
+ }
48
+ // Posts
49
+ async createPost(input) {
50
+ return this.request("POST", "/posts", input);
51
+ }
52
+ async listPosts(options) {
53
+ const params = new URLSearchParams();
54
+ if (options?.status) params.set("status", options.status);
55
+ if (options?.account_id) params.set("account_id", options.account_id);
56
+ if (options?.limit) params.set("limit", String(options.limit));
57
+ if (options?.offset) params.set("offset", String(options.offset));
58
+ const qs = params.toString();
59
+ return this.request("GET", `/posts${qs ? `?${qs}` : ""}`);
60
+ }
61
+ async getPost(id) {
62
+ return this.request("GET", `/posts/${id}`);
63
+ }
64
+ async deletePost(id) {
65
+ return this.request("DELETE", `/posts/${id}`);
66
+ }
67
+ // Threads
68
+ async createThread(input) {
69
+ return this.request("POST", "/threads", input);
70
+ }
71
+ // Accounts
72
+ async listAccounts() {
73
+ return this.request("GET", "/accounts");
74
+ }
75
+ async connectAccount() {
76
+ return this.request("POST", "/accounts");
77
+ }
78
+ // Keys
79
+ async createKey(name) {
80
+ return this.request(
81
+ "POST",
82
+ "/keys",
83
+ name ? { name } : void 0
84
+ );
85
+ }
86
+ async listKeys() {
87
+ return this.request("GET", "/keys");
88
+ }
89
+ async revokeKey(id) {
90
+ return this.request(
91
+ "DELETE",
92
+ `/keys?id=${id}`
93
+ );
94
+ }
95
+ // Analytics
96
+ async getPostAnalytics(postId) {
97
+ return this.request("GET", `/analytics/posts/${postId}`);
98
+ }
99
+ };
100
+
101
+ // src/config.ts
102
+ import { readFileSync, writeFileSync, mkdirSync, chmodSync, existsSync, unlinkSync } from "fs";
103
+ import { join } from "path";
104
+ import { homedir } from "os";
105
+ var CONFIG_DIR = join(homedir(), ".chirpie");
106
+ var CONFIG_FILE = join(CONFIG_DIR, "config.json");
107
+ function getConfig() {
108
+ const envKey = process.env.CHIRPIE_API_KEY;
109
+ if (envKey) {
110
+ return {
111
+ api_key: envKey,
112
+ base_url: process.env.CHIRPIE_BASE_URL ?? "https://chirpie.ai"
113
+ };
114
+ }
115
+ if (!existsSync(CONFIG_FILE)) return null;
116
+ try {
117
+ return JSON.parse(readFileSync(CONFIG_FILE, "utf-8"));
118
+ } catch {
119
+ return null;
120
+ }
121
+ }
122
+ function saveConfig(apiKey, baseUrl) {
123
+ mkdirSync(CONFIG_DIR, { recursive: true });
124
+ const config = {
125
+ api_key: apiKey,
126
+ base_url: baseUrl ?? "https://chirpie.ai"
127
+ };
128
+ writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
129
+ chmodSync(CONFIG_FILE, 384);
130
+ }
131
+ function deleteConfig() {
132
+ if (existsSync(CONFIG_FILE)) {
133
+ unlinkSync(CONFIG_FILE);
134
+ return true;
135
+ }
136
+ return false;
137
+ }
138
+ function requireConfig() {
139
+ const config = getConfig();
140
+ if (!config) {
141
+ throw new Error(
142
+ "Not authenticated. Run `chirpie login` or set CHIRPIE_API_KEY environment variable."
143
+ );
144
+ }
145
+ return config;
146
+ }
147
+ export {
148
+ ChirpieApiError,
149
+ ChirpieClient,
150
+ ChirpieError,
151
+ deleteConfig,
152
+ getConfig,
153
+ requireConfig,
154
+ saveConfig
155
+ };
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@chirpie/sdk",
3
+ "version": "0.1.0",
4
+ "description": "Chirpie SDK — TypeScript client for the Chirpie social media API",
5
+ "repository": { "type": "git", "url": "https://github.com/Firefloco/chirpie", "directory": "packages/sdk" },
6
+ "homepage": "https://chirpie.ai/docs/sdk",
7
+ "publishConfig": { "access": "public" },
8
+ "main": "./dist/index.cjs",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.cjs",
15
+ "types": "./dist/index.d.ts"
16
+ }
17
+ },
18
+ "files": ["dist"],
19
+ "scripts": {
20
+ "build": "tsup",
21
+ "dev": "tsup --watch"
22
+ },
23
+ "keywords": ["chirpie", "social-media", "api", "sdk", "twitter", "x"],
24
+ "license": "MIT",
25
+ "devDependencies": {
26
+ "tsup": "^8",
27
+ "typescript": "^5"
28
+ }
29
+ }