mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-12-01 09:24:46 +00:00
Name logicsrc apps in the User-Agent of CoinPay calls (#293)
logicsrc.com (Next), app.logicsrc.com (pwa) and the rotation CLI now send a descriptive User-Agent on every server-side CoinPay request, so CoinPay's logs and throttle can tell them apart from the other apps on dev2: - logicsrc.com: logicsrc.com/<version> (+https://logicsrc.com) on merchant eligibility, checkout sessions, OAuth token and userinfo; x402-gateway ^0.18.2 names the site on crawl-gateway calls. - app.logicsrc.com: app.logicsrc.com/<version> on the CoinPay OAuth calls and, through coinpay-onboard 0.3.1's fetch hook, on the auto-rotation client. - logicsrc CLI rotators: logicsrc-cli/<version> (+https://logicsrc.com). Co-authored-by: riotcoder <riotcoder@profullstack.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d8a08c006b
commit
b20afe6f50
10 changed files with 44 additions and 12 deletions
|
|
@ -17,7 +17,7 @@
|
|||
"@profullstack/autoblog": "^0.5.0",
|
||||
"@profullstack/footer": "latest",
|
||||
"@profullstack/stack": "^0.5.0",
|
||||
"@profullstack/x402-gateway": "^0.18.1",
|
||||
"@profullstack/x402-gateway": "^0.18.2",
|
||||
"@supabase/supabase-js": "^2.118.0",
|
||||
"marked": "^18.1.1",
|
||||
"next": "16.4.3",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import type { NextRequest } from "next/server";
|
||||
import { json } from "@/lib/http";
|
||||
import { COINPAY_UA } from "@/lib/coinpay-ua";
|
||||
import { COINPAY_SESSION_COOKIE, parseJson, verifySession } from "@/lib/coinpay";
|
||||
import { HIRE_US_PRODUCT } from "@/lib/coinpay-webhook";
|
||||
import { hireUsCheckoutStore } from "@/lib/hire-us-payments";
|
||||
|
|
@ -75,7 +76,8 @@ export async function POST(request: NextRequest) {
|
|||
method: "POST",
|
||||
headers: {
|
||||
authorization: `Bearer ${apiKey}`,
|
||||
"content-type": "application/json"
|
||||
"content-type": "application/json",
|
||||
"user-agent": COINPAY_UA
|
||||
},
|
||||
body: JSON.stringify({
|
||||
amount: amountUsdDue,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { json } from "@/lib/http";
|
||||
import { COINPAY_UA } from "@/lib/coinpay-ua";
|
||||
import {
|
||||
COINPAY_OAUTH_STATE_COOKIE,
|
||||
COINPAY_SESSION_COOKIE,
|
||||
|
|
@ -49,7 +50,7 @@ export async function GET(request: NextRequest) {
|
|||
try {
|
||||
const tokenResponse = await fetch(new URL("/api/oauth/token", config.issuer), {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/x-www-form-urlencoded" },
|
||||
headers: { "content-type": "application/x-www-form-urlencoded", "user-agent": COINPAY_UA },
|
||||
body: new URLSearchParams({
|
||||
grant_type: "authorization_code",
|
||||
code,
|
||||
|
|
@ -70,7 +71,7 @@ export async function GET(request: NextRequest) {
|
|||
}
|
||||
|
||||
const userResponse = await fetch(new URL("/api/oauth/userinfo", config.issuer), {
|
||||
headers: { authorization: `Bearer ${tokenPayload.access_token}` }
|
||||
headers: { authorization: `Bearer ${tokenPayload.access_token}`, "user-agent": COINPAY_UA }
|
||||
});
|
||||
const userText = await userResponse.text();
|
||||
const userInfo = userResponse.ok ? parseJson(userText) : {};
|
||||
|
|
|
|||
4
apps/logicsrc-web/src/lib/coinpay-ua.ts
Normal file
4
apps/logicsrc-web/src/lib/coinpay-ua.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import pkg from "../../package.json";
|
||||
|
||||
/** Sent on every server-side call to CoinPay so its logs and throttle can tell this app apart. */
|
||||
export const COINPAY_UA = `logicsrc.com/${pkg.version} (+https://logicsrc.com)`;
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import { createHmac, timingSafeEqual } from "node:crypto";
|
||||
import { COINPAY_UA } from "./coinpay-ua";
|
||||
|
||||
// Server-side CoinPay + session helpers, ported from the legacy server.js so the
|
||||
// Next API routes keep identical behavior (eligibility-driven payment rails,
|
||||
|
|
@ -48,7 +49,7 @@ export async function fetchMerchantEligibility(
|
|||
const url = new URL("/api/payments/merchant-eligibility", apiUrl);
|
||||
url.searchParams.set("merchant_id", merchantId);
|
||||
const response = await fetch(url, {
|
||||
headers: { authorization: `Bearer ${apiKey ?? ""}` }
|
||||
headers: { authorization: `Bearer ${apiKey ?? ""}`, "user-agent": COINPAY_UA }
|
||||
});
|
||||
const text = await response.text();
|
||||
const payload = parseJson(text);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue