@oobe-protocol-labs/synapse-sap-sdk 0.13.0 → 0.15.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 (418) hide show
  1. package/dist/cjs/accounts/index.js +286 -0
  2. package/dist/cjs/accounts/index.js.map +1 -0
  3. package/dist/cjs/client.js +125 -0
  4. package/dist/cjs/client.js.map +1 -0
  5. package/dist/cjs/constants/seeds.js +9 -9
  6. package/dist/cjs/constants/seeds.js.map +1 -1
  7. package/dist/cjs/constants.js +66 -0
  8. package/dist/cjs/constants.js.map +1 -0
  9. package/dist/cjs/errors.js +260 -0
  10. package/dist/cjs/errors.js.map +1 -0
  11. package/dist/cjs/events/index.js +37 -123
  12. package/dist/cjs/events/index.js.map +1 -1
  13. package/dist/cjs/idlTypes.js +4 -0
  14. package/dist/cjs/idlTypes.js.map +1 -0
  15. package/dist/cjs/index.js +75 -241
  16. package/dist/cjs/index.js.map +1 -1
  17. package/dist/cjs/instructions/agent.js +90 -0
  18. package/dist/cjs/instructions/agent.js.map +1 -0
  19. package/dist/cjs/instructions/attestation.js +113 -0
  20. package/dist/cjs/instructions/attestation.js.map +1 -0
  21. package/dist/cjs/instructions/digest.js +29 -0
  22. package/dist/cjs/instructions/digest.js.map +1 -0
  23. package/dist/cjs/instructions/dispute.js +117 -0
  24. package/dist/cjs/instructions/dispute.js.map +1 -0
  25. package/dist/cjs/instructions/escrow.js +102 -0
  26. package/dist/cjs/instructions/escrow.js.map +1 -0
  27. package/dist/cjs/instructions/global.js +29 -0
  28. package/dist/cjs/instructions/global.js.map +1 -0
  29. package/dist/cjs/instructions/index.js +31 -0
  30. package/dist/cjs/instructions/index.js.map +1 -0
  31. package/dist/cjs/instructions/indexing.js +222 -0
  32. package/dist/cjs/instructions/indexing.js.map +1 -0
  33. package/dist/cjs/instructions/misc.js +74 -0
  34. package/dist/cjs/instructions/misc.js.map +1 -0
  35. package/dist/cjs/instructions/session.js +90 -0
  36. package/dist/cjs/instructions/session.js.map +1 -0
  37. package/dist/cjs/instructions/staking.js +133 -0
  38. package/dist/cjs/instructions/staking.js.map +1 -0
  39. package/dist/cjs/instructions/subscription.js +81 -0
  40. package/dist/cjs/instructions/subscription.js.map +1 -0
  41. package/dist/cjs/instructions/tools.js +110 -0
  42. package/dist/cjs/instructions/tools.js.map +1 -0
  43. package/dist/cjs/instructions/vault.js +107 -0
  44. package/dist/cjs/instructions/vault.js.map +1 -0
  45. package/dist/cjs/pdas/index.js +120 -0
  46. package/dist/cjs/pdas/index.js.map +1 -0
  47. package/dist/cjs/registries/fairscale.js +1 -1
  48. package/dist/cjs/registries/fairscale.js.map +1 -1
  49. package/dist/cjs/registries/metaplex-bridge.js +1 -1
  50. package/dist/cjs/registries/metaplex-bridge.js.map +1 -1
  51. package/dist/cjs/types.js +45 -0
  52. package/dist/cjs/types.js.map +1 -0
  53. package/dist/cjs/utils/escrow-validation.js +1 -1
  54. package/dist/cjs/utils/escrow-validation.js.map +1 -1
  55. package/dist/cjs/utils/index.js +32 -83
  56. package/dist/cjs/utils/index.js.map +1 -1
  57. package/dist/cjs/utils/merchant-validator.js +5 -5
  58. package/dist/cjs/utils/merchant-validator.js.map +1 -1
  59. package/dist/cjs/utils/validate.js +236 -0
  60. package/dist/cjs/utils/validate.js.map +1 -0
  61. package/dist/cjs/utils/volume-curve.js +1 -1
  62. package/dist/cjs/utils/volume-curve.js.map +1 -1
  63. package/dist/esm/accounts/index.d.ts +11 -0
  64. package/dist/esm/accounts/index.d.ts.map +1 -0
  65. package/dist/esm/accounts/index.js +273 -0
  66. package/dist/esm/accounts/index.js.map +1 -0
  67. package/dist/esm/client.d.ts +55 -0
  68. package/dist/esm/client.d.ts.map +1 -0
  69. package/dist/esm/client.js +87 -0
  70. package/dist/esm/client.js.map +1 -0
  71. package/dist/esm/constants/addresses.d.ts +117 -0
  72. package/dist/esm/constants/addresses.d.ts.map +1 -0
  73. package/dist/esm/constants/index.d.ts +31 -0
  74. package/dist/esm/constants/index.d.ts.map +1 -0
  75. package/dist/esm/constants/limits.d.ts +149 -0
  76. package/dist/esm/constants/limits.d.ts.map +1 -0
  77. package/{src/constants/network.ts → dist/esm/constants/network.d.ts} +23 -31
  78. package/dist/esm/constants/network.d.ts.map +1 -0
  79. package/{src/constants/payments.ts → dist/esm/constants/payments.d.ts} +11 -35
  80. package/dist/esm/constants/payments.d.ts.map +1 -0
  81. package/{src/constants/programs.ts → dist/esm/constants/programs.d.ts} +6 -20
  82. package/dist/esm/constants/programs.d.ts.map +1 -0
  83. package/dist/esm/constants/seeds.d.ts +80 -0
  84. package/dist/esm/constants/seeds.d.ts.map +1 -0
  85. package/dist/esm/constants/seeds.js +9 -9
  86. package/dist/esm/constants/seeds.js.map +1 -1
  87. package/dist/esm/constants.d.ts +39 -0
  88. package/dist/esm/constants.d.ts.map +1 -0
  89. package/dist/esm/constants.js +41 -0
  90. package/dist/esm/constants.js.map +1 -0
  91. package/dist/esm/core/client.d.ts +452 -0
  92. package/dist/esm/core/client.d.ts.map +1 -0
  93. package/dist/esm/core/connection.d.ts +305 -0
  94. package/dist/esm/core/connection.d.ts.map +1 -0
  95. package/{src/core/index.ts → dist/esm/core/index.d.ts} +1 -1
  96. package/dist/esm/core/index.d.ts.map +1 -0
  97. package/dist/esm/errors/index.d.ts +276 -0
  98. package/dist/esm/errors/index.d.ts.map +1 -0
  99. package/dist/esm/errors.d.ts +119 -0
  100. package/dist/esm/errors.d.ts.map +1 -0
  101. package/dist/esm/errors.js +252 -0
  102. package/dist/esm/errors.js.map +1 -0
  103. package/dist/esm/events/geyser.d.ts +150 -0
  104. package/dist/esm/events/geyser.d.ts.map +1 -0
  105. package/dist/esm/events/index.d.ts +17 -0
  106. package/dist/esm/events/index.d.ts.map +1 -0
  107. package/dist/esm/events/index.js +34 -122
  108. package/dist/esm/events/index.js.map +1 -1
  109. package/{src/idl/index.ts → dist/esm/idl/index.d.ts} +9 -15
  110. package/dist/esm/idl/index.d.ts.map +1 -0
  111. package/dist/esm/idlTypes.d.ts +925 -0
  112. package/dist/esm/idlTypes.d.ts.map +1 -0
  113. package/dist/esm/idlTypes.js +3 -0
  114. package/dist/esm/idlTypes.js.map +1 -0
  115. package/dist/esm/index.d.ts +12 -0
  116. package/dist/esm/index.d.ts.map +1 -0
  117. package/dist/esm/index.js +15 -88
  118. package/dist/esm/index.js.map +1 -1
  119. package/dist/esm/instructions/agent.d.ts +71 -0
  120. package/dist/esm/instructions/agent.d.ts.map +1 -0
  121. package/dist/esm/instructions/agent.js +86 -0
  122. package/dist/esm/instructions/agent.js.map +1 -0
  123. package/dist/esm/instructions/attestation.d.ts +76 -0
  124. package/dist/esm/instructions/attestation.d.ts.map +1 -0
  125. package/dist/esm/instructions/attestation.js +109 -0
  126. package/dist/esm/instructions/attestation.js.map +1 -0
  127. package/dist/esm/instructions/digest.d.ts +20 -0
  128. package/dist/esm/instructions/digest.d.ts.map +1 -0
  129. package/dist/esm/instructions/digest.js +25 -0
  130. package/dist/esm/instructions/digest.js.map +1 -0
  131. package/dist/esm/instructions/dispute.d.ts +81 -0
  132. package/dist/esm/instructions/dispute.d.ts.map +1 -0
  133. package/dist/esm/instructions/dispute.js +113 -0
  134. package/dist/esm/instructions/dispute.js.map +1 -0
  135. package/dist/esm/instructions/escrow.d.ts +79 -0
  136. package/dist/esm/instructions/escrow.d.ts.map +1 -0
  137. package/dist/esm/instructions/escrow.js +98 -0
  138. package/dist/esm/instructions/escrow.js.map +1 -0
  139. package/dist/esm/instructions/global.d.ts +14 -0
  140. package/dist/esm/instructions/global.d.ts.map +1 -0
  141. package/dist/esm/instructions/global.js +25 -0
  142. package/dist/esm/instructions/global.js.map +1 -0
  143. package/dist/esm/instructions/index.d.ts +14 -0
  144. package/dist/esm/instructions/index.d.ts.map +1 -0
  145. package/dist/esm/instructions/index.js +15 -0
  146. package/dist/esm/instructions/index.js.map +1 -0
  147. package/dist/esm/instructions/indexing.d.ts +150 -0
  148. package/dist/esm/instructions/indexing.d.ts.map +1 -0
  149. package/dist/esm/instructions/indexing.js +218 -0
  150. package/dist/esm/instructions/indexing.js.map +1 -0
  151. package/dist/esm/instructions/memory.d.ts +8 -0
  152. package/dist/esm/instructions/memory.d.ts.map +1 -0
  153. package/dist/esm/instructions/memory.js +234 -0
  154. package/dist/esm/instructions/memory.js.map +1 -0
  155. package/dist/esm/instructions/misc.d.ts +50 -0
  156. package/dist/esm/instructions/misc.d.ts.map +1 -0
  157. package/dist/esm/instructions/misc.js +70 -0
  158. package/dist/esm/instructions/misc.js.map +1 -0
  159. package/dist/esm/instructions/session.d.ts +57 -0
  160. package/dist/esm/instructions/session.d.ts.map +1 -0
  161. package/dist/esm/instructions/session.js +86 -0
  162. package/dist/esm/instructions/session.js.map +1 -0
  163. package/dist/esm/instructions/staking.d.ts +85 -0
  164. package/dist/esm/instructions/staking.d.ts.map +1 -0
  165. package/dist/esm/instructions/staking.js +129 -0
  166. package/dist/esm/instructions/staking.js.map +1 -0
  167. package/dist/esm/instructions/subscription.d.ts +50 -0
  168. package/dist/esm/instructions/subscription.d.ts.map +1 -0
  169. package/dist/esm/instructions/subscription.js +77 -0
  170. package/dist/esm/instructions/subscription.js.map +1 -0
  171. package/dist/esm/instructions/tools.d.ts +88 -0
  172. package/dist/esm/instructions/tools.d.ts.map +1 -0
  173. package/dist/esm/instructions/tools.js +106 -0
  174. package/dist/esm/instructions/tools.js.map +1 -0
  175. package/dist/esm/instructions/vault.d.ts +84 -0
  176. package/dist/esm/instructions/vault.d.ts.map +1 -0
  177. package/dist/esm/instructions/vault.js +103 -0
  178. package/dist/esm/instructions/vault.js.map +1 -0
  179. package/dist/esm/modules/agent.d.ts +166 -0
  180. package/dist/esm/modules/agent.d.ts.map +1 -0
  181. package/dist/esm/modules/attestation.d.ts +96 -0
  182. package/dist/esm/modules/attestation.d.ts.map +1 -0
  183. package/dist/esm/modules/base.d.ts +161 -0
  184. package/dist/esm/modules/base.d.ts.map +1 -0
  185. package/dist/esm/modules/escrow-v2.d.ts +169 -0
  186. package/dist/esm/modules/escrow-v2.d.ts.map +1 -0
  187. package/dist/esm/modules/feedback.d.ts +105 -0
  188. package/dist/esm/modules/feedback.d.ts.map +1 -0
  189. package/{src/modules/index.ts → dist/esm/modules/index.d.ts} +1 -1
  190. package/dist/esm/modules/index.d.ts.map +1 -0
  191. package/dist/esm/modules/indexing.d.ts +200 -0
  192. package/dist/esm/modules/indexing.d.ts.map +1 -0
  193. package/dist/esm/modules/ledger.d.ts +150 -0
  194. package/dist/esm/modules/ledger.d.ts.map +1 -0
  195. package/dist/esm/modules/receipt.d.ts +77 -0
  196. package/dist/esm/modules/receipt.d.ts.map +1 -0
  197. package/dist/esm/modules/staking.d.ts +51 -0
  198. package/dist/esm/modules/staking.d.ts.map +1 -0
  199. package/dist/esm/modules/subscription.d.ts +33 -0
  200. package/dist/esm/modules/subscription.d.ts.map +1 -0
  201. package/dist/esm/modules/tools.d.ts +182 -0
  202. package/dist/esm/modules/tools.d.ts.map +1 -0
  203. package/dist/esm/modules/vault.d.ts +240 -0
  204. package/dist/esm/modules/vault.d.ts.map +1 -0
  205. package/dist/esm/parser/client.d.ts +123 -0
  206. package/dist/esm/parser/client.d.ts.map +1 -0
  207. package/dist/esm/parser/complete.d.ts +90 -0
  208. package/dist/esm/parser/complete.d.ts.map +1 -0
  209. package/{src/parser/index.ts → dist/esm/parser/index.d.ts} +6 -37
  210. package/dist/esm/parser/index.d.ts.map +1 -0
  211. package/dist/esm/parser/inner.d.ts +114 -0
  212. package/dist/esm/parser/inner.d.ts.map +1 -0
  213. package/{src/parser/instructions.ts → dist/esm/parser/instructions.d.ts} +4 -63
  214. package/dist/esm/parser/instructions.d.ts.map +1 -0
  215. package/dist/esm/parser/transaction.d.ts +77 -0
  216. package/dist/esm/parser/transaction.d.ts.map +1 -0
  217. package/dist/esm/parser/types.d.ts +154 -0
  218. package/dist/esm/parser/types.d.ts.map +1 -0
  219. package/{src/pda/index.ts → dist/esm/pda/index.d.ts} +33 -442
  220. package/dist/esm/pda/index.d.ts.map +1 -0
  221. package/dist/esm/pdas/index.d.ts +37 -0
  222. package/dist/esm/pdas/index.d.ts.map +1 -0
  223. package/dist/esm/pdas/index.js +101 -0
  224. package/dist/esm/pdas/index.js.map +1 -0
  225. package/dist/esm/plugin/index.d.ts +171 -0
  226. package/dist/esm/plugin/index.d.ts.map +1 -0
  227. package/dist/esm/plugin/protocols.d.ts +152 -0
  228. package/dist/esm/plugin/protocols.d.ts.map +1 -0
  229. package/dist/esm/plugin/schemas.d.ts +829 -0
  230. package/dist/esm/plugin/schemas.d.ts.map +1 -0
  231. package/dist/esm/postgres/adapter.d.ts +355 -0
  232. package/dist/esm/postgres/adapter.d.ts.map +1 -0
  233. package/dist/esm/postgres/index.d.ts +24 -0
  234. package/dist/esm/postgres/index.d.ts.map +1 -0
  235. package/dist/esm/postgres/serializers.d.ts +30 -0
  236. package/dist/esm/postgres/serializers.d.ts.map +1 -0
  237. package/dist/esm/postgres/sync.d.ts +156 -0
  238. package/dist/esm/postgres/sync.d.ts.map +1 -0
  239. package/dist/esm/postgres/types.d.ts +167 -0
  240. package/dist/esm/postgres/types.d.ts.map +1 -0
  241. package/dist/esm/registries/builder.d.ts +340 -0
  242. package/dist/esm/registries/builder.d.ts.map +1 -0
  243. package/dist/esm/registries/discovery.d.ts +333 -0
  244. package/dist/esm/registries/discovery.d.ts.map +1 -0
  245. package/dist/esm/registries/fairscale.d.ts +680 -0
  246. package/dist/esm/registries/fairscale.d.ts.map +1 -0
  247. package/dist/esm/registries/fairscale.js +1 -1
  248. package/dist/esm/registries/fairscale.js.map +1 -1
  249. package/dist/esm/registries/index.d.ts +52 -0
  250. package/dist/esm/registries/index.d.ts.map +1 -0
  251. package/dist/esm/registries/metaplex-bridge.d.ts +489 -0
  252. package/dist/esm/registries/metaplex-bridge.d.ts.map +1 -0
  253. package/dist/esm/registries/metaplex-bridge.js +1 -1
  254. package/dist/esm/registries/metaplex-bridge.js.map +1 -1
  255. package/dist/esm/registries/session.d.ts +323 -0
  256. package/dist/esm/registries/session.d.ts.map +1 -0
  257. package/dist/esm/registries/x402.d.ts +530 -0
  258. package/dist/esm/registries/x402.d.ts.map +1 -0
  259. package/dist/esm/types/accounts.d.ts +765 -0
  260. package/dist/esm/types/accounts.d.ts.map +1 -0
  261. package/dist/esm/types/common.d.ts +166 -0
  262. package/dist/esm/types/common.d.ts.map +1 -0
  263. package/dist/esm/types/endpoint.d.ts +161 -0
  264. package/dist/esm/types/endpoint.d.ts.map +1 -0
  265. package/dist/esm/types/enums.d.ts +353 -0
  266. package/dist/esm/types/enums.d.ts.map +1 -0
  267. package/dist/esm/types/index.d.ts +29 -0
  268. package/dist/esm/types/index.d.ts.map +1 -0
  269. package/dist/esm/types/instructions.d.ts +400 -0
  270. package/dist/esm/types/instructions.d.ts.map +1 -0
  271. package/dist/esm/types.d.ts +236 -0
  272. package/dist/esm/types.d.ts.map +1 -0
  273. package/dist/esm/types.js +40 -0
  274. package/dist/esm/types.js.map +1 -0
  275. package/dist/esm/utils/anchor-errors.d.ts +61 -0
  276. package/dist/esm/utils/anchor-errors.d.ts.map +1 -0
  277. package/dist/esm/utils/endpoint-validator.d.ts +110 -0
  278. package/dist/esm/utils/endpoint-validator.d.ts.map +1 -0
  279. package/dist/esm/utils/escrow-validation.d.ts +145 -0
  280. package/dist/esm/utils/escrow-validation.d.ts.map +1 -0
  281. package/dist/esm/utils/escrow-validation.js +1 -1
  282. package/dist/esm/utils/escrow-validation.js.map +1 -1
  283. package/{src/utils/hash.ts → dist/esm/utils/hash.d.ts} +4 -42
  284. package/dist/esm/utils/hash.d.ts.map +1 -0
  285. package/dist/esm/utils/index.d.ts +6 -0
  286. package/dist/esm/utils/index.d.ts.map +1 -0
  287. package/dist/esm/utils/index.js +16 -33
  288. package/dist/esm/utils/index.js.map +1 -1
  289. package/dist/esm/utils/merchant-validator.d.ts +176 -0
  290. package/dist/esm/utils/merchant-validator.d.ts.map +1 -0
  291. package/dist/esm/utils/merchant-validator.js +1 -1
  292. package/dist/esm/utils/merchant-validator.js.map +1 -1
  293. package/dist/esm/utils/network-normalizer.d.ts +120 -0
  294. package/dist/esm/utils/network-normalizer.d.ts.map +1 -0
  295. package/dist/esm/utils/priority-fee.d.ts +205 -0
  296. package/dist/esm/utils/priority-fee.d.ts.map +1 -0
  297. package/dist/esm/utils/rpc-strategy.d.ts +172 -0
  298. package/dist/esm/utils/rpc-strategy.d.ts.map +1 -0
  299. package/dist/esm/utils/schemas.d.ts +351 -0
  300. package/dist/esm/utils/schemas.d.ts.map +1 -0
  301. package/{src/utils/serialization.ts → dist/esm/utils/serialization.d.ts} +3 -32
  302. package/dist/esm/utils/serialization.d.ts.map +1 -0
  303. package/dist/esm/utils/validate.d.ts +66 -0
  304. package/dist/esm/utils/validate.d.ts.map +1 -0
  305. package/dist/esm/utils/validate.js +221 -0
  306. package/dist/esm/utils/validate.js.map +1 -0
  307. package/{src/utils/validation.ts → dist/esm/utils/validation.d.ts} +2 -9
  308. package/dist/esm/utils/validation.d.ts.map +1 -0
  309. package/{src/utils/volume-curve.ts → dist/esm/utils/volume-curve.d.ts} +2 -73
  310. package/dist/esm/utils/volume-curve.d.ts.map +1 -0
  311. package/dist/esm/utils/volume-curve.js +1 -1
  312. package/dist/esm/utils/volume-curve.js.map +1 -1
  313. package/dist/esm/utils/x402-direct.d.ts +114 -0
  314. package/dist/esm/utils/x402-direct.d.ts.map +1 -0
  315. package/dist/types/constants/seeds.d.ts +2 -0
  316. package/dist/types/constants/seeds.d.ts.map +1 -1
  317. package/dist/types/core/client.d.ts +21 -6
  318. package/dist/types/core/client.d.ts.map +1 -1
  319. package/dist/types/errors/index.d.ts +59 -0
  320. package/dist/types/errors/index.d.ts.map +1 -1
  321. package/dist/types/index.d.ts +3 -2
  322. package/dist/types/index.d.ts.map +1 -1
  323. package/dist/types/modules/agent.d.ts +9 -19
  324. package/dist/types/modules/agent.d.ts.map +1 -1
  325. package/dist/types/modules/attestation.d.ts.map +1 -1
  326. package/dist/types/modules/base.d.ts +54 -0
  327. package/dist/types/modules/base.d.ts.map +1 -1
  328. package/dist/types/modules/escrow-v2.d.ts +117 -1
  329. package/dist/types/modules/escrow-v2.d.ts.map +1 -1
  330. package/dist/types/modules/index.d.ts +1 -2
  331. package/dist/types/modules/index.d.ts.map +1 -1
  332. package/dist/types/modules/receipt.d.ts +14 -0
  333. package/dist/types/modules/receipt.d.ts.map +1 -1
  334. package/dist/types/modules/subscription.d.ts.map +1 -1
  335. package/dist/types/modules/tools.d.ts +0 -10
  336. package/dist/types/modules/tools.d.ts.map +1 -1
  337. package/dist/types/modules/vault.d.ts.map +1 -1
  338. package/dist/types/pda/index.d.ts +17 -0
  339. package/dist/types/pda/index.d.ts.map +1 -1
  340. package/dist/types/plugin/index.d.ts.map +1 -1
  341. package/dist/types/registries/builder.d.ts +2 -9
  342. package/dist/types/registries/builder.d.ts.map +1 -1
  343. package/dist/types/registries/metaplex-bridge.d.ts.map +1 -1
  344. package/dist/types/registries/session.d.ts +3 -9
  345. package/dist/types/registries/session.d.ts.map +1 -1
  346. package/dist/types/registries/x402.d.ts +2 -9
  347. package/dist/types/registries/x402.d.ts.map +1 -1
  348. package/dist/types/types/accounts.d.ts +52 -0
  349. package/dist/types/types/accounts.d.ts.map +1 -1
  350. package/dist/types/types/index.d.ts +1 -1
  351. package/dist/types/types/index.d.ts.map +1 -1
  352. package/dist/types/utils/rpc-strategy.d.ts +7 -0
  353. package/dist/types/utils/rpc-strategy.d.ts.map +1 -1
  354. package/package.json +59 -183
  355. package/src/constants/addresses.ts +0 -162
  356. package/src/constants/index.ts +0 -69
  357. package/src/constants/limits.ts +0 -165
  358. package/src/constants/seeds.ts +0 -85
  359. package/src/core/client.ts +0 -583
  360. package/src/core/connection.ts +0 -461
  361. package/src/errors/index.ts +0 -346
  362. package/src/events/geyser.ts +0 -384
  363. package/src/events/index.ts +0 -335
  364. package/src/events/yellowstone.d.ts +0 -7
  365. package/src/idl/synapse_agent_sap.json +0 -14595
  366. package/src/index.ts +0 -421
  367. package/src/modules/agent.ts +0 -319
  368. package/src/modules/attestation.ts +0 -168
  369. package/src/modules/base.ts +0 -247
  370. package/src/modules/escrow-v2.ts +0 -871
  371. package/src/modules/escrow.ts +0 -439
  372. package/src/modules/feedback.ts +0 -186
  373. package/src/modules/indexing.ts +0 -444
  374. package/src/modules/ledger.ts +0 -262
  375. package/src/modules/receipt.ts +0 -212
  376. package/src/modules/staking.ts +0 -223
  377. package/src/modules/subscription.ts +0 -147
  378. package/src/modules/tools.ts +0 -454
  379. package/src/modules/vault.ts +0 -558
  380. package/src/parser/client.ts +0 -211
  381. package/src/parser/complete.ts +0 -232
  382. package/src/parser/inner.ts +0 -255
  383. package/src/parser/transaction.ts +0 -200
  384. package/src/parser/types.ts +0 -182
  385. package/src/plugin/index.ts +0 -1224
  386. package/src/plugin/protocols.ts +0 -404
  387. package/src/plugin/schemas.ts +0 -941
  388. package/src/postgres/adapter.ts +0 -904
  389. package/src/postgres/index.ts +0 -59
  390. package/src/postgres/schema.sql +0 -683
  391. package/src/postgres/serializers.ts +0 -485
  392. package/src/postgres/sync.ts +0 -340
  393. package/src/postgres/types.ts +0 -245
  394. package/src/registries/builder.ts +0 -607
  395. package/src/registries/discovery.ts +0 -572
  396. package/src/registries/fairscale.ts +0 -1278
  397. package/src/registries/index.ts +0 -143
  398. package/src/registries/metaplex-bridge.ts +0 -1199
  399. package/src/registries/session.ts +0 -613
  400. package/src/registries/x402.ts +0 -1048
  401. package/src/types/accounts.ts +0 -858
  402. package/src/types/common.ts +0 -187
  403. package/src/types/endpoint.ts +0 -181
  404. package/src/types/enums.ts +0 -333
  405. package/src/types/index.ts +0 -121
  406. package/src/types/instructions.ts +0 -453
  407. package/src/utils/anchor-errors.ts +0 -461
  408. package/src/utils/endpoint-validator.ts +0 -300
  409. package/src/utils/escrow-validation.ts +0 -301
  410. package/src/utils/index.ts +0 -118
  411. package/src/utils/merchant-validator.ts +0 -359
  412. package/src/utils/network-normalizer.ts +0 -240
  413. package/src/utils/priority-fee.ts +0 -325
  414. package/src/utils/rpc-strategy.ts +0 -322
  415. package/src/utils/schemas.ts +0 -359
  416. package/src/utils/x402-direct.ts +0 -370
  417. /package/dist/{types → esm}/modules/escrow.d.ts +0 -0
  418. /package/dist/{types → esm}/modules/escrow.d.ts.map +0 -0
@@ -1,322 +0,0 @@
1
- /**
2
- * @module utils/rpc-strategy
3
- * @description Dual-connection RPC strategy and idempotent ATA creation.
4
- *
5
- * Solves two interoperability problems:
6
- *
7
- * 1. **WebSocket 400 loop**: Some authenticated RPCs reject WebSocket
8
- * connections for SPL token operations. This module exposes a
9
- * dual-connection strategy: primary RPC for SAP program calls,
10
- * fallback public RPC for token operations.
11
- *
12
- * 2. **Idempotent ATA creation**: Wraps `getOrCreateAssociatedTokenAccount`
13
- * with retries so "account already exists" doesn't surface as a
14
- * hard error.
15
- *
16
- * @category Utils
17
- * @since v0.6.0
18
- */
19
-
20
- import {
21
- Connection,
22
- type Commitment,
23
- PublicKey,
24
- type TransactionSignature,
25
- } from "@solana/web3.js";
26
-
27
- // ═══════════════════════════════════════════════════════════════════
28
- // RPC Strategy Types
29
- // ═══════════════════════════════════════════════════════════════════
30
-
31
- /**
32
- * @interface RpcConfig
33
- * @description Configuration for dual-connection RPC strategy.
34
- * @category Utils
35
- * @since v0.6.0
36
- */
37
- export interface RpcConfig {
38
- /** Primary RPC URL (for SAP program calls). */
39
- readonly primaryUrl: string;
40
- /** Fallback RPC URL (for SPL token ops, public RPCs). */
41
- readonly fallbackUrl?: string;
42
- /** Commitment level. */
43
- readonly commitment?: Commitment;
44
- }
45
-
46
- /**
47
- * @interface DualConnection
48
- * @description Dual RPC connections: primary for SAP, fallback for tokens.
49
- * @category Utils
50
- * @since v0.6.0
51
- */
52
- export interface DualConnection {
53
- /** Primary connection for SAP program calls. */
54
- readonly primary: Connection;
55
- /** Fallback connection for SPL token operations. */
56
- readonly fallback: Connection;
57
- }
58
-
59
- // ═══════════════════════════════════════════════════════════════════
60
- // Default Public RPCs
61
- // ═══════════════════════════════════════════════════════════════════
62
-
63
- /** Well-known public fallback RPCs by cluster. */
64
- const PUBLIC_RPCS: Record<string, string> = {
65
- "mainnet-beta": "https://api.mainnet-beta.solana.com",
66
- devnet: "https://api.devnet.solana.com",
67
- localnet: "http://localhost:8899",
68
- };
69
-
70
- // ═══════════════════════════════════════════════════════════════════
71
- // Public API
72
- // ═══════════════════════════════════════════════════════════════════
73
-
74
- /**
75
- * @name getRpcUrl
76
- * @description Get the primary RPC URL from environment or config.
77
- *
78
- * Resolution order:
79
- * 1. Explicit `config.primaryUrl`
80
- * 2. `SOLANA_RPC_URL` env var
81
- * 3. Cluster-appropriate public RPC
82
- *
83
- * @param config - Optional RPC configuration.
84
- * @param cluster - Cluster hint (defaults to "mainnet-beta").
85
- * @returns The resolved primary RPC URL.
86
- *
87
- * @category Utils
88
- * @since v0.6.0
89
- */
90
- export function getRpcUrl(
91
- config?: Partial<RpcConfig>,
92
- cluster: string = "mainnet-beta",
93
- ): string {
94
- if (config?.primaryUrl) return config.primaryUrl;
95
-
96
- // Environment variable
97
- const envUrl =
98
- typeof process !== "undefined" ? process.env?.SOLANA_RPC_URL : undefined;
99
- if (envUrl) return envUrl;
100
-
101
- return PUBLIC_RPCS[cluster] ?? PUBLIC_RPCS["mainnet-beta"]!;
102
- }
103
-
104
- /**
105
- * @name getFallbackRpcUrl
106
- * @description Get the fallback RPC URL for SPL token operations.
107
- *
108
- * This avoids the WebSocket-400 loop when the primary RPC is
109
- * an authenticated endpoint that rejects token-related WebSocket
110
- * subscriptions.
111
- *
112
- * @param config - Optional RPC configuration.
113
- * @param cluster - Cluster hint (defaults to "mainnet-beta").
114
- * @returns The resolved fallback RPC URL.
115
- *
116
- * @category Utils
117
- * @since v0.6.0
118
- */
119
- export function getFallbackRpcUrl(
120
- config?: Partial<RpcConfig>,
121
- cluster: string = "mainnet-beta",
122
- ): string {
123
- if (config?.fallbackUrl) return config.fallbackUrl;
124
-
125
- // Env fallback
126
- const envUrl =
127
- typeof process !== "undefined"
128
- ? process.env?.SOLANA_FALLBACK_RPC_URL
129
- : undefined;
130
- if (envUrl) return envUrl;
131
-
132
- return PUBLIC_RPCS[cluster] ?? PUBLIC_RPCS["mainnet-beta"]!;
133
- }
134
-
135
- /**
136
- * @name createDualConnection
137
- * @description Create a dual-connection pair: primary for SAP program calls,
138
- * fallback for SPL token operations.
139
- *
140
- * @param config - RPC configuration.
141
- * @param cluster - Cluster hint.
142
- * @returns A {@link DualConnection} with both connections.
143
- *
144
- * @category Utils
145
- * @since v0.6.0
146
- *
147
- * @example
148
- * ```ts
149
- * const { primary, fallback } = createDualConnection({
150
- * primaryUrl: "https://my-rpc.example.com",
151
- * }, "mainnet-beta");
152
- *
153
- * // Use primary for SAP calls
154
- * const provider = new AnchorProvider(primary, wallet, {});
155
- *
156
- * // Use fallback for SPL token account creation
157
- * const ata = await getOrCreateATA(fallback, mint, owner);
158
- * ```
159
- */
160
- export function createDualConnection(
161
- config: Partial<RpcConfig>,
162
- cluster: string = "mainnet-beta",
163
- ): DualConnection {
164
- const commitment = config.commitment ?? "confirmed";
165
- const primaryUrl = getRpcUrl(config, cluster);
166
- const fallbackUrl = getFallbackRpcUrl(config, cluster);
167
-
168
- return {
169
- primary: new Connection(primaryUrl, { commitment }),
170
- fallback: new Connection(fallbackUrl, { commitment }),
171
- };
172
- }
173
-
174
- // ═══════════════════════════════════════════════════════════════════
175
- // Idempotent ATA Creation
176
- // ═══════════════════════════════════════════════════════════════════
177
-
178
- /**
179
- * @interface AtaResult
180
- * @description Result of idempotent ATA creation attempt.
181
- * @category Utils
182
- * @since v0.6.0
183
- */
184
- export interface AtaResult {
185
- /** The ATA public key (exists or newly created). */
186
- readonly address: PublicKey;
187
- /** Whether the ATA already existed. */
188
- readonly existed: boolean;
189
- /** Transaction signature (only if newly created). */
190
- readonly txSignature?: TransactionSignature;
191
- }
192
-
193
- /**
194
- * @name findATA
195
- * @description Derive the Associated Token Account address.
196
- * Uses the standard ATA PDA derivation without importing the full
197
- * `@solana/spl-token` package.
198
- *
199
- * @param owner - The token account owner.
200
- * @param mint - The token mint.
201
- * @param programId - Token program ID (defaults to TOKEN_PROGRAM_ID).
202
- * @returns The derived ATA public key.
203
- *
204
- * @category Utils
205
- * @since v0.6.0
206
- */
207
- export function findATA(
208
- owner: PublicKey,
209
- mint: PublicKey,
210
- programId: PublicKey = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"),
211
- ): PublicKey {
212
- const ASSOCIATED_TOKEN_PROGRAM_ID = new PublicKey(
213
- "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
214
- );
215
-
216
- const [ata] = PublicKey.findProgramAddressSync(
217
- [owner.toBuffer(), programId.toBuffer(), mint.toBuffer()],
218
- ASSOCIATED_TOKEN_PROGRAM_ID,
219
- );
220
- return ata;
221
- }
222
-
223
- // ═══════════════════════════════════════════════════════════════════
224
- // Error Classification
225
- // ═══════════════════════════════════════════════════════════════════
226
-
227
- /**
228
- * Anchor error code to friendly message mapping.
229
- * Converts cryptic Anchor errors into actionable messages.
230
- */
231
- const ANCHOR_ERROR_MESSAGES: Record<number, string> = {
232
- 6000: "Agent already registered for this wallet",
233
- 6001: "Agent not found — register first",
234
- 6002: "Name exceeds maximum length (64 bytes)",
235
- 6003: "Description exceeds maximum length (256 bytes)",
236
- 6004: "Too many capabilities (max 10)",
237
- 6005: "Too many pricing tiers (max 5)",
238
- 6006: "Too many protocols (max 5)",
239
- 6007: "Feedback score out of range (0-1000)",
240
- 6008: "Unauthorized — only the agent owner can perform this action",
241
- 6009: "Escrow expired",
242
- 6010: "Insufficient escrow balance",
243
- 6011: "Max calls exceeded",
244
- 6012: "Invalid settlement — calls must be > 0",
245
- 6013: "Escrow not empty — withdraw balance before closing",
246
- 6014: "Invalid token program — make sure you passed TOKEN_PROGRAM_ID as the 3rd remaining account",
247
- 6015: "Vault already initialized",
248
- 6016: "Session already exists",
249
- 6017: "Session closed — cannot write to closed session",
250
- 6018: "Data exceeds maximum write size (750 bytes)",
251
- 6019: "Ring buffer overflow — seal before writing more",
252
- };
253
-
254
- /**
255
- * @name classifyAnchorError
256
- * @description Convert an Anchor error code into a friendly, actionable message.
257
- *
258
- * @param errorCode - The numeric Anchor error code.
259
- * @returns A human-readable error message, or a generic message for unknown codes.
260
- *
261
- * @category Utils
262
- * @since v0.6.0
263
- *
264
- * @example
265
- * ```ts
266
- * try {
267
- * await client.escrow.create(...);
268
- * } catch (err) {
269
- * const code = extractAnchorErrorCode(err);
270
- * if (code !== null) {
271
- * console.error(classifyAnchorError(code));
272
- * }
273
- * }
274
- * ```
275
- */
276
- export function classifyAnchorError(errorCode: number): string {
277
- return (
278
- ANCHOR_ERROR_MESSAGES[errorCode] ??
279
- `Unknown SAP program error (code ${errorCode}). Check the IDL for details.`
280
- );
281
- }
282
-
283
- /**
284
- * @name extractAnchorErrorCode
285
- * @description Attempt to extract an Anchor error code from an Error object.
286
- *
287
- * Anchor errors typically have the structure `{ code: number, msg: string }`.
288
- * This function handles both the direct `error.code` pattern and the
289
- * `error.error.errorCode.number` nested pattern.
290
- *
291
- * @param err - The caught error object.
292
- * @returns The numeric error code, or `null` if not an Anchor error.
293
- *
294
- * @category Utils
295
- * @since v0.6.0
296
- */
297
- export function extractAnchorErrorCode(err: unknown): number | null {
298
- if (err == null || typeof err !== "object") return null;
299
-
300
- // Direct code property
301
- const direct = (err as Record<string, unknown>).code;
302
- if (typeof direct === "number") return direct;
303
-
304
- // Nested Anchor format: error.error.errorCode.number
305
- const nested = (err as Record<string, unknown>).error;
306
- if (nested && typeof nested === "object") {
307
- const errorCode = (nested as Record<string, unknown>).errorCode;
308
- if (errorCode && typeof errorCode === "object") {
309
- const num = (errorCode as Record<string, unknown>).number;
310
- if (typeof num === "number") return num;
311
- }
312
- }
313
-
314
- // AnchorError pattern: { logs: [...], error: { errorCode: { number } } }
315
- const msg = (err as Error).message;
316
- if (typeof msg === "string") {
317
- const match = msg.match(/custom program error:\s*0x([0-9a-fA-F]+)/);
318
- if (match?.[1]) return parseInt(match[1], 16);
319
- }
320
-
321
- return null;
322
- }
@@ -1,359 +0,0 @@
1
- /**
2
- * @module utils/schemas
3
- * @description Zod schemas for runtime validation of environment variables,
4
- * tool arguments, agent manifests, and x402 payment parameters.
5
- *
6
- * These schemas enforce correctness at the boundary: CLI scripts refuse
7
- * to run if required fields are missing or mis-typed, and SDK methods
8
- * validate inputs before hitting the chain.
9
- *
10
- * Zod is a peer dependency — these schemas are tree-shaken if not imported.
11
- *
12
- * @category Utils
13
- * @since v0.6.0
14
- */
15
-
16
- // ═══════════════════════════════════════════════════════════════════
17
- // Dynamic Zod import (peer dependency)
18
- // ═══════════════════════════════════════════════════════════════════
19
-
20
- // We use a lazy getter pattern to avoid hard failures when zod is not installed
21
- let _z: typeof import("zod") | null = null;
22
-
23
- function getZod(): typeof import("zod") {
24
- if (!_z) {
25
- try {
26
- // eslint-disable-next-line @typescript-eslint/no-require-imports
27
- _z = require("zod");
28
- } catch {
29
- throw new Error(
30
- "[SAP SDK] Zod is required for schema validation. Install it: npm install zod",
31
- );
32
- }
33
- }
34
- return _z!;
35
- }
36
-
37
- // ═══════════════════════════════════════════════════════════════════
38
- // Environment Schemas
39
- // ═══════════════════════════════════════════════════════════════════
40
-
41
- /**
42
- * @name createEnvSchema
43
- * @description Create a Zod schema for SAP SDK environment variables.
44
- * Validates that all required env vars are present and correctly typed.
45
- *
46
- * @returns A Zod schema object for env validation.
47
- *
48
- * @category Utils
49
- * @since v0.6.0
50
- *
51
- * @example
52
- * ```ts
53
- * import { createEnvSchema } from "@synapse-sap/sdk";
54
- *
55
- * const schema = createEnvSchema();
56
- * const env = schema.parse(process.env);
57
- * // env.SOLANA_CLUSTER is typed as "mainnet-beta" | "devnet" | "localnet"
58
- * ```
59
- */
60
- export function createEnvSchema() {
61
- const z = getZod();
62
-
63
- return z.object({
64
- SOLANA_CLUSTER: z
65
- .enum(["mainnet-beta", "devnet", "localnet"])
66
- .default("devnet")
67
- .describe("Solana cluster"),
68
- SOLANA_RPC_URL: z
69
- .string()
70
- .url()
71
- .optional()
72
- .describe("Primary RPC endpoint URL"),
73
- SOLANA_FALLBACK_RPC_URL: z
74
- .string()
75
- .url()
76
- .optional()
77
- .describe("Fallback RPC for SPL token ops"),
78
- SOLANA_WS_URL: z
79
- .string()
80
- .url()
81
- .optional()
82
- .describe("WebSocket endpoint URL"),
83
- WALLET_KEYPAIR_PATH: z
84
- .string()
85
- .optional()
86
- .describe("Path to keypair JSON file"),
87
- WALLET_PRIVATE_KEY: z
88
- .string()
89
- .optional()
90
- .describe("Base58 private key (alternative to file)"),
91
- SAP_PROGRAM_ID: z
92
- .string()
93
- .optional()
94
- .describe("Custom SAP program ID override"),
95
- DATABASE_URL: z
96
- .string()
97
- .optional()
98
- .describe("PostgreSQL connection URL"),
99
- LOG_LEVEL: z
100
- .enum(["debug", "info", "warn", "error"])
101
- .default("info")
102
- .describe("Log level"),
103
- X402_ENDPOINT: z
104
- .string()
105
- .url()
106
- .optional()
107
- .describe("Agent x402 payment endpoint"),
108
- AGENT_URI: z
109
- .string()
110
- .url()
111
- .optional()
112
- .describe("Agent public API URI"),
113
- });
114
- }
115
-
116
- // ═══════════════════════════════════════════════════════════════════
117
- // Endpoint Schemas
118
- // ═══════════════════════════════════════════════════════════════════
119
-
120
- /**
121
- * @name createEndpointDescriptorSchema
122
- * @description Zod schema for {@link EndpointDescriptor}.
123
- * @returns A Zod schema for endpoint descriptor validation.
124
- * @category Utils
125
- * @since v0.6.0
126
- */
127
- export function createEndpointDescriptorSchema() {
128
- const z = getZod();
129
-
130
- return z.object({
131
- url: z.string().url(),
132
- method: z.enum(["GET", "POST", "PUT", "DELETE"]).default("POST"),
133
- contentType: z.string().default("application/json"),
134
- requiresAuth: z.boolean().default(false),
135
- authType: z.enum(["bearer", "api-key", "x402", "none"]).optional(),
136
- requiresCSRF: z.boolean().default(false),
137
- requiresCookies: z.boolean().default(false),
138
- corsOrigins: z.array(z.string()).optional(),
139
- requiredHeaders: z.record(z.string(), z.string()).optional(),
140
- });
141
- }
142
-
143
- /**
144
- * @name createHealthCheckSchema
145
- * @description Zod schema for {@link HealthCheckDescriptor}.
146
- * @returns A Zod schema for health check validation.
147
- * @category Utils
148
- * @since v0.6.0
149
- */
150
- export function createHealthCheckSchema() {
151
- const z = getZod();
152
-
153
- return z.object({
154
- url: z.string().url(),
155
- expectedStatus: z.number().int().min(100).max(599).default(200),
156
- timeoutMs: z.number().int().min(100).max(60_000).default(5000),
157
- method: z.enum(["GET", "HEAD"]).default("GET"),
158
- });
159
- }
160
-
161
- // ═══════════════════════════════════════════════════════════════════
162
- // Tool Manifest Schemas
163
- // ═══════════════════════════════════════════════════════════════════
164
-
165
- /**
166
- * @name createToolManifestEntrySchema
167
- * @description Zod schema for a single tool in an agent manifest.
168
- * @returns A Zod schema for tool manifest entry validation.
169
- * @category Utils
170
- * @since v0.6.0
171
- */
172
- export function createToolManifestEntrySchema() {
173
- const z = getZod();
174
-
175
- return z.object({
176
- name: z.string().min(1).max(64),
177
- description: z.string().max(256),
178
- protocol: z.string().min(1).max(64),
179
- category: z.string().min(1),
180
- inputSchema: z.record(z.string(), z.unknown()),
181
- outputSchema: z.record(z.string(), z.unknown()),
182
- httpMethod: z.enum(["GET", "POST", "PUT", "DELETE", "COMPOUND"]).default("POST"),
183
- paymentMode: z.enum(["x402", "free", "prepaid", "subscription"]).default("x402"),
184
- pricePerCall: z.number().int().min(0).default(0),
185
- requiredArgs: z.array(z.string()).default([]),
186
- prerequisites: z.array(z.string()).default([]),
187
- endpointOverride: createEndpointDescriptorSchema().optional(),
188
- });
189
- }
190
-
191
- /**
192
- * @name createAgentManifestSchema
193
- * @description Zod schema for a complete agent manifest.
194
- * @returns A Zod schema for manifest validation.
195
- * @category Utils
196
- * @since v0.6.0
197
- *
198
- * @example
199
- * ```ts
200
- * import { createAgentManifestSchema } from "@synapse-sap/sdk";
201
- *
202
- * const schema = createAgentManifestSchema();
203
- * const manifest = schema.parse(JSON.parse(fs.readFileSync("manifest.json", "utf-8")));
204
- * ```
205
- */
206
- export function createAgentManifestSchema() {
207
- const z = getZod();
208
-
209
- return z.object({
210
- version: z.literal("1.0.0"),
211
- wallet: z.string().min(32).max(50),
212
- name: z.string().min(1).max(64),
213
- description: z.string().max(256),
214
- endpoint: createEndpointDescriptorSchema(),
215
- healthCheck: createHealthCheckSchema().optional(),
216
- tools: z.array(createToolManifestEntrySchema()),
217
- supportedNetworks: z.array(z.string()).min(1),
218
- generatedAt: z.string().datetime(),
219
- });
220
- }
221
-
222
- // ═══════════════════════════════════════════════════════════════════
223
- // x402 Payment Schemas
224
- // ═══════════════════════════════════════════════════════════════════
225
-
226
- /**
227
- * @name createPreparePaymentSchema
228
- * @description Zod schema for x402 payment preparation parameters.
229
- * @returns A Zod schema for payment option validation.
230
- * @category Utils
231
- * @since v0.6.0
232
- */
233
- export function createPreparePaymentSchema() {
234
- const z = getZod();
235
-
236
- return z.object({
237
- pricePerCall: z.union([z.number(), z.string(), z.bigint()]),
238
- maxCalls: z.union([z.number(), z.string(), z.bigint()]).optional(),
239
- deposit: z.union([z.number(), z.string(), z.bigint()]),
240
- expiresAt: z.union([z.number(), z.string(), z.bigint()]).optional(),
241
- volumeCurve: z
242
- .array(
243
- z.object({
244
- afterCalls: z.number().int().min(1),
245
- pricePerCall: z.union([z.number(), z.string(), z.bigint()]),
246
- }),
247
- )
248
- .optional(),
249
- tokenMint: z.string().optional(),
250
- tokenDecimals: z.number().int().min(0).max(18).default(9),
251
- networkIdentifier: z.string().optional(),
252
- });
253
- }
254
-
255
- // ═══════════════════════════════════════════════════════════════════
256
- // Agent Registration Schemas
257
- // ═══════════════════════════════════════════════════════════════════
258
-
259
- /**
260
- * @name createRegisterAgentSchema
261
- * @description Zod schema for agent registration arguments.
262
- * @returns A Zod schema for registration validation.
263
- * @category Utils
264
- * @since v0.6.0
265
- */
266
- export function createRegisterAgentSchema() {
267
- const z = getZod();
268
-
269
- return z.object({
270
- name: z.string().min(1).max(64),
271
- description: z.string().min(1).max(256),
272
- agentId: z.string().max(128).optional().nullable(),
273
- agentUri: z.string().max(256).optional().nullable(),
274
- x402Endpoint: z.string().url().max(256).optional().nullable(),
275
- capabilities: z
276
- .array(
277
- z.object({
278
- id: z.string().min(1),
279
- description: z.string().nullable().optional(),
280
- protocolId: z.string().nullable().optional(),
281
- version: z.string().nullable().optional(),
282
- }),
283
- )
284
- .max(10)
285
- .default([]),
286
- protocols: z.array(z.string()).max(5).default([]),
287
- pricing: z
288
- .array(
289
- z.object({
290
- tierId: z.string().min(1),
291
- pricePerCall: z.union([z.number(), z.string()]),
292
- rateLimit: z.number().int().min(0),
293
- tokenType: z.enum(["sol", "usdc", "spl"]).default("sol"),
294
- settlementMode: z.enum(["instant", "escrow", "batched", "x402"]).default("x402"),
295
- }),
296
- )
297
- .max(5)
298
- .default([]),
299
- });
300
- }
301
-
302
- // ═══════════════════════════════════════════════════════════════════
303
- // CLI Script Argument Schemas
304
- // ═══════════════════════════════════════════════════════════════════
305
-
306
- /**
307
- * @name createCallArgsSchema
308
- * @description Zod schema for `npm run call` script arguments.
309
- * Ensures all required fields are present before executing an x402 call.
310
- *
311
- * @returns A Zod schema for call argument validation.
312
- * @category Utils
313
- * @since v0.6.0
314
- */
315
- export function createCallArgsSchema() {
316
- const z = getZod();
317
-
318
- return z.object({
319
- agentWallet: z.string().min(32).max(50).describe("Agent wallet (base58)"),
320
- tool: z.string().min(1).describe("Tool name to invoke"),
321
- args: z.record(z.string(), z.unknown()).default({}).describe("Tool arguments (JSON)"),
322
- endpoint: z.string().url().optional().describe("Endpoint URL override"),
323
- network: z.string().optional().describe("Network identifier override"),
324
- maxRetries: z.number().int().min(0).max(10).default(2),
325
- timeoutMs: z.number().int().min(1000).max(120_000).default(30_000),
326
- });
327
- }
328
-
329
- /**
330
- * @name validateOrThrow
331
- * @description Validate a value against a Zod schema, throwing a SapValidationError
332
- * with a friendly message if validation fails.
333
- *
334
- * @param schema - A Zod schema.
335
- * @param value - The value to validate.
336
- * @param label - A label for error messages (e.g. "environment", "call args").
337
- * @returns The parsed and typed value.
338
- * @throws {Error} With formatted validation errors.
339
- *
340
- * @category Utils
341
- * @since v0.6.0
342
- */
343
- export function validateOrThrow<T>(
344
- schema: { parse: (v: unknown) => T; safeParse: (v: unknown) => { success: boolean; error?: { issues: Array<{ path: Array<string | number>; message: string }> } } },
345
- value: unknown,
346
- label: string,
347
- ): T {
348
- const result = schema.safeParse(value);
349
- if (result.success) return schema.parse(value);
350
-
351
- const issues = result.error?.issues ?? [];
352
- const formatted = issues
353
- .map((i) => ` • ${i.path.join(".")}: ${i.message}`)
354
- .join("\n");
355
-
356
- throw new Error(
357
- `[SAP SDK] Invalid ${label}:\n${formatted}`,
358
- );
359
- }