From 282c8f1decbc6ca78bf06840a2976fafe4e650d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20=C5=BBuraw?= <9116238+krzysztofzuraw@users.noreply.github.com> Date: Mon, 5 May 2025 11:29:08 +0200 Subject: [PATCH 1/2] Add readonly arrays --- .changeset/early-cities-jam.md | 5 +++++ src/handlers/shared/sync-webhook-response-builder.ts | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 .changeset/early-cities-jam.md diff --git a/.changeset/early-cities-jam.md b/.changeset/early-cities-jam.md new file mode 100644 index 00000000..c2663bce --- /dev/null +++ b/.changeset/early-cities-jam.md @@ -0,0 +1,5 @@ +--- +"@saleor/app-sdk": patch +--- + +Add `readonly` to actions for `TRANSACTION_CHARGE_REQUESTED`, `TRANSACTION_REFUND_REQUESTED`, `TRANSACTION_CANCELATION_REQUESTED`, `TRANSACTION_INITIALIZE_SESSION` & `TRANSACTION_PROCESS_SESSION` events. diff --git a/src/handlers/shared/sync-webhook-response-builder.ts b/src/handlers/shared/sync-webhook-response-builder.ts index 3006981a..e9a447aa 100644 --- a/src/handlers/shared/sync-webhook-response-builder.ts +++ b/src/handlers/shared/sync-webhook-response-builder.ts @@ -37,7 +37,7 @@ export type SyncWebhookResponsesMap = { time?: string; externalUrl?: string; message?: string; - actions?: Array<"CHARGE" | "REFUND" | "CANCEL">; + readonly actions?: Array<"CHARGE" | "REFUND" | "CANCEL">; }; // https://docs.saleor.io/developer/extending/webhooks/synchronous-events/transaction#sync-flow-2 TRANSACTION_REFUND_REQUESTED: { @@ -47,7 +47,7 @@ export type SyncWebhookResponsesMap = { time?: string; externalUrl?: string; message?: string; - actions?: Array<"CHARGE" | "REFUND" | "CANCEL">; + readonly actions?: Array<"CHARGE" | "REFUND" | "CANCEL">; }; // https://docs.saleor.io/developer/extending/webhooks/synchronous-events/transaction#response-1 TRANSACTION_CANCELATION_REQUESTED: { @@ -57,7 +57,7 @@ export type SyncWebhookResponsesMap = { time?: string; externalUrl?: string; message?: string; - actions?: Array<"CHARGE" | "REFUND" | "CANCEL">; + readonly actions?: Array<"CHARGE" | "REFUND" | "CANCEL">; }; PAYMENT_GATEWAY_INITIALIZE_SESSION: { data: unknown; @@ -79,7 +79,7 @@ export type SyncWebhookResponsesMap = { time?: string; externalUrl?: string; message?: string; - actions?: Array<"CHARGE" | "REFUND" | "CANCEL">; + readonly actions?: Array<"CHARGE" | "REFUND" | "CANCEL">; }; // https://docs.saleor.io/developer/extending/webhooks/synchronous-events/transaction#response-5 TRANSACTION_PROCESS_SESSION: { @@ -98,7 +98,7 @@ export type SyncWebhookResponsesMap = { time?: string; externalUrl?: string; message?: string; - actions?: Array<"CHARGE" | "REFUND" | "CANCEL">; + readonly actions?: Array<"CHARGE" | "REFUND" | "CANCEL">; }; PAYMENT_METHOD_PROCESS_TOKENIZATION_SESSION: | { From 356f8cb221e9270ecd1fff76dc03925c00a24ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20=C5=BBuraw?= <9116238+krzysztofzuraw@users.noreply.github.com> Date: Mon, 5 May 2025 11:49:15 +0200 Subject: [PATCH 2/2] update solution --- src/handlers/shared/sync-webhook-response-builder.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/handlers/shared/sync-webhook-response-builder.ts b/src/handlers/shared/sync-webhook-response-builder.ts index e9a447aa..3477a0c4 100644 --- a/src/handlers/shared/sync-webhook-response-builder.ts +++ b/src/handlers/shared/sync-webhook-response-builder.ts @@ -1,5 +1,7 @@ import { SyncWebhookEventType } from "../../types"; +type TransactionActions = "CHARGE" | "REFUND" | "CANCEL"; + export type SyncWebhookResponsesMap = { CHECKOUT_CALCULATE_TAXES: { shipping_price_gross_amount: number; @@ -37,7 +39,7 @@ export type SyncWebhookResponsesMap = { time?: string; externalUrl?: string; message?: string; - readonly actions?: Array<"CHARGE" | "REFUND" | "CANCEL">; + actions?: readonly TransactionActions[]; }; // https://docs.saleor.io/developer/extending/webhooks/synchronous-events/transaction#sync-flow-2 TRANSACTION_REFUND_REQUESTED: { @@ -47,7 +49,7 @@ export type SyncWebhookResponsesMap = { time?: string; externalUrl?: string; message?: string; - readonly actions?: Array<"CHARGE" | "REFUND" | "CANCEL">; + actions?: readonly TransactionActions[]; }; // https://docs.saleor.io/developer/extending/webhooks/synchronous-events/transaction#response-1 TRANSACTION_CANCELATION_REQUESTED: { @@ -57,7 +59,7 @@ export type SyncWebhookResponsesMap = { time?: string; externalUrl?: string; message?: string; - readonly actions?: Array<"CHARGE" | "REFUND" | "CANCEL">; + actions?: readonly TransactionActions[]; }; PAYMENT_GATEWAY_INITIALIZE_SESSION: { data: unknown; @@ -79,7 +81,7 @@ export type SyncWebhookResponsesMap = { time?: string; externalUrl?: string; message?: string; - readonly actions?: Array<"CHARGE" | "REFUND" | "CANCEL">; + actions?: readonly TransactionActions[]; }; // https://docs.saleor.io/developer/extending/webhooks/synchronous-events/transaction#response-5 TRANSACTION_PROCESS_SESSION: { @@ -98,7 +100,7 @@ export type SyncWebhookResponsesMap = { time?: string; externalUrl?: string; message?: string; - readonly actions?: Array<"CHARGE" | "REFUND" | "CANCEL">; + actions?: readonly TransactionActions[]; }; PAYMENT_METHOD_PROCESS_TOKENIZATION_SESSION: | {