Skip to content

App Store レビュー取得を Connect API に移行 - #6299

Merged
TinyKitten merged 2 commits into
devfrom
feature/appstore-connect-api-reviews
Jun 21, 2026
Merged

TinyKitten merged 2 commits into
devfrom
feature/appstore-connect-api-reviews

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jun 21, 2026 •

Copy link
Copy Markdown
Member

概要

App Store レビュー取得を RSS JSON フィードから App Store Connect API に移行する。

変更の種類

  • バグ修正
  • 新機能
  • リファクタリング
  • ドキュメント
  • CI/CD
  • その他

変更内容

  • App Store Connect API (ES256 JWT 認証) によるレビュー取得に切り替え
  • functions/src/lib/apple/accessToken.ts を新規追加(JWT 生成)
  • parseAppStoreJson を parseApiReviews に置き換え、API レスポンス形式に対応
  • 環境変数 APPSTORE_CONNECT_KEY / APPSTORE_APP_ID を追加し、旧 APPSTORE_REVIEW_FEED_URL を削除
  • レビュー型から version / url を除去し territory を追加
  • テストを API レスポンス形式に合わせて書き直し
  • ページネーション URL の origin 検証を追加(JWT 漏洩防止)
  • 同一タイムスタンプのレビュー重複通知を防止

テスト

  • npm run lint が通ること
  • npm test が通ること
  • npm run typecheck が通ること

関連Issue

スクリーンショット(任意)

Summary by CodeRabbit

リリースノート

  • 新機能
    • App Store レビューの取得を RSS から App Store Connect API へ切り替え、ページングに対応して効率よく取得できるようにしました。
    • Discord通知の表示(投稿日/リンク生成)と取得データの更新判定をAPIベースに変更しました。
  • テスト
    • App Store Connect API のレスポンス形式に合わせてテストを更新しました(欠損時の挙動などを検証)。
  • その他
    • 認証用の環境変数(App Store Connect キー、アプリID)を追加/調整しました。

@TinyKitten TinyKitten self-assigned this Jun 21, 2026
@coderabbitai

coderabbitai Bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cc2fe403-5243-41d6-87af-799f3d6b83e0

📥 Commits

Reviewing files that changed from the base of the PR and between 89e9f75 and aa97d73.

📒 Files selected for processing (2)
  • functions/src/scheduled/appStoreReviews.test.ts
  • functions/src/scheduled/appStoreReviews.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • functions/src/scheduled/appStoreReviews.test.ts
  • functions/src/scheduled/appStoreReviews.ts

📝 Walkthrough

Walkthrough

App Store レビュー取得の実装を RSS フィードから App Store Connect API へ移行。ES256 JWT 生成モジュールを新規追加し、API パーサー・フェッチ・ページング・Discord 投稿・ジョブ本体をすべて更新。Env 型と設定コメントも新しいシークレット名へ対応。テスト全体を新しいパーサー向けに置き換え。

Changes

App Store Connect API 移行

Layer / File(s) Summary
ES256 JWT 生成
functions/src/lib/apple/accessToken.ts
AppStoreConnectKey インターフェースを定義し、Web Crypto の crypto.subtle で PEM 秘密鍵を PKCS8/ECDSA/P-256 としてインポートして ES256 署名した JWT を返す createAppStoreConnectJwt を追加。
Env 型更新
functions/src/types.ts
Env に APPSTORE_CONNECT_KEY を追加し APPSTORE_REVIEW_FEED_URL を APPSTORE_APP_ID へ置換。App Store Connect API 認証と構成管理に対応。
API 型・パーサー・フェッチ
functions/src/scheduled/appStoreReviews.ts
ApiResponse 型を定義し parseApiReviews で API レスポンスから AppStoreReview 配列へ変換(createdDate 必須・欠損スキップ・デフォルト正規化)。fetchReviewsPage で Bearer 認証 GET を実装し JSON パース・検証・エラーハンドリングを行う。
ジョブ本体・Discord 投稿・状態管理
functions/src/scheduled/appStoreReviews.ts
runAppStoreReviewJob で JWT 生成後 links.next を辿り最大 5 ページを収集。forceCount 選別で送信対象を選定し postToDiscord で新規・更新レビューを投稿(appId からリンク生成、dayjs で投稿日整形)。送信成功時に最新 timestamp と対応 id 群を KV に保存。
設定ドキュメント
functions/wrangler.jsonc
シークレット投入コメントに APPSTORE_CONNECT_KEY を追記し、新しい認証方式の秘密管理手順を明示。
parseApiReviews テスト更新
functions/src/scheduled/appStoreReviews.test.ts
parseAppStoreJson の全テストを parseApiReviews 向けに置き換え。基本フィールド抽出・複数エントリ・空データ・必須フィールド欠損スキップ・任意フィールドのデフォルト値を検証。

Sequence Diagram(s)

sequenceDiagram
  participant Scheduler
  participant runAppStoreReviewJob
  participant createAppStoreConnectJwt
  participant fetchReviewsPage as App Store Connect API
  participant postToDiscord as Discord Webhook
  participant KV

  Scheduler->>runAppStoreReviewJob: 定期実行
  runAppStoreReviewJob->>createAppStoreConnectJwt: APPSTORE_CONNECT_KEY (JSON)
  createAppStoreConnectJwt-->>runAppStoreReviewJob: ES256 JWT
  loop links.next がある間(最大5ページ)
    runAppStoreReviewJob->>fetchReviewsPage: GET /customerReviews (Bearer JWT)
    fetchReviewsPage-->>runAppStoreReviewJob: ApiResponse { data[], links.next }
  end
  runAppStoreReviewJob->>postToDiscord: reviews[], appId, webhookUrl
  postToDiscord-->>runAppStoreReviewJob: posted: boolean
  runAppStoreReviewJob->>KV: saveReviewState(lastUpdated, updatedIds)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested labels

functions

🐰 RSS の古い巣を抜け出して、
JWT の鍵でドアを叩く。
Connect API へ跳んで跳んで、
レビューをページごとかき集め、
Discord に届ける春の声。 🌸

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed PR のタイトルは、RSS フィード から App Store Connect API への移行という主要な変更を明確に説明しており、変更内容と完全に一致しています。
Description check ✅ Passed PR の説明は、テンプレートの必須セクション(概要、変更の種類、変更内容、テスト)をすべてカバーしており、詳細で包括的な情報が含まれています。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/appstore-connect-api-reviews

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@functions/src/scheduled/appStoreReviews.test.ts`:
- Around line 3-99: The test file is missing an afterEach hook that clears mocks
between tests, which violates the testing guidelines. Add an afterEach hook with
jest.clearAllMocks() inside the describe block for parseApiReviews to ensure
mocks are properly cleared and prevent test pollution when mocks are added to
this file in the future.

In `@functions/src/scheduled/appStoreReviews.ts`:
- Around line 58-68: The fetchReviewsPage function has a security vulnerability
where it accepts any URL and adds an Authorization header with the JWT token
without validating the URL origin. Since the URL parameter comes from external
API responses (specifically links.next from line 158), it could redirect to
malicious endpoints and leak the JWT token. Validate that the provided URL
belongs to Apple's App Store Connect domain (check that the URL origin matches
Apple's official App Store Connect API domain) before making the fetch request
with the Authorization header. Only proceed with the fetch if the URL origin
validation passes, otherwise throw an error to prevent token leakage.
- Around line 192-200: The issue is that `lastIds` is being populated with only
the first 5 item IDs from `all.slice(0, 5).map((x) => x.id)`, but `lastUpdated`
is set to the `newest` item's timestamp. When there are 6 or more reviews with
the same timestamp as the newest review, the IDs beyond the first 5 won't be
saved in `lastIds`, causing them to match the same `lastUpdated` timestamp again
on the next run and trigger duplicate notifications. Replace `all.slice(0,
5).map((x) => x.id)` with filtering logic that includes all IDs from items that
have the same `updated` timestamp as the `newest` item, not just the first 5
items.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 577d3f39-a83a-4c0e-aab4-e1ab2e65c5d9

📥 Commits

Reviewing files that changed from the base of the PR and between 79f5092 and 89e9f75.

📒 Files selected for processing (5)
  • functions/src/lib/apple/accessToken.ts
  • functions/src/scheduled/appStoreReviews.test.ts
  • functions/src/scheduled/appStoreReviews.ts
  • functions/src/types.ts
  • functions/wrangler.jsonc

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@TinyKitten

Copy link
Copy Markdown
Member Author

Fixes Applied Successfully

Fixed 2 file(s) based on 3 CodeRabbit feedback item(s).

Files modified:

  • functions/src/scheduled/appStoreReviews.ts
  • functions/src/scheduled/appStoreReviews.test.ts

Commit: aa97d7370

The latest autofix changes are on the feature/appstore-connect-api-reviews branch.

@TinyKitten
TinyKitten merged commit e763bc1 into dev Jun 21, 2026
3 checks passed
@TinyKitten
TinyKitten deleted the feature/appstore-connect-api-reviews branch June 21, 2026 09:32
@TinyKitten TinyKitten mentioned this pull request Jun 21, 2026
6 of 9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant