@notifi-network/fusion-sdk 0.0.10-alpha.3 → 0.0.10-alpha.4
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.
|
@@ -6,6 +6,7 @@ import { FetchResponse, HttpMethod, Region } from "../protos_gen/services/fetch_
|
|
|
6
6
|
export declare class FetchProxyWrapper {
|
|
7
7
|
private client;
|
|
8
8
|
private contextId;
|
|
9
|
+
private isProxyEnabled;
|
|
9
10
|
/**
|
|
10
11
|
* Creates an instance of FetchProxy.
|
|
11
12
|
* @param contextId - The context ID for the gRPC requests.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FusionFetchProxyClient } from "../protos_gen/services/fetch_proxy/v1/fetch_proxy.js";
|
|
1
|
+
import { FusionFetchProxyClient, HttpMethod } from "../protos_gen/services/fetch_proxy/v1/fetch_proxy.js";
|
|
2
2
|
import { Metadata, credentials } from "@grpc/grpc-js";
|
|
3
3
|
/**
|
|
4
4
|
* Class for interacting with the Fusion Fetch Proxy service.
|
|
@@ -7,12 +7,14 @@ import { Metadata, credentials } from "@grpc/grpc-js";
|
|
|
7
7
|
export class FetchProxyWrapper {
|
|
8
8
|
client;
|
|
9
9
|
contextId;
|
|
10
|
+
isProxyEnabled = true;
|
|
10
11
|
/**
|
|
11
12
|
* Creates an instance of FetchProxy.
|
|
12
13
|
* @param contextId - The context ID for the gRPC requests.
|
|
13
14
|
*/
|
|
14
15
|
constructor(contextId) {
|
|
15
16
|
this.contextId = contextId;
|
|
17
|
+
this.isProxyEnabled = !!process.env.FUSION_FETCH_PROXY_ADDRESS;
|
|
16
18
|
const address = process.env.FUSION_FETCH_PROXY_ADDRESS || "localhost:50051";
|
|
17
19
|
this.client = new FusionFetchProxyClient(address, address.startsWith("localhost") || process.env.GRPC_INSECURE === "true" ? credentials.createInsecure() : credentials.createSsl());
|
|
18
20
|
}
|
|
@@ -26,6 +28,36 @@ export class FetchProxyWrapper {
|
|
|
26
28
|
* @returns A promise that resolves to the FetchResponse.
|
|
27
29
|
*/
|
|
28
30
|
async fetch(url, headers, httpMethod, bodyJson, region) {
|
|
31
|
+
if (!this.isProxyEnabled) {
|
|
32
|
+
// Use built in fetch()
|
|
33
|
+
const fetchOptions = {
|
|
34
|
+
method: HttpMethod[httpMethod],
|
|
35
|
+
headers: new Headers(headers),
|
|
36
|
+
};
|
|
37
|
+
if (bodyJson) {
|
|
38
|
+
fetchOptions.body = bodyJson;
|
|
39
|
+
}
|
|
40
|
+
const resp = await fetch(url, fetchOptions);
|
|
41
|
+
if (!resp.ok) {
|
|
42
|
+
const responseBody = await resp.text();
|
|
43
|
+
console.error('Error fetching urlForBlob. ResponseBody:', responseBody, ', Status:', resp.status, ', ContextId:', this.contextId);
|
|
44
|
+
// Return status code and message in FetchResponse. Return responseBody as Uint8Array on response member
|
|
45
|
+
return {
|
|
46
|
+
statusCode: resp.status,
|
|
47
|
+
response: new Uint8Array(Buffer.from(responseBody)),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
const arrayBuffer = await resp.arrayBuffer();
|
|
52
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
|
53
|
+
// Return status code and message in FetchResponse. Return responseBody as Uint8Array on response member
|
|
54
|
+
return {
|
|
55
|
+
statusCode: resp.status,
|
|
56
|
+
response: uint8Array,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Use gRPC Fetch Proxy
|
|
29
61
|
const request = {
|
|
30
62
|
url,
|
|
31
63
|
headers,
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import winston from 'winston';
|
|
2
|
-
import { BlockchainType } from '../protos_gen/notifi/common/v1/types.js';
|
|
3
2
|
export type SolanaBlob = {
|
|
4
3
|
solanaBlock: any;
|
|
5
|
-
blockchain: BlockchainType;
|
|
6
|
-
slotId: string;
|
|
7
4
|
};
|
|
8
5
|
export declare const getParserBlobInput: (contextId: string, urlForBlob: string, logger: winston.Logger) => Promise<SolanaBlob | any>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notifi-network/fusion-sdk",
|
|
3
|
-
"version": "0.0.10-alpha.
|
|
3
|
+
"version": "0.0.10-alpha.4",
|
|
4
4
|
"description": "SDK utils for Notifi Fusion parser development. This includes types and helpers for accessing ephemeral/persistent storage, RPCs for different chains, and other utilities.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|