agisboye / app-store-server-api

A Node.js client for the App Store Server API
MIT License
218 stars 36 forks source link

export "DecodedNotificationDataPayload" and "DecodedNotificationSummaryPayload" #31

Closed fariassdev closed 1 year ago

fariassdev commented 1 year ago

Hi August!

We found it useful to export the concrete types DecodedNotificationDataPayload and DecodedNotificationSummaryPayload. This allows us to use a type guard function and then utilise these types as input parameters, for instance.

const normalizeAppleV2DataNotification = async (
  notification: DecodedNotificationDataPayload, // <- Here, we used the type guard before calling this function, and now we want to directly use the concrete type
): Promise<AppleNormalizedNotificationV2> => {
  // If we don't export the concrete types, we have to type the param as "DecodedNotificationPayload" and use the type guard function here again
  const transactionInfo = await decodeTransaction(
    notification.data.signedTransactionInfo,
  );

  const renewalInfo = await decodeRenewalInfo(
    notification.data.signedRenewalInfo,
  );

  const startTime = new Date(Number(transactionInfo.purchaseDate));
  // The implementation continues from here...
}

Apologies for not considering this in the previous pull request. Thank you once again for your hard work!

agisboye commented 1 year ago

Makes sense 😊 I've merged your PR and released v0.10.1.