async function getSubscriptionStatusFromDynamo()

in typescript/src/subscription-status/googleSubStatus.ts [135:167]


async function getSubscriptionStatusFromDynamo(
  purchaseToken: string,
  purchaseTokenHash: string,
): Promise<SubscriptionStatus | null> {
  try {
    console.log(
      `Fetching subscription from Dynamo for purchaseToken hash: ${purchaseTokenHash}`,
    );
    const itemToQuery = new SubscriptionEmpty();
    itemToQuery.setSubscriptionId(purchaseToken);
    const subscription = await dynamoMapper.get(itemToQuery);
    const subscriptionExpiryDate = new Date(subscription.endTimestamp);
    const dynamoSubscriptionStatus = subscriptionStatus(subscriptionExpiryDate);
    console.log(
      `Dynamo SubscriptionStatus for purchaseToken hash: ${purchaseTokenHash}: ${JSON.stringify(
        dynamoSubscriptionStatus,
      )}`,
    );
    return dynamoSubscriptionStatus;
  } catch (error: any) {
    if (error.name === 'ItemNotFoundException') {
      console.log(
        `No subscription found in Dynamo with purchaseToken hash: ${purchaseTokenHash}`,
      );
    } else {
      console.log(
        `The following Dynamo error occurred when attempting to retrieve a subscription with purchaseToken hash: ${purchaseTokenHash}: ${error}`,
      );
    }
    // All exceptions are swallowed here as we fall-back on the Google API for all failure modes (including cache misses)
    return null;
  }
}