🔐revenuecat-entitlements-gate
- プラグイン
- revenuecat
- ソース
- GitHub で見る ↗
説明
RevenueCatユーザーが、エンタイトルメントを通じて有料機能へのアクセス権を現在持っているかどうかを確認します。 次のような場合に使用: - 機能をプレミアム会員限定にしたい場合 - ユーザーがProサブスクリプションに加入しているか確認したい場合 - `customerInfo` のアクティブなエンタイトルメントを読み取りたい場合 - サブスクリプションの状態に応じて機能の表示・非表示を切り替えたい場合 - エンタイトルメントの変更に反応したい場合 - iOS、Android、Kotlin Multiplatform、Flutter、またはReact Nativeで「ユーザーがサブスクライブしているか」を確認したい場合
原文を表示
Check whether a RevenueCat user currently has access to a paid feature via entitlements. Use when the user asks to gate a feature behind premium, check if the user has a pro subscription, read customerInfo active entitlements, show or hide a feature based on subscription status, react to entitlement changes, or 'is the user subscribed' on iOS, Android, Kotlin Multiplatform, Flutter, or React Native.
ユースケース
- ✓機能をプレミアム会員限定にしたい場合
- ✓ユーザーがProサブスクリプションに加入しているか確認したい場合
- ✓サブスクリプション状態に応じて機能の表示・非表示を切り替えたい場合
- ✓ユーザーがサブスクライブしているか確認したい場合
- ✓エンタイトルメントの変更に反応したい場合
本文(日本語訳)
revenuecat-entitlements-gate: RevenueCat エンタイトルメントの確認
次のような場合に使用:
ユーザーが、有効な RevenueCat エンタイトルメントに基づいて機能の表示・非表示を制御したい場合。
このスキルは、ワンショットチェックとリアクティブリスナーをカバーします。
購入フロー(revenuecat-purchase-flow を参照)や認証(revenuecat-identify-user を参照)はカバーしません。
1. プラットフォームの検出
作業ディレクトリを調べ、上から順に最初にマッチした項目を採用してください:
- React Native:
package.jsonにreact-native-purchasesのエントリ、または依存関係にreact-nativeがある →platforms/react-native.mdを読む。expoも依存関係にある場合は、Expo プロジェクトとして記録する。 - Flutter: プロジェクトルートに
pubspec.yamlが存在する →platforms/flutter.mdを読む。 - Kotlin Multiplatform:
build.gradle.ktsにkotlin { … }のマルチプラットフォームソースセットブロックがある、またはcom.revenuecat.purchases:purchases-kmp*に依存している →platforms/kmp.mdを読む。 - Android(ネイティブ):
build.gradle(.kts)がcom.android.applicationを適用している(かつ KMP ではない)→platforms/android.mdを読む。 - iOS(ネイティブ): プロジェクトルートに
Package.swift、*.xcodeproj、*.xcworkspace、またはPodfileがある →platforms/ios.mdを読む。
複数マッチする場合(例: Flutter プロジェクト内の ios/ フォルダ)は、ビルドを管理している最も外側のプロジェクトを選択してください。
それでも判断できない場合は、ユーザーにどのプラットフォームを設定するか確認してください。
2. 共通の概念(全プラットフォーム共通)
-
プロダクト ID ではなく、エンタイトルメント識別子を確認すること。 識別子(例:
"premium")は RevenueCat ダッシュボードで設定され、1 つ以上のプロダクトにマッピングされます。 エンタイトルメントを使用することで、アプリのコードに触れることなく、プロダクト・価格・ストアを変更できます。 -
customerInfo.entitlements.activeが信頼できる唯一の情報源です。 これはエンタイトルメント識別子をキーとしたMap<String, EntitlementInfo>です。activeに存在する = ユーザーが現在アクセス権を持っている。存在しない = 過去の購入履歴にかかわらず、アクセス権がない。 -
購入履歴を元にゲートを設けないこと。 期限切れのサブスクリプションは
customerInfo.entitlements.allには残りますが、activeからは除外されます。 必ずactiveのみを使用してください。 -
最初に 1 回取得し、その後はサブスクライブすること。 初回の
customerInfo呼び出しはキャッシュされた値を素早く返し、SDK はバックグラウンドで更新を行います。 すべての SDK は、エンタイトルメントに変化が生じた際(購入・復元・更新・期限切れの後)に発火するリスナーまたはストリームを提供しています。 ポーリングではなく、このリスナーをサブスクライブしてください。 -
SDK が事前に設定されている必要があります。
Purchases.configure(…)が実行されていない場合、エンタイトルメントの呼び出しは失敗します。 このスキルを使用する前に、integrate-revenuecatを通じて SDK をセットアップしてください。
3. 実装
検出結果に対応するプラットフォームファイルを読んでください:
platforms/ios.mdplatforms/android.mdplatforms/kmp.mdplatforms/flutter.mdplatforms/react-native.md
各プラットフォームファイルには、ワンショットチェック、リアクティブサブスクリプション、および典型的なアプリでのそれぞれの配置場所が記載されています。
4. 検証
以下をすべて確認するまで、ゲートが機能していると判断しないでください:
- 有効なエンタイトルメントを持つユーザーにはゲートされた機能が表示され、持っていないユーザーには表示されないこと。
- エンタイトルメントの状態が変化したとき(サンドボックス購入またはダッシュボードでの手動付与でテスト)、手動での再起動なしに UI が更新されること。これによりリスナーが正しく接続されていることを確認します。
- コード内のエンタイトルメント識別子が、RevenueCat ダッシュボードに存在する識別子と一致していること。 タイポがあると、すべてのユーザーが静かにゲートアウトされてしまいます。
原文(English)を表示
revenuecat-entitlements-gate: check a RevenueCat entitlement
Use this skill when the user wants to decide whether to show or hide a feature based on an active RevenueCat entitlement. The skill covers the one shot check and the reactive listener; it does not cover purchasing (see revenuecat-purchase-flow) or auth (revenuecat-identify-user).
1. Detect the platform
Inspect the working directory and pick the first match, from top to bottom:
- React Native:
package.jsonhas areact-native-purchasesentry, orreact-nativeas a dependency → readplatforms/react-native.md. Ifexpois also a dependency, note it as an Expo project. - Flutter:
pubspec.yamlexists at the project root → readplatforms/flutter.md. - Kotlin Multiplatform:
build.gradle.ktscontains akotlin { … }multiplatform source sets block, or depends oncom.revenuecat.purchases:purchases-kmp*→ readplatforms/kmp.md. - Android (native):
build.gradle(.kts)appliescom.android.application(and is not KMP) → readplatforms/android.md. - iOS (native):
Package.swift,*.xcodeproj,*.xcworkspace, orPodfileat the project root → readplatforms/ios.md.
If several match (e.g. an ios/ folder inside a Flutter project), pick the outermost project, the one that owns the build. If still ambiguous, ask the user which platform they want to configure.
2. Shared concepts (all platforms)
- Check the entitlement identifier, not the product ID. The identifier (for example
"premium") is configured in the RevenueCat dashboard and mapped to one or more products. Using the entitlement lets you change products, prices, and stores without touching app code. customerInfo.entitlements.activeis the source of truth. It is aMap<String, EntitlementInfo>keyed by entitlement identifier. Presence inactivemeans the user currently has access. Absence means they do not, regardless of past purchases.- Do not gate on purchase history. Expired subscriptions still appear in
customerInfo.entitlements.allbut drop out ofactive. Useactiveonly. - Fetch once, then subscribe. The first
customerInfocall returns a cached value quickly, and the SDK refreshes in the background. Every SDK exposes a listener or stream that fires when entitlements change (after a purchase, restore, renewal, or expiration). Subscribe to that instead of polling. - The SDK must be configured first. If
Purchases.configure(…)has not run, the entitlement call will fail. Set up the SDK viaintegrate-revenuecatbefore using this skill.
3. Implementation
Read the platform file that matches detection:
platforms/ios.mdplatforms/android.mdplatforms/kmp.mdplatforms/flutter.mdplatforms/react-native.md
Each platform file shows the one shot check, the reactive subscription, and where to place each in a typical app.
4. Verify
Do not claim the gate works until:
- A user with an active entitlement sees the gated feature, and a user without it does not.
- When the entitlement state changes (test with a sandbox purchase or a manual grant in the dashboard), the UI updates without a manual restart, confirming the listener is wired.
- The entitlement identifier in the code matches an identifier that exists in the RevenueCat dashboard. A typo here silently gates everyone out.
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。