export async function toDynamoEvent_google_async()

in typescript/src/pubsub/google-common.ts [150:193]


export async function toDynamoEvent_google_async(
  notification: SubscriptionNotification,
  metaData?: GoogleSubscriptionMetaData,
): Promise<SubscriptionEvent> {
  const eventTime = optionalMsToDate(notification.eventTimeMillis);
  if (!eventTime) {
    // this is tested while parsing the payload in order to return HTTP 400 early.
    // Therefore we should never reach this part of the code
    throw new Error("eventTimeMillis can't be null");
  }
  const eventTimestamp = eventTime.toISOString();
  const date = eventTimestamp.substring(0, 10);
  const eventType = notification.subscriptionNotification.notificationType;
  const eventTypeString =
    GOOGLE_SUBS_EVENT_TYPE[eventType] ?? eventType.toString();
  const platform = googlePackageNameToPlatform(
    notification.packageName,
  )?.toString();
  if (!platform) {
    console.warn(`Unknown package name ${notification.packageName}`);
  }

  const subscription = new SubscriptionEvent(
    notification.subscriptionNotification.purchaseToken,
    eventTimestamp + '|' + eventTypeString,
    date,
    eventTimestamp,
    eventTypeString,
    platform ?? 'unknown',
    notification.packageName,
    metaData?.freeTrial,
    notification,
    null,
    dateToSecondTimestamp(thirtyMonths(eventTime)),
    null, // string | null ; Introduced during the Apple extension of SubscriptionEvent [2023-11-03]
    null, // string | null ; Introduced during the Apple extension of SubscriptionEvent [2023-11-03]
    undefined, // any ; Introduced during the Apple extension of SubscriptionEvent [2023-11-03]
    undefined, // any ; Introduced during the Apple extension of SubscriptionEvent [2023-11-03]
    undefined, // any ; Introduced during the Apple extension of SubscriptionEvent [2023-11-03]
    '', // extra
  );

  return Promise.resolve(subscription);
}