mirror of
https://github.com/GMGNAI/gmgn-skills.git
synced 2026-07-27 16:57:44 +00:00
feat(client): send User-Agent header on all API requests
Add a `User-Agent: gmgn-cli/<version>` header (version read from package.json) to both authExistRequest and authSignedRequest, so upstream can identify CLI traffic and gateways that reject empty/default UAs do not block requests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -6,11 +6,16 @@
|
|||||||
* Signed (swap and order routes): X-APIKEY + timestamp + client_id + X-Signature (private key signature)
|
* Signed (swap and order routes): X-APIKEY + timestamp + client_id + X-Signature (private key signature)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { createRequire } from "node:module";
|
||||||
|
|
||||||
import { buildAuthQuery, buildMessage, detectAlgorithm, sign } from "./signer.js";
|
import { buildAuthQuery, buildMessage, detectAlgorithm, sign } from "./signer.js";
|
||||||
|
|
||||||
const RATE_LIMIT_RETRY_BUFFER_MS = 1000;
|
const RATE_LIMIT_RETRY_BUFFER_MS = 1000;
|
||||||
const DEFAULT_RATE_LIMIT_AUTO_RETRY_MAX_WAIT_MS = 5000;
|
const DEFAULT_RATE_LIMIT_AUTO_RETRY_MAX_WAIT_MS = 5000;
|
||||||
|
|
||||||
|
const { version: CLI_VERSION } = createRequire(import.meta.url)("../../package.json") as { version: string };
|
||||||
|
const USER_AGENT = `gmgn-cli/${CLI_VERSION}`;
|
||||||
|
|
||||||
interface PreparedRequest {
|
interface PreparedRequest {
|
||||||
method: string;
|
method: string;
|
||||||
subPath: string;
|
subPath: string;
|
||||||
@@ -530,6 +535,7 @@ export class OpenApiClient {
|
|||||||
const headers: Record<string, string> = {
|
const headers: Record<string, string> = {
|
||||||
"X-APIKEY": this.apiKey,
|
"X-APIKEY": this.apiKey,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
"User-Agent": USER_AGENT,
|
||||||
};
|
};
|
||||||
const bodyStr = body !== null ? JSON.stringify(body) : null;
|
const bodyStr = body !== null ? JSON.stringify(body) : null;
|
||||||
return {
|
return {
|
||||||
@@ -565,6 +571,7 @@ export class OpenApiClient {
|
|||||||
"X-APIKEY": this.apiKey,
|
"X-APIKEY": this.apiKey,
|
||||||
"X-Signature": signature,
|
"X-Signature": signature,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
"User-Agent": USER_AGENT,
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
method,
|
method,
|
||||||
|
|||||||
Reference in New Issue
Block a user