export async function fetchMetadata()

in typescript/src/pubsub/google-common.ts [120:148]


export async function fetchMetadata(
  notification: SubscriptionNotification,
): Promise<GoogleSubscriptionMetaData | undefined> {
  try {
    const subscription = await fetchGoogleSubscription(
      notification.subscriptionNotification.subscriptionId,
      notification.subscriptionNotification.purchaseToken,
      notification.packageName,
    );
    return {
      freeTrial: subscription?.paymentState === GOOGLE_PAYMENT_STATE.FREE_TRIAL,
    };
  } catch (exception) {
    // here we really don't want to stop the processing of that event if we can't fetch metadata,
    // as storing the event in the dynamo DB, and posting to the SQS queue are higher priority.
    // So even if something goes horribly wrong, we'll cary on the processing
    console.error(
      `Unable to fetch the subscription associated with the event`,
      exception,
    );

    // Log the notification 5% of the time for debugging - I don't want this to be too noisy
    if (Math.random() < 0.05) {
      console.error('Notification was: ', notification);
    }

    return undefined;
  }
}