1
1
import { Buffer } from "@onflow/rlp"
2
- import { send as defaultSend } from "@onflow/transport-http"
3
2
import { initInteraction , pipe } from "../interaction/interaction"
4
3
import * as ixModule from "../interaction/interaction"
5
- import { invariant } from "../build/build-invariant.js "
4
+ import { invariant } from "../build/build-invariant"
6
5
import { response } from "../response/response"
7
6
import { config } from "@onflow/config"
8
- import { resolve as defaultResolve } from "../resolve/resolve.js"
7
+ import { resolve as defaultResolve } from "../resolve/resolve"
8
+ import { getTransport } from "./transport"
9
9
10
10
/**
11
11
* @description - Sends arbitrary scripts, transactions, and requests to Flow
12
- * @param { Array.<Function> | Function } args - An array of functions that take interaction and return interaction
13
- * @param { object } opts - Optional parameters
14
- * @returns { Promise<*> } - A promise that resolves to a response
12
+ * @param args - An array of functions that take interaction and return interaction
13
+ * @param opts - Optional parameters
14
+ * @returns - A promise that resolves to a response
15
15
*/
16
- export const send = async ( args = [ ] , opts = { } ) => {
17
- const sendFn = await config . first (
18
- [ "sdk.transport" , "sdk.send" ] ,
19
- opts . send || defaultSend
20
- )
16
+ export const send = async (
17
+ args : Function | Function [ ] = [ ] ,
18
+ opts : any = { }
19
+ ) : Promise < any > => {
20
+ const { send : sendFn } = await getTransport ( opts )
21
21
22
22
invariant (
23
23
sendFn ,
@@ -31,10 +31,10 @@ export const send = async (args = [], opts = {}) => {
31
31
32
32
opts . node = opts . node || ( await config ( ) . get ( "accessNode.api" ) )
33
33
34
- if ( Array . isArray ( args ) ) args = pipe ( initInteraction ( ) , args )
34
+ if ( Array . isArray ( args ) ) args = pipe ( initInteraction ( ) , args as any ) as any
35
35
return sendFn (
36
36
await resolveFn ( args ) ,
37
- { config, response, ix : ixModule , Buffer} ,
37
+ { config, response, ix : ixModule , Buffer} as any ,
38
38
opts
39
39
)
40
40
}
0 commit comments