@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 +1 @@
1
- {"version":3,"sources":["../src/errors.ts"],"sourcesContent":["import type {\n ComposeErrorKind,\n ComposeRouteErrorKind,\n FailedPreparedOp,\n GenericComposeErrorKind,\n SimulationRevert,\n} from '@lifi/compose-spec';\nimport z from 'zod';\n\nimport {\n parseServerErrorBody,\n type ServerErrorBody,\n} from './responseSchemas.js';\n\n/**\n * Machine-readable error codes returned by the SDK.\n *\n * - `NETWORK_ERROR` — The HTTP request failed (DNS, timeout, connection refused).\n * - `VALIDATION_ERROR` — The server rejected the request (HTTP 400/422).\n * - `UNAUTHENTICATED` — The request lacks valid authentication credentials (HTTP 401).\n * - `FORBIDDEN` — The server understood the request but refuses to authorise it (HTTP 403).\n * - `SERVER_ERROR` — The server returned a 5xx status.\n * - `RATE_LIMITED` — The server returned HTTP 429.\n * - `NOT_FOUND` — The requested resource does not exist (HTTP 404).\n * - `UNKNOWN_ERROR` — An unexpected error that doesn't fit other categories.\n */\nexport type ComposeErrorCode =\n | 'NETWORK_ERROR'\n | 'VALIDATION_ERROR'\n | 'UNAUTHENTICATED'\n | 'FORBIDDEN'\n | 'SERVER_ERROR'\n | 'RATE_LIMITED'\n | 'NOT_FOUND'\n | 'UNKNOWN_ERROR';\n\n/** Version details returned when the backend rejects an outdated SDK. */\nexport interface ComposeSdkOutdated {\n readonly sdkVersion: string;\n readonly serverVersion: string;\n readonly minimumSdkVersion: string;\n}\n\n/**\n * Version details attached when the SDK is ahead of the backend it reached.\n * Raised by the backend's version gate, or by the SDK itself when the\n * `x-lifi-composer-version` response header names an older contract than the\n * one this SDK was built against.\n */\nexport interface ComposeServerOutdated {\n readonly sdkVersion: string;\n readonly serverVersion: string;\n}\n\n/**\n * Error class for all failures originating from the Compose SDK or API.\n *\n * Includes structured metadata beyond the error message to support\n * programmatic error handling.\n *\n * @example\n * ```ts\n * try {\n * await builder.compile(run);\n * } catch (e) {\n * if (isComposeError(e) && e.code === 'VALIDATION_ERROR') {\n * console.error('Invalid request:', e.message, e.path);\n * }\n * }\n * ```\n */\nexport class ComposeError extends Error {\n override readonly name = 'ComposeError';\n /** Machine-readable error category. */\n readonly code: ComposeErrorCode;\n /** HTTP status code, when the error originated from an HTTP response. */\n readonly status?: number;\n /** The request URL that produced the error. */\n readonly url?: string;\n /** Server-provided error kind for finer-grained classification. */\n readonly kind?: ComposeErrorKind | ComposeRouteErrorKind;\n /**\n * Where a validation error points: the node id for a rejection of an\n * authored node, or a JSON-pointer path for a rejection of the request shape.\n */\n readonly path?: string;\n /**\n * The input port of {@link ComposeError.path}'s node whose binding caused the\n * error. Set when the rejection is about what a port binds rather than about\n * the node's config.\n */\n readonly port?: string;\n /**\n * The one edit that clears the error, written for whoever authored the flow.\n * Set on `continuation.settle` authoring rejections; may be absent on other\n * `validation_error`s.\n */\n readonly fix?: string;\n /**\n * Simulation revert diagnostics attached to `simulation_revert` errors.\n * Contains the raw error bytes and decoded error candidates when the\n * backend can parse the revert reason.\n */\n readonly details?: SimulationRevert;\n /**\n * The prepared ops that failed, attached to `preparation_error` errors.\n * Each entry carries the `callId` of the failing node so callers can drop\n * the unroutable legs and resubmit a smaller flow.\n */\n readonly failedOps?: readonly FailedPreparedOp[];\n /**\n * The `callId`s of the prepared ops that succeeded, attached to\n * `preparation_error` errors alongside {@link ComposeError.failedOps}.\n */\n readonly succeededOps?: readonly string[];\n /** Version details attached only to `sdk_outdated` errors. */\n readonly sdkOutdated?: ComposeSdkOutdated;\n /** Version details attached only to `server_outdated` errors. */\n readonly serverOutdated?: ComposeServerOutdated;\n\n constructor(\n code: ComposeErrorCode,\n message: string,\n options?: {\n status?: number;\n url?: string;\n cause?: unknown;\n kind?: ComposeErrorKind | ComposeRouteErrorKind;\n path?: string;\n port?: string;\n fix?: string;\n details?: SimulationRevert;\n failedOps?: readonly FailedPreparedOp[];\n succeededOps?: readonly string[];\n sdkOutdated?: ComposeSdkOutdated;\n serverOutdated?: ComposeServerOutdated;\n },\n ) {\n super(message, { cause: options?.cause });\n this.code = code;\n this.status = options?.status;\n this.url = options?.url;\n this.kind = options?.kind;\n this.path = options?.path;\n this.port = options?.port;\n this.fix = options?.fix;\n this.details = options?.details;\n this.failedOps = options?.failedOps;\n this.succeededOps = options?.succeededOps;\n this.sdkOutdated = options?.sdkOutdated;\n this.serverOutdated = options?.serverOutdated;\n }\n}\n\n/**\n * The per-op preparation diagnostics carried by `preparation_error` responses,\n * with both arrays known to be present. Produced by narrowing with\n * {@link isComposePreparationError}.\n */\nexport interface ComposePreparationOps {\n readonly failedOps: readonly FailedPreparedOp[];\n readonly succeededOps: readonly string[];\n}\n\n/**\n * Type guard that narrows an unknown error to {@link ComposeError}.\n * @param e - The value to check.\n * @returns `true` if `e` is an instance of `ComposeError`.\n */\nexport const isComposeError = (e: unknown): e is ComposeError =>\n e instanceof ComposeError ||\n (e instanceof Error && e.name === 'ComposeError' && 'code' in e);\n\n/**\n * Type guard for `preparation_error` failures (HTTP 422): a mixed basket where\n * some prepared ops failed and others succeeded. Narrows both\n * {@link ComposeError.failedOps} and {@link ComposeError.succeededOps} to\n * present, so callers can read them without a cast or a truthiness check.\n *\n * @param e - The value to check.\n * @returns `true` if `e` is a `ComposeError` carrying per-op preparation diagnostics.\n *\n * @example\n * ```ts\n * try {\n * await builder.compile(run);\n * } catch (e) {\n * if (isComposePreparationError(e)) {\n * console.error('Failed ops:', e.failedOps);\n * console.error('Succeeded ops:', e.succeededOps);\n * }\n * }\n * ```\n */\nexport const isComposePreparationError = (\n e: unknown,\n): e is ComposeError & ComposePreparationOps =>\n isComposeError(e) &&\n e.kind === 'preparation_error' &&\n Array.isArray(e.failedOps) &&\n Array.isArray(e.succeededOps);\n\n// `isComposeError` accepts a structurally-similar error by name, so an error\n// raised by a *second* copy of this package in the dependency tree reaches the\n// guard below without its `sdkOutdated` field being type-guaranteed. Parse it.\nconst sdkOutdatedSchema = z.object({\n sdkVersion: z.string(),\n serverVersion: z.string(),\n minimumSdkVersion: z.string(),\n});\n\n/**\n * Narrows an outdated-SDK rejection to its required version details.\n *\n * @example\n * ```ts\n * try {\n * await builder.compile(run);\n * } catch (e) {\n * if (isComposeSdkOutdatedError(e)) {\n * console.error(`Upgrade to at least ${e.sdkOutdated.minimumSdkVersion}`);\n * return;\n * }\n * throw e;\n * }\n * ```\n */\nexport const isComposeSdkOutdatedError = (\n e: unknown,\n): e is ComposeError & { readonly sdkOutdated: ComposeSdkOutdated } =>\n isComposeError(e) &&\n e.kind === 'sdk_outdated' &&\n sdkOutdatedSchema.safeParse(e.sdkOutdated).success;\n\nconst serverOutdatedSchema = z.object({\n sdkVersion: z.string(),\n serverVersion: z.string(),\n});\n\n/**\n * Narrows a server-behind-SDK rejection to its required version details.\n *\n * This is the deploy-window error: the SDK on npm is ahead of the backend that\n * answered. Pin the SDK to the server's `major.minor`, or wait for the rollout.\n *\n * @example\n * ```ts\n * try {\n * await builder.compile(run);\n * } catch (e) {\n * if (isComposeServerOutdatedError(e)) {\n * console.error(`Server serves ${e.serverOutdated.serverVersion}`);\n * return;\n * }\n * throw e;\n * }\n * ```\n */\nexport const isComposeServerOutdatedError = (\n e: unknown,\n): e is ComposeError & { readonly serverOutdated: ComposeServerOutdated } =>\n isComposeError(e) &&\n e.kind === 'server_outdated' &&\n serverOutdatedSchema.safeParse(e.serverOutdated).success;\n\nconst STATUS_TO_CODE: ReadonlyMap<number, ComposeErrorCode> = new Map<\n number,\n ComposeErrorCode\n>([\n [400, 'VALIDATION_ERROR'],\n [401, 'UNAUTHENTICATED'],\n [403, 'FORBIDDEN'],\n [404, 'NOT_FOUND'],\n [422, 'VALIDATION_ERROR'],\n [429, 'RATE_LIMITED'],\n]);\n\nconst tryParseErrorBody = (body: string): ServerErrorBody | null => {\n let json: unknown;\n try {\n json = JSON.parse(body);\n } catch {\n return null;\n }\n return parseServerErrorBody(json);\n};\n\n/**\n * Extracts the version triple an `sdk_outdated` or `server_outdated` envelope\n * carries. The slots reuse the same schemas the type guards narrow with. Zod\n * strips keys the schema does not declare, so the parsed value is exactly the\n * triple; a partial payload fails the parse and yields `undefined` rather than\n * a half-populated object.\n */\nconst readVersionSlots = (serverError: ServerErrorBody['error']) => ({\n sdkOutdated:\n serverError?.kind === 'sdk_outdated'\n ? sdkOutdatedSchema.safeParse(serverError).data\n : undefined,\n serverOutdated:\n serverError?.kind === 'server_outdated'\n ? serverOutdatedSchema.safeParse(serverError).data\n : undefined,\n});\n\n/**\n * Constructs a {@link ComposeError} from an HTTP error response, extracting\n * structured error details from the response body when available.\n *\n * @param status - The HTTP status code.\n * @param body - The raw response body text.\n * @param url - The request URL that produced the error.\n * @returns A `ComposeError` with the appropriate error code and metadata.\n */\nexport const errorFromHttpResponse = (\n status: number,\n body: string,\n url: string,\n): ComposeError => {\n const parsed = tryParseErrorBody(body);\n const serverError = parsed?.error;\n const { sdkOutdated, serverOutdated } = readVersionSlots(serverError);\n\n return new ComposeError(\n STATUS_TO_CODE.get(status) ??\n (status >= 500 ? 'SERVER_ERROR' : 'UNKNOWN_ERROR'),\n (serverError?.message ?? body) || `HTTP ${status}`,\n {\n status,\n url,\n kind: serverError?.kind as\n ComposeErrorKind | ComposeRouteErrorKind | undefined,\n path: serverError?.path,\n port: serverError?.port,\n fix: serverError?.fix,\n details: serverError?.details,\n // The wire schema types `kind` as a bare string; the server only ever\n // reports generic kinds for individual ops.\n failedOps: serverError?.failedOps?.map((op) => ({\n ...op,\n kind: op.kind as GenericComposeErrorKind,\n })),\n succeededOps: serverError?.succeededOps,\n sdkOutdated,\n serverOutdated,\n },\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,iBAAc;AAEd,6BAGO;AA2DA,MAAM,qBAAqB,MAAM;AAAA,EACpB,OAAO;AAAA;AAAA,EAEhB;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA;A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B;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;","names":["z"]}
1
+ {"version":3,"file":"errors.cjs","names":["z","parseServerErrorBody"],"sources":["../src/errors.ts"],"sourcesContent":["import type {\n ComposeErrorKind,\n ComposeRouteErrorKind,\n FailedPreparedOp,\n GenericComposeErrorKind,\n SimulationRevert,\n} from '@lifi/compose-spec';\nimport z from 'zod';\n\nimport {\n parseServerErrorBody,\n type ServerErrorBody,\n} from './responseSchemas.js';\n\n/**\n * Machine-readable error codes returned by the SDK.\n *\n * - `NETWORK_ERROR` — The HTTP request failed (DNS, timeout, connection refused).\n * - `VALIDATION_ERROR` — The server rejected the request (HTTP 400/422).\n * - `UNAUTHENTICATED` — The request lacks valid authentication credentials (HTTP 401).\n * - `FORBIDDEN` — The server understood the request but refuses to authorise it (HTTP 403).\n * - `SERVER_ERROR` — The server returned a 5xx status.\n * - `RATE_LIMITED` — The server returned HTTP 429.\n * - `NOT_FOUND` — The requested resource does not exist (HTTP 404).\n * - `UNKNOWN_ERROR` — An unexpected error that doesn't fit other categories.\n */\nexport type ComposeErrorCode =\n | 'NETWORK_ERROR'\n | 'VALIDATION_ERROR'\n | 'UNAUTHENTICATED'\n | 'FORBIDDEN'\n | 'SERVER_ERROR'\n | 'RATE_LIMITED'\n | 'NOT_FOUND'\n | 'UNKNOWN_ERROR';\n\n/** Version details returned when the backend rejects an outdated SDK. */\nexport interface ComposeSdkOutdated {\n readonly sdkVersion: string;\n readonly serverVersion: string;\n readonly minimumSdkVersion: string;\n}\n\n/**\n * Version details attached when the SDK is ahead of the backend it reached.\n * Raised by the backend's version gate, or by the SDK itself when the\n * `x-lifi-composer-version` response header names an older contract than the\n * one this SDK was built against.\n */\nexport interface ComposeServerOutdated {\n readonly sdkVersion: string;\n readonly serverVersion: string;\n}\n\n/**\n * Error class for all failures originating from the Compose SDK or API.\n *\n * Includes structured metadata beyond the error message to support\n * programmatic error handling.\n *\n * @example\n * ```ts\n * try {\n * await builder.compile(run);\n * } catch (e) {\n * if (isComposeError(e) && e.code === 'VALIDATION_ERROR') {\n * console.error('Invalid request:', e.message, e.path);\n * }\n * }\n * ```\n */\nexport class ComposeError extends Error {\n override readonly name = 'ComposeError';\n /** Machine-readable error category. */\n readonly code: ComposeErrorCode;\n /** HTTP status code, when the error originated from an HTTP response. */\n readonly status?: number;\n /** The request URL that produced the error. */\n readonly url?: string;\n /** Server-provided error kind for finer-grained classification. */\n readonly kind?: ComposeErrorKind | ComposeRouteErrorKind;\n /**\n * Where a validation error points: the node id for a rejection of an\n * authored node, or a JSON-pointer path for a rejection of the request shape.\n */\n readonly path?: string;\n /**\n * The input port of {@link ComposeError.path}'s node whose binding caused the\n * error. Set when the rejection is about what a port binds rather than about\n * the node's config.\n */\n readonly port?: string;\n /**\n * The one edit that clears the error, written for whoever authored the flow.\n * Set on `continuation.settle` authoring rejections; may be absent on other\n * `validation_error`s.\n */\n readonly fix?: string;\n /**\n * Simulation revert diagnostics attached to `simulation_revert` errors.\n * Contains the raw error bytes and decoded error candidates when the\n * backend can parse the revert reason.\n */\n readonly details?: SimulationRevert;\n /**\n * The prepared ops that failed, attached to `preparation_error` errors.\n * Each entry carries the `callId` of the failing node so callers can drop\n * the unroutable legs and resubmit a smaller flow.\n */\n readonly failedOps?: readonly FailedPreparedOp[];\n /**\n * The `callId`s of the prepared ops that succeeded, attached to\n * `preparation_error` errors alongside {@link ComposeError.failedOps}.\n */\n readonly succeededOps?: readonly string[];\n /** Version details attached only to `sdk_outdated` errors. */\n readonly sdkOutdated?: ComposeSdkOutdated;\n /** Version details attached only to `server_outdated` errors. */\n readonly serverOutdated?: ComposeServerOutdated;\n\n constructor(\n code: ComposeErrorCode,\n message: string,\n options?: {\n status?: number;\n url?: string;\n cause?: unknown;\n kind?: ComposeErrorKind | ComposeRouteErrorKind;\n path?: string;\n port?: string;\n fix?: string;\n details?: SimulationRevert;\n failedOps?: readonly FailedPreparedOp[];\n succeededOps?: readonly string[];\n sdkOutdated?: ComposeSdkOutdated;\n serverOutdated?: ComposeServerOutdated;\n },\n ) {\n super(message, { cause: options?.cause });\n this.code = code;\n this.status = options?.status;\n this.url = options?.url;\n this.kind = options?.kind;\n this.path = options?.path;\n this.port = options?.port;\n this.fix = options?.fix;\n this.details = options?.details;\n this.failedOps = options?.failedOps;\n this.succeededOps = options?.succeededOps;\n this.sdkOutdated = options?.sdkOutdated;\n this.serverOutdated = options?.serverOutdated;\n }\n}\n\n/**\n * The per-op preparation diagnostics carried by `preparation_error` responses,\n * with both arrays known to be present. Produced by narrowing with\n * {@link isComposePreparationError}.\n */\nexport interface ComposePreparationOps {\n readonly failedOps: readonly FailedPreparedOp[];\n readonly succeededOps: readonly string[];\n}\n\n/**\n * Type guard that narrows an unknown error to {@link ComposeError}.\n * @param e - The value to check.\n * @returns `true` if `e` is an instance of `ComposeError`.\n */\nexport const isComposeError = (e: unknown): e is ComposeError =>\n e instanceof ComposeError ||\n (e instanceof Error && e.name === 'ComposeError' && 'code' in e);\n\n/**\n * Type guard for `preparation_error` failures (HTTP 422): a mixed basket where\n * some prepared ops failed and others succeeded. Narrows both\n * {@link ComposeError.failedOps} and {@link ComposeError.succeededOps} to\n * present, so callers can read them without a cast or a truthiness check.\n *\n * @param e - The value to check.\n * @returns `true` if `e` is a `ComposeError` carrying per-op preparation diagnostics.\n *\n * @example\n * ```ts\n * try {\n * await builder.compile(run);\n * } catch (e) {\n * if (isComposePreparationError(e)) {\n * console.error('Failed ops:', e.failedOps);\n * console.error('Succeeded ops:', e.succeededOps);\n * }\n * }\n * ```\n */\nexport const isComposePreparationError = (\n e: unknown,\n): e is ComposeError & ComposePreparationOps =>\n isComposeError(e) &&\n e.kind === 'preparation_error' &&\n Array.isArray(e.failedOps) &&\n Array.isArray(e.succeededOps);\n\n// `isComposeError` accepts a structurally-similar error by name, so an error\n// raised by a *second* copy of this package in the dependency tree reaches the\n// guard below without its `sdkOutdated` field being type-guaranteed. Parse it.\nconst sdkOutdatedSchema = z.object({\n sdkVersion: z.string(),\n serverVersion: z.string(),\n minimumSdkVersion: z.string(),\n});\n\n/**\n * Narrows an outdated-SDK rejection to its required version details.\n *\n * @example\n * ```ts\n * try {\n * await builder.compile(run);\n * } catch (e) {\n * if (isComposeSdkOutdatedError(e)) {\n * console.error(`Upgrade to at least ${e.sdkOutdated.minimumSdkVersion}`);\n * return;\n * }\n * throw e;\n * }\n * ```\n */\nexport const isComposeSdkOutdatedError = (\n e: unknown,\n): e is ComposeError & { readonly sdkOutdated: ComposeSdkOutdated } =>\n isComposeError(e) &&\n e.kind === 'sdk_outdated' &&\n sdkOutdatedSchema.safeParse(e.sdkOutdated).success;\n\nconst serverOutdatedSchema = z.object({\n sdkVersion: z.string(),\n serverVersion: z.string(),\n});\n\n/**\n * Narrows a server-behind-SDK rejection to its required version details.\n *\n * This is the deploy-window error: the SDK on npm is ahead of the backend that\n * answered. Pin the SDK to the server's `major.minor`, or wait for the rollout.\n *\n * @example\n * ```ts\n * try {\n * await builder.compile(run);\n * } catch (e) {\n * if (isComposeServerOutdatedError(e)) {\n * console.error(`Server serves ${e.serverOutdated.serverVersion}`);\n * return;\n * }\n * throw e;\n * }\n * ```\n */\nexport const isComposeServerOutdatedError = (\n e: unknown,\n): e is ComposeError & { readonly serverOutdated: ComposeServerOutdated } =>\n isComposeError(e) &&\n e.kind === 'server_outdated' &&\n serverOutdatedSchema.safeParse(e.serverOutdated).success;\n\nconst STATUS_TO_CODE: ReadonlyMap<number, ComposeErrorCode> = new Map<\n number,\n ComposeErrorCode\n>([\n [400, 'VALIDATION_ERROR'],\n [401, 'UNAUTHENTICATED'],\n [403, 'FORBIDDEN'],\n [404, 'NOT_FOUND'],\n [422, 'VALIDATION_ERROR'],\n [429, 'RATE_LIMITED'],\n]);\n\nconst tryParseErrorBody = (body: string): ServerErrorBody | null => {\n let json: unknown;\n try {\n json = JSON.parse(body);\n } catch {\n return null;\n }\n return parseServerErrorBody(json);\n};\n\n/**\n * Extracts the version triple an `sdk_outdated` or `server_outdated` envelope\n * carries. The slots reuse the same schemas the type guards narrow with. Zod\n * strips keys the schema does not declare, so the parsed value is exactly the\n * triple; a partial payload fails the parse and yields `undefined` rather than\n * a half-populated object.\n */\nconst readVersionSlots = (serverError: ServerErrorBody['error']) => ({\n sdkOutdated:\n serverError?.kind === 'sdk_outdated'\n ? sdkOutdatedSchema.safeParse(serverError).data\n : undefined,\n serverOutdated:\n serverError?.kind === 'server_outdated'\n ? serverOutdatedSchema.safeParse(serverError).data\n : undefined,\n});\n\n/**\n * Constructs a {@link ComposeError} from an HTTP error response, extracting\n * structured error details from the response body when available.\n *\n * @param status - The HTTP status code.\n * @param body - The raw response body text.\n * @param url - The request URL that produced the error.\n * @returns A `ComposeError` with the appropriate error code and metadata.\n */\nexport const errorFromHttpResponse = (\n status: number,\n body: string,\n url: string,\n): ComposeError => {\n const parsed = tryParseErrorBody(body);\n const serverError = parsed?.error;\n const { sdkOutdated, serverOutdated } = readVersionSlots(serverError);\n\n return new ComposeError(\n STATUS_TO_CODE.get(status) ??\n (status >= 500 ? 'SERVER_ERROR' : 'UNKNOWN_ERROR'),\n (serverError?.message ?? body) || `HTTP ${status}`,\n {\n status,\n url,\n kind: serverError?.kind as\n ComposeErrorKind | ComposeRouteErrorKind | undefined,\n path: serverError?.path,\n port: serverError?.port,\n fix: serverError?.fix,\n details: serverError?.details,\n // The wire schema types `kind` as a bare string; the server only ever\n // reports generic kinds for individual ops.\n failedOps: serverError?.failedOps?.map((op) => ({\n ...op,\n kind: op.kind as GenericComposeErrorKind,\n })),\n succeededOps: serverError?.succeededOps,\n sdkOutdated,\n serverOutdated,\n },\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuEA,IAAa,eAAb,cAAkC,MAAM;CACtC,OAAyB;;CAEzB;;CAEA;;CAEA;;CAEA;;;;;CAKA;;;;;;CAMA;;;;;;CAMA;;;;;;CAMA;;;;;;CAMA;;;;;CAKA;;CAEA;;CAEA;CAEA,YACE,MACA,SACA,SAcA;EACA,MAAM,SAAS,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BAAkB;CACxB,CAAC,KAAK,cAAc;AACtB,CAAC;AAED,MAAM,qBAAqB,SAAyC;CAClE,IAAI;CACJ,IAAI;EACF,OAAO,KAAK,MAAM,IAAI;CACxB,QAAQ;EACN,OAAO;CACT;CACA,OAAOC,wBAAAA,qBAAqB,IAAI;AAClC;;;;;;;;AASA,MAAM,oBAAoB,iBAA2C;CACnE,aACE,aAAa,SAAS,iBAClB,kBAAkB,UAAU,WAAW,CAAC,CAAC,OACzC,KAAA;CACN,gBACE,aAAa,SAAS,oBAClB,qBAAqB,UAAU,WAAW,CAAC,CAAC,OAC5C,KAAA;AACR;;;;;;;;;;AAWA,MAAa,yBACX,QACA,MACA,QACiB;CAEjB,MAAM,cADS,kBAAkB,IACR,CAAC,EAAE;CAC5B,MAAM,EAAE,aAAa,mBAAmB,iBAAiB,WAAW;CAEpE,OAAO,IAAI,aACT,eAAe,IAAI,MAAM,MACtB,UAAU,MAAM,iBAAiB,mBACnC,aAAa,WAAW,SAAS,QAAQ,UAC1C;EACE;EACA;EACA,MAAM,aAAa;EAEnB,MAAM,aAAa;EACnB,MAAM,aAAa;EACnB,KAAK,aAAa;EAClB,SAAS,aAAa;EAGtB,WAAW,aAAa,WAAW,KAAK,QAAQ;GAC9C,GAAG;GACH,MAAM,GAAG;EACX,EAAE;EACF,cAAc,aAAa;EAC3B;EACA;CACF,CACF;AACF"}
package/dist/errors.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { ComposeErrorKind, ComposeRouteErrorKind, SimulationRevert, FailedPreparedOp } from '@lifi/compose-spec';
2
-
1
+ import { ComposeErrorKind, ComposeRouteErrorKind, FailedPreparedOp, SimulationRevert } from "@lifi/compose-spec";
2
+ //#region src/errors.d.ts
3
3
  /**
4
4
  * Machine-readable error codes returned by the SDK.
5
5
  *
@@ -12,12 +12,12 @@ import { ComposeErrorKind, ComposeRouteErrorKind, SimulationRevert, FailedPrepar
12
12
  * - `NOT_FOUND` — The requested resource does not exist (HTTP 404).
13
13
  * - `UNKNOWN_ERROR` — An unexpected error that doesn't fit other categories.
14
14
  */
15
- type ComposeErrorCode = 'NETWORK_ERROR' | 'VALIDATION_ERROR' | 'UNAUTHENTICATED' | 'FORBIDDEN' | 'SERVER_ERROR' | 'RATE_LIMITED' | 'NOT_FOUND' | 'UNKNOWN_ERROR';
15
+ export type ComposeErrorCode = "NETWORK_ERROR" | "VALIDATION_ERROR" | "UNAUTHENTICATED" | "FORBIDDEN" | "SERVER_ERROR" | "RATE_LIMITED" | "NOT_FOUND" | "UNKNOWN_ERROR";
16
16
  /** Version details returned when the backend rejects an outdated SDK. */
17
- interface ComposeSdkOutdated {
18
- readonly sdkVersion: string;
19
- readonly serverVersion: string;
20
- readonly minimumSdkVersion: string;
17
+ export interface ComposeSdkOutdated {
18
+ readonly sdkVersion: string;
19
+ readonly serverVersion: string;
20
+ readonly minimumSdkVersion: string;
21
21
  }
22
22
  /**
23
23
  * Version details attached when the SDK is ahead of the backend it reached.
@@ -25,9 +25,9 @@ interface ComposeSdkOutdated {
25
25
  * `x-lifi-composer-version` response header names an older contract than the
26
26
  * one this SDK was built against.
27
27
  */
28
- interface ComposeServerOutdated {
29
- readonly sdkVersion: string;
30
- readonly serverVersion: string;
28
+ export interface ComposeServerOutdated {
29
+ readonly sdkVersion: string;
30
+ readonly serverVersion: string;
31
31
  }
32
32
  /**
33
33
  * Error class for all failures originating from the Compose SDK or API.
@@ -46,84 +46,84 @@ interface ComposeServerOutdated {
46
46
  * }
47
47
  * ```
48
48
  */
49
- declare class ComposeError extends Error {
50
- readonly name = "ComposeError";
51
- /** Machine-readable error category. */
52
- readonly code: ComposeErrorCode;
53
- /** HTTP status code, when the error originated from an HTTP response. */
54
- readonly status?: number;
55
- /** The request URL that produced the error. */
56
- readonly url?: string;
57
- /** Server-provided error kind for finer-grained classification. */
58
- readonly kind?: ComposeErrorKind | ComposeRouteErrorKind;
59
- /**
60
- * Where a validation error points: the node id for a rejection of an
61
- * authored node, or a JSON-pointer path for a rejection of the request shape.
62
- */
63
- readonly path?: string;
64
- /**
65
- * The input port of {@link ComposeError.path}'s node whose binding caused the
66
- * error. Set when the rejection is about what a port binds rather than about
67
- * the node's config.
68
- */
69
- readonly port?: string;
70
- /**
71
- * The one edit that clears the error, written for whoever authored the flow.
72
- * Set on `continuation.settle` authoring rejections; may be absent on other
73
- * `validation_error`s.
74
- */
75
- readonly fix?: string;
76
- /**
77
- * Simulation revert diagnostics attached to `simulation_revert` errors.
78
- * Contains the raw error bytes and decoded error candidates when the
79
- * backend can parse the revert reason.
80
- */
81
- readonly details?: SimulationRevert;
82
- /**
83
- * The prepared ops that failed, attached to `preparation_error` errors.
84
- * Each entry carries the `callId` of the failing node so callers can drop
85
- * the unroutable legs and resubmit a smaller flow.
86
- */
87
- readonly failedOps?: readonly FailedPreparedOp[];
88
- /**
89
- * The `callId`s of the prepared ops that succeeded, attached to
90
- * `preparation_error` errors alongside {@link ComposeError.failedOps}.
91
- */
92
- readonly succeededOps?: readonly string[];
93
- /** Version details attached only to `sdk_outdated` errors. */
94
- readonly sdkOutdated?: ComposeSdkOutdated;
95
- /** Version details attached only to `server_outdated` errors. */
96
- readonly serverOutdated?: ComposeServerOutdated;
97
- constructor(code: ComposeErrorCode, message: string, options?: {
98
- status?: number;
99
- url?: string;
100
- cause?: unknown;
101
- kind?: ComposeErrorKind | ComposeRouteErrorKind;
102
- path?: string;
103
- port?: string;
104
- fix?: string;
105
- details?: SimulationRevert;
106
- failedOps?: readonly FailedPreparedOp[];
107
- succeededOps?: readonly string[];
108
- sdkOutdated?: ComposeSdkOutdated;
109
- serverOutdated?: ComposeServerOutdated;
110
- });
49
+ export declare class ComposeError extends Error {
50
+ override readonly name = "ComposeError";
51
+ /** Machine-readable error category. */
52
+ readonly code: ComposeErrorCode;
53
+ /** HTTP status code, when the error originated from an HTTP response. */
54
+ readonly status?: number;
55
+ /** The request URL that produced the error. */
56
+ readonly url?: string;
57
+ /** Server-provided error kind for finer-grained classification. */
58
+ readonly kind?: ComposeErrorKind | ComposeRouteErrorKind;
59
+ /**
60
+ * Where a validation error points: the node id for a rejection of an
61
+ * authored node, or a JSON-pointer path for a rejection of the request shape.
62
+ */
63
+ readonly path?: string;
64
+ /**
65
+ * The input port of {@link ComposeError.path}'s node whose binding caused the
66
+ * error. Set when the rejection is about what a port binds rather than about
67
+ * the node's config.
68
+ */
69
+ readonly port?: string;
70
+ /**
71
+ * The one edit that clears the error, written for whoever authored the flow.
72
+ * Set on `continuation.settle` authoring rejections; may be absent on other
73
+ * `validation_error`s.
74
+ */
75
+ readonly fix?: string;
76
+ /**
77
+ * Simulation revert diagnostics attached to `simulation_revert` errors.
78
+ * Contains the raw error bytes and decoded error candidates when the
79
+ * backend can parse the revert reason.
80
+ */
81
+ readonly details?: SimulationRevert;
82
+ /**
83
+ * The prepared ops that failed, attached to `preparation_error` errors.
84
+ * Each entry carries the `callId` of the failing node so callers can drop
85
+ * the unroutable legs and resubmit a smaller flow.
86
+ */
87
+ readonly failedOps?: readonly FailedPreparedOp[];
88
+ /**
89
+ * The `callId`s of the prepared ops that succeeded, attached to
90
+ * `preparation_error` errors alongside {@link ComposeError.failedOps}.
91
+ */
92
+ readonly succeededOps?: readonly string[];
93
+ /** Version details attached only to `sdk_outdated` errors. */
94
+ readonly sdkOutdated?: ComposeSdkOutdated;
95
+ /** Version details attached only to `server_outdated` errors. */
96
+ readonly serverOutdated?: ComposeServerOutdated;
97
+ constructor(code: ComposeErrorCode, message: string, options?: {
98
+ status?: number;
99
+ url?: string;
100
+ cause?: unknown;
101
+ kind?: ComposeErrorKind | ComposeRouteErrorKind;
102
+ path?: string;
103
+ port?: string;
104
+ fix?: string;
105
+ details?: SimulationRevert;
106
+ failedOps?: readonly FailedPreparedOp[];
107
+ succeededOps?: readonly string[];
108
+ sdkOutdated?: ComposeSdkOutdated;
109
+ serverOutdated?: ComposeServerOutdated;
110
+ });
111
111
  }
112
112
  /**
113
113
  * The per-op preparation diagnostics carried by `preparation_error` responses,
114
114
  * with both arrays known to be present. Produced by narrowing with
115
115
  * {@link isComposePreparationError}.
116
116
  */
117
- interface ComposePreparationOps {
118
- readonly failedOps: readonly FailedPreparedOp[];
119
- readonly succeededOps: readonly string[];
117
+ export interface ComposePreparationOps {
118
+ readonly failedOps: readonly FailedPreparedOp[];
119
+ readonly succeededOps: readonly string[];
120
120
  }
121
121
  /**
122
122
  * Type guard that narrows an unknown error to {@link ComposeError}.
123
123
  * @param e - The value to check.
124
124
  * @returns `true` if `e` is an instance of `ComposeError`.
125
125
  */
126
- declare const isComposeError: (e: unknown) => e is ComposeError;
126
+ export declare const isComposeError: (e: unknown) => e is ComposeError;
127
127
  /**
128
128
  * Type guard for `preparation_error` failures (HTTP 422): a mixed basket where
129
129
  * some prepared ops failed and others succeeded. Narrows both
@@ -145,7 +145,7 @@ declare const isComposeError: (e: unknown) => e is ComposeError;
145
145
  * }
146
146
  * ```
147
147
  */
148
- declare const isComposePreparationError: (e: unknown) => e is ComposeError & ComposePreparationOps;
148
+ export declare const isComposePreparationError: (e: unknown) => e is ComposeError & ComposePreparationOps;
149
149
  /**
150
150
  * Narrows an outdated-SDK rejection to its required version details.
151
151
  *
@@ -162,8 +162,8 @@ declare const isComposePreparationError: (e: unknown) => e is ComposeError & Com
162
162
  * }
163
163
  * ```
164
164
  */
165
- declare const isComposeSdkOutdatedError: (e: unknown) => e is ComposeError & {
166
- readonly sdkOutdated: ComposeSdkOutdated;
165
+ export declare const isComposeSdkOutdatedError: (e: unknown) => e is ComposeError & {
166
+ readonly sdkOutdated: ComposeSdkOutdated;
167
167
  };
168
168
  /**
169
169
  * Narrows a server-behind-SDK rejection to its required version details.
@@ -184,8 +184,8 @@ declare const isComposeSdkOutdatedError: (e: unknown) => e is ComposeError & {
184
184
  * }
185
185
  * ```
186
186
  */
187
- declare const isComposeServerOutdatedError: (e: unknown) => e is ComposeError & {
188
- readonly serverOutdated: ComposeServerOutdated;
187
+ export declare const isComposeServerOutdatedError: (e: unknown) => e is ComposeError & {
188
+ readonly serverOutdated: ComposeServerOutdated;
189
189
  };
190
190
  /**
191
191
  * Constructs a {@link ComposeError} from an HTTP error response, extracting
@@ -196,6 +196,6 @@ declare const isComposeServerOutdatedError: (e: unknown) => e is ComposeError &
196
196
  * @param url - The request URL that produced the error.
197
197
  * @returns A `ComposeError` with the appropriate error code and metadata.
198
198
  */
199
- declare const errorFromHttpResponse: (status: number, body: string, url: string) => ComposeError;
200
-
201
- export { ComposeError, type ComposeErrorCode, type ComposePreparationOps, type ComposeSdkOutdated, type ComposeServerOutdated, errorFromHttpResponse, isComposeError, isComposePreparationError, isComposeSdkOutdatedError, isComposeServerOutdatedError };
199
+ export declare const errorFromHttpResponse: (status: number, body: string, url: string) => ComposeError;
200
+ //#endregion
201
+ //# sourceMappingURL=errors.d.cts.map
package/dist/errors.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ComposeErrorKind, ComposeRouteErrorKind, SimulationRevert, FailedPreparedOp } from '@lifi/compose-spec';
2
-
1
+ import { ComposeErrorKind, ComposeRouteErrorKind, FailedPreparedOp, SimulationRevert } from "@lifi/compose-spec";
2
+ //#region src/errors.d.ts
3
3
  /**
4
4
  * Machine-readable error codes returned by the SDK.
5
5
  *
@@ -12,12 +12,12 @@ import { ComposeErrorKind, ComposeRouteErrorKind, SimulationRevert, FailedPrepar
12
12
  * - `NOT_FOUND` — The requested resource does not exist (HTTP 404).
13
13
  * - `UNKNOWN_ERROR` — An unexpected error that doesn't fit other categories.
14
14
  */
15
- type ComposeErrorCode = 'NETWORK_ERROR' | 'VALIDATION_ERROR' | 'UNAUTHENTICATED' | 'FORBIDDEN' | 'SERVER_ERROR' | 'RATE_LIMITED' | 'NOT_FOUND' | 'UNKNOWN_ERROR';
15
+ export type ComposeErrorCode = "NETWORK_ERROR" | "VALIDATION_ERROR" | "UNAUTHENTICATED" | "FORBIDDEN" | "SERVER_ERROR" | "RATE_LIMITED" | "NOT_FOUND" | "UNKNOWN_ERROR";
16
16
  /** Version details returned when the backend rejects an outdated SDK. */
17
- interface ComposeSdkOutdated {
18
- readonly sdkVersion: string;
19
- readonly serverVersion: string;
20
- readonly minimumSdkVersion: string;
17
+ export interface ComposeSdkOutdated {
18
+ readonly sdkVersion: string;
19
+ readonly serverVersion: string;
20
+ readonly minimumSdkVersion: string;
21
21
  }
22
22
  /**
23
23
  * Version details attached when the SDK is ahead of the backend it reached.
@@ -25,9 +25,9 @@ interface ComposeSdkOutdated {
25
25
  * `x-lifi-composer-version` response header names an older contract than the
26
26
  * one this SDK was built against.
27
27
  */
28
- interface ComposeServerOutdated {
29
- readonly sdkVersion: string;
30
- readonly serverVersion: string;
28
+ export interface ComposeServerOutdated {
29
+ readonly sdkVersion: string;
30
+ readonly serverVersion: string;
31
31
  }
32
32
  /**
33
33
  * Error class for all failures originating from the Compose SDK or API.
@@ -46,84 +46,84 @@ interface ComposeServerOutdated {
46
46
  * }
47
47
  * ```
48
48
  */
49
- declare class ComposeError extends Error {
50
- readonly name = "ComposeError";
51
- /** Machine-readable error category. */
52
- readonly code: ComposeErrorCode;
53
- /** HTTP status code, when the error originated from an HTTP response. */
54
- readonly status?: number;
55
- /** The request URL that produced the error. */
56
- readonly url?: string;
57
- /** Server-provided error kind for finer-grained classification. */
58
- readonly kind?: ComposeErrorKind | ComposeRouteErrorKind;
59
- /**
60
- * Where a validation error points: the node id for a rejection of an
61
- * authored node, or a JSON-pointer path for a rejection of the request shape.
62
- */
63
- readonly path?: string;
64
- /**
65
- * The input port of {@link ComposeError.path}'s node whose binding caused the
66
- * error. Set when the rejection is about what a port binds rather than about
67
- * the node's config.
68
- */
69
- readonly port?: string;
70
- /**
71
- * The one edit that clears the error, written for whoever authored the flow.
72
- * Set on `continuation.settle` authoring rejections; may be absent on other
73
- * `validation_error`s.
74
- */
75
- readonly fix?: string;
76
- /**
77
- * Simulation revert diagnostics attached to `simulation_revert` errors.
78
- * Contains the raw error bytes and decoded error candidates when the
79
- * backend can parse the revert reason.
80
- */
81
- readonly details?: SimulationRevert;
82
- /**
83
- * The prepared ops that failed, attached to `preparation_error` errors.
84
- * Each entry carries the `callId` of the failing node so callers can drop
85
- * the unroutable legs and resubmit a smaller flow.
86
- */
87
- readonly failedOps?: readonly FailedPreparedOp[];
88
- /**
89
- * The `callId`s of the prepared ops that succeeded, attached to
90
- * `preparation_error` errors alongside {@link ComposeError.failedOps}.
91
- */
92
- readonly succeededOps?: readonly string[];
93
- /** Version details attached only to `sdk_outdated` errors. */
94
- readonly sdkOutdated?: ComposeSdkOutdated;
95
- /** Version details attached only to `server_outdated` errors. */
96
- readonly serverOutdated?: ComposeServerOutdated;
97
- constructor(code: ComposeErrorCode, message: string, options?: {
98
- status?: number;
99
- url?: string;
100
- cause?: unknown;
101
- kind?: ComposeErrorKind | ComposeRouteErrorKind;
102
- path?: string;
103
- port?: string;
104
- fix?: string;
105
- details?: SimulationRevert;
106
- failedOps?: readonly FailedPreparedOp[];
107
- succeededOps?: readonly string[];
108
- sdkOutdated?: ComposeSdkOutdated;
109
- serverOutdated?: ComposeServerOutdated;
110
- });
49
+ export declare class ComposeError extends Error {
50
+ override readonly name = "ComposeError";
51
+ /** Machine-readable error category. */
52
+ readonly code: ComposeErrorCode;
53
+ /** HTTP status code, when the error originated from an HTTP response. */
54
+ readonly status?: number;
55
+ /** The request URL that produced the error. */
56
+ readonly url?: string;
57
+ /** Server-provided error kind for finer-grained classification. */
58
+ readonly kind?: ComposeErrorKind | ComposeRouteErrorKind;
59
+ /**
60
+ * Where a validation error points: the node id for a rejection of an
61
+ * authored node, or a JSON-pointer path for a rejection of the request shape.
62
+ */
63
+ readonly path?: string;
64
+ /**
65
+ * The input port of {@link ComposeError.path}'s node whose binding caused the
66
+ * error. Set when the rejection is about what a port binds rather than about
67
+ * the node's config.
68
+ */
69
+ readonly port?: string;
70
+ /**
71
+ * The one edit that clears the error, written for whoever authored the flow.
72
+ * Set on `continuation.settle` authoring rejections; may be absent on other
73
+ * `validation_error`s.
74
+ */
75
+ readonly fix?: string;
76
+ /**
77
+ * Simulation revert diagnostics attached to `simulation_revert` errors.
78
+ * Contains the raw error bytes and decoded error candidates when the
79
+ * backend can parse the revert reason.
80
+ */
81
+ readonly details?: SimulationRevert;
82
+ /**
83
+ * The prepared ops that failed, attached to `preparation_error` errors.
84
+ * Each entry carries the `callId` of the failing node so callers can drop
85
+ * the unroutable legs and resubmit a smaller flow.
86
+ */
87
+ readonly failedOps?: readonly FailedPreparedOp[];
88
+ /**
89
+ * The `callId`s of the prepared ops that succeeded, attached to
90
+ * `preparation_error` errors alongside {@link ComposeError.failedOps}.
91
+ */
92
+ readonly succeededOps?: readonly string[];
93
+ /** Version details attached only to `sdk_outdated` errors. */
94
+ readonly sdkOutdated?: ComposeSdkOutdated;
95
+ /** Version details attached only to `server_outdated` errors. */
96
+ readonly serverOutdated?: ComposeServerOutdated;
97
+ constructor(code: ComposeErrorCode, message: string, options?: {
98
+ status?: number;
99
+ url?: string;
100
+ cause?: unknown;
101
+ kind?: ComposeErrorKind | ComposeRouteErrorKind;
102
+ path?: string;
103
+ port?: string;
104
+ fix?: string;
105
+ details?: SimulationRevert;
106
+ failedOps?: readonly FailedPreparedOp[];
107
+ succeededOps?: readonly string[];
108
+ sdkOutdated?: ComposeSdkOutdated;
109
+ serverOutdated?: ComposeServerOutdated;
110
+ });
111
111
  }
112
112
  /**
113
113
  * The per-op preparation diagnostics carried by `preparation_error` responses,
114
114
  * with both arrays known to be present. Produced by narrowing with
115
115
  * {@link isComposePreparationError}.
116
116
  */
117
- interface ComposePreparationOps {
118
- readonly failedOps: readonly FailedPreparedOp[];
119
- readonly succeededOps: readonly string[];
117
+ export interface ComposePreparationOps {
118
+ readonly failedOps: readonly FailedPreparedOp[];
119
+ readonly succeededOps: readonly string[];
120
120
  }
121
121
  /**
122
122
  * Type guard that narrows an unknown error to {@link ComposeError}.
123
123
  * @param e - The value to check.
124
124
  * @returns `true` if `e` is an instance of `ComposeError`.
125
125
  */
126
- declare const isComposeError: (e: unknown) => e is ComposeError;
126
+ export declare const isComposeError: (e: unknown) => e is ComposeError;
127
127
  /**
128
128
  * Type guard for `preparation_error` failures (HTTP 422): a mixed basket where
129
129
  * some prepared ops failed and others succeeded. Narrows both
@@ -145,7 +145,7 @@ declare const isComposeError: (e: unknown) => e is ComposeError;
145
145
  * }
146
146
  * ```
147
147
  */
148
- declare const isComposePreparationError: (e: unknown) => e is ComposeError & ComposePreparationOps;
148
+ export declare const isComposePreparationError: (e: unknown) => e is ComposeError & ComposePreparationOps;
149
149
  /**
150
150
  * Narrows an outdated-SDK rejection to its required version details.
151
151
  *
@@ -162,8 +162,8 @@ declare const isComposePreparationError: (e: unknown) => e is ComposeError & Com
162
162
  * }
163
163
  * ```
164
164
  */
165
- declare const isComposeSdkOutdatedError: (e: unknown) => e is ComposeError & {
166
- readonly sdkOutdated: ComposeSdkOutdated;
165
+ export declare const isComposeSdkOutdatedError: (e: unknown) => e is ComposeError & {
166
+ readonly sdkOutdated: ComposeSdkOutdated;
167
167
  };
168
168
  /**
169
169
  * Narrows a server-behind-SDK rejection to its required version details.
@@ -184,8 +184,8 @@ declare const isComposeSdkOutdatedError: (e: unknown) => e is ComposeError & {
184
184
  * }
185
185
  * ```
186
186
  */
187
- declare const isComposeServerOutdatedError: (e: unknown) => e is ComposeError & {
188
- readonly serverOutdated: ComposeServerOutdated;
187
+ export declare const isComposeServerOutdatedError: (e: unknown) => e is ComposeError & {
188
+ readonly serverOutdated: ComposeServerOutdated;
189
189
  };
190
190
  /**
191
191
  * Constructs a {@link ComposeError} from an HTTP error response, extracting
@@ -196,6 +196,6 @@ declare const isComposeServerOutdatedError: (e: unknown) => e is ComposeError &
196
196
  * @param url - The request URL that produced the error.
197
197
  * @returns A `ComposeError` with the appropriate error code and metadata.
198
198
  */
199
- declare const errorFromHttpResponse: (status: number, body: string, url: string) => ComposeError;
200
-
201
- export { ComposeError, type ComposeErrorCode, type ComposePreparationOps, type ComposeSdkOutdated, type ComposeServerOutdated, errorFromHttpResponse, isComposeError, isComposePreparationError, isComposeSdkOutdatedError, isComposeServerOutdatedError };
199
+ export declare const errorFromHttpResponse: (status: number, body: string, url: string) => ComposeError;
200
+ //#endregion
201
+ //# sourceMappingURL=errors.d.ts.map