From 86037899098b736ef43d3d487887034c949dde78 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 2 Mar 2026 20:57:23 +0000 Subject: [PATCH 1/2] feat: add User-Agent header to all HTTP requests (DIS-41) Add User-Agent: opensea-cli/ header to all requests made by OpenSeaClient. Version is dynamically read from package.json using createRequire. Updates both get() and post() methods and corresponding test assertions. Co-Authored-By: Chris K --- src/client.ts | 7 +++++++ test/client.test.ts | 15 +++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/client.ts b/src/client.ts index 41eba54..4c8bebb 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,7 +1,12 @@ +import { createRequire } from "node:module" import type { OpenSeaClientConfig } from "./types/index.js" +const require = createRequire(import.meta.url) +const { version } = require("../package.json") as { version: string } + const DEFAULT_BASE_URL = "https://api.opensea.io" const DEFAULT_TIMEOUT_MS = 30_000 +const USER_AGENT = `opensea-cli/${version}` export class OpenSeaClient { private apiKey: string @@ -37,6 +42,7 @@ export class OpenSeaClient { method: "GET", headers: { Accept: "application/json", + "User-Agent": USER_AGENT, "x-api-key": this.apiKey, }, signal: AbortSignal.timeout(this.timeoutMs), @@ -71,6 +77,7 @@ export class OpenSeaClient { const headers: Record = { Accept: "application/json", + "User-Agent": USER_AGENT, "x-api-key": this.apiKey, } diff --git a/test/client.test.ts b/test/client.test.ts index d068dde..dd7cc0f 100644 --- a/test/client.test.ts +++ b/test/client.test.ts @@ -39,10 +39,11 @@ describe("OpenSeaClient", () => { "https://api.opensea.io/api/v2/test", expect.objectContaining({ method: "GET", - headers: { + headers: expect.objectContaining({ Accept: "application/json", + "User-Agent": expect.stringMatching(/^opensea-cli\/\d+/), "x-api-key": "test-key", - }, + }), }), ) expect(result).toEqual(mockResponse) @@ -93,10 +94,11 @@ describe("OpenSeaClient", () => { "https://api.opensea.io/api/v2/refresh", expect.objectContaining({ method: "POST", - headers: { + headers: expect.objectContaining({ Accept: "application/json", + "User-Agent": expect.stringMatching(/^opensea-cli\/\d+/), "x-api-key": "test-key", - }, + }), }), ) expect(result).toEqual(mockResponse) @@ -111,11 +113,12 @@ describe("OpenSeaClient", () => { "https://api.opensea.io/api/v2/create", expect.objectContaining({ method: "POST", - headers: { + headers: expect.objectContaining({ Accept: "application/json", "Content-Type": "application/json", + "User-Agent": expect.stringMatching(/^opensea-cli\/\d+/), "x-api-key": "test-key", - }, + }), body: JSON.stringify({ name: "test" }), }), ) From 4f09f4d8b7d131d92c64baf15e8fcb2468618601 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 2 Mar 2026 21:02:36 +0000 Subject: [PATCH 2/2] fix: use stricter semver regex in User-Agent test assertions Co-Authored-By: Chris K --- test/client.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/client.test.ts b/test/client.test.ts index dd7cc0f..5fb3912 100644 --- a/test/client.test.ts +++ b/test/client.test.ts @@ -41,7 +41,7 @@ describe("OpenSeaClient", () => { method: "GET", headers: expect.objectContaining({ Accept: "application/json", - "User-Agent": expect.stringMatching(/^opensea-cli\/\d+/), + "User-Agent": expect.stringMatching(/^opensea-cli\/\d+\.\d+\.\d+/), "x-api-key": "test-key", }), }), @@ -96,7 +96,7 @@ describe("OpenSeaClient", () => { method: "POST", headers: expect.objectContaining({ Accept: "application/json", - "User-Agent": expect.stringMatching(/^opensea-cli\/\d+/), + "User-Agent": expect.stringMatching(/^opensea-cli\/\d+\.\d+\.\d+/), "x-api-key": "test-key", }), }), @@ -116,7 +116,7 @@ describe("OpenSeaClient", () => { headers: expect.objectContaining({ Accept: "application/json", "Content-Type": "application/json", - "User-Agent": expect.stringMatching(/^opensea-cli\/\d+/), + "User-Agent": expect.stringMatching(/^opensea-cli\/\d+\.\d+\.\d+/), "x-api-key": "test-key", }), body: JSON.stringify({ name: "test" }),