@metalift/sdk
Advanced tools
| /** Compliance headers required by Metalift Cloud. */ | ||
| export declare const B2B_ATTESTATION_HEADER = "X-B2B-Attestation"; | ||
| export declare const B2B_ATTESTATION_VALUE = "I-confirm-B2B-use"; | ||
| export declare const CLIENT_ID_HEADER = "X-Metalift-Client"; | ||
| export declare const CLIENT_ID_VALUE = "sdk-ts/1.0.11"; | ||
| export declare const AUTH_DOCS = "https://metalift.ai/docs/getting-started#authentication"; | ||
| export declare function b2bAttestationRequiredMessage(): string; | ||
| export declare function isB2bAttestationError(body: unknown, status: number): boolean; |
| /** Compliance headers required by Metalift Cloud. */ | ||
| export const B2B_ATTESTATION_HEADER = "X-B2B-Attestation"; | ||
| export const B2B_ATTESTATION_VALUE = "I-confirm-B2B-use"; | ||
| export const CLIENT_ID_HEADER = "X-Metalift-Client"; | ||
| export const CLIENT_ID_VALUE = "sdk-ts/1.0.11"; | ||
| export const AUTH_DOCS = "https://metalift.ai/docs/getting-started#authentication"; | ||
| export function b2bAttestationRequiredMessage() { | ||
| return (`B2B attestation required — send ${B2B_ATTESTATION_HEADER}: ${B2B_ATTESTATION_VALUE}. ` + | ||
| `Official SDKs and MCP send this automatically. See ${AUTH_DOCS}.`); | ||
| } | ||
| export function isB2bAttestationError(body, status) { | ||
| if (status !== 403 && status !== 401) | ||
| return false; | ||
| if (typeof body !== "object" || body === null) | ||
| return false; | ||
| const record = body; | ||
| const code = typeof record.code === "string" ? record.code : ""; | ||
| const detail = typeof record.detail === "string" | ||
| ? record.detail | ||
| : typeof record.detail === "object" && | ||
| record.detail !== null && | ||
| typeof record.detail.code === "string" | ||
| ? String(record.detail.code) | ||
| : ""; | ||
| return /b2b_attestation|b2b attestation/i.test(`${code} ${detail}`); | ||
| } |
| export {}; |
| import assert from "node:assert/strict"; | ||
| import test from "node:test"; | ||
| import { B2B_ATTESTATION_HEADER, B2B_ATTESTATION_VALUE, b2bAttestationRequiredMessage, isB2bAttestationError, } from "./compliance.js"; | ||
| test("isB2bAttestationError detects cloud attestation response", () => { | ||
| assert.equal(isB2bAttestationError({ detail: "B2B attestation required — send X-B2B-Attestation: I-confirm-B2B-use", code: "B2B_ATTESTATION_REQUIRED" }, 403), true); | ||
| assert.equal(isB2bAttestationError({ detail: "Invalid or inactive API key" }, 401), false); | ||
| }); | ||
| test("b2bAttestationRequiredMessage includes header value", () => { | ||
| const msg = b2bAttestationRequiredMessage(); | ||
| assert.match(msg, new RegExp(B2B_ATTESTATION_HEADER)); | ||
| assert.match(msg, new RegExp(B2B_ATTESTATION_VALUE)); | ||
| }); |
+1
-0
@@ -0,1 +1,2 @@ | ||
| export { B2B_ATTESTATION_HEADER, B2B_ATTESTATION_VALUE, } from "./compliance.js"; | ||
| export interface MetaliftConfig { | ||
@@ -2,0 +3,0 @@ apiUrl?: string; |
+10
-1
@@ -0,2 +1,4 @@ | ||
| import { B2B_ATTESTATION_HEADER, B2B_ATTESTATION_VALUE, CLIENT_ID_HEADER, CLIENT_ID_VALUE, b2bAttestationRequiredMessage, isB2bAttestationError, } from "./compliance.js"; | ||
| import { formatSearchApiError } from "./search-errors.js"; | ||
| export { B2B_ATTESTATION_HEADER, B2B_ATTESTATION_VALUE, } from "./compliance.js"; | ||
| export class Metalift { | ||
@@ -10,3 +12,7 @@ apiUrl; | ||
| headers() { | ||
| const headers = { "Content-Type": "application/json" }; | ||
| const headers = { | ||
| "Content-Type": "application/json", | ||
| [B2B_ATTESTATION_HEADER]: B2B_ATTESTATION_VALUE, | ||
| [CLIENT_ID_HEADER]: CLIENT_ID_VALUE, | ||
| }; | ||
| if (this.apiKey) | ||
@@ -23,2 +29,5 @@ headers.Authorization = `Bearer ${this.apiKey}`; | ||
| if (!response.ok) { | ||
| if (isB2bAttestationError(body, response.status)) { | ||
| throw new Error(b2bAttestationRequiredMessage()); | ||
| } | ||
| const searchError = path === "/v1/search" ? formatSearchApiError(this.apiUrl, body, response.status) : null; | ||
@@ -25,0 +34,0 @@ throw new Error(searchError || body.detail || body.error || response.statusText); |
+2
-1
| { | ||
| "name": "@metalift/sdk", | ||
| "version": "1.0.10", | ||
| "version": "1.0.12", | ||
| "description": "Metalift TypeScript SDK", | ||
@@ -11,2 +11,3 @@ "license": "SEE LICENSE IN LICENSE", | ||
| "build": "tsc", | ||
| "test": "npm run build && node --test dist/search-errors.test.js dist/compliance.test.js", | ||
| "prepublishOnly": "npm run build && node ../../scripts/npm-prepare-publish.mjs strip", | ||
@@ -13,0 +14,0 @@ "postpublish": "node ../../scripts/npm-prepare-publish.mjs restore" |
+2
-0
@@ -65,2 +65,4 @@ # @metalift/sdk | ||
| Metalift Cloud requires `X-B2B-Attestation: I-confirm-B2B-use` on authenticated requests. **@metalift/sdk ≥ 1.0.11** sends this header automatically. | ||
| ## CommonJS projects | ||
@@ -67,0 +69,0 @@ |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
17073
25.12%13
44.44%296
23.85%1
-50%81
2.53%