export function buildHandler()

in typescript/src/feast/update-subs/apple.ts [139:165]


export function buildHandler(
  fetchSubscriptionsFromApple: FetchSubsFromApple = defaultFetchSubscriptionsFromApple,
  storeSubscriptionInDynamo: StoreSubInDynamo = defaultStoreSubscriptionInDynamo,
  sendSubscriptionToHistoricalQueue: SendSubToHistoricalQueue = defaultSendSubscriptionToHistoricalQueue,
  exchangeExternalIdForIdentityId: ExchangeExternalIdForIdentityId = getIdentityIdFromBraze,
  storeUserSubscriptionInDynamo: StoreUserSubInDynamo = defaultStoreUserSubscriptionInDynamo,
): (event: SQSEvent) => Promise<string> {
  return (event: SQSEvent) => {
    const promises = event.Records.map((record) => {
      return processRecordWithErrorHandling(
        fetchSubscriptionsFromApple,
        storeSubscriptionInDynamo,
        sendSubscriptionToHistoricalQueue,
        exchangeExternalIdForIdentityId,
        storeUserSubscriptionInDynamo,
        record,
      );
    });

    return Promise.all(promises)
      .then((promises) => {
        console.log(`Successfully processed ${promises.length} record(s)`);
        return promises;
      })
      .then((_) => 'OK');
  };
}