@polyester/sdk 0.19.3 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/dist/gen/auth/v1/social_verification_pb.d.ts +4 -2
- package/dist/gen/auth/v1/social_verification_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/social_verification_pb.js.map +1 -1
- package/dist/gen/auth/v1/subaccounts_pb.d.ts +1 -1
- package/dist/gen/auth/v1/subaccounts_pb.js +1 -1
- package/dist/gen/chain/withdraw/v1/withdraw_pb.d.ts +290 -2
- package/dist/gen/chain/withdraw/v1/withdraw_pb.d.ts.map +1 -1
- package/dist/gen/chain/withdraw/v1/withdraw_pb.js +288 -9
- package/dist/gen/chain/withdraw/v1/withdraw_pb.js.map +1 -1
- package/dist/gen/index.d.ts +10 -10
- package/dist/gen/index.js +7 -7
- package/dist/gen/ledger/read/v1/ledger_read_pb.d.ts +1 -1
- package/dist/gen/ledger/read/v1/ledger_read_pb.js +1 -1
- package/dist/gen/orderbook/v1/orderbook_pb.d.ts +5 -3
- package/dist/gen/orderbook/v1/orderbook_pb.d.ts.map +1 -1
- package/dist/gen/orderbook/v1/orderbook_pb.js.map +1 -1
- package/dist/gen/orders/v1/orders_pb.d.ts +14 -6
- package/dist/gen/orders/v1/orders_pb.d.ts.map +1 -1
- package/dist/gen/orders/v1/orders_pb.js +7 -1
- package/dist/gen/orders/v1/orders_pb.js.map +1 -1
- package/dist/gen/orders/v1/orders_read_pb.d.ts +1 -1
- package/dist/gen/orders/v1/orders_read_pb.js +2 -2
- package/dist/gen/transfer/v1/internal_transfer_pb.d.ts +200 -2
- package/dist/gen/transfer/v1/internal_transfer_pb.d.ts.map +1 -1
- package/dist/gen/transfer/v1/internal_transfer_pb.js +193 -4
- package/dist/gen/transfer/v1/internal_transfer_pb.js.map +1 -1
- package/dist/gen/triggers/v1/triggers_pb.d.ts +47 -2
- package/dist/gen/triggers/v1/triggers_pb.d.ts.map +1 -1
- package/dist/gen/triggers/v1/triggers_pb.js +1 -1
- package/dist/gen/triggers/v1/triggers_pb.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -2
- package/dist/services/auth/profile/profile.js +1 -1
- package/dist/services/balances/balances.js +1 -1
- package/dist/services/balances/balances.schemas.js +1 -1
- package/dist/services/candles/candles.schemas.d.ts +10 -10
- package/dist/services/heatmap/heatmap.schemas.d.ts +13 -13
- package/dist/services/internal-transfers/internal-transfers.js +1 -1
- package/dist/services/lifecycle/lifecycle.schemas.d.ts +42 -42
- package/dist/services/market-overview/market-overview.js +1 -1
- package/dist/services/market-overview/market-overview.schemas.d.ts +3 -3
- package/dist/services/market-overview/market-overview.schemas.js +1 -1
- package/dist/services/orderbook/orderbook.schemas.d.ts +1 -1
- package/dist/services/orders/index.d.ts +1 -1
- package/dist/services/orders/order-errors.schemas.d.ts +1 -1
- package/dist/services/orders/orders-batch.schemas.d.ts +20 -20
- package/dist/services/orders/orders-batch.schemas.js +1 -1
- package/dist/services/orders/orders-input.schemas.d.ts +7 -7
- package/dist/services/orders/orders-input.schemas.js +2 -2
- package/dist/services/orders/orders-input.schemas.js.map +1 -1
- package/dist/services/orders/orders-output.schemas.d.ts +6 -6
- package/dist/services/orders/orders.d.ts +1 -1
- package/dist/services/orders/orders.d.ts.map +1 -1
- package/dist/services/orders/orders.js +5 -3
- package/dist/services/orders/orders.js.map +1 -1
- package/dist/services/orders/orders.schemas.d.ts +1 -1
- package/dist/services/orders/orders.types.d.ts +1 -1
- package/dist/services/subaccounts/subaccounts.schemas.d.ts +4 -4
- package/dist/services/trading-withdraws/trading-withdraws.d.ts +1 -1
- package/dist/services/trading-withdraws/trading-withdraws.js +1 -1
- package/dist/services/trading-withdraws/trading-withdraws.schemas.js +1 -1
- package/dist/services/transfers/transfers.js +1 -1
- package/dist/services/transfers/transfers.schemas.js +1 -1
- package/dist/services/triggers/trigger-child-order.schemas.js +25 -4
- package/dist/services/triggers/trigger-child-order.schemas.js.map +1 -1
- package/dist/services/triggers/trigger-input.schemas.d.ts +39 -3
- package/dist/services/triggers/trigger-input.schemas.d.ts.map +1 -1
- package/dist/services/triggers/trigger-input.schemas.js +3 -26
- package/dist/services/triggers/trigger-input.schemas.js.map +1 -1
- package/dist/services/triggers/triggers-output.schemas.d.ts +92 -17
- package/dist/services/triggers/triggers-output.schemas.d.ts.map +1 -1
- package/dist/services/triggers/triggers-output.schemas.js +36 -25
- package/dist/services/triggers/triggers-output.schemas.js.map +1 -1
- package/dist/shared/connect-error-mapping.d.ts.map +1 -1
- package/dist/shared/connect-error-mapping.js +50 -50
- package/dist/shared/connect-error-mapping.js.map +1 -1
- package/dist/shared/error-detail.d.ts +37 -0
- package/dist/shared/error-detail.d.ts.map +1 -0
- package/dist/shared/error-detail.js +106 -0
- package/dist/shared/error-detail.js.map +1 -0
- package/dist/shared/errors.d.ts +11 -6
- package/dist/shared/errors.d.ts.map +1 -1
- package/dist/shared/errors.js +3 -1
- package/dist/shared/errors.js.map +1 -1
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +1 -15
- package/dist/utils/errors.js.map +1 -1
- package/dist/wired-services.js +5 -5
- package/package.json +1 -1
- package/dist/utils/connect-order-errors.d.ts +0 -15
- package/dist/utils/connect-order-errors.d.ts.map +0 -1
- package/dist/utils/connect-order-errors.js +0 -41
- package/dist/utils/connect-order-errors.js.map +0 -1
|
@@ -64,6 +64,20 @@ const ConditionalConfigurationRawSchema = v.object({
|
|
|
64
64
|
side: v.enum(Side),
|
|
65
65
|
child: v.optional(v.object({ execution: ConditionalExecutionRawSchema }))
|
|
66
66
|
});
|
|
67
|
+
const MaxSlippageRawSchema = v.variant("case", [
|
|
68
|
+
v.object({
|
|
69
|
+
case: v.literal("maxSlippageTicks"),
|
|
70
|
+
value: v.number()
|
|
71
|
+
}),
|
|
72
|
+
v.object({
|
|
73
|
+
case: v.literal("maxSlippageBps"),
|
|
74
|
+
value: v.number()
|
|
75
|
+
}),
|
|
76
|
+
v.object({
|
|
77
|
+
case: v.undefined(),
|
|
78
|
+
value: v.optional(v.undefined())
|
|
79
|
+
})
|
|
80
|
+
]);
|
|
67
81
|
const TrailingConfigurationRawSchema = v.object({
|
|
68
82
|
trailingDistance: v.variant("case", [
|
|
69
83
|
v.object({
|
|
@@ -80,20 +94,7 @@ const TrailingConfigurationRawSchema = v.object({
|
|
|
80
94
|
})
|
|
81
95
|
]),
|
|
82
96
|
activationPriceTicks: v.bigint(),
|
|
83
|
-
maxSlippage:
|
|
84
|
-
v.object({
|
|
85
|
-
case: v.literal("maxSlippageTicks"),
|
|
86
|
-
value: v.number()
|
|
87
|
-
}),
|
|
88
|
-
v.object({
|
|
89
|
-
case: v.literal("maxSlippageBps"),
|
|
90
|
-
value: v.number()
|
|
91
|
-
}),
|
|
92
|
-
v.object({
|
|
93
|
-
case: v.undefined(),
|
|
94
|
-
value: v.optional(v.undefined())
|
|
95
|
-
})
|
|
96
|
-
]),
|
|
97
|
+
maxSlippage: MaxSlippageRawSchema,
|
|
97
98
|
side: v.enum(Side)
|
|
98
99
|
});
|
|
99
100
|
const TwapConfigurationRawSchema = v.object({
|
|
@@ -103,7 +104,7 @@ const TwapConfigurationRawSchema = v.object({
|
|
|
103
104
|
execution: v.variant("case", [
|
|
104
105
|
v.object({
|
|
105
106
|
case: v.literal("marketIoc"),
|
|
106
|
-
value: v.object({})
|
|
107
|
+
value: v.object({ maxSlippage: MaxSlippageRawSchema })
|
|
107
108
|
}),
|
|
108
109
|
v.object({
|
|
109
110
|
case: v.literal("limitGtc"),
|
|
@@ -187,20 +188,17 @@ function transformTriggerConfiguration(configuration, scales) {
|
|
|
187
188
|
bps: configuration.value.trailingDistance.value
|
|
188
189
|
} : { kind: "unspecified" },
|
|
189
190
|
activationPrice: configuration.value.activationPriceTicks > 0n ? scaledToDecimalOutput(configuration.value.activationPriceTicks, scales.price()) : void 0,
|
|
190
|
-
maxSlippage: configuration.value.maxSlippage
|
|
191
|
-
kind: "slippage",
|
|
192
|
-
slippage: scaledToDecimalOutput(BigInt(configuration.value.maxSlippage.value), scales.price())
|
|
193
|
-
} : configuration.value.maxSlippage.case === "maxSlippageBps" ? {
|
|
194
|
-
kind: "bps",
|
|
195
|
-
bps: configuration.value.maxSlippage.value
|
|
196
|
-
} : { kind: "none" }
|
|
191
|
+
maxSlippage: formatMaxSlippage(configuration.value.maxSlippage, scales)
|
|
197
192
|
};
|
|
198
193
|
case "twap": return {
|
|
199
194
|
type: "twap",
|
|
200
195
|
side: requiredEnumLabel(OrderSideCodec.protoToOutput, configuration.value.side, "TriggerConfigurationSchema", "side"),
|
|
201
196
|
durationMs: Number(configuration.value.durationMs),
|
|
202
197
|
sliceIntervalMs: Number(configuration.value.sliceIntervalMs),
|
|
203
|
-
execution: configuration.value.execution.case === "marketIoc" ? {
|
|
198
|
+
execution: configuration.value.execution.case === "marketIoc" ? {
|
|
199
|
+
type: "market_ioc",
|
|
200
|
+
maxSlippage: formatMaxSlippage(configuration.value.execution.value.maxSlippage, scales)
|
|
201
|
+
} : configuration.value.execution.case === "limitGtc" ? {
|
|
204
202
|
type: "limit_gtc",
|
|
205
203
|
price: scaledToDecimalOutput(configuration.value.execution.value.priceTicks, scales.price())
|
|
206
204
|
} : { type: "unspecified" }
|
|
@@ -216,6 +214,15 @@ function transformTriggerConfiguration(configuration, scales) {
|
|
|
216
214
|
default: return { type: "unspecified" };
|
|
217
215
|
}
|
|
218
216
|
}
|
|
217
|
+
function formatMaxSlippage(maxSlippage, scales) {
|
|
218
|
+
return maxSlippage.case === "maxSlippageTicks" ? {
|
|
219
|
+
kind: "slippage",
|
|
220
|
+
slippage: scaledToDecimalOutput(BigInt(maxSlippage.value), scales.price())
|
|
221
|
+
} : maxSlippage.case === "maxSlippageBps" ? {
|
|
222
|
+
kind: "bps",
|
|
223
|
+
bps: maxSlippage.value
|
|
224
|
+
} : { kind: "none" };
|
|
225
|
+
}
|
|
219
226
|
const TerminalReasonRawSchema = v.variant("case", [
|
|
220
227
|
v.object({
|
|
221
228
|
case: v.literal("cancelReason"),
|
|
@@ -273,7 +280,9 @@ const LadderDetailsRawSchema = v.object({
|
|
|
273
280
|
ladderPriceMinTicks: v.bigint(),
|
|
274
281
|
ladderPriceMaxTicks: v.bigint(),
|
|
275
282
|
ladderLevels: v.number(),
|
|
276
|
-
ladderDistribution: v.enum(LadderDistribution)
|
|
283
|
+
ladderDistribution: v.enum(LadderDistribution),
|
|
284
|
+
executedQtyScaled: v.bigint(),
|
|
285
|
+
executedLevels: v.number()
|
|
277
286
|
});
|
|
278
287
|
const TriggerDetailsRawSchema = v.variant("case", [
|
|
279
288
|
v.object({
|
|
@@ -330,7 +339,9 @@ function transformTriggerDetails(details, scales, symbolId) {
|
|
|
330
339
|
ladderPriceMin: scaledToDecimalOutput(details.value.ladderPriceMinTicks, scales.price()),
|
|
331
340
|
ladderPriceMax: scaledToDecimalOutput(details.value.ladderPriceMaxTicks, scales.price()),
|
|
332
341
|
ladderLevels: details.value.ladderLevels,
|
|
333
|
-
ladderDistribution: requiredEnumLabel(LadderDistributionCodec.protoToOutput, details.value.ladderDistribution, "TriggerDetailsSchema", "ladder distribution")
|
|
342
|
+
ladderDistribution: requiredEnumLabel(LadderDistributionCodec.protoToOutput, details.value.ladderDistribution, "TriggerDetailsSchema", "ladder distribution"),
|
|
343
|
+
executedQty: scaledToDecimalOutput(details.value.executedQtyScaled, scales.baseQty(symbolId)),
|
|
344
|
+
executedLevels: details.value.executedLevels
|
|
334
345
|
};
|
|
335
346
|
default: return { case: void 0 };
|
|
336
347
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"triggers-output.schemas.js","names":["Proto.TriggerStatus","ProtoOrders.Side","TriggerSideCodec","Proto.TriggerCancelReason","Proto.TriggerFailureReason","ProtoOrders.TriggerPriceSource","ProtoOrders.TriggerDirection","Proto.LadderDistribution","ProtoOrders.FeeAsset","ProtoOrders.SelfTradePreventionMode","Proto.TriggerType","Proto.TriggerEventType"],"sources":["../../../src/services/triggers/triggers-output.schemas.ts"],"sourcesContent":["import * as Proto from \"../../gen/triggers/v1/triggers_pb.js\";\nimport * as ProtoOrders from \"../../gen/orders/v1/orders_pb.js\";\nimport * as v from \"valibot\";\nimport {\n BigIntStringSchema,\n OptionalTimestampMsSchema,\n TimestampSchema,\n PublicIdSchema,\n} from \"../../shared/schemas.js\";\nimport { requiredEnumLabel } from \"../../shared/proto-enum-codec.js\";\nimport { scaledToDecimalOutput, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport { tsNsToMs, tsObjToMs } from \"../../utils/time.js\";\nimport { formatId } from \"../../utils/base58-id.js\";\nimport { SymbolIdInputSchema } from \"../shared.js\";\nimport {\n TriggerTypeCodec,\n TriggerStatusCodec,\n FeeAssetCodec,\n SelfTradePreventionModeCodec,\n TriggerPriceSourceCodec,\n TriggerDirectionCodec,\n LadderDistributionCodec,\n TriggerSideCodec,\n TriggerEventTypeCodec,\n TriggerCancelReasonCodec,\n TriggerFailureReasonCodec,\n} from \"./triggers.codecs.js\";\n\ntype TriggerPriceSourceLabel = \"last\" | \"index\" | \"mark\" | \"unspecified\";\n\ntype TriggerDirectionLabel = \"above\" | \"below\" | \"unspecified\";\n\ntype LadderDistributionLabel = \"linear\" | \"geometric\" | \"weighted_favorable\" | \"unspecified\";\n\nconst TriggerResultStatusSchema = v.pipe(\n v.enum(Proto.TriggerStatus),\n v.transform((status) =>\n requiredEnumLabel(\n TriggerStatusCodec.protoToOutput,\n status,\n \"TriggerResultSchema\",\n \"status\",\n ),\n ),\n);\n\nconst TriggerMutationResultBaseSchema = v.pipe(\n v.object({\n triggerId: PublicIdSchema,\n status: TriggerResultStatusSchema,\n tsNs: v.bigint(),\n }),\n v.transform(({ tsNs, ...result }) => ({\n ...result,\n ts: tsNsToMs(tsNs),\n tsNs: tsNs.toString(),\n })),\n);\n\nexport const CreateTriggerResultSchema = v.pipe(\n v.object({\n triggerId: PublicIdSchema,\n clientTriggerId: v.string(),\n acceptedAt: OptionalTimestampMsSchema,\n acceptedAtTsNs: BigIntStringSchema,\n }),\n v.transform(({ acceptedAt, acceptedAtTsNs, ...result }) => ({\n ...result,\n acceptedAt: acceptedAt ?? tsNsToMs(BigInt(acceptedAtTsNs)),\n acceptedAtNs: acceptedAtTsNs,\n })),\n);\n\nexport type CreateTriggerResult = v.InferOutput<typeof CreateTriggerResultSchema>;\n\nexport const CancelTriggerResultSchema = TriggerMutationResultBaseSchema;\n\nexport type CancelTriggerResult = v.InferOutput<typeof CancelTriggerResultSchema>;\n\nexport const ModifyTriggerResultSchema = TriggerMutationResultBaseSchema;\n\nexport type ModifyTriggerResult = v.InferOutput<typeof ModifyTriggerResultSchema>;\n\nexport const PauseTriggerResultSchema = TriggerMutationResultBaseSchema;\nexport type PauseTriggerResult = v.InferOutput<typeof PauseTriggerResultSchema>;\n\nexport const ResumeTriggerResultSchema = TriggerMutationResultBaseSchema;\nexport type ResumeTriggerResult = v.InferOutput<typeof ResumeTriggerResultSchema>;\n\nconst ConditionalExecutionRawSchema = v.variant(\"case\", [\n v.object({\n case: v.literal(\"marketIoc\"),\n value: v.object({}),\n }),\n v.object({\n case: v.literal(\"limitGtc\"),\n value: v.object({\n priceTicks: v.bigint(),\n postOnly: v.boolean(),\n }),\n }),\n v.object({\n case: v.literal(\"limitIoc\"),\n value: v.object({ priceTicks: v.bigint() }),\n }),\n v.object({\n case: v.literal(\"limitFok\"),\n value: v.object({ priceTicks: v.bigint() }),\n }),\n v.object({ case: v.undefined(), value: v.optional(v.undefined()) }),\n]);\n\nconst ConditionalConfigurationRawSchema = v.object({\n triggerPriceTicks: v.bigint(),\n side: v.enum(ProtoOrders.Side),\n child: v.optional(\n v.object({\n execution: ConditionalExecutionRawSchema,\n }),\n ),\n});\n\nconst TrailingConfigurationRawSchema = v.object({\n trailingDistance: v.variant(\"case\", [\n v.object({ case: v.literal(\"trailingDistanceTicks\"), value: v.bigint() }),\n v.object({ case: v.literal(\"trailingDistanceBps\"), value: v.number() }),\n v.object({ case: v.undefined(), value: v.optional(v.undefined()) }),\n ]),\n activationPriceTicks: v.bigint(),\n maxSlippage: v.variant(\"case\", [\n v.object({ case: v.literal(\"maxSlippageTicks\"), value: v.number() }),\n v.object({ case: v.literal(\"maxSlippageBps\"), value: v.number() }),\n v.object({ case: v.undefined(), value: v.optional(v.undefined()) }),\n ]),\n side: v.enum(ProtoOrders.Side),\n});\n\nconst TwapConfigurationRawSchema = v.object({\n side: v.enum(ProtoOrders.Side),\n durationMs: v.bigint(),\n sliceIntervalMs: v.bigint(),\n execution: v.variant(\"case\", [\n v.object({ case: v.literal(\"marketIoc\"), value: v.object({}) }),\n v.object({\n case: v.literal(\"limitGtc\"),\n value: v.object({ priceTicks: v.bigint() }),\n }),\n v.object({ case: v.undefined(), value: v.optional(v.undefined()) }),\n ]),\n});\n\nconst LadderConfigurationRawSchema = v.object({\n side: v.enum(ProtoOrders.Side),\n priceMinTicks: v.bigint(),\n priceMaxTicks: v.bigint(),\n levels: v.number(),\n postOnly: v.boolean(),\n});\n\nconst TriggerConfigurationRawSchema = v.variant(\"case\", [\n v.object({ case: v.literal(\"stopLoss\"), value: ConditionalConfigurationRawSchema }),\n v.object({ case: v.literal(\"takeProfit\"), value: ConditionalConfigurationRawSchema }),\n v.object({ case: v.literal(\"trailingStop\"), value: TrailingConfigurationRawSchema }),\n v.object({ case: v.literal(\"twap\"), value: TwapConfigurationRawSchema }),\n v.object({ case: v.literal(\"ladder\"), value: LadderConfigurationRawSchema }),\n v.object({ case: v.undefined(), value: v.optional(v.undefined()) }),\n]);\n\nfunction transformConditionalExecution(\n execution: v.InferOutput<typeof ConditionalExecutionRawSchema>,\n scales: SdkScales,\n) {\n switch (execution.case) {\n case \"marketIoc\":\n return { type: \"market_ioc\" } as const;\n case \"limitGtc\":\n return {\n type: \"limit_gtc\",\n price: scaledToDecimalOutput(execution.value.priceTicks, scales.price()),\n postOnly: execution.value.postOnly,\n } as const;\n case \"limitIoc\":\n return {\n type: \"limit_ioc\",\n price: scaledToDecimalOutput(execution.value.priceTicks, scales.price()),\n } as const;\n case \"limitFok\":\n return {\n type: \"limit_fok\",\n price: scaledToDecimalOutput(execution.value.priceTicks, scales.price()),\n } as const;\n default:\n return { type: \"unspecified\" } as const;\n }\n}\n\nfunction transformTriggerConfiguration(\n configuration: v.InferOutput<typeof TriggerConfigurationRawSchema>,\n scales: SdkScales,\n) {\n switch (configuration.case) {\n case \"stopLoss\":\n case \"takeProfit\":\n return {\n type:\n configuration.case === \"stopLoss\"\n ? (\"stop_loss\" as const)\n : (\"take_profit\" as const),\n side: requiredEnumLabel(\n TriggerSideCodec.protoToOutput,\n configuration.value.side,\n \"TriggerConfigurationSchema\",\n \"side\",\n ),\n triggerPrice: scaledToDecimalOutput(\n configuration.value.triggerPriceTicks,\n scales.price(),\n ),\n execution: transformConditionalExecution(\n configuration.value.child?.execution ?? { case: undefined },\n scales,\n ),\n };\n case \"trailingStop\":\n return {\n type: \"trailing_stop\" as const,\n side: requiredEnumLabel(\n TriggerSideCodec.protoToOutput,\n configuration.value.side,\n \"TriggerConfigurationSchema\",\n \"side\",\n ),\n trailingDistance:\n configuration.value.trailingDistance.case === \"trailingDistanceTicks\"\n ? {\n kind: \"distance\" as const,\n distance: scaledToDecimalOutput(\n configuration.value.trailingDistance.value,\n scales.price(),\n ),\n }\n : configuration.value.trailingDistance.case === \"trailingDistanceBps\"\n ? {\n kind: \"bps\" as const,\n bps: configuration.value.trailingDistance.value,\n }\n : { kind: \"unspecified\" as const },\n activationPrice:\n configuration.value.activationPriceTicks > 0n\n ? scaledToDecimalOutput(\n configuration.value.activationPriceTicks,\n scales.price(),\n )\n : undefined,\n maxSlippage:\n configuration.value.maxSlippage.case === \"maxSlippageTicks\"\n ? {\n kind: \"slippage\" as const,\n slippage: scaledToDecimalOutput(\n BigInt(configuration.value.maxSlippage.value),\n scales.price(),\n ),\n }\n : configuration.value.maxSlippage.case === \"maxSlippageBps\"\n ? {\n kind: \"bps\" as const,\n bps: configuration.value.maxSlippage.value,\n }\n : { kind: \"none\" as const },\n };\n case \"twap\":\n return {\n type: \"twap\" as const,\n side: requiredEnumLabel(\n TriggerSideCodec.protoToOutput,\n configuration.value.side,\n \"TriggerConfigurationSchema\",\n \"side\",\n ),\n durationMs: Number(configuration.value.durationMs),\n sliceIntervalMs: Number(configuration.value.sliceIntervalMs),\n execution:\n configuration.value.execution.case === \"marketIoc\"\n ? ({ type: \"market_ioc\" } as const)\n : configuration.value.execution.case === \"limitGtc\"\n ? ({\n type: \"limit_gtc\",\n price: scaledToDecimalOutput(\n configuration.value.execution.value.priceTicks,\n scales.price(),\n ),\n } as const)\n : ({ type: \"unspecified\" } as const),\n };\n case \"ladder\":\n return {\n type: \"ladder\" as const,\n side: requiredEnumLabel(\n TriggerSideCodec.protoToOutput,\n configuration.value.side,\n \"TriggerConfigurationSchema\",\n \"side\",\n ),\n priceMin: scaledToDecimalOutput(configuration.value.priceMinTicks, scales.price()),\n priceMax: scaledToDecimalOutput(configuration.value.priceMaxTicks, scales.price()),\n levels: configuration.value.levels,\n postOnly: configuration.value.postOnly,\n };\n default:\n return { type: \"unspecified\" as const };\n }\n}\n\nconst TerminalReasonRawSchema = v.variant(\"case\", [\n v.object({ case: v.literal(\"cancelReason\"), value: v.enum(Proto.TriggerCancelReason) }),\n v.object({ case: v.literal(\"failureReason\"), value: v.enum(Proto.TriggerFailureReason) }),\n v.object({ case: v.undefined(), value: v.optional(v.undefined()) }),\n]);\n\nfunction transformTerminalReason(reason: v.InferOutput<typeof TerminalReasonRawSchema>) {\n switch (reason.case) {\n case \"cancelReason\":\n return {\n cancelReason: requiredEnumLabel(\n TriggerCancelReasonCodec.protoToOutput,\n reason.value,\n \"TerminalReasonSchema\",\n \"cancel reason\",\n ),\n failureReason: undefined,\n };\n case \"failureReason\":\n return {\n cancelReason: undefined,\n failureReason: requiredEnumLabel(\n TriggerFailureReasonCodec.protoToOutput,\n reason.value,\n \"TerminalReasonSchema\",\n \"failure reason\",\n ),\n };\n default:\n return { cancelReason: undefined, failureReason: undefined };\n }\n}\n\nconst StopDetailsRawSchema = v.object({\n triggerPriceTicks: v.bigint(),\n triggerPriceSource: v.enum(ProtoOrders.TriggerPriceSource),\n triggerDirection: v.enum(ProtoOrders.TriggerDirection),\n});\n\nconst TrailingDetailsRawSchema = v.object({\n trailingDistanceTicks: v.bigint(),\n activationPriceTicks: v.bigint(),\n peakPriceTicks: v.bigint(),\n troughPriceTicks: v.bigint(),\n trailingDistanceBps: v.number(),\n maxSlippageTicks: v.number(),\n maxSlippageBps: v.number(),\n triggerPriceSource: v.enum(ProtoOrders.TriggerPriceSource),\n triggerDirection: v.enum(ProtoOrders.TriggerDirection),\n});\n\nconst TwapDetailsRawSchema = v.object({\n twapDurationMs: v.bigint(),\n twapSliceIntervalMs: v.bigint(),\n sliceIdx: v.number(),\n sliceCount: v.number(),\n executedQtyScaled: v.bigint(),\n});\n\nconst LadderDetailsRawSchema = v.object({\n ladderPriceMinTicks: v.bigint(),\n ladderPriceMaxTicks: v.bigint(),\n ladderLevels: v.number(),\n ladderDistribution: v.enum(Proto.LadderDistribution),\n});\n\nconst TriggerDetailsRawSchema = v.variant(\"case\", [\n v.object({ case: v.literal(\"stop\"), value: StopDetailsRawSchema }),\n v.object({ case: v.literal(\"trailing\"), value: TrailingDetailsRawSchema }),\n v.object({ case: v.literal(\"twapState\"), value: TwapDetailsRawSchema }),\n v.object({ case: v.literal(\"ladderState\"), value: LadderDetailsRawSchema }),\n v.object({ case: v.undefined(), value: v.optional(v.undefined()) }),\n]);\n\nexport type StopDetailsOutput = {\n case: \"stop\";\n triggerPrice: string;\n triggerPriceSource: TriggerPriceSourceLabel;\n triggerDirection: TriggerDirectionLabel;\n};\n\nexport type TrailingDetailsOutput = {\n case: \"trailing\";\n trailingDistance: string | undefined;\n trailingDistanceBps: number;\n activationPrice: string | undefined;\n peakPrice: string | undefined;\n troughPrice: string | undefined;\n maxSlippage: string | undefined;\n maxSlippageBps: number;\n triggerPriceSource: TriggerPriceSourceLabel;\n triggerDirection: TriggerDirectionLabel;\n};\n\nexport type TwapDetailsOutput = {\n case: \"twap\";\n twapDurationMs: number;\n twapSliceIntervalMs: number;\n sliceIdx: number;\n sliceCount: number;\n /** Cumulative filled child-order base quantity. */\n executedQty: string;\n};\n\nexport type LadderDetailsOutput = {\n case: \"ladder\";\n ladderPriceMin: string;\n ladderPriceMax: string;\n ladderLevels: number;\n ladderDistribution: LadderDistributionLabel;\n};\n\nexport type TriggerDetailsOutput =\n | StopDetailsOutput\n | TrailingDetailsOutput\n | TwapDetailsOutput\n | LadderDetailsOutput\n | { case: undefined };\n\nfunction transformTriggerDetails(\n details: v.InferOutput<typeof TriggerDetailsRawSchema>,\n scales: SdkScales,\n symbolId: number,\n): TriggerDetailsOutput {\n switch (details.case) {\n case \"stop\":\n return {\n case: \"stop\",\n triggerPrice: scaledToDecimalOutput(\n details.value.triggerPriceTicks,\n scales.price(),\n ),\n triggerPriceSource: requiredEnumLabel(\n TriggerPriceSourceCodec.protoToOutput,\n details.value.triggerPriceSource,\n \"TriggerDetailsSchema\",\n \"trigger price source\",\n ),\n triggerDirection: requiredEnumLabel(\n TriggerDirectionCodec.protoToOutput,\n details.value.triggerDirection,\n \"TriggerDetailsSchema\",\n \"trigger direction\",\n ),\n };\n case \"trailing\":\n return {\n case: \"trailing\",\n trailingDistance:\n details.value.trailingDistanceTicks > 0n\n ? scaledToDecimalOutput(details.value.trailingDistanceTicks, scales.price())\n : undefined,\n trailingDistanceBps: details.value.trailingDistanceBps,\n activationPrice:\n details.value.activationPriceTicks > 0n\n ? scaledToDecimalOutput(details.value.activationPriceTicks, scales.price())\n : undefined,\n peakPrice:\n details.value.peakPriceTicks > 0n\n ? scaledToDecimalOutput(details.value.peakPriceTicks, scales.price())\n : undefined,\n troughPrice:\n details.value.troughPriceTicks > 0n\n ? scaledToDecimalOutput(details.value.troughPriceTicks, scales.price())\n : undefined,\n maxSlippage:\n details.value.maxSlippageTicks > 0\n ? scaledToDecimalOutput(\n BigInt(details.value.maxSlippageTicks),\n scales.price(),\n )\n : undefined,\n maxSlippageBps: details.value.maxSlippageBps,\n triggerPriceSource: requiredEnumLabel(\n TriggerPriceSourceCodec.protoToOutput,\n details.value.triggerPriceSource,\n \"TriggerDetailsSchema\",\n \"trigger price source\",\n ),\n triggerDirection: requiredEnumLabel(\n TriggerDirectionCodec.protoToOutput,\n details.value.triggerDirection,\n \"TriggerDetailsSchema\",\n \"trigger direction\",\n ),\n };\n case \"twapState\":\n return {\n case: \"twap\",\n twapDurationMs: Number(details.value.twapDurationMs),\n twapSliceIntervalMs: Number(details.value.twapSliceIntervalMs),\n sliceIdx: details.value.sliceIdx,\n sliceCount: details.value.sliceCount,\n executedQty: scaledToDecimalOutput(\n details.value.executedQtyScaled,\n scales.baseQty(symbolId),\n ),\n };\n case \"ladderState\":\n return {\n case: \"ladder\",\n ladderPriceMin: scaledToDecimalOutput(\n details.value.ladderPriceMinTicks,\n scales.price(),\n ),\n ladderPriceMax: scaledToDecimalOutput(\n details.value.ladderPriceMaxTicks,\n scales.price(),\n ),\n ladderLevels: details.value.ladderLevels,\n ladderDistribution: requiredEnumLabel(\n LadderDistributionCodec.protoToOutput,\n details.value.ladderDistribution,\n \"TriggerDetailsSchema\",\n \"ladder distribution\",\n ),\n };\n default:\n return { case: undefined };\n }\n}\n\n/** Builds the public trigger output schema using each record's symbol ID for quantity scaling. */\nexport function createTriggerSchema(scales: SdkScales) {\n return v.pipe(\n v.object({\n triggerId: v.bigint(),\n subaccountId: v.bigint(),\n symbolId: SymbolIdInputSchema,\n status: v.enum(Proto.TriggerStatus),\n parentOrderId: v.optional(v.bigint()),\n qtyScaled: v.bigint(),\n feeAsset: v.enum(ProtoOrders.FeeAsset),\n selfTradePreventionMode: v.enum(ProtoOrders.SelfTradePreventionMode),\n configuration: TriggerConfigurationRawSchema,\n clientTriggerId: v.string(),\n createdAt: v.optional(TimestampSchema),\n updatedAt: v.optional(TimestampSchema),\n armedAt: v.optional(TimestampSchema),\n completedAt: v.optional(TimestampSchema),\n terminalReason: TerminalReasonRawSchema,\n runtimeDetails: TriggerDetailsRawSchema,\n }),\n v.transform((t) => ({\n triggerId: formatId(t.triggerId),\n subaccountId: formatId(t.subaccountId),\n symbolId: t.symbolId,\n status: requiredEnumLabel(\n TriggerStatusCodec.protoToOutput,\n t.status,\n \"TriggerSchema\",\n \"status\",\n ),\n parentOrderId: t.parentOrderId ? formatId(t.parentOrderId) : undefined,\n qty: scaledToDecimalOutput(t.qtyScaled, scales.baseQty(t.symbolId)),\n feeAsset: requiredEnumLabel(\n FeeAssetCodec.protoToOutput,\n t.feeAsset,\n \"TriggerSchema\",\n \"fee asset\",\n ),\n selfTradePreventionMode: requiredEnumLabel(\n SelfTradePreventionModeCodec.protoToOutput,\n t.selfTradePreventionMode,\n \"TriggerSchema\",\n \"STP mode\",\n ),\n configuration: transformTriggerConfiguration(t.configuration, scales),\n clientTriggerId: t.clientTriggerId,\n createdTs: t.createdAt ? tsObjToMs(t.createdAt) : undefined,\n updatedTs: t.updatedAt ? tsObjToMs(t.updatedAt) : undefined,\n armedTs: t.armedAt ? tsObjToMs(t.armedAt) : undefined,\n completedTs: t.completedAt ? tsObjToMs(t.completedAt) : undefined,\n ...transformTerminalReason(t.terminalReason),\n runtimeDetails: transformTriggerDetails(t.runtimeDetails, scales, t.symbolId),\n })),\n );\n}\n\n/** A normalized standalone trigger record. */\nexport type Trigger = v.InferOutput<ReturnType<typeof createTriggerSchema>>;\n\nexport function createTriggerEventSchema(scales: SdkScales) {\n return v.pipe(\n v.object({\n triggerId: v.bigint(),\n subaccountId: v.bigint(),\n symbolId: v.number(),\n triggerType: v.enum(Proto.TriggerType),\n eventType: v.enum(Proto.TriggerEventType),\n tsNs: v.bigint(),\n childSeq: v.number(),\n childOrderId: v.bigint(),\n firePriceTicks: v.optional(v.bigint()),\n terminalReason: TerminalReasonRawSchema,\n }),\n v.transform((e) => ({\n triggerId: formatId(e.triggerId),\n subaccountId: formatId(e.subaccountId),\n symbolId: e.symbolId,\n triggerType: requiredEnumLabel(\n TriggerTypeCodec.protoToOutput,\n e.triggerType,\n \"TriggerEventSchema\",\n \"trigger type\",\n ),\n eventType: requiredEnumLabel(\n TriggerEventTypeCodec.protoToOutput,\n e.eventType,\n \"TriggerEventSchema\",\n \"event type\",\n ),\n ts: tsNsToMs(e.tsNs),\n childSeq: e.childSeq,\n childOrderId: e.childOrderId > 0n ? formatId(e.childOrderId) : undefined,\n firePrice:\n e.firePriceTicks !== undefined && e.firePriceTicks > 0n\n ? scaledToDecimalOutput(e.firePriceTicks, scales.price())\n : undefined,\n ...transformTerminalReason(e.terminalReason),\n })),\n );\n}\n\nexport type TriggerEvent = v.InferOutput<ReturnType<typeof createTriggerEventSchema>>;\n\nexport type ListTriggerEventsResult = {\n events: TriggerEvent[];\n nextPageToken: string;\n};\n"],"mappings":";;;;;;;;;;;;AAkCA,MAAM,4BAA4B,EAAE,KAChC,EAAE,KAAKA,aAAmB,GAC1B,EAAE,WAAW,WACT,kBACI,mBAAmB,eACnB,QACA,uBACA,QACJ,CACJ,CACJ;AAEA,MAAM,kCAAkC,EAAE,KACtC,EAAE,OAAO;CACL,WAAW;CACX,QAAQ;CACR,MAAM,EAAE,OAAO;AACnB,CAAC,GACD,EAAE,WAAW,EAAE,MAAM,GAAG,cAAc;CAClC,GAAG;CACH,IAAI,SAAS,IAAI;CACjB,MAAM,KAAK,SAAS;AACxB,EAAE,CACN;AAEA,MAAa,4BAA4B,EAAE,KACvC,EAAE,OAAO;CACL,WAAW;CACX,iBAAiB,EAAE,OAAO;CAC1B,YAAY;CACZ,gBAAgB;AACpB,CAAC,GACD,EAAE,WAAW,EAAE,YAAY,gBAAgB,GAAG,cAAc;CACxD,GAAG;CACH,YAAY,cAAc,SAAS,OAAO,cAAc,CAAC;CACzD,cAAc;AAClB,EAAE,CACN;AAIA,MAAa,4BAA4B;AAIzC,MAAa,4BAA4B;AAIzC,MAAa,2BAA2B;AAGxC,MAAa,4BAA4B;A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;EACvB,gBAAgB,EAAE,SAAS,EAAE,OAAO,CAAC;EACrC,gBAAgB;CACpB,CAAC,GACD,EAAE,WAAW,OAAO;EAChB,WAAW,SAAS,EAAE,SAAS;EAC/B,cAAc,SAAS,EAAE,YAAY;EACrC,UAAU,EAAE;EACZ,aAAa,kBACT,iBAAiB,eACjB,EAAE,aACF,sBACA,cACJ;EACA,WAAW,kBACP,sBAAsB,eACtB,EAAE,WACF,sBACA,YACJ;EACA,IAAI,SAAS,EAAE,IAAI;EACnB,UAAU,EAAE;EACZ,cAAc,EAAE,eAAe,KAAK,SAAS,EAAE,YAAY,IAAI,KAAA;EAC/D,WACI,EAAE,mBAAmB,KAAA,KAAa,EAAE,iBAAiB,KAC/C,sBAAsB,EAAE,gBAAgB,OAAO,MAAM,CAAC,IACtD,KAAA;EACV,GAAG,wBAAwB,EAAE,cAAc;CAC/C,EAAE,CACN;AACJ"}
|
|
1
|
+
{"version":3,"file":"triggers-output.schemas.js","names":["Proto.TriggerStatus","ProtoOrders.Side","TriggerSideCodec","Proto.TriggerCancelReason","Proto.TriggerFailureReason","ProtoOrders.TriggerPriceSource","ProtoOrders.TriggerDirection","Proto.LadderDistribution","ProtoOrders.FeeAsset","ProtoOrders.SelfTradePreventionMode","Proto.TriggerType","Proto.TriggerEventType"],"sources":["../../../src/services/triggers/triggers-output.schemas.ts"],"sourcesContent":["import * as Proto from \"../../gen/triggers/v1/triggers_pb.js\";\nimport * as ProtoOrders from \"../../gen/orders/v1/orders_pb.js\";\nimport * as v from \"valibot\";\nimport {\n BigIntStringSchema,\n OptionalTimestampMsSchema,\n TimestampSchema,\n PublicIdSchema,\n} from \"../../shared/schemas.js\";\nimport { requiredEnumLabel } from \"../../shared/proto-enum-codec.js\";\nimport { scaledToDecimalOutput, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport { tsNsToMs, tsObjToMs } from \"../../utils/time.js\";\nimport { formatId } from \"../../utils/base58-id.js\";\nimport { SymbolIdInputSchema } from \"../shared.js\";\nimport {\n TriggerTypeCodec,\n TriggerStatusCodec,\n FeeAssetCodec,\n SelfTradePreventionModeCodec,\n TriggerPriceSourceCodec,\n TriggerDirectionCodec,\n LadderDistributionCodec,\n TriggerSideCodec,\n TriggerEventTypeCodec,\n TriggerCancelReasonCodec,\n TriggerFailureReasonCodec,\n} from \"./triggers.codecs.js\";\n\ntype TriggerPriceSourceLabel = \"last\" | \"index\" | \"mark\" | \"unspecified\";\n\ntype TriggerDirectionLabel = \"above\" | \"below\" | \"unspecified\";\n\ntype LadderDistributionLabel = \"linear\" | \"geometric\" | \"weighted_favorable\" | \"unspecified\";\n\nconst TriggerResultStatusSchema = v.pipe(\n v.enum(Proto.TriggerStatus),\n v.transform((status) =>\n requiredEnumLabel(\n TriggerStatusCodec.protoToOutput,\n status,\n \"TriggerResultSchema\",\n \"status\",\n ),\n ),\n);\n\nconst TriggerMutationResultBaseSchema = v.pipe(\n v.object({\n triggerId: PublicIdSchema,\n status: TriggerResultStatusSchema,\n tsNs: v.bigint(),\n }),\n v.transform(({ tsNs, ...result }) => ({\n ...result,\n ts: tsNsToMs(tsNs),\n tsNs: tsNs.toString(),\n })),\n);\n\nexport const CreateTriggerResultSchema = v.pipe(\n v.object({\n triggerId: PublicIdSchema,\n clientTriggerId: v.string(),\n acceptedAt: OptionalTimestampMsSchema,\n acceptedAtTsNs: BigIntStringSchema,\n }),\n v.transform(({ acceptedAt, acceptedAtTsNs, ...result }) => ({\n ...result,\n acceptedAt: acceptedAt ?? tsNsToMs(BigInt(acceptedAtTsNs)),\n acceptedAtNs: acceptedAtTsNs,\n })),\n);\n\nexport type CreateTriggerResult = v.InferOutput<typeof CreateTriggerResultSchema>;\n\nexport const CancelTriggerResultSchema = TriggerMutationResultBaseSchema;\n\nexport type CancelTriggerResult = v.InferOutput<typeof CancelTriggerResultSchema>;\n\nexport const ModifyTriggerResultSchema = TriggerMutationResultBaseSchema;\n\nexport type ModifyTriggerResult = v.InferOutput<typeof ModifyTriggerResultSchema>;\n\nexport const PauseTriggerResultSchema = TriggerMutationResultBaseSchema;\nexport type PauseTriggerResult = v.InferOutput<typeof PauseTriggerResultSchema>;\n\nexport const ResumeTriggerResultSchema = TriggerMutationResultBaseSchema;\nexport type ResumeTriggerResult = v.InferOutput<typeof ResumeTriggerResultSchema>;\n\nconst ConditionalExecutionRawSchema = v.variant(\"case\", [\n v.object({\n case: v.literal(\"marketIoc\"),\n value: v.object({}),\n }),\n v.object({\n case: v.literal(\"limitGtc\"),\n value: v.object({\n priceTicks: v.bigint(),\n postOnly: v.boolean(),\n }),\n }),\n v.object({\n case: v.literal(\"limitIoc\"),\n value: v.object({ priceTicks: v.bigint() }),\n }),\n v.object({\n case: v.literal(\"limitFok\"),\n value: v.object({ priceTicks: v.bigint() }),\n }),\n v.object({ case: v.undefined(), value: v.optional(v.undefined()) }),\n]);\n\nconst ConditionalConfigurationRawSchema = v.object({\n triggerPriceTicks: v.bigint(),\n side: v.enum(ProtoOrders.Side),\n child: v.optional(\n v.object({\n execution: ConditionalExecutionRawSchema,\n }),\n ),\n});\n\nconst MaxSlippageRawSchema = v.variant(\"case\", [\n v.object({ case: v.literal(\"maxSlippageTicks\"), value: v.number() }),\n v.object({ case: v.literal(\"maxSlippageBps\"), value: v.number() }),\n v.object({ case: v.undefined(), value: v.optional(v.undefined()) }),\n]);\n\nconst TrailingConfigurationRawSchema = v.object({\n trailingDistance: v.variant(\"case\", [\n v.object({ case: v.literal(\"trailingDistanceTicks\"), value: v.bigint() }),\n v.object({ case: v.literal(\"trailingDistanceBps\"), value: v.number() }),\n v.object({ case: v.undefined(), value: v.optional(v.undefined()) }),\n ]),\n activationPriceTicks: v.bigint(),\n maxSlippage: MaxSlippageRawSchema,\n side: v.enum(ProtoOrders.Side),\n});\n\nconst TwapConfigurationRawSchema = v.object({\n side: v.enum(ProtoOrders.Side),\n durationMs: v.bigint(),\n sliceIntervalMs: v.bigint(),\n execution: v.variant(\"case\", [\n v.object({\n case: v.literal(\"marketIoc\"),\n value: v.object({ maxSlippage: MaxSlippageRawSchema }),\n }),\n v.object({\n case: v.literal(\"limitGtc\"),\n value: v.object({ priceTicks: v.bigint() }),\n }),\n v.object({ case: v.undefined(), value: v.optional(v.undefined()) }),\n ]),\n});\n\nconst LadderConfigurationRawSchema = v.object({\n side: v.enum(ProtoOrders.Side),\n priceMinTicks: v.bigint(),\n priceMaxTicks: v.bigint(),\n levels: v.number(),\n postOnly: v.boolean(),\n});\n\nconst TriggerConfigurationRawSchema = v.variant(\"case\", [\n v.object({ case: v.literal(\"stopLoss\"), value: ConditionalConfigurationRawSchema }),\n v.object({ case: v.literal(\"takeProfit\"), value: ConditionalConfigurationRawSchema }),\n v.object({ case: v.literal(\"trailingStop\"), value: TrailingConfigurationRawSchema }),\n v.object({ case: v.literal(\"twap\"), value: TwapConfigurationRawSchema }),\n v.object({ case: v.literal(\"ladder\"), value: LadderConfigurationRawSchema }),\n v.object({ case: v.undefined(), value: v.optional(v.undefined()) }),\n]);\n\nfunction transformConditionalExecution(\n execution: v.InferOutput<typeof ConditionalExecutionRawSchema>,\n scales: SdkScales,\n) {\n switch (execution.case) {\n case \"marketIoc\":\n return { type: \"market_ioc\" } as const;\n case \"limitGtc\":\n return {\n type: \"limit_gtc\",\n price: scaledToDecimalOutput(execution.value.priceTicks, scales.price()),\n postOnly: execution.value.postOnly,\n } as const;\n case \"limitIoc\":\n return {\n type: \"limit_ioc\",\n price: scaledToDecimalOutput(execution.value.priceTicks, scales.price()),\n } as const;\n case \"limitFok\":\n return {\n type: \"limit_fok\",\n price: scaledToDecimalOutput(execution.value.priceTicks, scales.price()),\n } as const;\n default:\n return { type: \"unspecified\" } as const;\n }\n}\n\nfunction transformTriggerConfiguration(\n configuration: v.InferOutput<typeof TriggerConfigurationRawSchema>,\n scales: SdkScales,\n) {\n switch (configuration.case) {\n case \"stopLoss\":\n case \"takeProfit\":\n return {\n type:\n configuration.case === \"stopLoss\"\n ? (\"stop_loss\" as const)\n : (\"take_profit\" as const),\n side: requiredEnumLabel(\n TriggerSideCodec.protoToOutput,\n configuration.value.side,\n \"TriggerConfigurationSchema\",\n \"side\",\n ),\n triggerPrice: scaledToDecimalOutput(\n configuration.value.triggerPriceTicks,\n scales.price(),\n ),\n execution: transformConditionalExecution(\n configuration.value.child?.execution ?? { case: undefined },\n scales,\n ),\n };\n case \"trailingStop\":\n return {\n type: \"trailing_stop\" as const,\n side: requiredEnumLabel(\n TriggerSideCodec.protoToOutput,\n configuration.value.side,\n \"TriggerConfigurationSchema\",\n \"side\",\n ),\n trailingDistance:\n configuration.value.trailingDistance.case === \"trailingDistanceTicks\"\n ? {\n kind: \"distance\" as const,\n distance: scaledToDecimalOutput(\n configuration.value.trailingDistance.value,\n scales.price(),\n ),\n }\n : configuration.value.trailingDistance.case === \"trailingDistanceBps\"\n ? {\n kind: \"bps\" as const,\n bps: configuration.value.trailingDistance.value,\n }\n : { kind: \"unspecified\" as const },\n activationPrice:\n configuration.value.activationPriceTicks > 0n\n ? scaledToDecimalOutput(\n configuration.value.activationPriceTicks,\n scales.price(),\n )\n : undefined,\n maxSlippage: formatMaxSlippage(configuration.value.maxSlippage, scales),\n };\n case \"twap\":\n return {\n type: \"twap\" as const,\n side: requiredEnumLabel(\n TriggerSideCodec.protoToOutput,\n configuration.value.side,\n \"TriggerConfigurationSchema\",\n \"side\",\n ),\n durationMs: Number(configuration.value.durationMs),\n sliceIntervalMs: Number(configuration.value.sliceIntervalMs),\n execution:\n configuration.value.execution.case === \"marketIoc\"\n ? ({\n type: \"market_ioc\",\n maxSlippage: formatMaxSlippage(\n configuration.value.execution.value.maxSlippage,\n scales,\n ),\n } as const)\n : configuration.value.execution.case === \"limitGtc\"\n ? ({\n type: \"limit_gtc\",\n price: scaledToDecimalOutput(\n configuration.value.execution.value.priceTicks,\n scales.price(),\n ),\n } as const)\n : ({ type: \"unspecified\" } as const),\n };\n case \"ladder\":\n return {\n type: \"ladder\" as const,\n side: requiredEnumLabel(\n TriggerSideCodec.protoToOutput,\n configuration.value.side,\n \"TriggerConfigurationSchema\",\n \"side\",\n ),\n priceMin: scaledToDecimalOutput(configuration.value.priceMinTicks, scales.price()),\n priceMax: scaledToDecimalOutput(configuration.value.priceMaxTicks, scales.price()),\n levels: configuration.value.levels,\n postOnly: configuration.value.postOnly,\n };\n default:\n return { type: \"unspecified\" as const };\n }\n}\n\nfunction formatMaxSlippage(\n maxSlippage: v.InferOutput<typeof MaxSlippageRawSchema>,\n scales: SdkScales,\n) {\n return maxSlippage.case === \"maxSlippageTicks\"\n ? {\n kind: \"slippage\" as const,\n slippage: scaledToDecimalOutput(BigInt(maxSlippage.value), scales.price()),\n }\n : maxSlippage.case === \"maxSlippageBps\"\n ? { kind: \"bps\" as const, bps: maxSlippage.value }\n : { kind: \"none\" as const };\n}\n\nconst TerminalReasonRawSchema = v.variant(\"case\", [\n v.object({ case: v.literal(\"cancelReason\"), value: v.enum(Proto.TriggerCancelReason) }),\n v.object({ case: v.literal(\"failureReason\"), value: v.enum(Proto.TriggerFailureReason) }),\n v.object({ case: v.undefined(), value: v.optional(v.undefined()) }),\n]);\n\nfunction transformTerminalReason(reason: v.InferOutput<typeof TerminalReasonRawSchema>) {\n switch (reason.case) {\n case \"cancelReason\":\n return {\n cancelReason: requiredEnumLabel(\n TriggerCancelReasonCodec.protoToOutput,\n reason.value,\n \"TerminalReasonSchema\",\n \"cancel reason\",\n ),\n failureReason: undefined,\n };\n case \"failureReason\":\n return {\n cancelReason: undefined,\n failureReason: requiredEnumLabel(\n TriggerFailureReasonCodec.protoToOutput,\n reason.value,\n \"TerminalReasonSchema\",\n \"failure reason\",\n ),\n };\n default:\n return { cancelReason: undefined, failureReason: undefined };\n }\n}\n\nconst StopDetailsRawSchema = v.object({\n triggerPriceTicks: v.bigint(),\n triggerPriceSource: v.enum(ProtoOrders.TriggerPriceSource),\n triggerDirection: v.enum(ProtoOrders.TriggerDirection),\n});\n\nconst TrailingDetailsRawSchema = v.object({\n trailingDistanceTicks: v.bigint(),\n activationPriceTicks: v.bigint(),\n peakPriceTicks: v.bigint(),\n troughPriceTicks: v.bigint(),\n trailingDistanceBps: v.number(),\n maxSlippageTicks: v.number(),\n maxSlippageBps: v.number(),\n triggerPriceSource: v.enum(ProtoOrders.TriggerPriceSource),\n triggerDirection: v.enum(ProtoOrders.TriggerDirection),\n});\n\nconst TwapDetailsRawSchema = v.object({\n twapDurationMs: v.bigint(),\n twapSliceIntervalMs: v.bigint(),\n sliceIdx: v.number(),\n sliceCount: v.number(),\n executedQtyScaled: v.bigint(),\n});\n\nconst LadderDetailsRawSchema = v.object({\n ladderPriceMinTicks: v.bigint(),\n ladderPriceMaxTicks: v.bigint(),\n ladderLevels: v.number(),\n ladderDistribution: v.enum(Proto.LadderDistribution),\n executedQtyScaled: v.bigint(),\n executedLevels: v.number(),\n});\n\nconst TriggerDetailsRawSchema = v.variant(\"case\", [\n v.object({ case: v.literal(\"stop\"), value: StopDetailsRawSchema }),\n v.object({ case: v.literal(\"trailing\"), value: TrailingDetailsRawSchema }),\n v.object({ case: v.literal(\"twapState\"), value: TwapDetailsRawSchema }),\n v.object({ case: v.literal(\"ladderState\"), value: LadderDetailsRawSchema }),\n v.object({ case: v.undefined(), value: v.optional(v.undefined()) }),\n]);\n\nexport type StopDetailsOutput = {\n case: \"stop\";\n triggerPrice: string;\n triggerPriceSource: TriggerPriceSourceLabel;\n triggerDirection: TriggerDirectionLabel;\n};\n\nexport type TrailingDetailsOutput = {\n case: \"trailing\";\n trailingDistance: string | undefined;\n trailingDistanceBps: number;\n activationPrice: string | undefined;\n peakPrice: string | undefined;\n troughPrice: string | undefined;\n maxSlippage: string | undefined;\n maxSlippageBps: number;\n triggerPriceSource: TriggerPriceSourceLabel;\n triggerDirection: TriggerDirectionLabel;\n};\n\nexport type TwapDetailsOutput = {\n case: \"twap\";\n twapDurationMs: number;\n twapSliceIntervalMs: number;\n sliceIdx: number;\n sliceCount: number;\n /** Cumulative filled child-order base quantity. */\n executedQty: string;\n};\n\nexport type LadderDetailsOutput = {\n case: \"ladder\";\n ladderPriceMin: string;\n ladderPriceMax: string;\n ladderLevels: number;\n ladderDistribution: LadderDistributionLabel;\n /** Cumulative filled child-order base quantity. */\n executedQty: string;\n /** Number of ladder levels with at least one fill. */\n executedLevels: number;\n};\n\nexport type TriggerDetailsOutput =\n | StopDetailsOutput\n | TrailingDetailsOutput\n | TwapDetailsOutput\n | LadderDetailsOutput\n | { case: undefined };\n\nfunction transformTriggerDetails(\n details: v.InferOutput<typeof TriggerDetailsRawSchema>,\n scales: SdkScales,\n symbolId: number,\n): TriggerDetailsOutput {\n switch (details.case) {\n case \"stop\":\n return {\n case: \"stop\",\n triggerPrice: scaledToDecimalOutput(\n details.value.triggerPriceTicks,\n scales.price(),\n ),\n triggerPriceSource: requiredEnumLabel(\n TriggerPriceSourceCodec.protoToOutput,\n details.value.triggerPriceSource,\n \"TriggerDetailsSchema\",\n \"trigger price source\",\n ),\n triggerDirection: requiredEnumLabel(\n TriggerDirectionCodec.protoToOutput,\n details.value.triggerDirection,\n \"TriggerDetailsSchema\",\n \"trigger direction\",\n ),\n };\n case \"trailing\":\n return {\n case: \"trailing\",\n trailingDistance:\n details.value.trailingDistanceTicks > 0n\n ? scaledToDecimalOutput(details.value.trailingDistanceTicks, scales.price())\n : undefined,\n trailingDistanceBps: details.value.trailingDistanceBps,\n activationPrice:\n details.value.activationPriceTicks > 0n\n ? scaledToDecimalOutput(details.value.activationPriceTicks, scales.price())\n : undefined,\n peakPrice:\n details.value.peakPriceTicks > 0n\n ? scaledToDecimalOutput(details.value.peakPriceTicks, scales.price())\n : undefined,\n troughPrice:\n details.value.troughPriceTicks > 0n\n ? scaledToDecimalOutput(details.value.troughPriceTicks, scales.price())\n : undefined,\n maxSlippage:\n details.value.maxSlippageTicks > 0\n ? scaledToDecimalOutput(\n BigInt(details.value.maxSlippageTicks),\n scales.price(),\n )\n : undefined,\n maxSlippageBps: details.value.maxSlippageBps,\n triggerPriceSource: requiredEnumLabel(\n TriggerPriceSourceCodec.protoToOutput,\n details.value.triggerPriceSource,\n \"TriggerDetailsSchema\",\n \"trigger price source\",\n ),\n triggerDirection: requiredEnumLabel(\n TriggerDirectionCodec.protoToOutput,\n details.value.triggerDirection,\n \"TriggerDetailsSchema\",\n \"trigger direction\",\n ),\n };\n case \"twapState\":\n return {\n case: \"twap\",\n twapDurationMs: Number(details.value.twapDurationMs),\n twapSliceIntervalMs: Number(details.value.twapSliceIntervalMs),\n sliceIdx: details.value.sliceIdx,\n sliceCount: details.value.sliceCount,\n executedQty: scaledToDecimalOutput(\n details.value.executedQtyScaled,\n scales.baseQty(symbolId),\n ),\n };\n case \"ladderState\":\n return {\n case: \"ladder\",\n ladderPriceMin: scaledToDecimalOutput(\n details.value.ladderPriceMinTicks,\n scales.price(),\n ),\n ladderPriceMax: scaledToDecimalOutput(\n details.value.ladderPriceMaxTicks,\n scales.price(),\n ),\n ladderLevels: details.value.ladderLevels,\n ladderDistribution: requiredEnumLabel(\n LadderDistributionCodec.protoToOutput,\n details.value.ladderDistribution,\n \"TriggerDetailsSchema\",\n \"ladder distribution\",\n ),\n executedQty: scaledToDecimalOutput(\n details.value.executedQtyScaled,\n scales.baseQty(symbolId),\n ),\n executedLevels: details.value.executedLevels,\n };\n default:\n return { case: undefined };\n }\n}\n\n/** Builds the public trigger output schema using each record's symbol ID for quantity scaling. */\nexport function createTriggerSchema(scales: SdkScales) {\n return v.pipe(\n v.object({\n triggerId: v.bigint(),\n subaccountId: v.bigint(),\n symbolId: SymbolIdInputSchema,\n status: v.enum(Proto.TriggerStatus),\n parentOrderId: v.optional(v.bigint()),\n qtyScaled: v.bigint(),\n feeAsset: v.enum(ProtoOrders.FeeAsset),\n selfTradePreventionMode: v.enum(ProtoOrders.SelfTradePreventionMode),\n configuration: TriggerConfigurationRawSchema,\n clientTriggerId: v.string(),\n createdAt: v.optional(TimestampSchema),\n updatedAt: v.optional(TimestampSchema),\n armedAt: v.optional(TimestampSchema),\n completedAt: v.optional(TimestampSchema),\n terminalReason: TerminalReasonRawSchema,\n runtimeDetails: TriggerDetailsRawSchema,\n }),\n v.transform((t) => ({\n triggerId: formatId(t.triggerId),\n subaccountId: formatId(t.subaccountId),\n symbolId: t.symbolId,\n status: requiredEnumLabel(\n TriggerStatusCodec.protoToOutput,\n t.status,\n \"TriggerSchema\",\n \"status\",\n ),\n parentOrderId: t.parentOrderId ? formatId(t.parentOrderId) : undefined,\n qty: scaledToDecimalOutput(t.qtyScaled, scales.baseQty(t.symbolId)),\n feeAsset: requiredEnumLabel(\n FeeAssetCodec.protoToOutput,\n t.feeAsset,\n \"TriggerSchema\",\n \"fee asset\",\n ),\n selfTradePreventionMode: requiredEnumLabel(\n SelfTradePreventionModeCodec.protoToOutput,\n t.selfTradePreventionMode,\n \"TriggerSchema\",\n \"STP mode\",\n ),\n configuration: transformTriggerConfiguration(t.configuration, scales),\n clientTriggerId: t.clientTriggerId,\n createdTs: t.createdAt ? tsObjToMs(t.createdAt) : undefined,\n updatedTs: t.updatedAt ? tsObjToMs(t.updatedAt) : undefined,\n armedTs: t.armedAt ? tsObjToMs(t.armedAt) : undefined,\n completedTs: t.completedAt ? tsObjToMs(t.completedAt) : undefined,\n ...transformTerminalReason(t.terminalReason),\n runtimeDetails: transformTriggerDetails(t.runtimeDetails, scales, t.symbolId),\n })),\n );\n}\n\n/** A normalized standalone trigger record. */\nexport type Trigger = v.InferOutput<ReturnType<typeof createTriggerSchema>>;\n\nexport function createTriggerEventSchema(scales: SdkScales) {\n return v.pipe(\n v.object({\n triggerId: v.bigint(),\n subaccountId: v.bigint(),\n symbolId: v.number(),\n triggerType: v.enum(Proto.TriggerType),\n eventType: v.enum(Proto.TriggerEventType),\n tsNs: v.bigint(),\n childSeq: v.number(),\n childOrderId: v.bigint(),\n firePriceTicks: v.optional(v.bigint()),\n terminalReason: TerminalReasonRawSchema,\n }),\n v.transform((e) => ({\n triggerId: formatId(e.triggerId),\n subaccountId: formatId(e.subaccountId),\n symbolId: e.symbolId,\n triggerType: requiredEnumLabel(\n TriggerTypeCodec.protoToOutput,\n e.triggerType,\n \"TriggerEventSchema\",\n \"trigger type\",\n ),\n eventType: requiredEnumLabel(\n TriggerEventTypeCodec.protoToOutput,\n e.eventType,\n \"TriggerEventSchema\",\n \"event type\",\n ),\n ts: tsNsToMs(e.tsNs),\n childSeq: e.childSeq,\n childOrderId: e.childOrderId > 0n ? formatId(e.childOrderId) : undefined,\n firePrice:\n e.firePriceTicks !== undefined && e.firePriceTicks > 0n\n ? scaledToDecimalOutput(e.firePriceTicks, scales.price())\n : undefined,\n ...transformTerminalReason(e.terminalReason),\n })),\n );\n}\n\nexport type TriggerEvent = v.InferOutput<ReturnType<typeof createTriggerEventSchema>>;\n\nexport type ListTriggerEventsResult = {\n events: TriggerEvent[];\n nextPageToken: string;\n};\n"],"mappings":";;;;;;;;;;;;AAkCA,MAAM,4BAA4B,EAAE,KAChC,EAAE,KAAKA,aAAmB,GAC1B,EAAE,WAAW,WACT,kBACI,mBAAmB,eACnB,QACA,uBACA,QACJ,CACJ,CACJ;AAEA,MAAM,kCAAkC,EAAE,KACtC,EAAE,OAAO;CACL,WAAW;CACX,QAAQ;CACR,MAAM,EAAE,OAAO;AACnB,CAAC,GACD,EAAE,WAAW,EAAE,MAAM,GAAG,cAAc;CAClC,GAAG;CACH,IAAI,SAAS,IAAI;CACjB,MAAM,KAAK,SAAS;AACxB,EAAE,CACN;AAEA,MAAa,4BAA4B,EAAE,KACvC,EAAE,OAAO;CACL,WAAW;CACX,iBAAiB,EAAE,OAAO;CAC1B,YAAY;CACZ,gBAAgB;AACpB,CAAC,GACD,EAAE,WAAW,EAAE,YAAY,gBAAgB,GAAG,cAAc;CACxD,GAAG;CACH,YAAY,cAAc,SAAS,OAAO,cAAc,CAAC;CACzD,cAAc;AAClB,EAAE,CACN;AAIA,MAAa,4BAA4B;AAIzC,MAAa,4BAA4B;AAIzC,MAAa,2BAA2B;AAGxC,MAAa,4BAA4B;AAGzC,MAAM,gCAAgC,EAAE,QAAQ,QAAQ;C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,KACL,EAAE,OAAO;EACL,WAAW,EAAE,OAAO;EACpB,cAAc,EAAE,OAAO;EACvB,UAAU,EAAE,OAAO;EACnB,aAAa,EAAE,KAAKC,WAAiB;EACrC,WAAW,EAAE,KAAKC,gBAAsB;EACxC,MAAM,EAAE,OAAO;EACf,UAAU,EAAE,OAAO;EACnB,cAAc,EAAE,OAAO;EACvB,gBAAgB,EAAE,SAAS,EAAE,OAAO,CAAC;EACrC,gBAAgB;CACpB,CAAC,GACD,EAAE,WAAW,OAAO;EAChB,WAAW,SAAS,EAAE,SAAS;EAC/B,cAAc,SAAS,EAAE,YAAY;EACrC,UAAU,EAAE;EACZ,aAAa,kBACT,iBAAiB,eACjB,EAAE,aACF,sBACA,cACJ;EACA,WAAW,kBACP,sBAAsB,eACtB,EAAE,WACF,sBACA,YACJ;EACA,IAAI,SAAS,EAAE,IAAI;EACnB,UAAU,EAAE;EACZ,cAAc,EAAE,eAAe,KAAK,SAAS,EAAE,YAAY,IAAI,KAAA;EAC/D,WACI,EAAE,mBAAmB,KAAA,KAAa,EAAE,iBAAiB,KAC/C,sBAAsB,EAAE,gBAAgB,OAAO,MAAM,CAAC,IACtD,KAAA;EACV,GAAG,wBAAwB,EAAE,cAAc;CAC/C,EAAE,CACN;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect-error-mapping.d.ts","names":[],"sources":["../../src/shared/connect-error-mapping.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"connect-error-mapping.d.ts","names":[],"sources":["../../src/shared/connect-error-mapping.ts"],"mappings":";;;;;;;iBA+HgB,6BAA6B,IAAI,eAAe;;;;;;iBAsJhD,iBAAiB;;;;;;iBAyBjB,iCAAiC"}
|
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
import { AlreadyExistsError, AuthenticationError, InternalServerError, MfaEnrollmentRequiredError, MfaLastFactorRequiredError, MfaVerificationError, PermissionError, PolicyInUseError, PolicyLockedError, PolicyScopeMismatchError, PolyesterError, PreconditionFailedError, RateLimitError, ResourceNotFoundError, RevisionConflictError, ServiceUnavailableError, SessionElevationRequiredError, StaleQuoteError, StepUpRequiredError, TimeoutError, TransientError, ValidationError, isAbortError, normalizeErrorMessage } from "./errors.js";
|
|
2
|
-
import {
|
|
3
|
-
import { ErrorDetailSchema } from "../gen/orders/v1/orders_pb.js";
|
|
4
|
-
import { RateLimitDetailSchema } from "./rate-limit.schemas.js";
|
|
2
|
+
import { parseConnectErrorDetail } from "./error-detail.js";
|
|
5
3
|
import { Code, ConnectError } from "@connectrpc/connect";
|
|
6
|
-
import * as v from "valibot";
|
|
7
4
|
//#region src/shared/connect-error-mapping.ts
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
5
|
+
function hasTransientTransferError(detail) {
|
|
6
|
+
if (detail?.service === "withdraw") return [
|
|
7
|
+
"SERVICE_UNAVAILABLE",
|
|
8
|
+
"SOURCE_SMART_ACCOUNT_UNAVAILABLE",
|
|
9
|
+
"CAPITAL_VIEW_UNAVAILABLE",
|
|
10
|
+
"CHAIN_METADATA_UNAVAILABLE",
|
|
11
|
+
"FEE_UNAVAILABLE",
|
|
12
|
+
"SUPPLY_UNAVAILABLE",
|
|
13
|
+
"STEP_UP_UNAVAILABLE",
|
|
14
|
+
"DESTINATION_VALIDATION_UNAVAILABLE",
|
|
15
|
+
"ACCOUNT_SHARD_UNAVAILABLE"
|
|
16
|
+
].includes(detail.code);
|
|
17
|
+
if (detail?.service === "internal_transfer") return [
|
|
18
|
+
"SERVICE_UNAVAILABLE",
|
|
19
|
+
"SMART_ACCOUNT_UNAVAILABLE",
|
|
20
|
+
"STEP_UP_UNAVAILABLE",
|
|
21
|
+
"CAPITAL_VIEW_UNAVAILABLE",
|
|
22
|
+
"ACCOUNT_SHARD_UNAVAILABLE"
|
|
23
|
+
].includes(detail.code);
|
|
24
|
+
return false;
|
|
26
25
|
}
|
|
27
26
|
function safeRetryAfterMs(rateLimit) {
|
|
28
27
|
if (rateLimit?.retryAfterMs === void 0) return void 0;
|
|
@@ -42,14 +41,10 @@ function getNormalizedConnectMessage(err) {
|
|
|
42
41
|
const raw = ConnectError.from(err).message ?? "";
|
|
43
42
|
return normalizeErrorMessage(raw);
|
|
44
43
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
function detectMfaErrorKind(err) {
|
|
50
|
-
if (hasAuthErrorCode(err, 38)) return "session-elevation";
|
|
51
|
-
if (hasAuthErrorCode(err, 31)) return "step-up";
|
|
52
|
-
if (hasAuthErrorCode(err, 20)) return "enrollment";
|
|
44
|
+
function mfaErrorKind(detail) {
|
|
45
|
+
if (detail?.service === "auth" && detail.code === "AUTH_MFA_ELEVATION_REQUIRED") return "session-elevation";
|
|
46
|
+
if (detail?.service === "auth" && detail.code === "AUTH_STEP_UP_REQUIRED") return "step-up";
|
|
47
|
+
if (detail?.service === "auth" && detail.code === "AUTH_MFA_NOT_ENROLLED") return "enrollment";
|
|
53
48
|
return null;
|
|
54
49
|
}
|
|
55
50
|
function parseRetryAfterMs(ce) {
|
|
@@ -74,26 +69,31 @@ const MFA_ERROR_CLASSES = {
|
|
|
74
69
|
*/
|
|
75
70
|
function connectErrorToPolyesterError(ce) {
|
|
76
71
|
const message = getNormalizedConnectMessage(ce);
|
|
77
|
-
const
|
|
72
|
+
const detail = parseConnectErrorDetail(ce);
|
|
73
|
+
const options = {
|
|
74
|
+
cause: ce,
|
|
75
|
+
detail
|
|
76
|
+
};
|
|
78
77
|
const withFallback = (fallback) => message || fallback;
|
|
79
|
-
if (
|
|
80
|
-
if (
|
|
81
|
-
if (
|
|
82
|
-
if (
|
|
83
|
-
if (
|
|
84
|
-
if (
|
|
85
|
-
if (
|
|
86
|
-
const mfaVerificationReason = getMfaVerificationFailureReason(
|
|
78
|
+
if (detail?.service === "auth" && detail.code === "AUTH_RESOURCE_NOT_FOUND") return new ResourceNotFoundError(withFallback("Resource not found."), options);
|
|
79
|
+
if (detail?.service === "auth" && detail.code === "AUTH_REVISION_CONFLICT") return new RevisionConflictError(withFallback("Resource changed since it was last read."), options);
|
|
80
|
+
if (detail?.service === "auth" && detail.code === "AUTH_POLICY_IN_USE") return new PolicyInUseError(withFallback("Policy is still in use."), options);
|
|
81
|
+
if (detail?.service === "auth" && detail.code === "AUTH_POLICY_LOCKED") return new PolicyLockedError(withFallback("Policy is locked."), options);
|
|
82
|
+
if (detail?.service === "auth" && detail.code === "AUTH_POLICY_SCOPE_MISMATCH") return new PolicyScopeMismatchError(withFallback("Policy does not belong to the target account scope."), options);
|
|
83
|
+
if (detail?.service === "auth" && detail.code === "AUTH_MFA_LAST_FACTOR_REQUIRED") return new MfaLastFactorRequiredError(withFallback("At least one active MFA factor must remain enrolled."), options);
|
|
84
|
+
if (detail?.service === "auth" && detail.code === "AUTH_INTERNAL_ERROR") return new InternalServerError(withFallback("Internal server error."), options);
|
|
85
|
+
const mfaVerificationReason = getMfaVerificationFailureReason(detail);
|
|
87
86
|
if (mfaVerificationReason) return new MfaVerificationError(withFallback("MFA verification failed."), mfaVerificationReason, options);
|
|
88
|
-
const mfaKind =
|
|
87
|
+
const mfaKind = mfaErrorKind(detail);
|
|
89
88
|
if (mfaKind) return new MFA_ERROR_CLASSES[mfaKind](withFallback("Multi-factor authentication required."), options);
|
|
90
|
-
if (
|
|
91
|
-
const rateLimit =
|
|
92
|
-
if (rateLimit ||
|
|
89
|
+
if (detail?.service === "orders" && detail.code === "STALE_QUOTE") return new StaleQuoteError(withFallback("The submitted market quote is stale."), options);
|
|
90
|
+
const rateLimit = detail?.service === "orders" ? detail.rateLimit : void 0;
|
|
91
|
+
if (rateLimit || (detail?.service === "orders" || detail?.service === "withdraw" || detail?.service === "internal_transfer") && detail.code === "RATE_LIMIT_EXCEEDED") return new RateLimitError(withFallback("Rate limit exceeded."), {
|
|
93
92
|
...options,
|
|
94
93
|
rateLimit,
|
|
95
94
|
retryAfterMs: safeRetryAfterMs(rateLimit) ?? parseRetryAfterMs(ce)
|
|
96
95
|
});
|
|
96
|
+
if (hasTransientTransferError(detail)) return new ServiceUnavailableError(withFallback("Service unavailable."), options);
|
|
97
97
|
switch (ce.code) {
|
|
98
98
|
case Code.InvalidArgument:
|
|
99
99
|
case Code.OutOfRange: return new ValidationError(withFallback("Invalid request."), options);
|
|
@@ -114,12 +114,12 @@ function connectErrorToPolyesterError(ce) {
|
|
|
114
114
|
return new InternalServerError(withFallback("Internal server error."), options);
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
-
function getMfaVerificationFailureReason(
|
|
118
|
-
if (
|
|
119
|
-
if (
|
|
120
|
-
if (
|
|
121
|
-
if (
|
|
122
|
-
if (
|
|
117
|
+
function getMfaVerificationFailureReason(detail) {
|
|
118
|
+
if (detail?.service === "auth" && detail.code === "AUTH_MFA_CHALLENGE_INVALID") return "challenge-invalid";
|
|
119
|
+
if (detail?.service === "auth" && detail.code === "AUTH_MFA_CHALLENGE_LOCKED") return "challenge-locked";
|
|
120
|
+
if (detail?.service === "auth" && detail.code === "AUTH_MFA_OTP_INVALID") return "otp-invalid";
|
|
121
|
+
if (detail?.service === "auth" && detail.code === "AUTH_MFA_RECOVERY_INVALID") return "recovery-code-invalid";
|
|
122
|
+
if (detail?.service === "auth" && detail.code === "AUTH_MFA_PASSKEY_CREDENTIAL_INVALID" || detail?.service === "auth" && detail.code === "AUTH_MFA_PASSKEY_VERIFY_FAILED") return "passkey-invalid";
|
|
123
123
|
return null;
|
|
124
124
|
}
|
|
125
125
|
function findPolyesterErrorInCauseChain(err) {
|
|
@@ -199,6 +199,6 @@ function createErrorMappingTransport(transport) {
|
|
|
199
199
|
};
|
|
200
200
|
}
|
|
201
201
|
//#endregion
|
|
202
|
-
export { connectErrorToPolyesterError, createErrorMappingInterceptor, createErrorMappingTransport,
|
|
202
|
+
export { connectErrorToPolyesterError, createErrorMappingInterceptor, createErrorMappingTransport, getNormalizedConnectMessage, toPolyesterError };
|
|
203
203
|
|
|
204
204
|
//# sourceMappingURL=connect-error-mapping.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect-error-mapping.js","names":["OrderErrorDetailSchema"],"sources":["../../src/shared/connect-error-mapping.ts"],"sourcesContent":["import { Code, ConnectError, type Interceptor, type Transport } from \"@connectrpc/connect\";\nimport * as v from \"valibot\";\nimport { AuthErrorCode, AuthErrorDetailSchema } from \"../gen/auth/v1/auth_pb.js\";\nimport {\n ErrorCode as OrderErrorCode,\n ErrorDetailSchema as OrderErrorDetailSchema,\n} from \"../gen/orders/v1/orders_pb.js\";\nimport {\n AlreadyExistsError,\n AuthenticationError,\n InternalServerError,\n isAbortError,\n MfaEnrollmentRequiredError,\n MfaLastFactorRequiredError,\n MfaVerificationError,\n type MfaVerificationFailureReason,\n normalizeErrorMessage,\n PermissionError,\n PolicyInUseError,\n PolicyLockedError,\n PolicyScopeMismatchError,\n PolyesterError,\n type PolyesterErrorOptions,\n PreconditionFailedError,\n RateLimitError,\n ResourceNotFoundError,\n RevisionConflictError,\n ServiceUnavailableError,\n SessionElevationRequiredError,\n StaleQuoteError,\n StepUpRequiredError,\n TimeoutError,\n TransientError,\n ValidationError,\n} from \"./errors.js\";\nimport { RateLimitDetailSchema, type RateLimitDetail } from \"./rate-limit.schemas.js\";\n\nfunction getAuthErrorDetails(err: unknown) {\n return ConnectError.from(err).findDetails(AuthErrorDetailSchema);\n}\n\nfunction hasAuthErrorCode(err: unknown, code: AuthErrorCode): boolean {\n return getAuthErrorDetails(err).some((detail) => detail.code === code);\n}\n\nfunction hasOrderErrorCode(err: unknown, code: OrderErrorCode): boolean {\n return getOrderErrorDetails(err).some((detail) => detail.code === code);\n}\n\nfunction getOrderErrorDetails(err: unknown) {\n return ConnectError.from(err).findDetails(OrderErrorDetailSchema);\n}\n\nfunction getRateLimitDetail(err: unknown): RateLimitDetail | undefined {\n for (const orderDetail of getOrderErrorDetails(err)) {\n if (!orderDetail.rateLimit) continue;\n const result = v.safeParse(RateLimitDetailSchema, orderDetail.rateLimit);\n if (result.success) return result.output;\n }\n return undefined;\n}\n\nfunction safeRetryAfterMs(rateLimit: RateLimitDetail | undefined): number | undefined {\n if (rateLimit?.retryAfterMs === undefined) return undefined;\n const value = BigInt(rateLimit.retryAfterMs);\n return value <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(value) : undefined;\n}\n\nconst HTTP_WEEKDAY = \"(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\";\nconst HTTP_WEEKDAY_LONG = \"(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)\";\nconst HTTP_MONTH = \"(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\";\nconst HTTP_DATE_RE = new RegExp(\n `^(?:${HTTP_WEEKDAY}, \\\\d{2} ${HTTP_MONTH} \\\\d{4} \\\\d{2}:\\\\d{2}:\\\\d{2} GMT|${HTTP_WEEKDAY_LONG}, \\\\d{2}-${HTTP_MONTH}-\\\\d{2} \\\\d{2}:\\\\d{2}:\\\\d{2} GMT|${HTTP_WEEKDAY} ${HTTP_MONTH} {1,2}\\\\d{1,2} \\\\d{2}:\\\\d{2}:\\\\d{2} \\\\d{4})$`,\n \"u\",\n);\n\n/**\n * Returns the error message without the leading \"[code] \" prefix that\n * `ConnectError` prepends, e.g. \"[invalid_argument] Insufficient funds.\"\n * becomes \"Insufficient funds.\".\n */\nexport function getNormalizedConnectMessage(err: unknown): string {\n const ce = ConnectError.from(err);\n const raw = ce.message ?? \"\";\n return normalizeErrorMessage(raw);\n}\n\nexport type MfaErrorKind = \"session-elevation\" | \"enrollment\" | \"step-up\";\n\n/**\n * Classifies an error as one of the MFA flows the backend can demand.\n * Classification is based only on stable structured auth error details.\n */\nexport function detectMfaErrorKind(err: unknown): MfaErrorKind | null {\n if (hasAuthErrorCode(err, AuthErrorCode.AUTH_MFA_ELEVATION_REQUIRED)) {\n return \"session-elevation\";\n }\n if (hasAuthErrorCode(err, AuthErrorCode.AUTH_STEP_UP_REQUIRED)) return \"step-up\";\n if (hasAuthErrorCode(err, AuthErrorCode.AUTH_MFA_NOT_ENROLLED)) return \"enrollment\";\n return null;\n}\n\nfunction parseRetryAfterMs(ce: ConnectError): number | undefined {\n const value = ce.metadata.get(\"retry-after\");\n if (!value) return undefined;\n if (/^\\d+$/u.test(value)) {\n const seconds = BigInt(value);\n const maxSafeSeconds = BigInt(Math.floor(Number.MAX_SAFE_INTEGER / 1000));\n return seconds <= maxSafeSeconds ? Number(seconds) * 1000 : undefined;\n }\n if (!HTTP_DATE_RE.test(value)) return undefined;\n const date = Date.parse(value);\n if (!Number.isNaN(date)) return Math.max(0, date - Date.now());\n return undefined;\n}\n\nconst MFA_ERROR_CLASSES = {\n \"session-elevation\": SessionElevationRequiredError,\n enrollment: MfaEnrollmentRequiredError,\n \"step-up\": StepUpRequiredError,\n} as const;\n\n/**\n * Maps a `ConnectError` from the Polyester backend onto the typed\n * {@link PolyesterError} tree. The original error is preserved as `cause`.\n */\nexport function connectErrorToPolyesterError(ce: ConnectError): PolyesterError {\n const message = getNormalizedConnectMessage(ce);\n const options: PolyesterErrorOptions = { cause: ce };\n const withFallback = (fallback: string) => message || fallback;\n\n if (hasAuthErrorCode(ce, AuthErrorCode.AUTH_RESOURCE_NOT_FOUND)) {\n return new ResourceNotFoundError(withFallback(\"Resource not found.\"), options);\n }\n\n if (hasAuthErrorCode(ce, AuthErrorCode.AUTH_REVISION_CONFLICT)) {\n return new RevisionConflictError(\n withFallback(\"Resource changed since it was last read.\"),\n options,\n );\n }\n\n if (hasAuthErrorCode(ce, AuthErrorCode.AUTH_POLICY_IN_USE)) {\n return new PolicyInUseError(withFallback(\"Policy is still in use.\"), options);\n }\n if (hasAuthErrorCode(ce, AuthErrorCode.AUTH_POLICY_LOCKED)) {\n return new PolicyLockedError(withFallback(\"Policy is locked.\"), options);\n }\n if (hasAuthErrorCode(ce, AuthErrorCode.AUTH_POLICY_SCOPE_MISMATCH)) {\n return new PolicyScopeMismatchError(\n withFallback(\"Policy does not belong to the target account scope.\"),\n options,\n );\n }\n if (hasAuthErrorCode(ce, AuthErrorCode.AUTH_MFA_LAST_FACTOR_REQUIRED)) {\n return new MfaLastFactorRequiredError(\n withFallback(\"At least one active MFA factor must remain enrolled.\"),\n options,\n );\n }\n if (hasAuthErrorCode(ce, AuthErrorCode.AUTH_INTERNAL_ERROR)) {\n return new InternalServerError(withFallback(\"Internal server error.\"), options);\n }\n\n const mfaVerificationReason = getMfaVerificationFailureReason(ce);\n if (mfaVerificationReason) {\n return new MfaVerificationError(\n withFallback(\"MFA verification failed.\"),\n mfaVerificationReason,\n options,\n );\n }\n\n const mfaKind = detectMfaErrorKind(ce);\n if (mfaKind) {\n return new MFA_ERROR_CLASSES[mfaKind](\n withFallback(\"Multi-factor authentication required.\"),\n options,\n );\n }\n\n if (hasOrderErrorCode(ce, OrderErrorCode.STALE_QUOTE)) {\n return new StaleQuoteError(withFallback(\"The submitted market quote is stale.\"), options);\n }\n\n const rateLimit = getRateLimitDetail(ce);\n if (rateLimit || hasOrderErrorCode(ce, OrderErrorCode.RATE_LIMIT_EXCEEDED)) {\n return new RateLimitError(withFallback(\"Rate limit exceeded.\"), {\n ...options,\n rateLimit,\n retryAfterMs: safeRetryAfterMs(rateLimit) ?? parseRetryAfterMs(ce),\n });\n }\n\n switch (ce.code) {\n case Code.InvalidArgument:\n case Code.OutOfRange:\n return new ValidationError(withFallback(\"Invalid request.\"), options);\n case Code.NotFound:\n return new ResourceNotFoundError(withFallback(\"Resource not found.\"), options);\n case Code.AlreadyExists:\n return new AlreadyExistsError(withFallback(\"Resource already exists.\"), options);\n case Code.PermissionDenied:\n return new PermissionError(withFallback(\"Permission denied.\"), options);\n case Code.Unauthenticated:\n return new AuthenticationError(withFallback(\"Authentication required.\"), options);\n case Code.FailedPrecondition:\n return new PreconditionFailedError(withFallback(\"Precondition failed.\"), options);\n case Code.ResourceExhausted:\n return new RateLimitError(withFallback(\"Rate limit exceeded.\"), {\n ...options,\n retryAfterMs: parseRetryAfterMs(ce),\n });\n case Code.DeadlineExceeded:\n return new TimeoutError(withFallback(\"Request timed out.\"), options);\n case Code.Unavailable:\n return new ServiceUnavailableError(withFallback(\"Service unavailable.\"), options);\n case Code.Aborted:\n return new TransientError(withFallback(\"Operation aborted by the backend.\"), options);\n default:\n // Gateways sometimes surface outages as Unknown with this stock phrase.\n if (/service temporarily unavailable/i.test(message)) {\n return new ServiceUnavailableError(withFallback(\"Service unavailable.\"), options);\n }\n return new InternalServerError(withFallback(\"Internal server error.\"), options);\n }\n}\n\nfunction getMfaVerificationFailureReason(err: unknown): MfaVerificationFailureReason | null {\n if (hasAuthErrorCode(err, AuthErrorCode.AUTH_MFA_CHALLENGE_INVALID)) {\n return \"challenge-invalid\";\n }\n if (hasAuthErrorCode(err, AuthErrorCode.AUTH_MFA_CHALLENGE_LOCKED)) {\n return \"challenge-locked\";\n }\n if (hasAuthErrorCode(err, AuthErrorCode.AUTH_MFA_OTP_INVALID)) return \"otp-invalid\";\n if (hasAuthErrorCode(err, AuthErrorCode.AUTH_MFA_RECOVERY_INVALID)) {\n return \"recovery-code-invalid\";\n }\n if (\n hasAuthErrorCode(err, AuthErrorCode.AUTH_MFA_PASSKEY_CREDENTIAL_INVALID) ||\n hasAuthErrorCode(err, AuthErrorCode.AUTH_MFA_PASSKEY_VERIFY_FAILED)\n ) {\n return \"passkey-invalid\";\n }\n\n return null;\n}\n\nfunction findPolyesterErrorInCauseChain(err: unknown): PolyesterError | null {\n let current: unknown = err;\n for (let depth = 0; depth < 5 && current instanceof Error; depth++) {\n current = current.cause;\n if (current instanceof PolyesterError) return current;\n }\n return null;\n}\n\n/**\n * Converts any RPC-layer failure into its typed SDK error. Abort errors and\n * caller-cancelled requests pass through unchanged, as do errors that are\n * already typed (e.g. a `NetworkError` from the SDK fetch wrapper).\n */\nexport function toPolyesterError(err: unknown): unknown {\n if (err instanceof PolyesterError) return err;\n if (isAbortError(err)) return err;\n if (err instanceof ConnectError) {\n if (err.code === Code.Canceled) return err;\n const wrapped = findPolyesterErrorInCauseChain(err);\n if (wrapped) return wrapped;\n return connectErrorToPolyesterError(err);\n }\n return err;\n}\n\nasync function* mapStreamErrors<T>(source: AsyncIterable<T>): AsyncIterable<T> {\n try {\n yield* source;\n } catch (err) {\n throw toPolyesterError(err);\n }\n}\n\n/**\n * Interceptor that converts every RPC failure (unary and streaming) into the\n * typed {@link PolyesterError} hierarchy. Installed outermost by\n * `createTransports`, so callers of SDK services always see typed errors.\n */\nexport function createErrorMappingInterceptor(): Interceptor {\n return (next) => async (req) => {\n try {\n const res = await next(req);\n if (res.stream) {\n return { ...res, message: mapStreamErrors(res.message) };\n }\n return res;\n } catch (err) {\n throw toPolyesterError(err);\n }\n };\n}\n\n/**\n * Wraps a Connect transport so errors are translated after Connect's call\n * runner has applied its own error normalization.\n */\nexport function createErrorMappingTransport(transport: Transport): Transport {\n return {\n async unary(method, signal, timeoutMs, header, input, contextValues) {\n try {\n return await transport.unary(\n method,\n signal,\n timeoutMs,\n header,\n input,\n contextValues,\n );\n } catch (error) {\n throw toPolyesterError(error);\n }\n },\n async stream(method, signal, timeoutMs, header, input, contextValues) {\n try {\n const response = await transport.stream(\n method,\n signal,\n timeoutMs,\n header,\n input,\n contextValues,\n );\n return { ...response, message: mapStreamErrors(response.message) };\n } catch (error) {\n throw toPolyesterError(error);\n }\n },\n };\n}\n"],"mappings":";;;;;;;AAqCA,SAAS,oBAAoB,KAAc;CACvC,OAAO,aAAa,KAAK,GAAG,CAAC,CAAC,YAAY,qBAAqB;AACnE;AAEA,SAAS,iBAAiB,KAAc,MAA8B;CAClE,OAAO,oBAAoB,GAAG,CAAC,CAAC,MAAM,WAAW,OAAO,SAAS,IAAI;AACz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AC9B;CACJ;AACJ;;;;;AAMA,SAAgB,4BAA4B,WAAiC;CACzE,OAAO;EACH,MAAM,MAAM,QAAQ,QAAQ,WAAW,QAAQ,OAAO,eAAe;GACjE,IAAI;IACA,OAAO,MAAM,UAAU,MACnB,QACA,QACA,WACA,QACA,OACA,aACJ;GACJ,SAAS,OAAO;IACZ,MAAM,iBAAiB,KAAK;GAChC;EACJ;EACA,MAAM,OAAO,QAAQ,QAAQ,WAAW,QAAQ,OAAO,eAAe;GAClE,IAAI;IACA,MAAM,WAAW,MAAM,UAAU,OAC7B,QACA,QACA,WACA,QACA,OACA,aACJ;IACA,OAAO;KAAE,GAAG;KAAU,SAAS,gBAAgB,SAAS,OAAO;IAAE;GACrE,SAAS,OAAO;IACZ,MAAM,iBAAiB,KAAK;GAChC;EACJ;CACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"connect-error-mapping.js","names":[],"sources":["../../src/shared/connect-error-mapping.ts"],"sourcesContent":["import { Code, ConnectError, type Interceptor, type Transport } from \"@connectrpc/connect\";\nimport { parseConnectErrorDetail, type PolyesterErrorDetail } from \"./error-detail.js\";\nimport {\n AlreadyExistsError,\n AuthenticationError,\n InternalServerError,\n isAbortError,\n MfaEnrollmentRequiredError,\n MfaLastFactorRequiredError,\n MfaVerificationError,\n type MfaVerificationFailureReason,\n normalizeErrorMessage,\n PermissionError,\n PolicyInUseError,\n PolicyLockedError,\n PolicyScopeMismatchError,\n PolyesterError,\n type PolyesterErrorOptions,\n PreconditionFailedError,\n RateLimitError,\n ResourceNotFoundError,\n RevisionConflictError,\n ServiceUnavailableError,\n SessionElevationRequiredError,\n StaleQuoteError,\n StepUpRequiredError,\n TimeoutError,\n TransientError,\n ValidationError,\n} from \"./errors.js\";\nimport type { RateLimitDetail } from \"./rate-limit.schemas.js\";\n\nfunction hasTransientTransferError(detail: PolyesterErrorDetail | undefined): boolean {\n if (detail?.service === \"withdraw\") {\n return [\n \"SERVICE_UNAVAILABLE\",\n \"SOURCE_SMART_ACCOUNT_UNAVAILABLE\",\n \"CAPITAL_VIEW_UNAVAILABLE\",\n \"CHAIN_METADATA_UNAVAILABLE\",\n \"FEE_UNAVAILABLE\",\n \"SUPPLY_UNAVAILABLE\",\n \"STEP_UP_UNAVAILABLE\",\n \"DESTINATION_VALIDATION_UNAVAILABLE\",\n \"ACCOUNT_SHARD_UNAVAILABLE\",\n ].includes(detail.code);\n }\n if (detail?.service === \"internal_transfer\") {\n return [\n \"SERVICE_UNAVAILABLE\",\n \"SMART_ACCOUNT_UNAVAILABLE\",\n \"STEP_UP_UNAVAILABLE\",\n \"CAPITAL_VIEW_UNAVAILABLE\",\n \"ACCOUNT_SHARD_UNAVAILABLE\",\n ].includes(detail.code);\n }\n return false;\n}\n\nfunction safeRetryAfterMs(rateLimit: RateLimitDetail | undefined): number | undefined {\n if (rateLimit?.retryAfterMs === undefined) return undefined;\n const value = BigInt(rateLimit.retryAfterMs);\n return value <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(value) : undefined;\n}\n\nconst HTTP_WEEKDAY = \"(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\";\nconst HTTP_WEEKDAY_LONG = \"(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)\";\nconst HTTP_MONTH = \"(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\";\nconst HTTP_DATE_RE = new RegExp(\n `^(?:${HTTP_WEEKDAY}, \\\\d{2} ${HTTP_MONTH} \\\\d{4} \\\\d{2}:\\\\d{2}:\\\\d{2} GMT|${HTTP_WEEKDAY_LONG}, \\\\d{2}-${HTTP_MONTH}-\\\\d{2} \\\\d{2}:\\\\d{2}:\\\\d{2} GMT|${HTTP_WEEKDAY} ${HTTP_MONTH} {1,2}\\\\d{1,2} \\\\d{2}:\\\\d{2}:\\\\d{2} \\\\d{4})$`,\n \"u\",\n);\n\n/**\n * Returns the error message without the leading \"[code] \" prefix that\n * `ConnectError` prepends, e.g. \"[invalid_argument] Insufficient funds.\"\n * becomes \"Insufficient funds.\".\n */\nexport function getNormalizedConnectMessage(err: unknown): string {\n const ce = ConnectError.from(err);\n const raw = ce.message ?? \"\";\n return normalizeErrorMessage(raw);\n}\n\nexport type MfaErrorKind = \"session-elevation\" | \"enrollment\" | \"step-up\";\n\n/**\n * Classifies an error as one of the MFA flows the backend can demand.\n * Classification is based only on stable structured auth error details.\n */\nexport function detectMfaErrorKind(err: unknown): MfaErrorKind | null {\n const mapped = toPolyesterError(err);\n return mfaErrorKind(mapped instanceof PolyesterError ? mapped.detail : undefined);\n}\n\nfunction mfaErrorKind(detail: PolyesterErrorDetail | undefined): MfaErrorKind | null {\n if (detail?.service === \"auth\" && detail.code === \"AUTH_MFA_ELEVATION_REQUIRED\") {\n return \"session-elevation\";\n }\n if (detail?.service === \"auth\" && detail.code === \"AUTH_STEP_UP_REQUIRED\") return \"step-up\";\n if (detail?.service === \"auth\" && detail.code === \"AUTH_MFA_NOT_ENROLLED\") return \"enrollment\";\n return null;\n}\n\nfunction parseRetryAfterMs(ce: ConnectError): number | undefined {\n const value = ce.metadata.get(\"retry-after\");\n if (!value) return undefined;\n if (/^\\d+$/u.test(value)) {\n const seconds = BigInt(value);\n const maxSafeSeconds = BigInt(Math.floor(Number.MAX_SAFE_INTEGER / 1000));\n return seconds <= maxSafeSeconds ? Number(seconds) * 1000 : undefined;\n }\n if (!HTTP_DATE_RE.test(value)) return undefined;\n const date = Date.parse(value);\n if (!Number.isNaN(date)) return Math.max(0, date - Date.now());\n return undefined;\n}\n\nconst MFA_ERROR_CLASSES = {\n \"session-elevation\": SessionElevationRequiredError,\n enrollment: MfaEnrollmentRequiredError,\n \"step-up\": StepUpRequiredError,\n} as const;\n\n/**\n * Maps a `ConnectError` from the Polyester backend onto the typed\n * {@link PolyesterError} tree. The original error is preserved as `cause`.\n */\nexport function connectErrorToPolyesterError(ce: ConnectError): PolyesterError {\n const message = getNormalizedConnectMessage(ce);\n const detail = parseConnectErrorDetail(ce);\n const options: PolyesterErrorOptions = { cause: ce, detail };\n const withFallback = (fallback: string) => message || fallback;\n\n if (detail?.service === \"auth\" && detail.code === \"AUTH_RESOURCE_NOT_FOUND\") {\n return new ResourceNotFoundError(withFallback(\"Resource not found.\"), options);\n }\n\n if (detail?.service === \"auth\" && detail.code === \"AUTH_REVISION_CONFLICT\") {\n return new RevisionConflictError(\n withFallback(\"Resource changed since it was last read.\"),\n options,\n );\n }\n\n if (detail?.service === \"auth\" && detail.code === \"AUTH_POLICY_IN_USE\") {\n return new PolicyInUseError(withFallback(\"Policy is still in use.\"), options);\n }\n if (detail?.service === \"auth\" && detail.code === \"AUTH_POLICY_LOCKED\") {\n return new PolicyLockedError(withFallback(\"Policy is locked.\"), options);\n }\n if (detail?.service === \"auth\" && detail.code === \"AUTH_POLICY_SCOPE_MISMATCH\") {\n return new PolicyScopeMismatchError(\n withFallback(\"Policy does not belong to the target account scope.\"),\n options,\n );\n }\n if (detail?.service === \"auth\" && detail.code === \"AUTH_MFA_LAST_FACTOR_REQUIRED\") {\n return new MfaLastFactorRequiredError(\n withFallback(\"At least one active MFA factor must remain enrolled.\"),\n options,\n );\n }\n if (detail?.service === \"auth\" && detail.code === \"AUTH_INTERNAL_ERROR\") {\n return new InternalServerError(withFallback(\"Internal server error.\"), options);\n }\n\n const mfaVerificationReason = getMfaVerificationFailureReason(detail);\n if (mfaVerificationReason) {\n return new MfaVerificationError(\n withFallback(\"MFA verification failed.\"),\n mfaVerificationReason,\n options,\n );\n }\n\n const mfaKind = mfaErrorKind(detail);\n if (mfaKind) {\n return new MFA_ERROR_CLASSES[mfaKind](\n withFallback(\"Multi-factor authentication required.\"),\n options,\n );\n }\n\n if (detail?.service === \"orders\" && detail.code === \"STALE_QUOTE\") {\n return new StaleQuoteError(withFallback(\"The submitted market quote is stale.\"), options);\n }\n\n const rateLimit = detail?.service === \"orders\" ? detail.rateLimit : undefined;\n if (\n rateLimit ||\n ((detail?.service === \"orders\" ||\n detail?.service === \"withdraw\" ||\n detail?.service === \"internal_transfer\") &&\n detail.code === \"RATE_LIMIT_EXCEEDED\")\n ) {\n return new RateLimitError(withFallback(\"Rate limit exceeded.\"), {\n ...options,\n rateLimit,\n retryAfterMs: safeRetryAfterMs(rateLimit) ?? parseRetryAfterMs(ce),\n });\n }\n\n if (hasTransientTransferError(detail)) {\n return new ServiceUnavailableError(withFallback(\"Service unavailable.\"), options);\n }\n\n switch (ce.code) {\n case Code.InvalidArgument:\n case Code.OutOfRange:\n return new ValidationError(withFallback(\"Invalid request.\"), options);\n case Code.NotFound:\n return new ResourceNotFoundError(withFallback(\"Resource not found.\"), options);\n case Code.AlreadyExists:\n return new AlreadyExistsError(withFallback(\"Resource already exists.\"), options);\n case Code.PermissionDenied:\n return new PermissionError(withFallback(\"Permission denied.\"), options);\n case Code.Unauthenticated:\n return new AuthenticationError(withFallback(\"Authentication required.\"), options);\n case Code.FailedPrecondition:\n return new PreconditionFailedError(withFallback(\"Precondition failed.\"), options);\n case Code.ResourceExhausted:\n return new RateLimitError(withFallback(\"Rate limit exceeded.\"), {\n ...options,\n retryAfterMs: parseRetryAfterMs(ce),\n });\n case Code.DeadlineExceeded:\n return new TimeoutError(withFallback(\"Request timed out.\"), options);\n case Code.Unavailable:\n return new ServiceUnavailableError(withFallback(\"Service unavailable.\"), options);\n case Code.Aborted:\n return new TransientError(withFallback(\"Operation aborted by the backend.\"), options);\n default:\n // Gateways sometimes surface outages as Unknown with this stock phrase.\n if (/service temporarily unavailable/i.test(message)) {\n return new ServiceUnavailableError(withFallback(\"Service unavailable.\"), options);\n }\n return new InternalServerError(withFallback(\"Internal server error.\"), options);\n }\n}\n\nfunction getMfaVerificationFailureReason(\n detail: PolyesterErrorDetail | undefined,\n): MfaVerificationFailureReason | null {\n if (detail?.service === \"auth\" && detail.code === \"AUTH_MFA_CHALLENGE_INVALID\") {\n return \"challenge-invalid\";\n }\n if (detail?.service === \"auth\" && detail.code === \"AUTH_MFA_CHALLENGE_LOCKED\") {\n return \"challenge-locked\";\n }\n if (detail?.service === \"auth\" && detail.code === \"AUTH_MFA_OTP_INVALID\") return \"otp-invalid\";\n if (detail?.service === \"auth\" && detail.code === \"AUTH_MFA_RECOVERY_INVALID\") {\n return \"recovery-code-invalid\";\n }\n if (\n (detail?.service === \"auth\" && detail.code === \"AUTH_MFA_PASSKEY_CREDENTIAL_INVALID\") ||\n (detail?.service === \"auth\" && detail.code === \"AUTH_MFA_PASSKEY_VERIFY_FAILED\")\n ) {\n return \"passkey-invalid\";\n }\n\n return null;\n}\n\nfunction findPolyesterErrorInCauseChain(err: unknown): PolyesterError | null {\n let current: unknown = err;\n for (let depth = 0; depth < 5 && current instanceof Error; depth++) {\n current = current.cause;\n if (current instanceof PolyesterError) return current;\n }\n return null;\n}\n\n/**\n * Converts any RPC-layer failure into its typed SDK error. Abort errors and\n * caller-cancelled requests pass through unchanged, as do errors that are\n * already typed (e.g. a `NetworkError` from the SDK fetch wrapper).\n */\nexport function toPolyesterError(err: unknown): unknown {\n if (err instanceof PolyesterError) return err;\n if (isAbortError(err)) return err;\n if (err instanceof ConnectError) {\n if (err.code === Code.Canceled) return err;\n const wrapped = findPolyesterErrorInCauseChain(err);\n if (wrapped) return wrapped;\n return connectErrorToPolyesterError(err);\n }\n return err;\n}\n\nasync function* mapStreamErrors<T>(source: AsyncIterable<T>): AsyncIterable<T> {\n try {\n yield* source;\n } catch (err) {\n throw toPolyesterError(err);\n }\n}\n\n/**\n * Interceptor that converts every RPC failure (unary and streaming) into the\n * typed {@link PolyesterError} hierarchy. Installed outermost by\n * `createTransports`, so callers of SDK services always see typed errors.\n */\nexport function createErrorMappingInterceptor(): Interceptor {\n return (next) => async (req) => {\n try {\n const res = await next(req);\n if (res.stream) {\n return { ...res, message: mapStreamErrors(res.message) };\n }\n return res;\n } catch (err) {\n throw toPolyesterError(err);\n }\n };\n}\n\n/**\n * Wraps a Connect transport so errors are translated after Connect's call\n * runner has applied its own error normalization.\n */\nexport function createErrorMappingTransport(transport: Transport): Transport {\n return {\n async unary(method, signal, timeoutMs, header, input, contextValues) {\n try {\n return await transport.unary(\n method,\n signal,\n timeoutMs,\n header,\n input,\n contextValues,\n );\n } catch (error) {\n throw toPolyesterError(error);\n }\n },\n async stream(method, signal, timeoutMs, header, input, contextValues) {\n try {\n const response = await transport.stream(\n method,\n signal,\n timeoutMs,\n header,\n input,\n contextValues,\n );\n return { ...response, message: mapStreamErrors(response.message) };\n } catch (error) {\n throw toPolyesterError(error);\n }\n },\n };\n}\n"],"mappings":";;;;AAgCA,SAAS,0BAA0B,QAAmD;CAClF,IAAI,QAAQ,YAAY,YACpB,OAAO;EACH;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACJ,CAAC,CAAC,SAAS,OAAO,IAAI;CAE1B,IAAI,QAAQ,YAAY,qBACpB,OAAO;EACH;EACA;EACA;EACA;EACA;CACJ,CAAC,CAAC,SAAS,OAAO,IAAI;CAE1B,OAAO;AACX;AAEA,SAAS,iBAAiB,WAA4D;CAClF,IAAI,WAAW,iBAAiB,KAAA,GAAW,OAAO,KAAA;CAClD,MAAM,QAAQ,OAAO,UAAU,YAAY;CAC3C,OAAO,SAAS,OAAO,OAAO,gBAAgB,IAAI,OAAO,KAAK,IAAI,KAAA;AACtE;AAEA,MAAM,eAAe;AACrB,MAAM,oBAAoB;AAC1B,MAAM,aAAa;AACnB,MAAM,eAAe,IAAI,OACrB,OAAO,aAAa,WAAW,WAAW,mCAAmC,kBAAkB,WAAW,WAAW,mCAAmC,aAAa,GAAG,WAAW,+CACnL,GACJ;;;;;;AAOA,SAAgB,4BAA4B,KAAsB;CAE9D,MAAM,MADK,aAAa,KAAK,GAChB,CAAC,CAAC,WAAW;CAC1B,OAAO,sBAAsB,GAAG;AACpC;AAaA,SAAS,aAAa,QAA+D;CACjF,IAAI,QAAQ,YAAY,UAAU,OAAO,SAAS,+BAC9C,OAAO;CAEX,IAAI,QAAQ,YAAY,UAAU,OAAO,SAAS,yBAAyB,OAAO;CAClF,IAAI,Q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a,GAAG,GAAG,OAAO;CAC9B,IAAI,eAAe,cAAc;EAC7B,IAAI,IAAI,SAAS,KAAK,UAAU,OAAO;EACvC,MAAM,UAAU,+BAA+B,GAAG;EAClD,IAAI,SAAS,OAAO;EACpB,OAAO,6BAA6B,GAAG;CAC3C;CACA,OAAO;AACX;AAEA,gBAAgB,gBAAmB,QAA4C;CAC3E,IAAI;EACA,OAAO;CACX,SAAS,KAAK;EACV,MAAM,iBAAiB,GAAG;CAC9B;AACJ;;;;;;AAOA,SAAgB,gCAA6C;CACzD,QAAQ,SAAS,OAAO,QAAQ;EAC5B,IAAI;GACA,MAAM,MAAM,MAAM,KAAK,GAAG;GAC1B,IAAI,IAAI,QACJ,OAAO;IAAE,GAAG;IAAK,SAAS,gBAAgB,IAAI,OAAO;GAAE;GAE3D,OAAO;EACX,SAAS,KAAK;GACV,MAAM,iBAAiB,GAAG;EAC9B;CACJ;AACJ;;;;;AAMA,SAAgB,4BAA4B,WAAiC;CACzE,OAAO;EACH,MAAM,MAAM,QAAQ,QAAQ,WAAW,QAAQ,OAAO,eAAe;GACjE,IAAI;IACA,OAAO,MAAM,UAAU,MACnB,QACA,QACA,WACA,QACA,OACA,aACJ;GACJ,SAAS,OAAO;IACZ,MAAM,iBAAiB,KAAK;GAChC;EACJ;EACA,MAAM,OAAO,QAAQ,QAAQ,WAAW,QAAQ,OAAO,eAAe;GAClE,IAAI;IACA,MAAM,WAAW,MAAM,UAAU,OAC7B,QACA,QACA,WACA,QACA,OACA,aACJ;IACA,OAAO;KAAE,GAAG;KAAU,SAAS,gBAAgB,SAAS,OAAO;IAAE;GACrE,SAAS,OAAO;IACZ,MAAM,iBAAiB,KAAK;GAChC;EACJ;CACJ;AACJ"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AuthErrorCode } from "../gen/auth/v1/auth_pb.js";
|
|
2
|
+
import { ProfileErrorCode } from "../gen/auth/v1/profile_pb.js";
|
|
3
|
+
import { ErrorCode } from "../gen/chain/withdraw/v1/withdraw_pb.js";
|
|
4
|
+
import { ErrorCode as ErrorCode$1 } from "../gen/ledger/read/v1/ledger_read_pb.js";
|
|
5
|
+
import { ErrorCode as ErrorCode$2 } from "../gen/marketoverview/v1/marketoverview_pb.js";
|
|
6
|
+
import { ErrorCode as ErrorCode$3 } from "../gen/transfer/v1/internal_transfer_pb.js";
|
|
7
|
+
import { OrderErrorDetail } from "../services/orders/order-errors.schemas.js";
|
|
8
|
+
import { ConnectError } from "@connectrpc/connect";
|
|
9
|
+
//#region src/shared/error-detail.d.ts
|
|
10
|
+
type NamedCode<Enum extends Record<number, string>> = keyof Enum;
|
|
11
|
+
type PolyesterErrorDetail = {
|
|
12
|
+
service: "auth";
|
|
13
|
+
code: NamedCode<typeof AuthErrorCode>;
|
|
14
|
+
message: string;
|
|
15
|
+
} | {
|
|
16
|
+
service: "profile";
|
|
17
|
+
code: NamedCode<typeof ProfileErrorCode>;
|
|
18
|
+
field: string;
|
|
19
|
+
message: string;
|
|
20
|
+
} | ({
|
|
21
|
+
service: "orders";
|
|
22
|
+
} & OrderErrorDetail) | {
|
|
23
|
+
service: "withdraw";
|
|
24
|
+
code: NamedCode<typeof ErrorCode>;
|
|
25
|
+
} | {
|
|
26
|
+
service: "internal_transfer";
|
|
27
|
+
code: NamedCode<typeof ErrorCode$3>;
|
|
28
|
+
} | {
|
|
29
|
+
service: "ledger";
|
|
30
|
+
code: NamedCode<typeof ErrorCode$1>;
|
|
31
|
+
} | {
|
|
32
|
+
service: "market_overview";
|
|
33
|
+
code: NamedCode<typeof ErrorCode$2>;
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
export { PolyesterErrorDetail };
|
|
37
|
+
//# sourceMappingURL=error-detail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-detail.d.ts","names":[],"sources":["../../src/shared/error-detail.ts"],"mappings":";;;;;;;;;KAiCK,UAAU,aAAa,gCAAgC;KAEhD;EACJ;EAAiB,MAAM,iBAAiB;EAAgB;;EAEtD;EACA,MAAM,iBAAiB;EACvB;EACA;;EAED;IAAsB;EACvB;EAAqB,MAAM,iBAAiB;;EAE1C;EACA,MAAM,iBAAiB;;EAEzB;EAAmB,MAAM,iBAAiB;;EAExC;EACA,MAAM,iBAAiB"}
|