Add entitlements endpoint
This commit is contained in:
@@ -6,6 +6,7 @@ import Stripe from 'stripe'
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
getMainSubscriptionProducts,
|
getMainSubscriptionProducts,
|
||||||
|
normalizeEntitlements,
|
||||||
RevenueCatProduct,
|
RevenueCatProduct,
|
||||||
RevenueCatSubscription,
|
RevenueCatSubscription,
|
||||||
} from './util'
|
} from './util'
|
||||||
@@ -156,9 +157,14 @@ export default new Hono<{Bindings: Bindings; Variables: Variables}>()
|
|||||||
const rc = c.get('rcv2')
|
const rc = c.get('rcv2')
|
||||||
const user = c.req.query('user')
|
const user = c.req.query('user')
|
||||||
|
|
||||||
const {items} = await rc.get<any>(`customers/${user}/subscriptions`).json()
|
const {items} = await rc
|
||||||
|
.get<{items: RevenueCatSubscription[]}>(`customers/${user}/subscriptions`)
|
||||||
|
.json()
|
||||||
|
const entitlements = normalizeEntitlements(
|
||||||
|
items.flatMap(sub => sub.entitlements.items),
|
||||||
|
)
|
||||||
|
|
||||||
return c.json(items)
|
return c.json({entitlements})
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -455,3 +455,36 @@ export function normalizeMainSubscriptionProduct({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum EntitlementId {
|
||||||
|
Main0 = 'main:0',
|
||||||
|
Main1 = 'main:1',
|
||||||
|
Main2 = 'main:2',
|
||||||
|
}
|
||||||
|
|
||||||
|
export function normalizeEntitlements(
|
||||||
|
entitlements: RevenueCatSubscription['entitlements']['items'],
|
||||||
|
) {
|
||||||
|
return entitlements.map(entitlement => {
|
||||||
|
let id = EntitlementId.Main0
|
||||||
|
|
||||||
|
switch (entitlement.lookup_key) {
|
||||||
|
case 'main:0': {
|
||||||
|
id = EntitlementId.Main0
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'main:1': {
|
||||||
|
id = EntitlementId.Main1
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'main:2': {
|
||||||
|
id = EntitlementId.Main2
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user