Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add revalidation flag for apple receipts revalidation lambda #1453

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions typescript/src/revalidate-receipts/appleRevalidateReceipts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import {AppleSubscriptionReference, SubscriptionReference} from "../models/subsc
import { Platform } from "../models/platform";
import { ScanIterator } from "@aws/dynamodb-data-mapper";

interface AppleSubscriptionReferenceWithRevalidateFlag extends AppleSubscriptionReference {
isRevalidation?: boolean
}

function endTimestampForQuery(event: ScheduleEvent): Date {
if (event.endTimestampFilter) {
return new Date(Date.parse(event.endTimestampFilter));
Expand Down Expand Up @@ -84,20 +88,20 @@ const defaultSubscriptions =
}

const defaultSendSubscriptionReferenceToQueue =
async (queue: string, ref: SubscriptionReference, delayInSeconds: number): Promise<void> => {
async (queue: string, ref: AppleSubscriptionReferenceWithRevalidateFlag, delayInSeconds: number): Promise<void> => {
await sendToSqs(queue, ref, delayInSeconds)
}

export function buildHandler(
subscriptions: (event: ScheduleEvent) => ScanIterator<EndTimeStampFilterSubscription> = defaultSubscriptions,
sendSubscriptionReferenceToQueue: (queue: string, ref: SubscriptionReference, delayInSeconds: number) => Promise<void> = defaultSendSubscriptionReferenceToQueue
sendSubscriptionReferenceToQueue: (queue: string, ref: AppleSubscriptionReferenceWithRevalidateFlag, delayInSeconds: number) => Promise<void> = defaultSendSubscriptionReferenceToQueue
): (event: ScheduleEvent) => Promise<void> {
return async (event: ScheduleEvent) => {
const sendCounts = { "feast": 0, "non-feast": 0 };
for await (const subscription of subscriptions(event)) {
const receipt: string | undefined = subscription.receipt;
if (receipt) {
const subscriptionReference: AppleSubscriptionReference = {receipt: receipt};
const subscriptionReference: AppleSubscriptionReferenceWithRevalidateFlag = {receipt: receipt, isRevalidation: true};
const countKey = subscription.platform == Platform.IosFeast ? "feast" : "non-feast";
const delayInSeconds = Math.min(Math.floor(sendCounts[countKey] / 10), 900);
const sqsUrl = queueUrlForPlatform(subscription.platform);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('appleRevalidateReceipts', () => {
});

expect(sendToQueue).toHaveBeenCalledTimes(2);
expect(sendToQueue).toHaveBeenCalledWith('FeastAppSqsUrl', { receipt: feastSub.receipt }, 0);
expect(sendToQueue).toHaveBeenCalledWith('LiveAppSqsUrl', { receipt: liveAppSub.receipt }, 0);
expect(sendToQueue).toHaveBeenCalledWith('FeastAppSqsUrl', { receipt: feastSub.receipt, isRevalidation: true }, 0);
expect(sendToQueue).toHaveBeenCalledWith('LiveAppSqsUrl', { receipt: liveAppSub.receipt, isRevalidation: true }, 0);
});
});
Loading