@getrecited/sdk 0.0.0-stage → 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/README.md +2 -2
- package/cli.js +19 -0
- package/index.d.ts +12 -0
- package/index.js +49 -0
- package/package.json +17 -4
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#
|
|
1
|
+
# GetRecited JavaScript/TypeScript SDK and CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official integration source. Usage, authentication, verification and publication status are maintained in the [canonical integration guide](../../../docs/guides/agent-integrations.md) and [public developer docs](https://getrecited.com/developers).
|
package/cli.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { parseArgs } from "node:util"
|
|
3
|
+
import { GetRecited, GetRecitedError } from "./index.js"
|
|
4
|
+
|
|
5
|
+
try {
|
|
6
|
+
const { values, positionals } = parseArgs({ allowPositionals: true, options: { days: { type: "string" }, limit: { type: "string" }, help: { type: "boolean", short: "h" }, "base-url": { type: "string" } } })
|
|
7
|
+
if (values.help || positionals.length === 0) {
|
|
8
|
+
process.stdout.write("GetRecited read CLI\nUsage: getrecited brands | visibility <workspace-brand-uuid> [--days 30] | scans [--limit 20] | describe\nSet GETRECITED_API_KEY to an API key or OAuth token. Optional GETRECITED_BASE_URL for isolated development.\n")
|
|
9
|
+
} else {
|
|
10
|
+
const [command, id, ...extra] = positionals
|
|
11
|
+
if (extra.length || !["brands", "visibility", "scans", "describe"].includes(command) || (command === "visibility" ? !id : !!id)) throw new Error("Invalid command. Run getrecited --help.")
|
|
12
|
+
const client = new GetRecited({ apiKey: process.env.GETRECITED_API_KEY, baseUrl: values["base-url"] ?? process.env.GETRECITED_BASE_URL })
|
|
13
|
+
const data = command === "brands" ? await client.brands() : command === "visibility" ? await client.visibility(id, { days: values.days === undefined ? 30 : Number(values.days) }) : command === "scans" ? await client.scans({ limit: values.limit === undefined ? 20 : Number(values.limit) }) : await client.describe()
|
|
14
|
+
process.stdout.write(JSON.stringify(data) + "\n")
|
|
15
|
+
}
|
|
16
|
+
} catch (error) {
|
|
17
|
+
process.stderr.write(JSON.stringify({ code: error instanceof GetRecitedError ? error.code : "invalid_command", message: error.message, ...(error instanceof GetRecitedError ? { status: error.status, request_id: error.requestId, retry_after: error.retryAfter } : {}) }) + "\n")
|
|
18
|
+
process.exitCode = 1
|
|
19
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type TrackedBrand = { id: string; brand_id: string; name: string; slug: string; domain: string | null; is_owned: boolean; visibility_7d: number | null; tracked_at: string }
|
|
2
|
+
export type VisibilityRow = { day: string; category_id: string; visibility_rate: number; mention_sov: number | null; citation_sov: number | null; avg_position: number | null; sentiment_score: number | null; ci_low: number; ci_high: number; is_signal: boolean; responses_sampled: number }
|
|
3
|
+
export type Scan = { id: string; status: string; sample_n: number; trigger: string; started_at: string | null; finished_at: string | null; cost_cents: number; created_at: string }
|
|
4
|
+
export type Data<T> = { data: T[] }
|
|
5
|
+
export class GetRecitedError extends Error { status: number; code: string; requestId?: string; retryAfter?: number }
|
|
6
|
+
export class GetRecited {
|
|
7
|
+
constructor(options: { apiKey: string; baseUrl?: string; fetch?: typeof globalThis.fetch })
|
|
8
|
+
describe(): Promise<{ name: string; version: string; scopes: string[] }>
|
|
9
|
+
brands(): Promise<Data<TrackedBrand>>
|
|
10
|
+
visibility(workspaceBrandId: string, options?: { days?: number }): Promise<Data<VisibilityRow>>
|
|
11
|
+
scans(options?: { limit?: number }): Promise<Data<Scan>>
|
|
12
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export class GetRecitedError extends Error {
|
|
2
|
+
constructor(status, code, requestId, retryAfter) {
|
|
3
|
+
super(`GetRecited request failed (${status}, ${code}). See https://getrecited.com/auth.md.`)
|
|
4
|
+
this.name = "GetRecitedError"
|
|
5
|
+
this.status = status
|
|
6
|
+
this.code = code
|
|
7
|
+
this.requestId = requestId
|
|
8
|
+
this.retryAfter = retryAfter
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class GetRecited {
|
|
12
|
+
#apiKey
|
|
13
|
+
#fetch
|
|
14
|
+
#baseUrl
|
|
15
|
+
constructor({ apiKey, baseUrl = "https://getrecited.com", fetch: fetchImpl = globalThis.fetch }) {
|
|
16
|
+
if (typeof apiKey !== "string" || !apiKey.trim() || /\s/.test(apiKey)) throw new TypeError("Provide a Bearer API key or access token.")
|
|
17
|
+
const url = new URL(baseUrl)
|
|
18
|
+
if (url.username || url.password || url.search || url.hash || !["", "/"].includes(url.pathname)) throw new TypeError("baseUrl must be an origin without credentials, path or query.")
|
|
19
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname))) throw new TypeError("Use HTTPS for remote origins; HTTP is permitted only for loopback development.")
|
|
20
|
+
this.#apiKey = apiKey
|
|
21
|
+
this.#fetch = fetchImpl
|
|
22
|
+
this.#baseUrl = url.origin
|
|
23
|
+
}
|
|
24
|
+
async #get(path) {
|
|
25
|
+
let response
|
|
26
|
+
try { response = await this.#fetch(`${this.#baseUrl}/api/v1${path}`, { headers: { Authorization: `Bearer ${this.#apiKey}`, Accept: "application/json" }, redirect: "error", signal: AbortSignal.timeout(10000) }) }
|
|
27
|
+
catch { throw new GetRecitedError(0, "connection_failed") }
|
|
28
|
+
let body
|
|
29
|
+
try { body = await response.json() } catch { body = null }
|
|
30
|
+
if (!response.ok || body === null) {
|
|
31
|
+
const code = typeof body?.code === "string" && /^[a-z_]{1,64}$/.test(body.code) ? body.code : "invalid_response"
|
|
32
|
+
const requestId = typeof body?.request_id === "string" && /^[a-zA-Z0-9_-]{1,100}$/.test(body.request_id) ? body.request_id : undefined
|
|
33
|
+
const delay = Number(response.headers.get("retry-after"))
|
|
34
|
+
throw new GetRecitedError(response.status, code, requestId, delay > 0 ? delay : undefined)
|
|
35
|
+
}
|
|
36
|
+
return body
|
|
37
|
+
}
|
|
38
|
+
async describe() { return this.#get("") }
|
|
39
|
+
async brands() { return this.#get("/brands") }
|
|
40
|
+
async visibility(workspaceBrandId, { days = 30 } = {}) {
|
|
41
|
+
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(workspaceBrandId)) throw new TypeError("workspaceBrandId must be a UUID.")
|
|
42
|
+
if (!Number.isInteger(days) || days < 1 || days > 90) throw new RangeError("days must be an integer from 1 to 90.")
|
|
43
|
+
return this.#get(`/brands/${workspaceBrandId}/visibility?days=${days}`)
|
|
44
|
+
}
|
|
45
|
+
async scans({ limit = 20 } = {}) {
|
|
46
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 100) throw new RangeError("limit must be an integer from 1 to 100.")
|
|
47
|
+
return this.#get(`/scans?limit=${limit}`)
|
|
48
|
+
}
|
|
49
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getrecited/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official GetRecited read API client and JSON CLI",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.js",
|
|
7
|
+
"types": "./index.d.ts",
|
|
8
|
+
"exports": { ".": { "types": "./index.d.ts", "import": "./index.js" } },
|
|
9
|
+
"bin": { "getrecited": "./cli.js" },
|
|
10
|
+
"files": ["index.js", "index.d.ts", "cli.js", "README.md"],
|
|
11
|
+
"engines": { "node": ">=20" },
|
|
12
|
+
"scripts": { "test": "node --test test.mjs" },
|
|
13
|
+
"homepage": "https://getrecited.com",
|
|
14
|
+
"repository": { "type": "git", "url": "git+https://github.com/AliMuhammadOfficial/getrecited-fe.git", "directory": "packages/sdk-js" },
|
|
15
|
+
"bugs": { "url": "https://github.com/AliMuhammadOfficial/getrecited-fe/issues" },
|
|
16
|
+
"license": "UNLICENSED",
|
|
17
|
+
"publishConfig": { "access": "public" },
|
|
18
|
+
"keywords": ["getrecited", "brand-tracking", "ai-visibility", "sdk", "cli"]
|
|
19
|
+
}
|