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

Types required by ctx.buildResponse are wrong #297

Open
peelar opened this issue Oct 12, 2023 · 0 comments
Open

Types required by ctx.buildResponse are wrong #297

peelar opened this issue Oct 12, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@peelar
Copy link
Member

peelar commented Oct 12, 2023

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 peelar assigned peelar and unassigned peelar Oct 12, 2023
@lkostrowski lkostrowski self-assigned this Nov 18, 2023
@lkostrowski lkostrowski added the bug Something isn't working label Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants