@lifi/composer-sdk 0.7.1 → 0.9.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.
Files changed (165) hide show
  1. package/README.md +5 -2
  2. package/dist/_virtual/_rolldown/runtime.cjs +33 -0
  3. package/dist/_virtual/_rolldown/runtime.js +13 -0
  4. package/dist/authoring/FlowBuilderCore.cjs +102 -120
  5. package/dist/authoring/FlowBuilderCore.cjs.map +1 -1
  6. package/dist/authoring/FlowBuilderCore.d.cts +58 -61
  7. package/dist/authoring/FlowBuilderCore.d.ts +58 -61
  8. package/dist/authoring/FlowBuilderCore.js +99 -97
  9. package/dist/authoring/FlowBuilderCore.js.map +1 -1
  10. package/dist/authoring/handles.cjs +25 -40
  11. package/dist/authoring/handles.cjs.map +1 -1
  12. package/dist/authoring/handles.d.cts +33 -34
  13. package/dist/authoring/handles.d.ts +33 -34
  14. package/dist/authoring/handles.js +21 -13
  15. package/dist/authoring/handles.js.map +1 -1
  16. package/dist/authoring/raw.cjs +85 -44
  17. package/dist/authoring/raw.cjs.map +1 -1
  18. package/dist/authoring/raw.d.cts +8 -8
  19. package/dist/authoring/raw.d.ts +8 -8
  20. package/dist/authoring/raw.js +83 -19
  21. package/dist/authoring/raw.js.map +1 -1
  22. package/dist/authoring/signatureArgs.cjs +81 -103
  23. package/dist/authoring/signatureArgs.cjs.map +1 -1
  24. package/dist/authoring/signatureArgs.d.cts +63 -64
  25. package/dist/authoring/signatureArgs.d.ts +63 -64
  26. package/dist/authoring/signatureArgs.js +76 -75
  27. package/dist/authoring/signatureArgs.js.map +1 -1
  28. package/dist/client.cjs +172 -220
  29. package/dist/client.cjs.map +1 -1
  30. package/dist/client.d.cts +131 -131
  31. package/dist/client.d.ts +131 -131
  32. package/dist/client.js +165 -198
  33. package/dist/client.js.map +1 -1
  34. package/dist/discovery.cjs +0 -17
  35. package/dist/discovery.d.cts +57 -56
  36. package/dist/discovery.d.ts +57 -56
  37. package/dist/discovery.js +1 -1
  38. package/dist/errors.cjs +211 -159
  39. package/dist/errors.cjs.map +1 -1
  40. package/dist/errors.d.cts +84 -84
  41. package/dist/errors.d.ts +84 -84
  42. package/dist/errors.js +201 -120
  43. package/dist/errors.js.map +1 -1
  44. package/dist/generated/config.generated.cjs +0 -17
  45. package/dist/generated/config.generated.d.cts +805 -895
  46. package/dist/generated/config.generated.d.ts +805 -895
  47. package/dist/generated/config.generated.js +1 -1
  48. package/dist/generated/guards.generated.cjs +27 -31
  49. package/dist/generated/guards.generated.cjs.map +1 -1
  50. package/dist/generated/guards.generated.d.cts +20 -4
  51. package/dist/generated/guards.generated.d.ts +20 -4
  52. package/dist/generated/guards.generated.js +21 -8
  53. package/dist/generated/guards.generated.js.map +1 -1
  54. package/dist/generated/materialisers.generated.cjs +25 -35
  55. package/dist/generated/materialisers.generated.cjs.map +1 -1
  56. package/dist/generated/materialisers.generated.d.cts +17 -4
  57. package/dist/generated/materialisers.generated.d.ts +17 -4
  58. package/dist/generated/materialisers.generated.js +19 -11
  59. package/dist/generated/materialisers.generated.js.map +1 -1
  60. package/dist/generated/operations.generated.cjs +236 -250
  61. package/dist/generated/operations.generated.cjs.map +1 -1
  62. package/dist/generated/operations.generated.d.cts +740 -657
  63. package/dist/generated/operations.generated.d.ts +740 -657
  64. package/dist/generated/operations.generated.js +235 -229
  65. package/dist/generated/operations.generated.js.map +1 -1
  66. package/dist/generated/preconditions.generated.cjs +25 -35
  67. package/dist/generated/preconditions.generated.cjs.map +1 -1
  68. package/dist/generated/preconditions.generated.d.cts +17 -4
  69. package/dist/generated/preconditions.generated.d.ts +17 -4
  70. package/dist/generated/preconditions.generated.js +19 -11
  71. package/dist/generated/preconditions.generated.js.map +1 -1
  72. package/dist/index.cjs +131 -97
  73. package/dist/index.cjs.map +1 -1
  74. package/dist/index.d.cts +29 -43
  75. package/dist/index.d.ts +29 -43
  76. package/dist/index.js +96 -45
  77. package/dist/index.js.map +1 -1
  78. package/dist/outputs.cjs +11 -32
  79. package/dist/outputs.cjs.map +1 -1
  80. package/dist/outputs.d.cts +5 -5
  81. package/dist/outputs.d.ts +5 -5
  82. package/dist/outputs.js +10 -8
  83. package/dist/outputs.js.map +1 -1
  84. package/dist/raw.cjs +21 -33
  85. package/dist/raw.cjs.map +1 -1
  86. package/dist/raw.d.cts +8 -4
  87. package/dist/raw.d.ts +8 -4
  88. package/dist/raw.js +12 -7
  89. package/dist/raw.js.map +1 -1
  90. package/dist/reachability.cjs +82 -112
  91. package/dist/reachability.cjs.map +1 -1
  92. package/dist/reachability.d.cts +33 -59
  93. package/dist/reachability.d.ts +33 -59
  94. package/dist/reachability.js +81 -88
  95. package/dist/reachability.js.map +1 -1
  96. package/dist/resources.cjs +47 -32
  97. package/dist/resources.cjs.map +1 -1
  98. package/dist/resources.d.cts +50 -3
  99. package/dist/resources.d.ts +50 -3
  100. package/dist/resources.js +42 -9
  101. package/dist/resources.js.map +1 -1
  102. package/dist/responseSchemas.cjs +99 -111
  103. package/dist/responseSchemas.cjs.map +1 -1
  104. package/dist/responseSchemas.d.cts +34 -34
  105. package/dist/responseSchemas.d.ts +34 -34
  106. package/dist/responseSchemas.js +85 -66
  107. package/dist/responseSchemas.js.map +1 -1
  108. package/dist/routeAmount.cjs +61 -31
  109. package/dist/routeAmount.cjs.map +1 -1
  110. package/dist/routeAmount.d.cts +52 -2
  111. package/dist/routeAmount.d.ts +52 -2
  112. package/dist/routeAmount.js +56 -8
  113. package/dist/routeAmount.js.map +1 -1
  114. package/dist/run/inputs.cjs +56 -48
  115. package/dist/run/inputs.cjs.map +1 -1
  116. package/dist/run/inputs.d.cts +70 -74
  117. package/dist/run/inputs.d.ts +70 -74
  118. package/dist/run/inputs.js +54 -23
  119. package/dist/run/inputs.js.map +1 -1
  120. package/dist/run/simulate.cjs +38 -43
  121. package/dist/run/simulate.cjs.map +1 -1
  122. package/dist/run/simulate.d.cts +36 -36
  123. package/dist/run/simulate.d.ts +36 -36
  124. package/dist/run/simulate.js +37 -19
  125. package/dist/run/simulate.js.map +1 -1
  126. package/dist/sdk.cjs +55 -66
  127. package/dist/sdk.cjs.map +1 -1
  128. package/dist/sdk.d.cts +108 -111
  129. package/dist/sdk.d.ts +108 -111
  130. package/dist/sdk.js +52 -44
  131. package/dist/sdk.js.map +1 -1
  132. package/dist/types.cjs +0 -17
  133. package/dist/types.d.cts +22 -22
  134. package/dist/types.d.ts +22 -22
  135. package/dist/types.js +1 -1
  136. package/package.json +4 -4
  137. package/src/client.ts +2 -2
  138. package/src/examples/aaveClaimRewards.ts +2 -1
  139. package/src/examples/emitCustomEvent.ts +1 -2
  140. package/src/examples/run.ts +14 -1
  141. package/src/examples/transferTokens.ts +21 -17
  142. package/src/examples/uniswapV2AddLiquidity.ts +106 -0
  143. package/src/examples/uniswapV3Mint.ts +95 -0
  144. package/src/generated/config.generated.ts +102 -47
  145. package/src/generated/guards.generated.ts +9 -0
  146. package/src/generated/operations.generated.ts +161 -5
  147. package/src/index.ts +0 -3
  148. package/dist/discovery.cjs.map +0 -1
  149. package/dist/discovery.js.map +0 -1
  150. package/dist/generated/config.generated.cjs.map +0 -1
  151. package/dist/generated/config.generated.js.map +0 -1
  152. package/dist/guards.generated-BPLFwe7y.d.ts +0 -19
  153. package/dist/guards.generated-M3VAIevI.d.cts +0 -19
  154. package/dist/materialisers.generated-BMkBQgWZ.d.ts +0 -24
  155. package/dist/materialisers.generated-BWq5oePO.d.cts +0 -24
  156. package/dist/preconditions.generated-DblS13Wq.d.cts +0 -24
  157. package/dist/preconditions.generated-U7YpVh30.d.ts +0 -24
  158. package/dist/raw-BvRghN3r.d.ts +0 -20
  159. package/dist/raw-s1rer8X3.d.cts +0 -20
  160. package/dist/resources-BKlFxjo8.d.cts +0 -56
  161. package/dist/resources-CYis1_DS.d.ts +0 -56
  162. package/dist/routeAmount-DdbJYJyM.d.cts +0 -55
  163. package/dist/routeAmount-DdbJYJyM.d.ts +0 -55
  164. package/dist/types.cjs.map +0 -1
  165. package/dist/types.js.map +0 -1
@@ -1,3 +1,4 @@
1
+ //#region src/discovery.d.ts
1
2
  /**
2
3
  * Types for the Compose discovery API (`GET /compose/zap-packs`, `GET /chains`).
3
4
  *
@@ -13,73 +14,73 @@
13
14
  /**
14
15
  * A chain the Compose deployment supports.
15
16
  */
16
- interface ChainSummary {
17
- /** EVM chain ID. The stable identifier — key on this. */
18
- readonly chainId: number;
19
- /**
20
- * Human-readable label, suitable for display in a chain selector.
21
- *
22
- * Maintained by the deployment rather than derived from canonical chain
23
- * branding, so it can differ from a chain's marketed name and can change
24
- * without notice. Never treat it as an identifier, and never match on it.
25
- * A chain the deployment has no configured label for reports `Chain <id>`.
26
- */
27
- readonly name: string;
17
+ export interface ChainSummary {
18
+ /** EVM chain ID. The stable identifier — key on this. */
19
+ readonly chainId: number;
20
+ /**
21
+ * Human-readable label, suitable for display in a chain selector.
22
+ *
23
+ * Maintained by the deployment rather than derived from canonical chain
24
+ * branding, so it can differ from a chain's marketed name and can change
25
+ * without notice. Never treat it as an identifier, and never match on it.
26
+ * A chain the deployment has no configured label for reports `Chain <id>`.
27
+ */
28
+ readonly name: string;
28
29
  }
29
30
  /**
30
31
  * A single routing edge representing a supported token-to-token path
31
32
  * through a DeFi protocol.
32
33
  */
33
- interface ZapPackEdge {
34
- /** Edge type (e.g. `"enter-position"`, `"exit-position"`, `"wrap"`). */
35
- readonly type: string;
36
- /** Input token. */
37
- readonly in: {
38
- readonly address: string;
39
- readonly chainId: number;
40
- };
41
- /** Output token. */
42
- readonly out: {
43
- readonly address: string;
44
- readonly chainId: number;
45
- };
46
- /** Minimum input amount accepted (stringified integer), if constrained. */
47
- readonly inAmountMin?: string;
48
- /** Maximum input amount accepted (stringified integer), if constrained. */
49
- readonly inAmountMax?: string;
50
- /**
51
- * Recipient binding obligation. `"required"` means the zap must bind its
52
- * `recipient` input. The output is externally owned, terminal, and unswept.
53
- * The loose string type preserves forward compatibility with new values.
54
- */
55
- readonly recipient?: string;
56
- /**
57
- * Output availability. `"future"` means the output becomes available only
58
- * after the initiating transaction settles; route via `lifi.zapAsync` with
59
- * a bound recipient. Absent means the output is available synchronously.
60
- * The loose string type preserves forward compatibility with new values.
61
- */
62
- readonly availability?: string;
34
+ export interface ZapPackEdge {
35
+ /** Edge type (e.g. `"enter-position"`, `"exit-position"`, `"wrap"`). */
36
+ readonly type: string;
37
+ /** Input token. */
38
+ readonly in: {
39
+ readonly address: string;
40
+ readonly chainId: number;
41
+ };
42
+ /** Output token. */
43
+ readonly out: {
44
+ readonly address: string;
45
+ readonly chainId: number;
46
+ };
47
+ /** Minimum input amount accepted (stringified integer), if constrained. */
48
+ readonly inAmountMin?: string;
49
+ /** Maximum input amount accepted (stringified integer), if constrained. */
50
+ readonly inAmountMax?: string;
51
+ /**
52
+ * Recipient binding obligation. `"required"` means the zap must bind its
53
+ * `recipient` input. The output is externally owned, terminal, and unswept.
54
+ * The loose string type preserves forward compatibility with new values.
55
+ */
56
+ readonly recipient?: string;
57
+ /**
58
+ * Output availability. `"future"` means the output becomes available only
59
+ * after the initiating transaction settles; route via `lifi.zapAsync` with
60
+ * a bound recipient. Absent means the output is available synchronously.
61
+ * The loose string type preserves forward compatibility with new values.
62
+ */
63
+ readonly availability?: string;
63
64
  }
64
65
  /**
65
66
  * All routing edges for a single protocol.
66
67
  */
67
- interface ZapPackOverview {
68
- /** Protocol identifier (e.g. `"aave"`, `"morpho"`). */
69
- readonly protocol: string;
70
- /** Available routing edges for this protocol. */
71
- readonly edges: readonly ZapPackEdge[];
68
+ export interface ZapPackOverview {
69
+ /** Protocol identifier (e.g. `"aave"`, `"morpho"`). */
70
+ readonly protocol: string;
71
+ /** Available routing edges for this protocol. */
72
+ readonly edges: readonly ZapPackEdge[];
72
73
  }
73
74
  /**
74
75
  * Options for {@link ComposeClient.getZapPacks}.
75
76
  */
76
- interface GetZapPacksOptions {
77
- /**
78
- * Filter to specific protocols. Pass a single string or an array.
79
- * Only edges belonging to the listed protocols are returned.
80
- * Omit to fetch all available protocols.
81
- */
82
- readonly protocols?: string | readonly string[];
77
+ export interface GetZapPacksOptions {
78
+ /**
79
+ * Filter to specific protocols. Pass a single string or an array.
80
+ * Only edges belonging to the listed protocols are returned.
81
+ * Omit to fetch all available protocols.
82
+ */
83
+ readonly protocols?: string | readonly string[];
83
84
  }
84
-
85
- export type { ChainSummary, GetZapPacksOptions, ZapPackEdge, ZapPackOverview };
85
+ //#endregion
86
+ //# sourceMappingURL=discovery.d.cts.map
@@ -1,3 +1,4 @@
1
+ //#region src/discovery.d.ts
1
2
  /**
2
3
  * Types for the Compose discovery API (`GET /compose/zap-packs`, `GET /chains`).
3
4
  *
@@ -13,73 +14,73 @@
13
14
  /**
14
15
  * A chain the Compose deployment supports.
15
16
  */
16
- interface ChainSummary {
17
- /** EVM chain ID. The stable identifier — key on this. */
18
- readonly chainId: number;
19
- /**
20
- * Human-readable label, suitable for display in a chain selector.
21
- *
22
- * Maintained by the deployment rather than derived from canonical chain
23
- * branding, so it can differ from a chain's marketed name and can change
24
- * without notice. Never treat it as an identifier, and never match on it.
25
- * A chain the deployment has no configured label for reports `Chain <id>`.
26
- */
27
- readonly name: string;
17
+ export interface ChainSummary {
18
+ /** EVM chain ID. The stable identifier — key on this. */
19
+ readonly chainId: number;
20
+ /**
21
+ * Human-readable label, suitable for display in a chain selector.
22
+ *
23
+ * Maintained by the deployment rather than derived from canonical chain
24
+ * branding, so it can differ from a chain's marketed name and can change
25
+ * without notice. Never treat it as an identifier, and never match on it.
26
+ * A chain the deployment has no configured label for reports `Chain <id>`.
27
+ */
28
+ readonly name: string;
28
29
  }
29
30
  /**
30
31
  * A single routing edge representing a supported token-to-token path
31
32
  * through a DeFi protocol.
32
33
  */
33
- interface ZapPackEdge {
34
- /** Edge type (e.g. `"enter-position"`, `"exit-position"`, `"wrap"`). */
35
- readonly type: string;
36
- /** Input token. */
37
- readonly in: {
38
- readonly address: string;
39
- readonly chainId: number;
40
- };
41
- /** Output token. */
42
- readonly out: {
43
- readonly address: string;
44
- readonly chainId: number;
45
- };
46
- /** Minimum input amount accepted (stringified integer), if constrained. */
47
- readonly inAmountMin?: string;
48
- /** Maximum input amount accepted (stringified integer), if constrained. */
49
- readonly inAmountMax?: string;
50
- /**
51
- * Recipient binding obligation. `"required"` means the zap must bind its
52
- * `recipient` input. The output is externally owned, terminal, and unswept.
53
- * The loose string type preserves forward compatibility with new values.
54
- */
55
- readonly recipient?: string;
56
- /**
57
- * Output availability. `"future"` means the output becomes available only
58
- * after the initiating transaction settles; route via `lifi.zapAsync` with
59
- * a bound recipient. Absent means the output is available synchronously.
60
- * The loose string type preserves forward compatibility with new values.
61
- */
62
- readonly availability?: string;
34
+ export interface ZapPackEdge {
35
+ /** Edge type (e.g. `"enter-position"`, `"exit-position"`, `"wrap"`). */
36
+ readonly type: string;
37
+ /** Input token. */
38
+ readonly in: {
39
+ readonly address: string;
40
+ readonly chainId: number;
41
+ };
42
+ /** Output token. */
43
+ readonly out: {
44
+ readonly address: string;
45
+ readonly chainId: number;
46
+ };
47
+ /** Minimum input amount accepted (stringified integer), if constrained. */
48
+ readonly inAmountMin?: string;
49
+ /** Maximum input amount accepted (stringified integer), if constrained. */
50
+ readonly inAmountMax?: string;
51
+ /**
52
+ * Recipient binding obligation. `"required"` means the zap must bind its
53
+ * `recipient` input. The output is externally owned, terminal, and unswept.
54
+ * The loose string type preserves forward compatibility with new values.
55
+ */
56
+ readonly recipient?: string;
57
+ /**
58
+ * Output availability. `"future"` means the output becomes available only
59
+ * after the initiating transaction settles; route via `lifi.zapAsync` with
60
+ * a bound recipient. Absent means the output is available synchronously.
61
+ * The loose string type preserves forward compatibility with new values.
62
+ */
63
+ readonly availability?: string;
63
64
  }
64
65
  /**
65
66
  * All routing edges for a single protocol.
66
67
  */
67
- interface ZapPackOverview {
68
- /** Protocol identifier (e.g. `"aave"`, `"morpho"`). */
69
- readonly protocol: string;
70
- /** Available routing edges for this protocol. */
71
- readonly edges: readonly ZapPackEdge[];
68
+ export interface ZapPackOverview {
69
+ /** Protocol identifier (e.g. `"aave"`, `"morpho"`). */
70
+ readonly protocol: string;
71
+ /** Available routing edges for this protocol. */
72
+ readonly edges: readonly ZapPackEdge[];
72
73
  }
73
74
  /**
74
75
  * Options for {@link ComposeClient.getZapPacks}.
75
76
  */
76
- interface GetZapPacksOptions {
77
- /**
78
- * Filter to specific protocols. Pass a single string or an array.
79
- * Only edges belonging to the listed protocols are returned.
80
- * Omit to fetch all available protocols.
81
- */
82
- readonly protocols?: string | readonly string[];
77
+ export interface GetZapPacksOptions {
78
+ /**
79
+ * Filter to specific protocols. Pass a single string or an array.
80
+ * Only edges belonging to the listed protocols are returned.
81
+ * Omit to fetch all available protocols.
82
+ */
83
+ readonly protocols?: string | readonly string[];
83
84
  }
84
-
85
- export type { ChainSummary, GetZapPacksOptions, ZapPackEdge, ZapPackOverview };
85
+ //#endregion
86
+ //# sourceMappingURL=discovery.d.ts.map
package/dist/discovery.js CHANGED
@@ -1 +1 @@
1
- //# sourceMappingURL=discovery.js.map
1
+ export {};
package/dist/errors.cjs CHANGED
@@ -1,175 +1,227 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
3
+ const require_responseSchemas = require("./responseSchemas.cjs");
4
+ let zod = require("zod");
5
+ zod = require_runtime.__toESM(zod, 1);
6
+ //#region src/errors.ts
7
+ /**
8
+ * Error class for all failures originating from the Compose SDK or API.
9
+ *
10
+ * Includes structured metadata beyond the error message to support
11
+ * programmatic error handling.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * try {
16
+ * await builder.compile(run);
17
+ * } catch (e) {
18
+ * if (isComposeError(e) && e.code === 'VALIDATION_ERROR') {
19
+ * console.error('Invalid request:', e.message, e.path);
20
+ * }
21
+ * }
22
+ * ```
23
+ */
24
+ var ComposeError = class extends Error {
25
+ name = "ComposeError";
26
+ /** Machine-readable error category. */
27
+ code;
28
+ /** HTTP status code, when the error originated from an HTTP response. */
29
+ status;
30
+ /** The request URL that produced the error. */
31
+ url;
32
+ /** Server-provided error kind for finer-grained classification. */
33
+ kind;
34
+ /**
35
+ * Where a validation error points: the node id for a rejection of an
36
+ * authored node, or a JSON-pointer path for a rejection of the request shape.
37
+ */
38
+ path;
39
+ /**
40
+ * The input port of {@link ComposeError.path}'s node whose binding caused the
41
+ * error. Set when the rejection is about what a port binds rather than about
42
+ * the node's config.
43
+ */
44
+ port;
45
+ /**
46
+ * The one edit that clears the error, written for whoever authored the flow.
47
+ * Set on `continuation.settle` authoring rejections; may be absent on other
48
+ * `validation_error`s.
49
+ */
50
+ fix;
51
+ /**
52
+ * Simulation revert diagnostics attached to `simulation_revert` errors.
53
+ * Contains the raw error bytes and decoded error candidates when the
54
+ * backend can parse the revert reason.
55
+ */
56
+ details;
57
+ /**
58
+ * The prepared ops that failed, attached to `preparation_error` errors.
59
+ * Each entry carries the `callId` of the failing node so callers can drop
60
+ * the unroutable legs and resubmit a smaller flow.
61
+ */
62
+ failedOps;
63
+ /**
64
+ * The `callId`s of the prepared ops that succeeded, attached to
65
+ * `preparation_error` errors alongside {@link ComposeError.failedOps}.
66
+ */
67
+ succeededOps;
68
+ /** Version details attached only to `sdk_outdated` errors. */
69
+ sdkOutdated;
70
+ /** Version details attached only to `server_outdated` errors. */
71
+ serverOutdated;
72
+ constructor(code, message, options) {
73
+ super(message, { cause: options?.cause });
74
+ this.code = code;
75
+ this.status = options?.status;
76
+ this.url = options?.url;
77
+ this.kind = options?.kind;
78
+ this.path = options?.path;
79
+ this.port = options?.port;
80
+ this.fix = options?.fix;
81
+ this.details = options?.details;
82
+ this.failedOps = options?.failedOps;
83
+ this.succeededOps = options?.succeededOps;
84
+ this.sdkOutdated = options?.sdkOutdated;
85
+ this.serverOutdated = options?.serverOutdated;
86
+ }
11
87
  };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var errors_exports = {};
30
- __export(errors_exports, {
31
- ComposeError: () => ComposeError,
32
- errorFromHttpResponse: () => errorFromHttpResponse,
33
- isComposeError: () => isComposeError,
34
- isComposePreparationError: () => isComposePreparationError,
35
- isComposeSdkOutdatedError: () => isComposeSdkOutdatedError,
36
- isComposeServerOutdatedError: () => isComposeServerOutdatedError
37
- });
38
- module.exports = __toCommonJS(errors_exports);
39
- var import_zod = __toESM(require("zod"), 1);
40
- var import_responseSchemas = require("./responseSchemas.js");
41
- class ComposeError extends Error {
42
- name = "ComposeError";
43
- /** Machine-readable error category. */
44
- code;
45
- /** HTTP status code, when the error originated from an HTTP response. */
46
- status;
47
- /** The request URL that produced the error. */
48
- url;
49
- /** Server-provided error kind for finer-grained classification. */
50
- kind;
51
- /**
52
- * Where a validation error points: the node id for a rejection of an
53
- * authored node, or a JSON-pointer path for a rejection of the request shape.
54
- */
55
- path;
56
- /**
57
- * The input port of {@link ComposeError.path}'s node whose binding caused the
58
- * error. Set when the rejection is about what a port binds rather than about
59
- * the node's config.
60
- */
61
- port;
62
- /**
63
- * The one edit that clears the error, written for whoever authored the flow.
64
- * Set on `continuation.settle` authoring rejections; may be absent on other
65
- * `validation_error`s.
66
- */
67
- fix;
68
- /**
69
- * Simulation revert diagnostics attached to `simulation_revert` errors.
70
- * Contains the raw error bytes and decoded error candidates when the
71
- * backend can parse the revert reason.
72
- */
73
- details;
74
- /**
75
- * The prepared ops that failed, attached to `preparation_error` errors.
76
- * Each entry carries the `callId` of the failing node so callers can drop
77
- * the unroutable legs and resubmit a smaller flow.
78
- */
79
- failedOps;
80
- /**
81
- * The `callId`s of the prepared ops that succeeded, attached to
82
- * `preparation_error` errors alongside {@link ComposeError.failedOps}.
83
- */
84
- succeededOps;
85
- /** Version details attached only to `sdk_outdated` errors. */
86
- sdkOutdated;
87
- /** Version details attached only to `server_outdated` errors. */
88
- serverOutdated;
89
- constructor(code, message, options) {
90
- super(message, { cause: options?.cause });
91
- this.code = code;
92
- this.status = options?.status;
93
- this.url = options?.url;
94
- this.kind = options?.kind;
95
- this.path = options?.path;
96
- this.port = options?.port;
97
- this.fix = options?.fix;
98
- this.details = options?.details;
99
- this.failedOps = options?.failedOps;
100
- this.succeededOps = options?.succeededOps;
101
- this.sdkOutdated = options?.sdkOutdated;
102
- this.serverOutdated = options?.serverOutdated;
103
- }
104
- }
88
+ /**
89
+ * Type guard that narrows an unknown error to {@link ComposeError}.
90
+ * @param e - The value to check.
91
+ * @returns `true` if `e` is an instance of `ComposeError`.
92
+ */
105
93
  const isComposeError = (e) => e instanceof ComposeError || e instanceof Error && e.name === "ComposeError" && "code" in e;
94
+ /**
95
+ * Type guard for `preparation_error` failures (HTTP 422): a mixed basket where
96
+ * some prepared ops failed and others succeeded. Narrows both
97
+ * {@link ComposeError.failedOps} and {@link ComposeError.succeededOps} to
98
+ * present, so callers can read them without a cast or a truthiness check.
99
+ *
100
+ * @param e - The value to check.
101
+ * @returns `true` if `e` is a `ComposeError` carrying per-op preparation diagnostics.
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * try {
106
+ * await builder.compile(run);
107
+ * } catch (e) {
108
+ * if (isComposePreparationError(e)) {
109
+ * console.error('Failed ops:', e.failedOps);
110
+ * console.error('Succeeded ops:', e.succeededOps);
111
+ * }
112
+ * }
113
+ * ```
114
+ */
106
115
  const isComposePreparationError = (e) => isComposeError(e) && e.kind === "preparation_error" && Array.isArray(e.failedOps) && Array.isArray(e.succeededOps);
107
- const sdkOutdatedSchema = import_zod.default.object({
108
- sdkVersion: import_zod.default.string(),
109
- serverVersion: import_zod.default.string(),
110
- minimumSdkVersion: import_zod.default.string()
116
+ const sdkOutdatedSchema = zod.default.object({
117
+ sdkVersion: zod.default.string(),
118
+ serverVersion: zod.default.string(),
119
+ minimumSdkVersion: zod.default.string()
111
120
  });
121
+ /**
122
+ * Narrows an outdated-SDK rejection to its required version details.
123
+ *
124
+ * @example
125
+ * ```ts
126
+ * try {
127
+ * await builder.compile(run);
128
+ * } catch (e) {
129
+ * if (isComposeSdkOutdatedError(e)) {
130
+ * console.error(`Upgrade to at least ${e.sdkOutdated.minimumSdkVersion}`);
131
+ * return;
132
+ * }
133
+ * throw e;
134
+ * }
135
+ * ```
136
+ */
112
137
  const isComposeSdkOutdatedError = (e) => isComposeError(e) && e.kind === "sdk_outdated" && sdkOutdatedSchema.safeParse(e.sdkOutdated).success;
113
- const serverOutdatedSchema = import_zod.default.object({
114
- sdkVersion: import_zod.default.string(),
115
- serverVersion: import_zod.default.string()
138
+ const serverOutdatedSchema = zod.default.object({
139
+ sdkVersion: zod.default.string(),
140
+ serverVersion: zod.default.string()
116
141
  });
142
+ /**
143
+ * Narrows a server-behind-SDK rejection to its required version details.
144
+ *
145
+ * This is the deploy-window error: the SDK on npm is ahead of the backend that
146
+ * answered. Pin the SDK to the server's `major.minor`, or wait for the rollout.
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * try {
151
+ * await builder.compile(run);
152
+ * } catch (e) {
153
+ * if (isComposeServerOutdatedError(e)) {
154
+ * console.error(`Server serves ${e.serverOutdated.serverVersion}`);
155
+ * return;
156
+ * }
157
+ * throw e;
158
+ * }
159
+ * ```
160
+ */
117
161
  const isComposeServerOutdatedError = (e) => isComposeError(e) && e.kind === "server_outdated" && serverOutdatedSchema.safeParse(e.serverOutdated).success;
118
162
  const STATUS_TO_CODE = /* @__PURE__ */ new Map([
119
- [400, "VALIDATION_ERROR"],
120
- [401, "UNAUTHENTICATED"],
121
- [403, "FORBIDDEN"],
122
- [404, "NOT_FOUND"],
123
- [422, "VALIDATION_ERROR"],
124
- [429, "RATE_LIMITED"]
163
+ [400, "VALIDATION_ERROR"],
164
+ [401, "UNAUTHENTICATED"],
165
+ [403, "FORBIDDEN"],
166
+ [404, "NOT_FOUND"],
167
+ [422, "VALIDATION_ERROR"],
168
+ [429, "RATE_LIMITED"]
125
169
  ]);
126
170
  const tryParseErrorBody = (body) => {
127
- let json;
128
- try {
129
- json = JSON.parse(body);
130
- } catch {
131
- return null;
132
- }
133
- return (0, import_responseSchemas.parseServerErrorBody)(json);
171
+ let json;
172
+ try {
173
+ json = JSON.parse(body);
174
+ } catch {
175
+ return null;
176
+ }
177
+ return require_responseSchemas.parseServerErrorBody(json);
134
178
  };
179
+ /**
180
+ * Extracts the version triple an `sdk_outdated` or `server_outdated` envelope
181
+ * carries. The slots reuse the same schemas the type guards narrow with. Zod
182
+ * strips keys the schema does not declare, so the parsed value is exactly the
183
+ * triple; a partial payload fails the parse and yields `undefined` rather than
184
+ * a half-populated object.
185
+ */
135
186
  const readVersionSlots = (serverError) => ({
136
- sdkOutdated: serverError?.kind === "sdk_outdated" ? sdkOutdatedSchema.safeParse(serverError).data : void 0,
137
- serverOutdated: serverError?.kind === "server_outdated" ? serverOutdatedSchema.safeParse(serverError).data : void 0
187
+ sdkOutdated: serverError?.kind === "sdk_outdated" ? sdkOutdatedSchema.safeParse(serverError).data : void 0,
188
+ serverOutdated: serverError?.kind === "server_outdated" ? serverOutdatedSchema.safeParse(serverError).data : void 0
138
189
  });
190
+ /**
191
+ * Constructs a {@link ComposeError} from an HTTP error response, extracting
192
+ * structured error details from the response body when available.
193
+ *
194
+ * @param status - The HTTP status code.
195
+ * @param body - The raw response body text.
196
+ * @param url - The request URL that produced the error.
197
+ * @returns A `ComposeError` with the appropriate error code and metadata.
198
+ */
139
199
  const errorFromHttpResponse = (status, body, url) => {
140
- const parsed = tryParseErrorBody(body);
141
- const serverError = parsed?.error;
142
- const { sdkOutdated, serverOutdated } = readVersionSlots(serverError);
143
- return new ComposeError(
144
- STATUS_TO_CODE.get(status) ?? (status >= 500 ? "SERVER_ERROR" : "UNKNOWN_ERROR"),
145
- (serverError?.message ?? body) || `HTTP ${status}`,
146
- {
147
- status,
148
- url,
149
- kind: serverError?.kind,
150
- path: serverError?.path,
151
- port: serverError?.port,
152
- fix: serverError?.fix,
153
- details: serverError?.details,
154
- // The wire schema types `kind` as a bare string; the server only ever
155
- // reports generic kinds for individual ops.
156
- failedOps: serverError?.failedOps?.map((op) => ({
157
- ...op,
158
- kind: op.kind
159
- })),
160
- succeededOps: serverError?.succeededOps,
161
- sdkOutdated,
162
- serverOutdated
163
- }
164
- );
200
+ const serverError = tryParseErrorBody(body)?.error;
201
+ const { sdkOutdated, serverOutdated } = readVersionSlots(serverError);
202
+ return new ComposeError(STATUS_TO_CODE.get(status) ?? (status >= 500 ? "SERVER_ERROR" : "UNKNOWN_ERROR"), (serverError?.message ?? body) || `HTTP ${status}`, {
203
+ status,
204
+ url,
205
+ kind: serverError?.kind,
206
+ path: serverError?.path,
207
+ port: serverError?.port,
208
+ fix: serverError?.fix,
209
+ details: serverError?.details,
210
+ failedOps: serverError?.failedOps?.map((op) => ({
211
+ ...op,
212
+ kind: op.kind
213
+ })),
214
+ succeededOps: serverError?.succeededOps,
215
+ sdkOutdated,
216
+ serverOutdated
217
+ });
165
218
  };
166
- // Annotate the CommonJS export names for ESM import in node:
167
- 0 && (module.exports = {
168
- ComposeError,
169
- errorFromHttpResponse,
170
- isComposeError,
171
- isComposePreparationError,
172
- isComposeSdkOutdatedError,
173
- isComposeServerOutdatedError
174
- });
219
+ //#endregion
220
+ exports.ComposeError = ComposeError;
221
+ exports.errorFromHttpResponse = errorFromHttpResponse;
222
+ exports.isComposeError = isComposeError;
223
+ exports.isComposePreparationError = isComposePreparationError;
224
+ exports.isComposeSdkOutdatedError = isComposeSdkOutdatedError;
225
+ exports.isComposeServerOutdatedError = isComposeServerOutdatedError;
226
+
175
227
  //# sourceMappingURL=errors.cjs.map