app-sdk icon indicating copy to clipboard operation
app-sdk copied to clipboard

Types required by `ctx.buildResponse` are wrong

Open peelar opened this issue 1 year ago • 0 comments

Problem

Version: 0.43 / 0.44

In my Next.js app, I define a sync webhook using the SaleorSyncWebhook Next handler:

export const transactionInitializeSessionSyncWebhook =
  new SaleorSyncWebhook<TransactionInitializeSessionEventFragment>({
    name: "TransactionInitializeSession",
    apl: saleorApp.apl,
    event: "TRANSACTION_INITIALIZE_SESSION",
    query: UntypedTransactionInitializeSessionDocument,
    webhookPath: "/api/webhooks/transaction-initialize-session",
  });

Then, I am peeking into SDK's src/handlers/next/saleor-webhooks/sync-webhook-response-builder.ts to see what type should I expect in the ctx.buildResponse function for the TRANSACTION_INITIALIZE_SESSION event:

...
  TRANSACTION_INITIALIZE_SESSION: {
    pspReference?: string;
    data?: unknown;
    result:
      | "CHARGE_SUCCESS"
      | "CHARGE_FAILURE"
      | "CHARGE_REQUESTED"
      | "CHARGE_ACTION_REQUIRED"
      | "AUTHORIZATION_SUCCESS"
      | "AUTHORIZATION_FAILURE"
      | "AUTHORIZATION_REQUESTED"
      | "AUTHORIZATION_ACTION_REQUIRED";
    amount: number;
    time?: string;
    externalUrl?: string;
    message?: string;
  };

And here is the proposed type I see in my IDE: image

So, I see:

  • fields from unrelated objects CHECKOUT_FILTER_SHIPPING_METHODS and CHECKOUT_CALCULATE_TAXES
  • all the fields from TRANSACTION_INITIALIZE_SESSION are optional

What I tried but didn't work

  • I tried modifying SyncWebhookResponsesMap type so it doesn't self-reference in:
  ORDER_CALCULATE_TAXES: SyncWebhookResponsesMap["CHECKOUT_CALCULATE_TAXES"];
  ORDER_FILTER_SHIPPING_METHODS: SyncWebhookResponsesMap["CHECKOUT_FILTER_SHIPPING_METHODS"];

because, as far as I can tell, those two objects are "leaking" into the type that I see in ctx.buildResponse.

peelar avatar Oct 12 '23 11:10 peelar