commit 960139825f14cc4d1e00465cbeb4fcca8b8a7c61
parent f808dafcd97b4c96bb5348401b195165369702fa
Author: Sebastian <sebasjm@taler-systems.com>
Date: Wed, 6 May 2026 08:47:02 -0300
fix: make new template parser backward compatible (reported by ivan)
Diffstat:
2 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/packages/taler-util/src/codec.ts b/packages/taler-util/src/codec.ts
@@ -246,6 +246,25 @@ class UnionCodecBuilder<
/**
* Define a property for the object.
*/
+ alternativeOnMissing<V>(
+ tagValue: TargetType[TagPropertyLabel],
+ codec: Codec<V>,
+ ): UnionCodecBuilder<
+ TargetType,
+ TagPropertyLabel,
+ CommonBaseType,
+ PartialTargetType | V
+ > {
+ if (!codec) {
+ throw Error("inner codec must be defined");
+ }
+ this.alternatives.set(undefined, { codec, tagValue });
+ return this as any;
+ }
+
+ /**
+ * Define a property for the object.
+ */
alternative<V>(
tagValue: TargetType[TagPropertyLabel],
codec: Codec<V>,
diff --git a/packages/taler-util/src/types-taler-merchant.ts b/packages/taler-util/src/types-taler-merchant.ts
@@ -4501,10 +4501,11 @@ export interface ExchangeStatusDetail {
keys_hint: string;
}
-export const codecForExchangeStatusResponse = (): Codec<ExchangeStatusResponse> =>
- buildCodecForObject<ExchangeStatusResponse>()
- .property("exchanges", codecForList(codecForExchangeStatusDetail()))
- .build("TalerMerchantApi.ExchangeStatusResponse");
+export const codecForExchangeStatusResponse =
+ (): Codec<ExchangeStatusResponse> =>
+ buildCodecForObject<ExchangeStatusResponse>()
+ .property("exchanges", codecForList(codecForExchangeStatusDetail()))
+ .build("TalerMerchantApi.ExchangeStatusResponse");
export const codecForExchangeStatusDetail = (): Codec<ExchangeStatusDetail> =>
buildCodecForObject<ExchangeStatusDetail>()
@@ -5406,7 +5407,14 @@ export const codecForTemplateContractDetails =
TemplateType.INVENTORY_CART,
codecForTemplateContractInventoryCart(),
)
- .alternative(TemplateType.PAIVANA, codecForTemplateContractPaivana())
+ .alternative(
+ TemplateType.PAIVANA,
+ codecForTemplateContractPaivana(),
+ )
+ .alternativeOnMissing(
+ TemplateType.FIXED_ORDER,
+ codecForTemplateContractFixedOrder(),
+ )
.build("TalerMerchantApi.TemplateContractDetails");
export const codecForTemplateContractDetailsDefaults =