@trustregistry/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 +26 -2
- package/index.d.ts +43 -0
- package/index.js +51 -0
- package/package.json +20 -4
package/README.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
-
#
|
|
1
|
+
# TrustRegistry JavaScript and TypeScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Internal package candidate for Business Verification. The package is marked private for review. Use Node.js 22+ and keep API keys on the server.
|
|
4
|
+
|
|
5
|
+
From this directory, run `npm pack`. From a separate ESM project, run `npm install /path/to/trustregistry-sdk-0.1.0.tgz`.
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { TrustRegistry } from '@trustregistry/sdk'
|
|
9
|
+
|
|
10
|
+
const client = new TrustRegistry({
|
|
11
|
+
apiKey: process.env.TR_API_KEY,
|
|
12
|
+
baseUrl: process.env.TR_API_BASE_URL, // Authorized TrustRegistry deployment origin.
|
|
13
|
+
})
|
|
14
|
+
const result = await client.verifyBusiness({ query: 'Example LLC', jurisdiction: 'TX', limit: 5 })
|
|
15
|
+
console.log(result.count, result.request_id)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
curl --fail-with-body "${TR_API_BASE_URL%/}/api/v1/verify" \
|
|
20
|
+
-H "Authorization: Bearer ${TR_API_KEY}" \
|
|
21
|
+
-H "Content-Type: application/json" \
|
|
22
|
+
--data '{"query":"Example LLC","jurisdiction":"TX","limit":5}'
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Use an authorized key with an active entitlement. An empty results array is a successful search with zero matches. The handler currently finalizes a reserved usage unit after any successful search, including zero matches. Reconcile that behavior with the commercial billing policy before public release. The SDK surfaces API errors with status, code and request ID and makes one request per call.
|
|
26
|
+
|
|
27
|
+
Before public release, verify the actual deployment origin, entitlement, billing, rate limits and package ownership. Verify a clean installation and authorized lookup against the release environment. Publish only after release approval.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface BusinessRecord {
|
|
2
|
+
business_id: string
|
|
3
|
+
legal_name: string
|
|
4
|
+
jurisdiction: string
|
|
5
|
+
entity_type: string
|
|
6
|
+
status: string
|
|
7
|
+
verified: boolean
|
|
8
|
+
trust_score: number | null
|
|
9
|
+
registered_at: string | null
|
|
10
|
+
registration_number: string | null
|
|
11
|
+
confidence_score: number | null
|
|
12
|
+
risk_score: number | null
|
|
13
|
+
risk_flags: unknown
|
|
14
|
+
trust_summary: string | null
|
|
15
|
+
entity_age_years: number | null
|
|
16
|
+
last_verified_at: string | null
|
|
17
|
+
source_url: string | null
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface VerificationResponse {
|
|
21
|
+
object: 'verification.search'
|
|
22
|
+
query: string
|
|
23
|
+
jurisdiction: string | null
|
|
24
|
+
count: number
|
|
25
|
+
results: BusinessRecord[]
|
|
26
|
+
source: string
|
|
27
|
+
authenticated: { mode: string; key: string; key_name: string | null }
|
|
28
|
+
request_id: string
|
|
29
|
+
latency_ms: number
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class TrustRegistryError extends Error {
|
|
33
|
+
constructor(status: number, code: string, message: string, requestId: string | null)
|
|
34
|
+
readonly status: number
|
|
35
|
+
readonly code: string
|
|
36
|
+
readonly requestId: string | null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class TrustRegistry {
|
|
40
|
+
constructor(options: { apiKey: string; baseUrl: string })
|
|
41
|
+
verifyBusiness(input: { query: string; jurisdiction?: string; limit?: number },
|
|
42
|
+
options?: { signal?: AbortSignal }): Promise<VerificationResponse>
|
|
43
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export class TrustRegistryError extends Error {
|
|
2
|
+
constructor(status, code, message, requestId) {
|
|
3
|
+
super(message)
|
|
4
|
+
this.name = 'TrustRegistryError'
|
|
5
|
+
this.status = status
|
|
6
|
+
this.code = code
|
|
7
|
+
this.requestId = requestId
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class TrustRegistry {
|
|
12
|
+
#apiKey
|
|
13
|
+
#endpoint
|
|
14
|
+
|
|
15
|
+
constructor({ apiKey, baseUrl }) {
|
|
16
|
+
if (typeof apiKey !== 'string' || !apiKey.trim()) {
|
|
17
|
+
throw new TypeError('A TrustRegistry API key is required.')
|
|
18
|
+
}
|
|
19
|
+
const origin = new URL(baseUrl)
|
|
20
|
+
if (origin.protocol !== 'https:' || origin.username || origin.password) {
|
|
21
|
+
throw new TypeError('Use a trusted HTTPS API base URL.')
|
|
22
|
+
}
|
|
23
|
+
this.#apiKey = apiKey.trim()
|
|
24
|
+
this.#endpoint = new URL('/api/v1/verify', origin)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async verifyBusiness({ query, jurisdiction, limit }, { signal } = {}) {
|
|
28
|
+
const response = await fetch(this.#endpoint, {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
headers: {
|
|
31
|
+
authorization: `Bearer ${this.#apiKey}`,
|
|
32
|
+
'content-type': 'application/json',
|
|
33
|
+
accept: 'application/json',
|
|
34
|
+
},
|
|
35
|
+
body: JSON.stringify({ query, jurisdiction, limit }),
|
|
36
|
+
signal,
|
|
37
|
+
redirect: 'error',
|
|
38
|
+
})
|
|
39
|
+
const requestId = response.headers.get('x-request-id')
|
|
40
|
+
const data = await response.json().catch(() => null)
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
throw new TrustRegistryError(response.status, data?.error?.code ?? 'HTTP_ERROR',
|
|
43
|
+
data?.error?.message ?? 'Business verification failed.', data?.request_id ?? requestId)
|
|
44
|
+
}
|
|
45
|
+
if (data?.object !== 'verification.search' || !Array.isArray(data.results)) {
|
|
46
|
+
throw new TrustRegistryError(response.status, 'INVALID_RESPONSE',
|
|
47
|
+
'The API returned an unexpected business verification response.', requestId)
|
|
48
|
+
}
|
|
49
|
+
return data
|
|
50
|
+
}
|
|
51
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trustregistry/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./index.d.ts",
|
|
8
|
+
"default": "./index.js"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"index.js",
|
|
13
|
+
"index.d.ts",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=22"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
}
|
|
22
|
+
}
|