Profiles to Subscription Receipts

Speed up entitlement lookups by having a simple API to see what products someone bought (receipts)

epe-receipts.conde.io/graphql

Wiki home: https://cnissues.atlassian.net/wiki/spaces/CMSG/pages/327942320/Entitlement+Receipts+Service

Requirements

Best practices

Glossary

Definitions are stored as living documentation in the GraphQL schema to avoid duplicating work.

GraphQL

Basic entitlement query:

mutation ExampleFetch {
    fetchProfile(input: { profile: { amgUuid: "24851284-1fae-4818-b92e-56da11555c6f" } }) {
        profile {
            viewEntitlements {
                product
                starts
                expires
                __typename
            }
        }
    }
}

Only return CDS results

mutation ExampleOnlyCDS {
    fetchProfile(
        input: {
            profile: { amgUuid: "24851284-1fae-4818-b92e-56da11555c6f" }
            refreshPolicy: "refresh"
        }
    ) {
        didRefresh
        didRefreshReason
        profile {
            viewEntitlements {
                ... on CdsViewEntitlements {
                    product
                    starts
                    expires
                }
            }
        }
    }
}

View what we know about a profile

query ExampleGetProfileByEmail {
    profile(email: "active@tt.com") {
        amgUuid
        receipts {
            providerId
            v
            timestamp
        }
        viewEntitlements {
            product
            starts
            expires
        }
    }
}

Force a refresh of a profile

mutation ExampleRefresh {
    fetchProfile(
        input: {
            profile: { amgUuid: "24851284-1fae-4818-b92e-56da11555c6f" }
            refreshPolicy: "refresh"
        }
    ) {
        profile {
            amgUuid
            receipts {
                providerId
                timestamp
            }
            viewEntitlements {
                product
                starts
                expires
            }
        }
    }
}

DynamoDB schema

entitlements-receipts

The original data from providers is stored in entitlements-receipts with amgUuid as the partition key and the providerId as the sort key. This is just a cache. All this data can get retrieved again.

CDS Global
---
amgUuid: '58383a82-eadc-4172-8685-ca800e7b9500'
providerId: 'cds.<accountNumber>.<magCode>'
data: <json body>
timestamp: 1531254336997
CDS UK
---
amgUuid: '58383a82-eadc-4172-8685-ca800e7b9500'
providerId: 'cdsuk.<URN>.<originator>'
data: <json body>
timestamp: 1531254336997
Apple Receipt
---
amgUuid: '58383a82-eadc-4172-8685-ca800e7b9500'
providerId: 'apple.<sha1 of base64 receipt data>'
data: <json verified receipt data>
timestamp: 1531254336997
Andros aka CNEE Legacy receipt
---
amgUuid: '58383a82-eadc-4172-8685-ca800e7b9500'
providerId: 'andros.<coupon code>'
data: <json body>
timestamp: 1531254336997

Using providerId as a sort key?

Instead of throwing everything into one document, we could use amgUuid as the partition key and provider id as a sort key with a query.

Extra DynamoDB fields

There are some special fields you may see:

Special cases

Development instruction

Prequisites

Starting the app

npm install
lerna bootstrap
npm run dev