Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions app/api/jpyc/services/teaser/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@

import { NextResponse } from 'next/server';
import { env } from '@/lib/env';
import { teaserChangesFor } from '@/lib/directory/monitorTeaser';
import { JPYC_SERVICES_RESOURCE } from '@/lib/directory/paidResources';
import {
createServiceMonitorEnvelope,
deltaEffectiveDate,
scopedChangelog,
SERVICE_MONITOR_MAX_LIMIT,
sortByDeltaEffectiveDate,
} from '@/lib/directory/serviceMonitor';
import { USDC_SERVICE_MONITOR } from '@/lib/directory/usdcResource';

export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';

const TEASER_EVENTS = 3;

export async function GET(): Promise<NextResponse> {
if (!env.enableWeb3Directory) {
return NextResponse.json({ ok: false, error: 'not_found' }, { status: 404 });
Expand All @@ -31,22 +27,18 @@ export async function GET(): Promise<NextResponse> {
{},
new Date().toISOString(),
);
// snapshot の changes は limit で切られた view (末尾 200 件・date 順)。件数が上限を超えると、date は古いが
// 記録は最新の backfill が先に落ちて latestRecordedAt を過小に出す → changelog 全体から計算する。
const recorded = sortByDeltaEffectiveDate(scopedChangelog('jpyc-services'));
// changes は limit で切られた snapshot view ではなく changelog 全体から (lib/directory/monitorTeaser.ts)。
const teaser = teaserChangesFor('jpyc-services');
return NextResponse.json(
{
schemaVersion: full.schemaVersion,
product: 'jpyc-service-monitor',
teaser: true,
// 「買う前に確かめる」は記録日で判定する (有料 delta と同じ実効日)。date だけだと、後から記録した
// 古い date のイベントが「新しい変更なし」に見えて買い控えが起きる (2026-09-23)。
latestChanges: recorded.slice(-TEASER_EVENTS).map(({ scopes: _scopes, ...event }) => event),
latestRecordedAt: recorded.length > 0 ? deltaEffectiveDate(recorded[recorded.length - 1]) : null,
// full.changes は limit で切られた view なので総数の権威にならない (件数が
// SERVICE_MONITOR_MAX_LIMIT を超えると開示が過少になる)。changelog の実数を使う
// (payments teaser が full.totalEvents を使うのと同じ意味)。
totalEvents: scopedChangelog('jpyc-services').length,
// 「買う前に確かめる」は記録日で判定する (有料 delta と同じ実効日)。
latestChanges: teaser.latestChanges,
latestRecordedAt: teaser.latestRecordedAt,
// full.changes は limit で切られた view なので総数の権威にならない。changelog の実数を使う。
totalEvents: teaser.totalEvents,
totalServices: full.totalServices,
generatedAt: full.generatedAt,
fullFeed: {
Expand Down
15 changes: 8 additions & 7 deletions app/api/stablecoin-payments/teaser/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@

import { NextResponse } from 'next/server';
import { env } from '@/lib/env';
import { teaserChangesFor } from '@/lib/directory/monitorTeaser';
import { JPYC_PAYMENTS_RESOURCE } from '@/lib/directory/paidResources';
import { createPaymentMonitorEnvelope } from '@/lib/directory/paymentMonitor';
import { deltaEffectiveDate, scopedChangelog, SERVICE_MONITOR_MAX_LIMIT, sortByDeltaEffectiveDate } from '@/lib/directory/serviceMonitor';
import { SERVICE_MONITOR_MAX_LIMIT } from '@/lib/directory/serviceMonitor';
import { USDC_PAYMENT_MONITOR } from '@/lib/directory/usdcResource';

export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';

const TEASER_EVENTS = 3;

export async function GET(): Promise<NextResponse> {
if (!env.enableWeb3Directory) {
return NextResponse.json({ ok: false, error: 'not_found' }, { status: 404 });
Expand All @@ -21,16 +20,18 @@ export async function GET(): Promise<NextResponse> {
{ limit: SERVICE_MONITOR_MAX_LIMIT },
new Date().toISOString(),
);
const recorded = sortByDeltaEffectiveDate(scopedChangelog('stablecoin-payments'));
// latestChanges は有料版の provider 投影行ではなく raw の changelog イベント (scope だけ除く)。
const teaser = teaserChangesFor('stablecoin-payments');
return NextResponse.json(
{
schemaVersion: full.schemaVersion,
product: 'japan-stablecoin-payment-monitor',
teaser: true,
// limit で切られた snapshot view ではなく changelog 全体から (backfill が最新でも取りこぼさない)。
latestChanges: recorded.slice(-TEASER_EVENTS).map(({ scopes: _scopes, ...event }) => event),
latestRecordedAt: recorded.length > 0 ? deltaEffectiveDate(recorded[recorded.length - 1]) : null,
totalEvents: full.totalEvents,
latestChanges: teaser.latestChanges,
latestRecordedAt: teaser.latestRecordedAt,
// = full.totalEvents (どちらも決済スコープの changelog 全件数)。
totalEvents: teaser.totalEvents,
generatedAt: full.generatedAt,
fullFeed: {
jpyc: 'https://open-pay.jp/api/paid/stablecoin-payments',
Expand Down
Loading
Loading