@socialrouter/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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SocialRouter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,225 @@
1
+ # SocialRouter SDK
2
+
3
+ A unified API to extract data from social media platforms. SocialRouter acts as an abstraction layer over multiple data providers (Lobstr, Apify, PhantomBuster, etc.), offering a single interface, normalized data format, and automatic failover.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @socialrouter/sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { SocialRouter } from "@socialrouter/sdk";
15
+
16
+ const client = new SocialRouter({
17
+ apiKey: "sr_live_xxxxxxxxxxxxx",
18
+ });
19
+
20
+ const result = await client.extractAndWait({
21
+ url: "https://www.linkedin.com/posts/johndoe_ai-sales-1234567890",
22
+ model: "lobstr/post.likes",
23
+ limit: 100,
24
+ });
25
+
26
+ for (const person of result.data) {
27
+ console.log(`${person.name} - ${person.title} @ ${person.company}`);
28
+ }
29
+ ```
30
+
31
+ ## Model Slugs
32
+
33
+ SocialRouter uses model slugs to specify which provider and extraction type to use, following the same pattern as OpenRouter. A model slug combines the provider and extraction type in a single string:
34
+
35
+ ```
36
+ provider/extraction_type
37
+ ```
38
+
39
+ ### Available Models
40
+
41
+ | Model | Description |
42
+ |-------|-------------|
43
+ | `lobstr/post.likes` | Post likes via Lobstr |
44
+ | `lobstr/post.comments` | Post comments via Lobstr |
45
+ | `lobstr/profile.info` | Profile info via Lobstr |
46
+ | `lobstr/profile.posts` | Profile posts via Lobstr |
47
+ | `apify/post.likes` | Post likes via Apify |
48
+ | `apify/post.comments` | Post comments via Apify |
49
+ | `apify/profile.info` | Profile info via Apify |
50
+ | `apify/profile.posts` | Profile posts via Apify |
51
+ | `apify/profile.followers` | Followers via Apify |
52
+
53
+ Browse all models and pricing at [socialrouter.io/providers](https://socialrouter.io/providers).
54
+
55
+ ## Supported Platforms
56
+
57
+ - **LinkedIn** - profiles, posts, likes, comments, followers
58
+ - **Instagram** - profiles, posts, likes, comments, followers
59
+ - **X (Twitter)** - profiles, posts, likes, comments, followers
60
+ - **Reddit** - profiles, posts, likes, comments, followers
61
+
62
+ ## Extraction Types
63
+
64
+ | Type | Description |
65
+ |------|-------------|
66
+ | `post.likes` | People who liked/reacted to a post |
67
+ | `post.comments` | People who commented on a post |
68
+ | `profile.info` | Profile metadata (name, bio, company, location) |
69
+ | `profile.posts` | Recent posts from a profile or page |
70
+ | `profile.followers` | Followers of a profile or page |
71
+
72
+ ## Configuration
73
+
74
+ ```typescript
75
+ const client = new SocialRouter({
76
+ apiKey: "sr_live_xxxxxxxxxxxxx", // Required
77
+ baseUrl: "https://api.socialrouter.io", // Optional (default value)
78
+ });
79
+ ```
80
+
81
+ ## Extracting Data
82
+
83
+ ### Extract and wait (recommended)
84
+
85
+ The simplest approach. Launches the extraction and polls automatically until the result is ready:
86
+
87
+ ```typescript
88
+ const result = await client.extractAndWait({
89
+ url: "https://www.linkedin.com/posts/johndoe_ai-sales-1234567890",
90
+ model: "lobstr/post.likes",
91
+ limit: 100,
92
+ });
93
+
94
+ console.log(result.status); // "completed" or "failed"
95
+ console.log(result.data); // ExtractionRecord[]
96
+ console.log(result.pagination.total); // Total available records
97
+ ```
98
+
99
+ You can customize the polling behavior:
100
+
101
+ ```typescript
102
+ const result = await client.extractAndWait(
103
+ { url: "...", model: "lobstr/post.likes" },
104
+ 5000, // Poll every 5 seconds (default: 3000)
105
+ 60000, // Timeout after 60 seconds (default: 120000)
106
+ );
107
+ ```
108
+
109
+ ### Extract options
110
+
111
+ ```typescript
112
+ await client.extract({
113
+ url: "https://linkedin.com/in/johndoe", // Social media URL
114
+ model: "apify/profile.info", // Model slug (provider/type)
115
+ limit: 50, // Max results (default: 100)
116
+ cache: true, // Enable caching (optional)
117
+ webhook_url: "https://myapp.com/hook", // Async callback URL (optional)
118
+ });
119
+ ```
120
+
121
+ ### Manual polling
122
+
123
+ If you prefer to manage polling yourself:
124
+
125
+ ```typescript
126
+ const extraction = await client.extract({
127
+ url: "https://linkedin.com/posts/...",
128
+ model: "lobstr/post.likes",
129
+ });
130
+
131
+ console.log(extraction.id); // "ext_abc123"
132
+
133
+ // Check the result later
134
+ const result = await client.getExtraction(extraction.id);
135
+
136
+ if (result.status === "completed") {
137
+ console.log(result.data);
138
+ } else if (result.status === "failed") {
139
+ console.error(result.error);
140
+ }
141
+ ```
142
+
143
+ ## Providers
144
+
145
+ ```typescript
146
+ // List all available providers
147
+ const providers = await client.listProviders();
148
+
149
+ for (const p of providers) {
150
+ console.log(`${p.name} [${p.status}] - ${p.supported_platforms.join(", ")}`);
151
+ }
152
+
153
+ // Get provider details including pricing
154
+ const detail = await client.getProvider("lobstr");
155
+ console.log(detail.pricing);
156
+ ```
157
+
158
+ ## Account
159
+
160
+ ```typescript
161
+ // Check credit balance
162
+ const balance = await client.getBalance();
163
+ console.log(`Balance: $${balance.balance} ${balance.currency}`);
164
+
165
+ // Get usage summary
166
+ const usage = await client.getUsage(30); // Last 30 days
167
+ console.log(`Requests: ${usage.total_requests}`);
168
+ console.log(`Records: ${usage.total_records}`);
169
+ console.log(`Credits used: $${usage.total_credits}`);
170
+ ```
171
+
172
+ ## Error Handling
173
+
174
+ The SDK exposes specific error classes for each failure case:
175
+
176
+ ```typescript
177
+ import {
178
+ SocialRouter,
179
+ AuthenticationError,
180
+ InsufficientCreditsError,
181
+ RateLimitError,
182
+ SocialRouterError,
183
+ } from "@socialrouter/sdk";
184
+
185
+ try {
186
+ await client.extractAndWait({ url: "...", model: "lobstr/post.likes" });
187
+ } catch (err) {
188
+ if (err instanceof AuthenticationError) {
189
+ // 401 - Invalid or missing API key
190
+ } else if (err instanceof InsufficientCreditsError) {
191
+ // 402 - Not enough credits
192
+ } else if (err instanceof RateLimitError) {
193
+ // 429 - Too many requests
194
+ console.log(`Retry after ${err.retryAfter} seconds`);
195
+ } else if (err instanceof SocialRouterError) {
196
+ // Other API error
197
+ console.error(err.code, err.message, err.status);
198
+ }
199
+ }
200
+ ```
201
+
202
+ ## TypeScript Types
203
+
204
+ All types are exported for direct use:
205
+
206
+ ```typescript
207
+ import type {
208
+ SocialRouterConfig,
209
+ ExtractOptions,
210
+ Extraction,
211
+ ExtractionRecord,
212
+ ExtractionType,
213
+ ExtractionStatus,
214
+ Platform,
215
+ ProviderInfo,
216
+ ProviderDetail,
217
+ AccountBalance,
218
+ UsageSummary,
219
+ ApiErrorDetail,
220
+ } from "@socialrouter/sdk";
221
+ ```
222
+
223
+ ## License
224
+
225
+ MIT
@@ -0,0 +1,24 @@
1
+ import type { SocialRouterConfig, ExtractOptions, Extraction, ProviderInfo, ProviderDetail, AccountBalance, UsageSummary } from "./types.js";
2
+ export declare class SocialRouter {
3
+ private apiKey;
4
+ private baseUrl;
5
+ constructor(config: SocialRouterConfig);
6
+ /** Run a data extraction */
7
+ extract(options: ExtractOptions): Promise<Extraction>;
8
+ /** Get extraction by ID (for polling async results) */
9
+ getExtraction(id: string): Promise<Extraction>;
10
+ /** Extract and poll until completed (convenience method) */
11
+ extractAndWait(options: ExtractOptions, pollIntervalMs?: number, timeoutMs?: number): Promise<Extraction>;
12
+ /** List all providers */
13
+ listProviders(): Promise<ProviderInfo[]>;
14
+ /** Get provider detail */
15
+ getProvider(id: string): Promise<ProviderDetail>;
16
+ /** Get credit balance */
17
+ getBalance(): Promise<AccountBalance>;
18
+ /** Get usage summary */
19
+ getUsage(days?: number): Promise<UsageSummary>;
20
+ private get;
21
+ private post;
22
+ private request;
23
+ }
24
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,YAAY,EACZ,cAAc,EACd,cAAc,EACd,YAAY,EACb,MAAM,YAAY,CAAC;AAUpB,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,kBAAkB;IAOtC,4BAA4B;IACtB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;IAU3D,uDAAuD;IACjD,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAIpD,4DAA4D;IACtD,cAAc,CAClB,OAAO,EAAE,cAAc,EACvB,cAAc,GAAE,MAAa,EAC7B,SAAS,GAAE,MAAe,GACzB,OAAO,CAAC,UAAU,CAAC;IAoBtB,yBAAyB;IACnB,aAAa,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAK9C,0BAA0B;IACpB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAMtD,yBAAyB;IACnB,UAAU,IAAI,OAAO,CAAC,cAAc,CAAC;IAI3C,wBAAwB;IAClB,QAAQ,CAAC,IAAI,GAAE,MAAW,GAAG,OAAO,CAAC,YAAY,CAAC;YAM1C,GAAG;YAIH,IAAI;YAIJ,OAAO;CAoCtB"}
package/dist/client.js ADDED
@@ -0,0 +1,99 @@
1
+ import { SocialRouterError, AuthenticationError, InsufficientCreditsError, RateLimitError, } from "./errors.js";
2
+ const DEFAULT_BASE_URL = "https://api.socialrouter.io";
3
+ export class SocialRouter {
4
+ apiKey;
5
+ baseUrl;
6
+ constructor(config) {
7
+ this.apiKey = config.apiKey;
8
+ this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
9
+ }
10
+ // ─── Extract ─────────────────────────────────────────
11
+ /** Run a data extraction */
12
+ async extract(options) {
13
+ return this.post("/v1/extract", {
14
+ url: options.url,
15
+ type: options.type,
16
+ limit: options.limit ?? 100,
17
+ provider: options.provider,
18
+ webhook_url: options.webhook_url,
19
+ });
20
+ }
21
+ /** Get extraction by ID (for polling async results) */
22
+ async getExtraction(id) {
23
+ return this.get(`/v1/extract/${id}`);
24
+ }
25
+ /** Extract and poll until completed (convenience method) */
26
+ async extractAndWait(options, pollIntervalMs = 3000, timeoutMs = 120000) {
27
+ const extraction = await this.extract(options);
28
+ if (extraction.status === "completed" || extraction.status === "failed") {
29
+ return extraction;
30
+ }
31
+ // Poll
32
+ const start = Date.now();
33
+ while (Date.now() - start < timeoutMs) {
34
+ await new Promise((r) => setTimeout(r, pollIntervalMs));
35
+ const result = await this.getExtraction(extraction.id);
36
+ if (result.status !== "pending")
37
+ return result;
38
+ }
39
+ throw new Error(`Extraction ${extraction.id} timed out after ${timeoutMs}ms`);
40
+ }
41
+ // ─── Providers ───────────────────────────────────────
42
+ /** List all providers */
43
+ async listProviders() {
44
+ const res = await this.get("/v1/providers");
45
+ return res.data;
46
+ }
47
+ /** Get provider detail */
48
+ async getProvider(id) {
49
+ return this.get(`/v1/providers/${id}`);
50
+ }
51
+ // ─── Account ─────────────────────────────────────────
52
+ /** Get credit balance */
53
+ async getBalance() {
54
+ return this.get("/v1/account/balance");
55
+ }
56
+ /** Get usage summary */
57
+ async getUsage(days = 30) {
58
+ return this.get(`/v1/account/usage?days=${days}`);
59
+ }
60
+ // ─── HTTP ────────────────────────────────────────────
61
+ async get(path) {
62
+ return this.request("GET", path);
63
+ }
64
+ async post(path, body) {
65
+ return this.request("POST", path, body);
66
+ }
67
+ async request(method, path, body) {
68
+ const url = `${this.baseUrl}${path}`;
69
+ const res = await fetch(url, {
70
+ method,
71
+ headers: {
72
+ Authorization: `Bearer ${this.apiKey}`,
73
+ "Content-Type": "application/json",
74
+ "User-Agent": "socialrouter-sdk/0.1.0",
75
+ },
76
+ ...(body ? { body: JSON.stringify(body) } : {}),
77
+ });
78
+ if (!res.ok) {
79
+ const json = await res.json().catch(() => ({
80
+ error: { code: "unknown", message: res.statusText, type: "unknown" },
81
+ }));
82
+ const detail = json.error ?? { code: "unknown", message: res.statusText, type: "unknown" };
83
+ switch (res.status) {
84
+ case 401:
85
+ throw new AuthenticationError(detail);
86
+ case 402:
87
+ throw new InsufficientCreditsError(detail);
88
+ case 429: {
89
+ const retryAfter = res.headers.get("X-RateLimit-Reset");
90
+ throw new RateLimitError(detail, retryAfter ? Number(retryAfter) : undefined);
91
+ }
92
+ default:
93
+ throw new SocialRouterError(detail, res.status);
94
+ }
95
+ }
96
+ return res.json();
97
+ }
98
+ }
99
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AASA,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,wBAAwB,EACxB,cAAc,GACf,MAAM,aAAa,CAAC;AAErB,MAAM,gBAAgB,GAAG,6BAA6B,CAAC;AAEvD,MAAM,OAAO,YAAY;IACf,MAAM,CAAS;IACf,OAAO,CA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AAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QAED,OAAO,GAAG,CAAC,IAAI,EAAgB,CAAC;IAClC,CAAC;CACF"}
@@ -0,0 +1,18 @@
1
+ import type { ApiErrorDetail } from "./types.js";
2
+ export declare class SocialRouterError extends Error {
3
+ code: string;
4
+ type: string;
5
+ status: number;
6
+ constructor(detail: ApiErrorDetail, status: number);
7
+ }
8
+ export declare class AuthenticationError extends SocialRouterError {
9
+ constructor(detail: ApiErrorDetail);
10
+ }
11
+ export declare class InsufficientCreditsError extends SocialRouterError {
12
+ constructor(detail: ApiErrorDetail);
13
+ }
14
+ export declare class RateLimitError extends SocialRouterError {
15
+ retryAfter?: number;
16
+ constructor(detail: ApiErrorDetail, retryAfter?: number);
17
+ }
18
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,qBAAa,iBAAkB,SAAQ,KAAK;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;gBAEV,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM;CAOnD;AAED,qBAAa,mBAAoB,SAAQ,iBAAiB;gBAC5C,MAAM,EAAE,cAAc;CAInC;AAED,qBAAa,wBAAyB,SAAQ,iBAAiB;gBACjD,MAAM,EAAE,cAAc;CAInC;AAED,qBAAa,cAAe,SAAQ,iBAAiB;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;gBAEf,MAAM,EAAE,cAAc,EAAE,UAAU,CAAC,EAAE,MAAM;CAKxD"}
package/dist/errors.js ADDED
@@ -0,0 +1,33 @@
1
+ export class SocialRouterError extends Error {
2
+ code;
3
+ type;
4
+ status;
5
+ constructor(detail, status) {
6
+ super(detail.message);
7
+ this.name = "SocialRouterError";
8
+ this.code = detail.code;
9
+ this.type = detail.type;
10
+ this.status = status;
11
+ }
12
+ }
13
+ export class AuthenticationError extends SocialRouterError {
14
+ constructor(detail) {
15
+ super(detail, 401);
16
+ this.name = "AuthenticationError";
17
+ }
18
+ }
19
+ export class InsufficientCreditsError extends SocialRouterError {
20
+ constructor(detail) {
21
+ super(detail, 402);
22
+ this.name = "InsufficientCreditsError";
23
+ }
24
+ }
25
+ export class RateLimitError extends SocialRouterError {
26
+ retryAfter;
27
+ constructor(detail, retryAfter) {
28
+ super(detail, 429);
29
+ this.name = "RateLimitError";
30
+ this.retryAfter = retryAfter;
31
+ }
32
+ }
33
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACnC,IAAI,CAAS;IACb,IAAI,CAAS;IACb,MAAM,CAAS;IAEtB,YAAY,MAAsB,EAAE,MAAc;QAChD,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,iBAAiB;IACxD,YAAY,MAAsB;QAChC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED,MAAM,OAAO,wBAAyB,SAAQ,iBAAiB;IAC7D,YAAY,MAAsB;QAChC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,iBAAiB;IAC5C,UAAU,CAAU;IAE3B,YAAY,MAAsB,EAAE,UAAmB;QACrD,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ export { SocialRouter } from "./client.js";
2
+ export { SocialRouterError, AuthenticationError, InsufficientCreditsError, RateLimitError, } from "./errors.js";
3
+ export type { SocialRouterConfig, ExtractOptions, Extraction, ExtractionRecord, ExtractionType, ExtractionStatus, Platform, ProviderInfo, ProviderDetail, AccountBalance, UsageSummary, ApiErrorDetail, } from "./types.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,wBAAwB,EACxB,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,cAAc,EACd,YAAY,EACZ,cAAc,GACf,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { SocialRouter } from "./client.js";
2
+ export { SocialRouterError, AuthenticationError, InsufficientCreditsError, RateLimitError, } from "./errors.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,wBAAwB,EACxB,cAAc,GACf,MAAM,aAAa,CAAC"}
@@ -0,0 +1,83 @@
1
+ export type ExtractionType = "post.likes" | "post.comments" | "profile.info" | "profile.posts" | "profile.followers";
2
+ export type Platform = "linkedin" | "instagram" | "x" | "reddit";
3
+ export type ExtractionStatus = "pending" | "completed" | "failed";
4
+ export interface ExtractOptions {
5
+ url: string;
6
+ type: ExtractionType;
7
+ limit?: number;
8
+ provider?: string;
9
+ webhook_url?: string;
10
+ }
11
+ export interface ExtractionRecord {
12
+ name: string;
13
+ title?: string;
14
+ company?: string;
15
+ location?: string;
16
+ profile_url: string;
17
+ source: Platform;
18
+ extracted_at: string;
19
+ [key: string]: unknown;
20
+ }
21
+ export interface Extraction {
22
+ id: string;
23
+ status: ExtractionStatus;
24
+ source: Platform;
25
+ type: ExtractionType;
26
+ url: string;
27
+ provider: string;
28
+ credits_used: number;
29
+ data: ExtractionRecord[];
30
+ pagination: {
31
+ total: number;
32
+ returned: number;
33
+ next_cursor: string | null;
34
+ };
35
+ error?: ApiErrorDetail;
36
+ created_at: string;
37
+ completed_at: string | null;
38
+ }
39
+ export interface ProviderInfo {
40
+ id: string;
41
+ name: string;
42
+ description: string;
43
+ status: string;
44
+ supported_platforms: Platform[];
45
+ supported_types: ExtractionType[];
46
+ }
47
+ export interface ProviderDetail extends ProviderInfo {
48
+ pricing: {
49
+ type: ExtractionType;
50
+ platforms: Platform[];
51
+ price_per_record: number;
52
+ }[];
53
+ }
54
+ export interface AccountBalance {
55
+ balance: number;
56
+ currency: string;
57
+ }
58
+ export interface UsageSummary {
59
+ period: string;
60
+ total_requests: number;
61
+ total_records: number;
62
+ total_credits: number;
63
+ by_provider: Record<string, {
64
+ requests: number;
65
+ records: number;
66
+ credits: number;
67
+ }>;
68
+ by_platform: Record<string, {
69
+ requests: number;
70
+ records: number;
71
+ credits: number;
72
+ }>;
73
+ }
74
+ export interface ApiErrorDetail {
75
+ code: string;
76
+ message: string;
77
+ type: string;
78
+ }
79
+ export interface SocialRouterConfig {
80
+ apiKey: string;
81
+ baseUrl?: string;
82
+ }
83
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GACtB,YAAY,GACZ,eAAe,GACf,cAAc,GACd,eAAe,GACf,mBAAmB,CAAC;AAExB,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,WAAW,GAAG,GAAG,GAAG,QAAQ,CAAC;AACjE,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;AAElE,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,QAAQ,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,gBAAgB,CAAC;IACzB,MAAM,EAAE,QAAQ,CAAC;IACjB,IAAI,EAAE,cAAc,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,gBAAgB,EAAE,CAAC;IACzB,UAAU,EAAE;Q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AO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@socialrouter/sdk",
3
+ "version": "0.1.0",
4
+ "description": "Official TypeScript SDK for the SocialRouter API",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": ["dist", "README.md", "LICENSE"],
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "dev": "tsc --watch",
18
+ "prepublishOnly": "npm run build"
19
+ },
20
+ "keywords": ["socialrouter", "social-media", "scraping", "api", "sdk", "linkedin", "instagram", "twitter", "x", "reddit"],
21
+ "author": "SocialRouter",
22
+ "license": "MIT",
23
+ "homepage": "https://www.socialrouter.io",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/socialrouter/sdk-ts.git"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/socialrouter/sdk-ts/issues"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "engines": {
35
+ "node": ">=18"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^25.5.2",
39
+ "typescript": "^6.0.2"
40
+ }
41
+ }