@symbiome-forge/cow-sdk-wasm 0.1.0-alpha.1

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 (119) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +278 -0
  3. package/dist/cloudflare/callbacks.cjs +2 -0
  4. package/dist/cloudflare/callbacks.d.ts +55 -0
  5. package/dist/cloudflare/callbacks.js +1 -0
  6. package/dist/cloudflare/envelope.cjs +2 -0
  7. package/dist/cloudflare/envelope.d.ts +5 -0
  8. package/dist/cloudflare/envelope.js +1 -0
  9. package/dist/cloudflare/errors.cjs +150 -0
  10. package/dist/cloudflare/errors.d.ts +82 -0
  11. package/dist/cloudflare/errors.js +145 -0
  12. package/dist/cloudflare/index.cjs +286 -0
  13. package/dist/cloudflare/index.d.ts +78 -0
  14. package/dist/cloudflare/index.js +1 -0
  15. package/dist/cloudflare/index.mjs +223 -0
  16. package/dist/cloudflare/internal.cjs +127 -0
  17. package/dist/cloudflare/internal.d.ts +40 -0
  18. package/dist/cloudflare/internal.js +115 -0
  19. package/dist/cloudflare/options.cjs +2 -0
  20. package/dist/cloudflare/options.d.ts +70 -0
  21. package/dist/cloudflare/options.js +1 -0
  22. package/dist/cloudflare/raw/cloudflare.cjs +65 -0
  23. package/dist/cloudflare/raw/cloudflare.d.ts +30 -0
  24. package/dist/cloudflare/raw/cloudflare.js +29 -0
  25. package/dist/default/callbacks.cjs +2 -0
  26. package/dist/default/callbacks.d.ts +55 -0
  27. package/dist/default/callbacks.js +1 -0
  28. package/dist/default/envelope.cjs +2 -0
  29. package/dist/default/envelope.d.ts +5 -0
  30. package/dist/default/envelope.js +1 -0
  31. package/dist/default/errors.cjs +150 -0
  32. package/dist/default/errors.d.ts +82 -0
  33. package/dist/default/errors.js +145 -0
  34. package/dist/default/index.cjs +359 -0
  35. package/dist/default/index.d.ts +94 -0
  36. package/dist/default/index.js +1 -0
  37. package/dist/default/index.mjs +295 -0
  38. package/dist/default/internal.cjs +127 -0
  39. package/dist/default/internal.d.ts +40 -0
  40. package/dist/default/internal.js +115 -0
  41. package/dist/default/options.cjs +2 -0
  42. package/dist/default/options.d.ts +70 -0
  43. package/dist/default/options.js +1 -0
  44. package/dist/default/raw/default.cjs +66 -0
  45. package/dist/default/raw/default.d.ts +31 -0
  46. package/dist/default/raw/default.js +30 -0
  47. package/dist/orderbook/callbacks.cjs +2 -0
  48. package/dist/orderbook/callbacks.d.ts +55 -0
  49. package/dist/orderbook/callbacks.js +1 -0
  50. package/dist/orderbook/envelope.cjs +2 -0
  51. package/dist/orderbook/envelope.d.ts +5 -0
  52. package/dist/orderbook/envelope.js +1 -0
  53. package/dist/orderbook/errors.cjs +150 -0
  54. package/dist/orderbook/errors.d.ts +82 -0
  55. package/dist/orderbook/errors.js +145 -0
  56. package/dist/orderbook/index.cjs +195 -0
  57. package/dist/orderbook/index.d.ts +57 -0
  58. package/dist/orderbook/index.js +1 -0
  59. package/dist/orderbook/index.mjs +139 -0
  60. package/dist/orderbook/internal.cjs +127 -0
  61. package/dist/orderbook/internal.d.ts +40 -0
  62. package/dist/orderbook/internal.js +115 -0
  63. package/dist/orderbook/options.cjs +2 -0
  64. package/dist/orderbook/options.d.ts +70 -0
  65. package/dist/orderbook/options.js +1 -0
  66. package/dist/orderbook/raw/orderbook.cjs +58 -0
  67. package/dist/orderbook/raw/orderbook.d.ts +23 -0
  68. package/dist/orderbook/raw/orderbook.js +22 -0
  69. package/dist/raw/cloudflare-web/cow_sdk_wasm.d.ts +2870 -0
  70. package/dist/raw/cloudflare-web/cow_sdk_wasm.js +2183 -0
  71. package/dist/raw/cloudflare-web/cow_sdk_wasm_bg.wasm +0 -0
  72. package/dist/raw/cloudflare-web/cow_sdk_wasm_bg.wasm.d.ts +65 -0
  73. package/dist/raw/default-bundler/cow_sdk_wasm.d.ts +2916 -0
  74. package/dist/raw/default-bundler/cow_sdk_wasm.js +9 -0
  75. package/dist/raw/default-bundler/cow_sdk_wasm_bg.js +2297 -0
  76. package/dist/raw/default-bundler/cow_sdk_wasm_bg.wasm +0 -0
  77. package/dist/raw/default-bundler/cow_sdk_wasm_bg.wasm.d.ts +75 -0
  78. package/dist/raw/default-nodejs/cow_sdk_wasm.cjs +2330 -0
  79. package/dist/raw/default-nodejs/cow_sdk_wasm.d.ts +2916 -0
  80. package/dist/raw/default-nodejs/cow_sdk_wasm_bg.wasm.d.ts +75 -0
  81. package/dist/raw/orderbook-bundler/cow_sdk_wasm.d.ts +1876 -0
  82. package/dist/raw/orderbook-bundler/cow_sdk_wasm.js +9 -0
  83. package/dist/raw/orderbook-bundler/cow_sdk_wasm_bg.js +1636 -0
  84. package/dist/raw/orderbook-bundler/cow_sdk_wasm_bg.wasm +0 -0
  85. package/dist/raw/orderbook-bundler/cow_sdk_wasm_bg.wasm.d.ts +50 -0
  86. package/dist/raw/orderbook-nodejs/cow_sdk_wasm.cjs +1661 -0
  87. package/dist/raw/orderbook-nodejs/cow_sdk_wasm.d.ts +1876 -0
  88. package/dist/raw/orderbook-nodejs/cow_sdk_wasm_bg.wasm.d.ts +50 -0
  89. package/dist/raw/signing-bundler/cow_sdk_wasm.d.ts +774 -0
  90. package/dist/raw/signing-bundler/cow_sdk_wasm.js +9 -0
  91. package/dist/raw/signing-bundler/cow_sdk_wasm_bg.js +1059 -0
  92. package/dist/raw/signing-bundler/cow_sdk_wasm_bg.wasm +0 -0
  93. package/dist/raw/signing-bundler/cow_sdk_wasm_bg.wasm.d.ts +27 -0
  94. package/dist/raw/signing-nodejs/cow_sdk_wasm.cjs +1078 -0
  95. package/dist/raw/signing-nodejs/cow_sdk_wasm.d.ts +774 -0
  96. package/dist/raw/signing-nodejs/cow_sdk_wasm_bg.wasm.d.ts +27 -0
  97. package/dist/signing/callbacks.cjs +2 -0
  98. package/dist/signing/callbacks.d.ts +55 -0
  99. package/dist/signing/callbacks.js +1 -0
  100. package/dist/signing/envelope.cjs +2 -0
  101. package/dist/signing/envelope.d.ts +5 -0
  102. package/dist/signing/envelope.js +1 -0
  103. package/dist/signing/errors.cjs +150 -0
  104. package/dist/signing/errors.d.ts +82 -0
  105. package/dist/signing/errors.js +145 -0
  106. package/dist/signing/index.cjs +93 -0
  107. package/dist/signing/index.d.ts +23 -0
  108. package/dist/signing/index.js +1 -0
  109. package/dist/signing/index.mjs +44 -0
  110. package/dist/signing/internal.cjs +127 -0
  111. package/dist/signing/internal.d.ts +40 -0
  112. package/dist/signing/internal.js +115 -0
  113. package/dist/signing/options.cjs +2 -0
  114. package/dist/signing/options.d.ts +70 -0
  115. package/dist/signing/options.js +1 -0
  116. package/dist/signing/raw/signing.cjs +52 -0
  117. package/dist/signing/raw/signing.d.ts +17 -0
  118. package/dist/signing/raw/signing.js +16 -0
  119. package/package.json +112 -0
@@ -0,0 +1,295 @@
1
+ import * as raw from "./raw/default.js";
2
+ import { assertActive, callAsync, callSync, defaultsFrom, disposeRaw, mergeOptions, mergeSigningOptions, translateClientConfig } from "./internal.js";
3
+ export class IpfsClient {
4
+ #inner;
5
+ #defaults;
6
+ #disposed = false;
7
+ constructor(config) {
8
+ try {
9
+ this.#defaults = defaultsFrom(config);
10
+ this.#inner = new raw.RawIpfsClient(translateClientConfig(config));
11
+ }
12
+ catch (error) {
13
+ throw callSync(() => {
14
+ throw error;
15
+ });
16
+ }
17
+ }
18
+ async fetchAppDataFromCid(cid, options) {
19
+ return this.#call((client, merged) => client.fetchAppDataFromCid(cid, merged), options);
20
+ }
21
+ async fetchAppDataFromHex(appDataHex, options) {
22
+ return this.#call((client, merged) => client.fetchAppDataFromHex(appDataHex, merged), options);
23
+ }
24
+ dispose() {
25
+ if (!this.#disposed) {
26
+ disposeRaw(this.#inner);
27
+ this.#disposed = true;
28
+ }
29
+ }
30
+ [Symbol.dispose]() {
31
+ this.dispose();
32
+ }
33
+ #call(operation, options) {
34
+ return callAsync(() => {
35
+ assertActive(this.#disposed);
36
+ return operation(this.#inner, mergeOptions(this.#defaults, options));
37
+ });
38
+ }
39
+ }
40
+ export class OrderBookClient {
41
+ #inner;
42
+ #defaults;
43
+ #disposed = false;
44
+ constructor(config) {
45
+ try {
46
+ this.#defaults = defaultsFrom(config);
47
+ this.#inner = new raw.RawOrderBookClient(translateClientConfig(config));
48
+ }
49
+ catch (error) {
50
+ throw callSync(() => {
51
+ throw error;
52
+ });
53
+ }
54
+ }
55
+ async cancelOrders(signed, options) {
56
+ return this.#call((client, merged) => client.cancelOrders(signed, merged), options);
57
+ }
58
+ async getNativePrice(token, options) {
59
+ return this.#call((client, merged) => client.getNativePrice(token, merged), options);
60
+ }
61
+ async getOrder(orderUid, options) {
62
+ return this.#call((client, merged) => client.getOrder(orderUid, merged), options);
63
+ }
64
+ async getOrders(owner, pagination, options) {
65
+ return this.#call((client, merged) => client.getOrders(owner, pagination ?? null, merged), options);
66
+ }
67
+ async getOrderMultiEnv(orderUid, options) {
68
+ return this.#call((client, merged) => client.getOrderMultiEnv(orderUid, merged), options);
69
+ }
70
+ async getTxOrders(txHash, options) {
71
+ return this.#call((client, merged) => client.getTxOrders(txHash, merged), options);
72
+ }
73
+ async getVersion(options) {
74
+ return this.#call((client, merged) => client.getVersion(merged), options);
75
+ }
76
+ getOrderLink(orderUid) {
77
+ assertActive(this.#disposed);
78
+ return callSync(() => this.#inner.getOrderLink(orderUid));
79
+ }
80
+ async getQuote(request, options) {
81
+ return this.#call((client, merged) => client.getQuote(request, merged), options);
82
+ }
83
+ async getTrades(query, options) {
84
+ return this.#call((client, merged) => client.getTrades(query, merged), options);
85
+ }
86
+ async getOrderCompetitionStatus(orderUid, options) {
87
+ return this.#call((client, merged) => client.getOrderCompetitionStatus(orderUid, merged), options);
88
+ }
89
+ async getTotalSurplus(owner, options) {
90
+ return this.#call((client, merged) => client.getTotalSurplus(owner, merged), options);
91
+ }
92
+ async getAppData(appDataHash, options) {
93
+ return this.#call((client, merged) => client.getAppData(appDataHash, merged), options);
94
+ }
95
+ async uploadAppData(appDataHash, fullAppData, options) {
96
+ return this.#call((client, merged) => client.uploadAppData(appDataHash, fullAppData, merged), options);
97
+ }
98
+ async sendOrder(signed, options) {
99
+ return this.#call((client, merged) => client.sendOrder(signed, merged), options);
100
+ }
101
+ async sendOrderCreation(input, options) {
102
+ return this.#call((client, merged) => client.sendOrderCreation(input, merged), options);
103
+ }
104
+ dispose() {
105
+ if (!this.#disposed) {
106
+ disposeRaw(this.#inner);
107
+ this.#disposed = true;
108
+ }
109
+ }
110
+ [Symbol.dispose]() {
111
+ this.dispose();
112
+ }
113
+ #call(operation, options) {
114
+ return callAsync(() => {
115
+ assertActive(this.#disposed);
116
+ return operation(this.#inner, mergeOptions(this.#defaults, options));
117
+ });
118
+ }
119
+ }
120
+ export class SubgraphClient {
121
+ #inner;
122
+ #defaults;
123
+ #disposed = false;
124
+ constructor(config) {
125
+ try {
126
+ this.#defaults = defaultsFrom(config);
127
+ this.#inner = new raw.RawSubgraphClient(translateClientConfig(config));
128
+ }
129
+ catch (error) {
130
+ throw callSync(() => {
131
+ throw error;
132
+ });
133
+ }
134
+ }
135
+ async getLastDaysVolume(days, options) {
136
+ return this.#call((client, merged) => client.getLastDaysVolume(days, merged), options);
137
+ }
138
+ async getLastHoursVolume(hours, options) {
139
+ return this.#call((client, merged) => client.getLastHoursVolume(hours, merged), options);
140
+ }
141
+ async getTotals(options) {
142
+ return this.#call((client, merged) => client.getTotals(merged), options);
143
+ }
144
+ async runQuery(request, options) {
145
+ return this.#call((client, merged) => client.runQuery(request, merged), options);
146
+ }
147
+ dispose() {
148
+ if (!this.#disposed) {
149
+ disposeRaw(this.#inner);
150
+ this.#disposed = true;
151
+ }
152
+ }
153
+ [Symbol.dispose]() {
154
+ this.dispose();
155
+ }
156
+ #call(operation, options) {
157
+ return callAsync(() => {
158
+ assertActive(this.#disposed);
159
+ return operation(this.#inner, mergeOptions(this.#defaults, options));
160
+ });
161
+ }
162
+ }
163
+ export class TradingClient {
164
+ #inner;
165
+ #defaults;
166
+ #disposed = false;
167
+ constructor(config) {
168
+ try {
169
+ this.#defaults = defaultsFrom(config);
170
+ this.#inner = new raw.RawTradingClient(translateClientConfig(config));
171
+ }
172
+ catch (error) {
173
+ throw callSync(() => {
174
+ throw error;
175
+ });
176
+ }
177
+ }
178
+ async buildSellNativeCurrencyTx(order, quoteId, from, options) {
179
+ return this.#call((client, merged) => client.buildSellNativeCurrencyTx(order, quoteId, from, merged), options);
180
+ }
181
+ async getCowProtocolAllowance(params, readContractCallback, options) {
182
+ return this.#call((client, merged) => client.getCowProtocolAllowance(params, readContractCallback, merged), options);
183
+ }
184
+ async buildApprovalTx(params, options) {
185
+ return this.#call((client, merged) => client.buildApprovalTx(params, merged), options);
186
+ }
187
+ async getQuote(params, options) {
188
+ return this.#call((client, merged) => client.getQuote(params, merged), options);
189
+ }
190
+ async postLimitOrder(params, owner, signerCallback, options) {
191
+ return this.#callSigning((client, merged) => client.postLimitOrder(params, owner, signerCallback, merged ?? null), options);
192
+ }
193
+ async postSwapOrder(params, owner, signerCallback, options) {
194
+ return this.#callSigning((client, merged) => client.postSwapOrder(params, owner, signerCallback, merged ?? null), options);
195
+ }
196
+ async postSwapOrderFromQuote(quoteResults, owner, signerCallback, options) {
197
+ return this.#callSigning((client, merged) => client.postSwapOrderFromQuote(quoteResults, owner, signerCallback, merged ?? null), options);
198
+ }
199
+ async postSwapOrderWithEip1271(params, owner, customCallback, options) {
200
+ return this.#callSigning((client, merged) => client.postSwapOrderWithEip1271(params, owner, customCallback, merged ?? null), options);
201
+ }
202
+ dispose() {
203
+ if (!this.#disposed) {
204
+ disposeRaw(this.#inner);
205
+ this.#disposed = true;
206
+ }
207
+ }
208
+ [Symbol.dispose]() {
209
+ this.dispose();
210
+ }
211
+ #call(operation, options) {
212
+ return callAsync(() => {
213
+ assertActive(this.#disposed);
214
+ return operation(this.#inner, mergeOptions(this.#defaults, options));
215
+ });
216
+ }
217
+ #callSigning(operation, options) {
218
+ return callAsync(() => {
219
+ assertActive(this.#disposed);
220
+ return operation(this.#inner, mergeSigningOptions(this.#defaults, options));
221
+ });
222
+ }
223
+ }
224
+ export function appDataDoc(doc) {
225
+ return callSync(() => raw.appDataDoc(doc));
226
+ }
227
+ export function appDataHexToCid(appDataHex) {
228
+ return callSync(() => raw.appDataHexToCid(appDataHex));
229
+ }
230
+ export function appDataInfo(doc) {
231
+ return callSync(() => raw.appDataInfo(doc));
232
+ }
233
+ export function buildCancelOrderTx(params) {
234
+ return callSync(() => raw.buildCancelOrderTx(params));
235
+ }
236
+ export function buildPresignTx(params) {
237
+ return callSync(() => raw.buildPresignTx(params));
238
+ }
239
+ export function cidToAppDataHex(cid) {
240
+ return callSync(() => raw.cidToAppDataHex(cid));
241
+ }
242
+ export function computeOrderUid(input, chainId, owner) {
243
+ return callSync(() => raw.computeOrderUid(input, chainId, owner));
244
+ }
245
+ export function decodeEthFlowLog(log) {
246
+ return callSync(() => raw.decodeEthFlowLog(log));
247
+ }
248
+ export function decodeSettlementLog(log) {
249
+ return callSync(() => raw.decodeSettlementLog(log));
250
+ }
251
+ export function deploymentAddresses(chainId, env) {
252
+ return callSync(() => raw.deploymentAddresses(chainId, env ?? null));
253
+ }
254
+ export function domainSeparator(chainId) {
255
+ return callSync(() => raw.domainSeparator(chainId));
256
+ }
257
+ export function eip1271SignaturePayload(input, ecdsaSignature) {
258
+ return callSync(() => raw.eip1271SignaturePayload(input, ecdsaSignature));
259
+ }
260
+ export function orderTypedData(input, chainId) {
261
+ return callSync(() => raw.orderTypedData(input, chainId));
262
+ }
263
+ export function signCancellationEthSignDigest(orderUids, chainId, digestSigner, options) {
264
+ return callAsync(() => raw.signCancellationEthSignDigest(orderUids, chainId, digestSigner, options ?? null));
265
+ }
266
+ export function signCancellationWithEip1193(orderUids, chainId, owner, requestCallback, options) {
267
+ return callAsync(() => raw.signCancellationWithEip1193(orderUids, chainId, owner, requestCallback, options ?? null));
268
+ }
269
+ export function signCancellationWithTypedDataSigner(orderUids, chainId, typedDataSigner, options) {
270
+ return callAsync(() => raw.signCancellationWithTypedDataSigner(orderUids, chainId, typedDataSigner, options ?? null));
271
+ }
272
+ export function signOrderEthSignDigest(input, chainId, owner, digestSigner, options) {
273
+ return callAsync(() => raw.signOrderEthSignDigest(input, chainId, owner, digestSigner, options ?? null));
274
+ }
275
+ export function signOrderWithCustomEip1271(input, chainId, owner, customCallback, options) {
276
+ return callAsync(() => raw.signOrderWithCustomEip1271(input, chainId, owner, customCallback, options ?? null));
277
+ }
278
+ export function signOrderWithEip1193(input, chainId, owner, requestCallback, options) {
279
+ return callAsync(() => raw.signOrderWithEip1193(input, chainId, owner, requestCallback, options ?? null));
280
+ }
281
+ export function signOrderWithEip1271(input, chainId, owner, typedDataSigner, options) {
282
+ return callAsync(() => raw.signOrderWithEip1271(input, chainId, owner, typedDataSigner, options ?? null));
283
+ }
284
+ export function signOrderWithTypedDataSigner(input, chainId, owner, typedDataSigner, options) {
285
+ return callAsync(() => raw.signOrderWithTypedDataSigner(input, chainId, owner, typedDataSigner, options ?? null));
286
+ }
287
+ export function supportedChainIds() {
288
+ return callSync(() => raw.supportedChainIds());
289
+ }
290
+ export function validateAppDataDoc(doc) {
291
+ return callSync(() => raw.validateAppDataDoc(doc));
292
+ }
293
+ export function wasmVersion() {
294
+ return callSync(() => raw.wasmVersion());
295
+ }
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.translateHttpTransport = translateHttpTransport;
4
+ exports.translateClientConfig = translateClientConfig;
5
+ exports.mergeOptions = mergeOptions;
6
+ exports.mergeSigningOptions = mergeSigningOptions;
7
+ exports.assertActive = assertActive;
8
+ exports.disposeRaw = disposeRaw;
9
+ exports.normalizeThrown = normalizeThrown;
10
+ exports.callAsync = callAsync;
11
+ exports.callSync = callSync;
12
+ exports.defaultsFrom = defaultsFrom;
13
+ const errors_js_1 = require("./errors.cjs");
14
+ function translateHttpTransport(transport) {
15
+ if (transport?.kind === "callback") {
16
+ return transport;
17
+ }
18
+ // An omitted transport (or `{ kind: "fetch" }` without an explicit fetch)
19
+ // defaults to the runtime's global `fetch`, matching the Rust builders'
20
+ // zero-config default.
21
+ const fetchFn = transport?.fetch ?? globalThis.fetch;
22
+ if (typeof fetchFn !== "function") {
23
+ throw (0, errors_js_1.invalidInput)("transport.fetch", "globalThis.fetch is unavailable; pass an explicit fetch function");
24
+ }
25
+ return {
26
+ kind: "callback",
27
+ callback: adaptFetchToCallback(fetchFn)
28
+ };
29
+ }
30
+ function translateClientConfig(config) {
31
+ const { signal: _signal, transport, ...rest } = config;
32
+ return {
33
+ ...rest,
34
+ transport: translateHttpTransport(transport)
35
+ };
36
+ }
37
+ function mergeOptions(defaults, options) {
38
+ const signal = options?.signal ?? defaults.signal;
39
+ if (signal?.aborted) {
40
+ throw (0, errors_js_1.cancelledError)();
41
+ }
42
+ const timeoutMs = options?.timeoutMs ?? defaults.timeoutMs ?? undefined;
43
+ if (signal || timeoutMs !== undefined) {
44
+ const merged = {};
45
+ if (signal) {
46
+ merged.signal = signal;
47
+ }
48
+ if (timeoutMs !== undefined && timeoutMs !== null) {
49
+ merged.timeoutMs = timeoutMs;
50
+ }
51
+ return merged;
52
+ }
53
+ return undefined;
54
+ }
55
+ /**
56
+ * Applies the client-level `signal`/`timeoutMs` defaults to a signing call
57
+ * while preserving the per-call `walletConfig`, and performs the same
58
+ * already-aborted short-circuit as {@link mergeOptions}. Signing methods take
59
+ * {@link SigningOptions} (a superset of {@link SdkClientOptions}), so the
60
+ * shared default propagation must not drop the wallet timeout.
61
+ */
62
+ function mergeSigningOptions(defaults, options) {
63
+ const merged = mergeOptions(defaults, options);
64
+ const walletConfig = options?.walletConfig;
65
+ if (walletConfig === undefined) {
66
+ return merged;
67
+ }
68
+ return { ...merged, walletConfig };
69
+ }
70
+ function assertActive(disposed) {
71
+ if (disposed) {
72
+ throw (0, errors_js_1.invalidInput)("client", "client has been disposed");
73
+ }
74
+ }
75
+ function disposeRaw(raw) {
76
+ raw?.free?.();
77
+ }
78
+ function normalizeThrown(error) {
79
+ return (0, errors_js_1.normalizeError)(error);
80
+ }
81
+ async function callAsync(operation) {
82
+ try {
83
+ return await operation();
84
+ }
85
+ catch (error) {
86
+ throw (0, errors_js_1.normalizeError)(error);
87
+ }
88
+ }
89
+ function callSync(operation) {
90
+ try {
91
+ return operation();
92
+ }
93
+ catch (error) {
94
+ throw (0, errors_js_1.normalizeError)(error);
95
+ }
96
+ }
97
+ function defaultsFrom(config) {
98
+ return {
99
+ signal: config.signal,
100
+ timeoutMs: config.timeoutMs
101
+ };
102
+ }
103
+ function adaptFetchToCallback(fetchFn) {
104
+ return async (request) => {
105
+ const init = {
106
+ method: request.method,
107
+ headers: request.headers
108
+ };
109
+ if (request.signal) {
110
+ init.signal = request.signal;
111
+ }
112
+ if (request.body !== undefined) {
113
+ init.body = request.body;
114
+ }
115
+ const response = await fetchFn(request.url, init);
116
+ const headers = {};
117
+ response.headers.forEach((value, key) => {
118
+ headers[key] = value;
119
+ });
120
+ return {
121
+ status: response.status,
122
+ statusText: response.statusText,
123
+ headers,
124
+ body: await response.text()
125
+ };
126
+ };
127
+ }
@@ -0,0 +1,40 @@
1
+ import { type CowError } from "./errors.js";
2
+ import type { CowFetchCallback } from "./callbacks.js";
3
+ import type { CommonClientConfig, HttpTransportConfig, SdkClientOptions, SigningOptions } from "./options.js";
4
+ export interface ClientDefaults {
5
+ signal: AbortSignal | undefined;
6
+ timeoutMs: number | null | undefined;
7
+ }
8
+ export type DisposableRawClient = {
9
+ free?: () => void;
10
+ };
11
+ export declare function translateHttpTransport(transport?: HttpTransportConfig): {
12
+ kind: "callback";
13
+ callback: CowFetchCallback;
14
+ };
15
+ export declare function translateClientConfig<T extends {
16
+ transport?: HttpTransportConfig;
17
+ }>(config: T): Omit<T, "signal" | "transport"> & {
18
+ transport: {
19
+ kind: "callback";
20
+ callback: CowFetchCallback;
21
+ };
22
+ };
23
+ export declare function mergeOptions(defaults: ClientDefaults, options?: SdkClientOptions | null): SdkClientOptions | undefined;
24
+ /**
25
+ * Applies the client-level `signal`/`timeoutMs` defaults to a signing call
26
+ * while preserving the per-call `walletConfig`, and performs the same
27
+ * already-aborted short-circuit as {@link mergeOptions}. Signing methods take
28
+ * {@link SigningOptions} (a superset of {@link SdkClientOptions}), so the
29
+ * shared default propagation must not drop the wallet timeout.
30
+ */
31
+ export declare function mergeSigningOptions(defaults: ClientDefaults, options?: SigningOptions | null): SigningOptions | undefined;
32
+ export declare function assertActive(disposed: boolean): void;
33
+ export declare function disposeRaw(raw: DisposableRawClient | undefined): void;
34
+ export declare function normalizeThrown(error: unknown): CowError;
35
+ export declare function callAsync<T>(operation: () => Promise<T>): Promise<T>;
36
+ export declare function callSync<T>(operation: () => T): T;
37
+ export declare function defaultsFrom(config: CommonClientConfig | {
38
+ signal?: AbortSignal;
39
+ timeoutMs?: number | null;
40
+ }): ClientDefaults;
@@ -0,0 +1,115 @@
1
+ import { cancelledError, invalidInput, normalizeError } from "./errors.js";
2
+ export function translateHttpTransport(transport) {
3
+ if (transport?.kind === "callback") {
4
+ return transport;
5
+ }
6
+ // An omitted transport (or `{ kind: "fetch" }` without an explicit fetch)
7
+ // defaults to the runtime's global `fetch`, matching the Rust builders'
8
+ // zero-config default.
9
+ const fetchFn = transport?.fetch ?? globalThis.fetch;
10
+ if (typeof fetchFn !== "function") {
11
+ throw invalidInput("transport.fetch", "globalThis.fetch is unavailable; pass an explicit fetch function");
12
+ }
13
+ return {
14
+ kind: "callback",
15
+ callback: adaptFetchToCallback(fetchFn)
16
+ };
17
+ }
18
+ export function translateClientConfig(config) {
19
+ const { signal: _signal, transport, ...rest } = config;
20
+ return {
21
+ ...rest,
22
+ transport: translateHttpTransport(transport)
23
+ };
24
+ }
25
+ export function mergeOptions(defaults, options) {
26
+ const signal = options?.signal ?? defaults.signal;
27
+ if (signal?.aborted) {
28
+ throw cancelledError();
29
+ }
30
+ const timeoutMs = options?.timeoutMs ?? defaults.timeoutMs ?? undefined;
31
+ if (signal || timeoutMs !== undefined) {
32
+ const merged = {};
33
+ if (signal) {
34
+ merged.signal = signal;
35
+ }
36
+ if (timeoutMs !== undefined && timeoutMs !== null) {
37
+ merged.timeoutMs = timeoutMs;
38
+ }
39
+ return merged;
40
+ }
41
+ return undefined;
42
+ }
43
+ /**
44
+ * Applies the client-level `signal`/`timeoutMs` defaults to a signing call
45
+ * while preserving the per-call `walletConfig`, and performs the same
46
+ * already-aborted short-circuit as {@link mergeOptions}. Signing methods take
47
+ * {@link SigningOptions} (a superset of {@link SdkClientOptions}), so the
48
+ * shared default propagation must not drop the wallet timeout.
49
+ */
50
+ export function mergeSigningOptions(defaults, options) {
51
+ const merged = mergeOptions(defaults, options);
52
+ const walletConfig = options?.walletConfig;
53
+ if (walletConfig === undefined) {
54
+ return merged;
55
+ }
56
+ return { ...merged, walletConfig };
57
+ }
58
+ export function assertActive(disposed) {
59
+ if (disposed) {
60
+ throw invalidInput("client", "client has been disposed");
61
+ }
62
+ }
63
+ export function disposeRaw(raw) {
64
+ raw?.free?.();
65
+ }
66
+ export function normalizeThrown(error) {
67
+ return normalizeError(error);
68
+ }
69
+ export async function callAsync(operation) {
70
+ try {
71
+ return await operation();
72
+ }
73
+ catch (error) {
74
+ throw normalizeError(error);
75
+ }
76
+ }
77
+ export function callSync(operation) {
78
+ try {
79
+ return operation();
80
+ }
81
+ catch (error) {
82
+ throw normalizeError(error);
83
+ }
84
+ }
85
+ export function defaultsFrom(config) {
86
+ return {
87
+ signal: config.signal,
88
+ timeoutMs: config.timeoutMs
89
+ };
90
+ }
91
+ function adaptFetchToCallback(fetchFn) {
92
+ return async (request) => {
93
+ const init = {
94
+ method: request.method,
95
+ headers: request.headers
96
+ };
97
+ if (request.signal) {
98
+ init.signal = request.signal;
99
+ }
100
+ if (request.body !== undefined) {
101
+ init.body = request.body;
102
+ }
103
+ const response = await fetchFn(request.url, init);
104
+ const headers = {};
105
+ response.headers.forEach((value, key) => {
106
+ headers[key] = value;
107
+ });
108
+ return {
109
+ status: response.status,
110
+ statusText: response.statusText,
111
+ headers,
112
+ body: await response.text()
113
+ };
114
+ };
115
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,70 @@
1
+ import type { CowEnv, CowFetchCallback, CowFetchRequest, CowFetchResponse } from "./callbacks.js";
2
+ export interface SdkClientOptions {
3
+ timeoutMs?: number;
4
+ signal?: AbortSignal;
5
+ }
6
+ export interface WalletConfig {
7
+ timeoutMs?: number;
8
+ }
9
+ export interface SigningOptions extends SdkClientOptions {
10
+ walletConfig?: WalletConfig;
11
+ }
12
+ export type HttpTransportConfig = {
13
+ kind: "fetch";
14
+ fetch?: typeof globalThis.fetch;
15
+ } | {
16
+ kind: "callback";
17
+ callback: CowFetchCallback;
18
+ };
19
+ export type JitterStrategyConfig = "none" | "full" | "equal" | "decorrelated";
20
+ export type LimiterScopeConfig = "global" | "perHost";
21
+ export interface RetryPolicyConfig {
22
+ /** Maximum attempts, including the initial request. */
23
+ maxAttempts?: number;
24
+ /** Base exponential-backoff delay in milliseconds. */
25
+ baseDelayMs?: number;
26
+ /** Maximum exponential-backoff delay in milliseconds. */
27
+ maxDelayMs?: number;
28
+ }
29
+ export interface RequestRateLimiterConfig {
30
+ /** Request tokens granted per interval. Zero disables limiting. */
31
+ tokensPerInterval?: number;
32
+ /** Limiter interval in milliseconds. */
33
+ intervalMs?: number;
34
+ /** Bucket scope. */
35
+ scope?: LimiterScopeConfig;
36
+ }
37
+ export interface TransportPolicyConfig {
38
+ retryPolicy?: RetryPolicyConfig;
39
+ requestRateLimiter?: RequestRateLimiterConfig;
40
+ jitterStrategy?: JitterStrategyConfig;
41
+ userAgent?: string;
42
+ }
43
+ export interface CommonClientConfig {
44
+ chainId: number;
45
+ env?: CowEnv | string | null;
46
+ apiKey?: string | null;
47
+ transport?: HttpTransportConfig;
48
+ transportPolicy?: TransportPolicyConfig | null;
49
+ timeoutMs?: number | null;
50
+ signal?: AbortSignal;
51
+ }
52
+ export interface IpfsClientConfig {
53
+ ipfsUri?: string | null;
54
+ transport?: HttpTransportConfig;
55
+ transportPolicy?: TransportPolicyConfig | null;
56
+ timeoutMs?: number | null;
57
+ signal?: AbortSignal;
58
+ }
59
+ export interface SubgraphClientConfig {
60
+ chainId: number;
61
+ apiKey: string;
62
+ transport?: HttpTransportConfig;
63
+ transportPolicy?: TransportPolicyConfig | null;
64
+ timeoutMs?: number | null;
65
+ signal?: AbortSignal;
66
+ }
67
+ export interface TradingClientConfig extends CommonClientConfig {
68
+ appCode: string;
69
+ }
70
+ export type { CowFetchCallback, CowFetchRequest, CowFetchResponse };
@@ -0,0 +1 @@
1
+ export {};