@herd-labs/sdk 0.3.1 → 0.5.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.
- package/dist/index.d.ts +17 -17
- package/dist/index.js +17 -17
- package/dist/src/config.d.ts +11 -11
- package/dist/src/config.js +9 -12
- package/dist/src/errors.d.ts +35 -44
- package/dist/src/errors.js +19 -16
- package/dist/src/live/ActionsServiceLive.d.ts +3 -3
- package/dist/src/live/ActionsServiceLive.js +14 -14
- package/dist/src/live/AdaptersServiceLive.d.ts +3 -3
- package/dist/src/live/AdaptersServiceLive.js +8 -8
- package/dist/src/live/AgentSafesServiceLive.d.ts +3 -3
- package/dist/src/live/AgentSafesServiceLive.js +5 -5
- package/dist/src/live/AgentWalletsServiceLive.d.ts +3 -3
- package/dist/src/live/AgentWalletsServiceLive.js +4 -4
- package/dist/src/live/AgentWorkflowsServiceLive.d.ts +3 -3
- package/dist/src/live/AgentWorkflowsServiceLive.js +14 -14
- package/dist/src/live/AuthServiceLive.d.ts +3 -3
- package/dist/src/live/AuthServiceLive.js +7 -7
- package/dist/src/live/BookmarksServiceLive.d.ts +3 -3
- package/dist/src/live/BookmarksServiceLive.js +20 -20
- package/dist/src/live/CodeBlocksServiceLive.d.ts +3 -3
- package/dist/src/live/CodeBlocksServiceLive.js +11 -11
- package/dist/src/live/CollectionsServiceLive.d.ts +3 -3
- package/dist/src/live/CollectionsServiceLive.js +6 -6
- package/dist/src/live/ContractsServiceLive.d.ts +3 -3
- package/dist/src/live/ContractsServiceLive.js +10 -10
- package/dist/src/live/DocsServiceLive.d.ts +3 -3
- package/dist/src/live/DocsServiceLive.js +4 -4
- package/dist/src/live/GroupsServiceLive.d.ts +3 -3
- package/dist/src/live/GroupsServiceLive.js +9 -9
- package/dist/src/live/HalServiceLive.d.ts +3 -3
- package/dist/src/live/HalServiceLive.js +12 -12
- package/dist/src/live/TransactionsServiceLive.d.ts +3 -3
- package/dist/src/live/TransactionsServiceLive.js +18 -18
- package/dist/src/live/WalletsServiceLive.d.ts +3 -3
- package/dist/src/live/WalletsServiceLive.js +18 -18
- package/dist/src/live/http.d.ts +6 -6
- package/dist/src/live/http.js +15 -15
- package/dist/src/schemas/actions.d.ts +179 -339
- package/dist/src/schemas/actions.js +80 -76
- package/dist/src/schemas/adapters.d.ts +7 -17
- package/dist/src/schemas/adapters.js +5 -5
- package/dist/src/schemas/agent-wallets.d.ts +98 -222
- package/dist/src/schemas/agent-wallets.js +52 -52
- package/dist/src/schemas/agent-workflows.d.ts +104 -104
- package/dist/src/schemas/agent-workflows.js +53 -49
- package/dist/src/schemas/auth.d.ts +35 -64
- package/dist/src/schemas/auth.js +16 -16
- package/dist/src/schemas/bookmarks.d.ts +98 -216
- package/dist/src/schemas/bookmarks.js +55 -51
- package/dist/src/schemas/codeblocks.d.ts +149 -308
- package/dist/src/schemas/codeblocks.js +72 -67
- package/dist/src/schemas/collections.d.ts +120 -232
- package/dist/src/schemas/collections.js +48 -44
- package/dist/src/schemas/common.d.ts +13 -29
- package/dist/src/schemas/common.js +8 -8
- package/dist/src/schemas/contracts.d.ts +256 -447
- package/dist/src/schemas/contracts.js +92 -103
- package/dist/src/schemas/docs.d.ts +12 -29
- package/dist/src/schemas/docs.js +9 -9
- package/dist/src/schemas/groups.d.ts +74 -74
- package/dist/src/schemas/groups.js +32 -32
- package/dist/src/schemas/hal.d.ts +109 -217
- package/dist/src/schemas/hal.js +44 -42
- package/dist/src/schemas/transactions.d.ts +648 -926
- package/dist/src/schemas/transactions.js +158 -162
- package/dist/src/schemas/wallets.d.ts +577 -731
- package/dist/src/schemas/wallets.js +206 -145
- package/dist/src/services/ActionsService.d.ts +3 -3
- package/dist/src/services/ActionsService.js +2 -2
- package/dist/src/services/AdaptersService.d.ts +1 -1
- package/dist/src/services/AdaptersService.js +2 -2
- package/dist/src/services/AgentSafesService.d.ts +5 -5
- package/dist/src/services/AgentSafesService.js +2 -2
- package/dist/src/services/AgentWalletsService.d.ts +3 -3
- package/dist/src/services/AgentWalletsService.js +2 -2
- package/dist/src/services/AgentWorkflowsService.d.ts +11 -11
- package/dist/src/services/AgentWorkflowsService.js +6 -2
- package/dist/src/services/AuthService.d.ts +5 -5
- package/dist/src/services/AuthService.js +2 -2
- package/dist/src/services/BookmarksService.d.ts +3 -3
- package/dist/src/services/BookmarksService.js +2 -2
- package/dist/src/services/CodeBlocksService.d.ts +1 -1
- package/dist/src/services/CodeBlocksService.js +2 -2
- package/dist/src/services/CollectionsService.d.ts +1 -1
- package/dist/src/services/CollectionsService.js +2 -2
- package/dist/src/services/ContractsService.d.ts +6 -6
- package/dist/src/services/ContractsService.js +2 -2
- package/dist/src/services/DocsService.d.ts +2 -2
- package/dist/src/services/DocsService.js +2 -2
- package/dist/src/services/GroupsService.d.ts +13 -13
- package/dist/src/services/GroupsService.js +4 -2
- package/dist/src/services/HalService.d.ts +1 -1
- package/dist/src/services/HalService.js +2 -2
- package/dist/src/services/TransactionsService.d.ts +5 -5
- package/dist/src/services/TransactionsService.js +2 -2
- package/dist/src/services/WalletsService.d.ts +5 -5
- package/dist/src/services/WalletsService.js +2 -2
- package/package.json +13 -18
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
import { ensureServiceError } from "../errors.js";
|
|
2
|
-
import {
|
|
2
|
+
import { LatestEventTransactionsSchema, LatestFunctionTransactionsSchema, TransactionQueryResponseSchema } from "../schemas/transactions.js";
|
|
3
3
|
import { TransactionsService } from "../services/TransactionsService.js";
|
|
4
4
|
import { authorizedClient, checkStatus, makeUrl } from "./http.js";
|
|
5
|
-
import { Effect,
|
|
6
|
-
import { HttpClientResponse } from "
|
|
5
|
+
import { Effect, Layer, Option, Record, pipe } from "effect";
|
|
6
|
+
import { HttpClientResponse } from "effect/unstable/http";
|
|
7
7
|
|
|
8
8
|
//#region src/live/TransactionsServiceLive.ts
|
|
9
|
-
const toOptionalQuery = (input) =>
|
|
10
|
-
const latestTxParamsToSnakeCaseQuery = (params) =>
|
|
9
|
+
const toOptionalQuery = (input) => Record.getSomes(Record.map(input, Option.fromNullishOr));
|
|
10
|
+
const latestTxParamsToSnakeCaseQuery = (params) => Record.getSomes(Record.map({
|
|
11
|
+
after_blocknumber: params?.afterBlocknumber,
|
|
12
|
+
after_timestamp: params?.afterTimestamp,
|
|
13
|
+
before_blocknumber: params?.beforeBlocknumber,
|
|
14
|
+
before_timestamp: params?.beforeTimestamp,
|
|
15
|
+
called_by: params?.calledBy,
|
|
16
|
+
direction: params?.direction,
|
|
11
17
|
limit: params?.limit,
|
|
12
18
|
offset: params?.offset,
|
|
13
19
|
page: params?.page,
|
|
14
|
-
before_timestamp: params?.beforeTimestamp,
|
|
15
|
-
after_timestamp: params?.afterTimestamp,
|
|
16
|
-
before_blocknumber: params?.beforeBlocknumber,
|
|
17
|
-
after_blocknumber: params?.afterBlocknumber,
|
|
18
20
|
success_only: params?.successOnly === true ? true : void 0,
|
|
19
|
-
direction: params?.direction,
|
|
20
21
|
topic1: params?.topic1,
|
|
21
22
|
topic2: params?.topic2,
|
|
22
|
-
topic3: params?.topic3
|
|
23
|
-
|
|
24
|
-
}, Record.filterMap(Option.liftNullable(Function.identity)));
|
|
23
|
+
topic3: params?.topic3
|
|
24
|
+
}, Option.fromNullishOr));
|
|
25
25
|
const TransactionsServiceLive = Layer.effect(TransactionsService, Effect.gen(function* () {
|
|
26
26
|
const { baseUrl, client } = yield* authorizedClient;
|
|
27
27
|
return {
|
|
28
|
-
|
|
29
|
-
getLatestFunctionTransactions: (blockchain, address, filter, params) => pipe(client.get(makeUrl(baseUrl, `/v1/contracts/${blockchain}/${address}/latest_function_transactions`, {
|
|
28
|
+
getLatestEventTransactions: (blockchain, address, filter, params) => pipe(client.get(makeUrl(baseUrl, `/v1/contracts/${blockchain}/${address}/latest_event_transactions`, {
|
|
30
29
|
...latestTxParamsToSnakeCaseQuery(params),
|
|
31
30
|
...toOptionalQuery({
|
|
32
31
|
name: filter.name,
|
|
33
32
|
signature: filter.signature
|
|
34
33
|
})
|
|
35
|
-
})), Effect.flatMap(checkStatus), Effect.flatMap(HttpClientResponse.schemaBodyJson(
|
|
36
|
-
|
|
34
|
+
})), Effect.flatMap(checkStatus), Effect.flatMap(HttpClientResponse.schemaBodyJson(LatestEventTransactionsSchema)), Effect.mapError(ensureServiceError("Failed to get latest event transactions"))),
|
|
35
|
+
getLatestFunctionTransactions: (blockchain, address, filter, params) => pipe(client.get(makeUrl(baseUrl, `/v1/contracts/${blockchain}/${address}/latest_function_transactions`, {
|
|
37
36
|
...latestTxParamsToSnakeCaseQuery(params),
|
|
38
37
|
...toOptionalQuery({
|
|
39
38
|
name: filter.name,
|
|
40
39
|
signature: filter.signature
|
|
41
40
|
})
|
|
42
|
-
})), Effect.flatMap(checkStatus), Effect.flatMap(HttpClientResponse.schemaBodyJson(
|
|
41
|
+
})), Effect.flatMap(checkStatus), Effect.flatMap(HttpClientResponse.schemaBodyJson(LatestFunctionTransactionsSchema)), Effect.mapError(ensureServiceError("Failed to get latest function transactions"))),
|
|
42
|
+
getTransaction: (blockchain, txHash) => pipe(client.get(makeUrl(baseUrl, `/v1/transactions/${blockchain}/${txHash}`)), Effect.flatMap(checkStatus), Effect.flatMap(HttpClientResponse.schemaBodyJson(TransactionQueryResponseSchema)), Effect.mapError(ensureServiceError("Failed to get transaction")))
|
|
43
43
|
};
|
|
44
44
|
}));
|
|
45
45
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HerdConfigService } from "../config.js";
|
|
2
2
|
import { WalletsService } from "../services/WalletsService.js";
|
|
3
3
|
import { Layer } from "effect";
|
|
4
|
-
import * as
|
|
4
|
+
import * as effect_unstable_http_HttpClient9 from "effect/unstable/http/HttpClient";
|
|
5
5
|
|
|
6
6
|
//#region src/live/WalletsServiceLive.d.ts
|
|
7
|
-
declare const WalletsServiceLive: Layer.Layer<WalletsService, never,
|
|
7
|
+
declare const WalletsServiceLive: Layer.Layer<WalletsService, never, HerdConfigService | effect_unstable_http_HttpClient9.HttpClient>;
|
|
8
8
|
//#endregion
|
|
9
9
|
export { WalletsServiceLive };
|
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
import { ensureServiceError } from "../errors.js";
|
|
2
|
-
import {
|
|
2
|
+
import { DeployedContractsSchema, TokenActivitySchema, TransactionActivitySchema, WalletOverviewSchema } from "../schemas/wallets.js";
|
|
3
3
|
import { WalletsService } from "../services/WalletsService.js";
|
|
4
4
|
import { authorizedClient, checkStatus, jsonBody, makeUrl } from "./http.js";
|
|
5
|
-
import { Effect,
|
|
6
|
-
import { HttpClientResponse } from "
|
|
5
|
+
import { Effect, Layer, Option, Record, pipe } from "effect";
|
|
6
|
+
import { HttpClientResponse } from "effect/unstable/http";
|
|
7
7
|
|
|
8
8
|
//#region src/live/WalletsServiceLive.ts
|
|
9
9
|
const WalletsServiceLive = Layer.effect(WalletsService, Effect.gen(function* () {
|
|
10
10
|
const { baseUrl, client } = yield* authorizedClient;
|
|
11
11
|
return {
|
|
12
|
+
getDeployedContracts: (blockchain, address, params) => pipe(client.get(makeUrl(baseUrl, `/v1/wallets/${blockchain}/${address}/created_contracts`, {
|
|
13
|
+
page: params?.page,
|
|
14
|
+
before_timestamp: params?.beforeTimestamp,
|
|
15
|
+
after_timestamp: params?.afterTimestamp,
|
|
16
|
+
before_blocknumber: params?.beforeBlocknumber,
|
|
17
|
+
after_blocknumber: params?.afterBlocknumber
|
|
18
|
+
})), Effect.flatMap(checkStatus), Effect.flatMap(HttpClientResponse.schemaBodyJson(DeployedContractsSchema)), Effect.mapError(ensureServiceError("Failed to get deployed contracts"))),
|
|
12
19
|
getOverview: (blockchain, address, params) => pipe(client.get(makeUrl(baseUrl, `/v1/wallets/${blockchain}/${address}/overview`, {
|
|
13
20
|
before_timestamp: params?.beforeTimestamp,
|
|
14
21
|
after_timestamp: params?.afterTimestamp,
|
|
15
22
|
before_blocknumber: params?.beforeBlocknumber,
|
|
16
23
|
after_blocknumber: params?.afterBlocknumber
|
|
17
|
-
})), Effect.flatMap(checkStatus), Effect.flatMap(HttpClientResponse.schemaBodyJson(
|
|
24
|
+
})), Effect.flatMap(checkStatus), Effect.flatMap(HttpClientResponse.schemaBodyJson(WalletOverviewSchema)), Effect.mapError(ensureServiceError("Failed to get wallet overview"))),
|
|
18
25
|
getTokenActivity: (blockchain, address, tokenAddress, params) => pipe(client.get(makeUrl(baseUrl, `/v1/wallets/${blockchain}/${address}/tokens/${tokenAddress}`, {
|
|
19
26
|
page: params?.page,
|
|
20
27
|
before_timestamp: params?.beforeTimestamp,
|
|
@@ -23,30 +30,23 @@ const WalletsServiceLive = Layer.effect(WalletsService, Effect.gen(function* ()
|
|
|
23
30
|
after_blocknumber: params?.afterBlocknumber,
|
|
24
31
|
from_address: params?.fromAddress,
|
|
25
32
|
to_address: params?.toAddress
|
|
26
|
-
})), Effect.flatMap(checkStatus), Effect.flatMap(HttpClientResponse.schemaBodyJson(
|
|
33
|
+
})), Effect.flatMap(checkStatus), Effect.flatMap(HttpClientResponse.schemaBodyJson(TokenActivitySchema)), Effect.mapError(ensureServiceError("Failed to get token activity"))),
|
|
27
34
|
getTransactions: (query) => {
|
|
28
|
-
const optionalFields =
|
|
35
|
+
const optionalFields = Record.getSomes(Record.map({
|
|
29
36
|
from_address: query.fromAddress,
|
|
30
37
|
to_addresses: query.toAddresses,
|
|
31
|
-
before_timestamp: query.beforeBlocknumber
|
|
32
|
-
after_timestamp: query.afterBlocknumber
|
|
38
|
+
before_timestamp: query.beforeBlocknumber === void 0 ? query.beforeTimestamp : void 0,
|
|
39
|
+
after_timestamp: query.afterBlocknumber === void 0 ? query.afterTimestamp : void 0,
|
|
33
40
|
before_blocknumber: query.beforeBlocknumber,
|
|
34
41
|
after_blocknumber: query.afterBlocknumber,
|
|
35
42
|
success_only: query.successOnly === true ? true : void 0
|
|
36
|
-
},
|
|
43
|
+
}, Option.fromNullishOr));
|
|
37
44
|
return pipe(client.post(makeUrl(baseUrl, "/v1/wallets/transaction-activity"), { body: jsonBody({
|
|
38
45
|
blockchain: query.blockchain,
|
|
39
46
|
page: query.page ?? 1,
|
|
40
47
|
...optionalFields
|
|
41
|
-
}) }), Effect.flatMap(checkStatus), Effect.flatMap(HttpClientResponse.schemaBodyJson(
|
|
42
|
-
}
|
|
43
|
-
getDeployedContracts: (blockchain, address, params) => pipe(client.get(makeUrl(baseUrl, `/v1/wallets/${blockchain}/${address}/created_contracts`, {
|
|
44
|
-
page: params?.page,
|
|
45
|
-
before_timestamp: params?.beforeTimestamp,
|
|
46
|
-
after_timestamp: params?.afterTimestamp,
|
|
47
|
-
before_blocknumber: params?.beforeBlocknumber,
|
|
48
|
-
after_blocknumber: params?.afterBlocknumber
|
|
49
|
-
})), Effect.flatMap(checkStatus), Effect.flatMap(HttpClientResponse.schemaBodyJson(DeployedContracts)), Effect.mapError(ensureServiceError("Failed to get deployed contracts")))
|
|
48
|
+
}) }), Effect.flatMap(checkStatus), Effect.flatMap(HttpClientResponse.schemaBodyJson(TransactionActivitySchema)), Effect.mapError(ensureServiceError("Failed to get wallet transactions")));
|
|
49
|
+
}
|
|
50
50
|
};
|
|
51
51
|
}));
|
|
52
52
|
|
package/dist/src/live/http.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HerdConfigService } from "../config.js";
|
|
2
2
|
import { ServiceError } from "../errors.js";
|
|
3
3
|
import { Effect, Schema } from "effect";
|
|
4
|
-
import { HttpBody, HttpClient, HttpClientResponse, UrlParams } from "
|
|
5
|
-
import * as
|
|
4
|
+
import { HttpBody, HttpClient, HttpClientResponse, UrlParams } from "effect/unstable/http";
|
|
5
|
+
import * as effect_unstable_http_HttpClientError0 from "effect/unstable/http/HttpClientError";
|
|
6
6
|
|
|
7
7
|
//#region src/live/http.d.ts
|
|
8
8
|
declare const makeUrl: (baseUrl: string, path: string, queryParams?: object) => string;
|
|
9
9
|
declare const authorizedClient: Effect.Effect<{
|
|
10
10
|
baseUrl: string;
|
|
11
|
-
client: HttpClient.HttpClient.With<
|
|
12
|
-
}, never,
|
|
13
|
-
declare const handleJsonResponse: <
|
|
11
|
+
client: HttpClient.HttpClient.With<effect_unstable_http_HttpClientError0.HttpClientError, never>;
|
|
12
|
+
}, never, HerdConfigService | HttpClient.HttpClient>;
|
|
13
|
+
declare const handleJsonResponse: <S extends Schema.Top>(schema: S) => (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<S["Type"], ServiceError, S["DecodingServices"]>;
|
|
14
14
|
declare const checkStatus: (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<HttpClientResponse.HttpClientResponse, ServiceError>;
|
|
15
15
|
declare const jsonBody: (body: unknown) => HttpBody.HttpBody;
|
|
16
16
|
declare const urlEncodedBody: (body: UrlParams.Input) => HttpBody.HttpBody;
|
package/dist/src/live/http.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HerdConfigService } from "../config.js";
|
|
2
2
|
import { ServiceError } from "../errors.js";
|
|
3
|
-
import { Effect,
|
|
4
|
-
import { HttpBody, HttpClient, HttpClientRequest, HttpClientResponse, UrlParams } from "
|
|
3
|
+
import { Effect, Function, Result, pipe } from "effect";
|
|
4
|
+
import { HttpBody, HttpClient, HttpClientRequest, HttpClientResponse, UrlParams } from "effect/unstable/http";
|
|
5
5
|
|
|
6
6
|
//#region src/live/http.ts
|
|
7
7
|
const makeUrl = (baseUrl, path, queryParams) => {
|
|
@@ -13,16 +13,16 @@ const makeUrl = (baseUrl, path, queryParams) => {
|
|
|
13
13
|
return url.toString();
|
|
14
14
|
};
|
|
15
15
|
const authorizedClient = Effect.gen(function* () {
|
|
16
|
-
const config = yield*
|
|
16
|
+
const config = yield* HerdConfigService;
|
|
17
17
|
const client = yield* HttpClient.HttpClient;
|
|
18
|
-
const { baseUrl, authHeaders } =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
const { baseUrl, authHeaders } = Result.match(config, {
|
|
19
|
+
onFailure: ({ baseUrl: innerBaseUrl, oauthAccessToken }) => ({
|
|
20
|
+
authHeaders: { Authorization: `Bearer ${oauthAccessToken}` },
|
|
21
|
+
baseUrl: innerBaseUrl
|
|
22
22
|
}),
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
onSuccess: ({ baseUrl: innerBaseUrl, apiKey }) => ({
|
|
24
|
+
authHeaders: { "x-api-key": apiKey },
|
|
25
|
+
baseUrl: innerBaseUrl
|
|
26
26
|
})
|
|
27
27
|
});
|
|
28
28
|
return {
|
|
@@ -45,18 +45,18 @@ const extractErrorMessage = (body) => {
|
|
|
45
45
|
};
|
|
46
46
|
const checkStatus = (response) => {
|
|
47
47
|
if (response.status >= 200 && response.status < 300) return Effect.succeed(response);
|
|
48
|
-
return pipe(response.json, Effect.
|
|
48
|
+
return pipe(response.json, Effect.catch(() => response.text.pipe(Effect.map((text) => text))), Effect.orElseSucceed(Function.constNull), Effect.flatMap((body) => {
|
|
49
49
|
const message = extractErrorMessage(body) ?? `HTTP ${String(response.status)} error`;
|
|
50
50
|
return Effect.fail(new ServiceError({
|
|
51
51
|
message,
|
|
52
52
|
metadata: {
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
body,
|
|
54
|
+
status: response.status
|
|
55
55
|
}
|
|
56
56
|
}));
|
|
57
57
|
}));
|
|
58
58
|
};
|
|
59
|
-
const jsonBody = (body) => HttpBody.
|
|
59
|
+
const jsonBody = (body) => HttpBody.jsonUnsafe(body);
|
|
60
60
|
const urlEncodedBody = (body) => HttpBody.urlParams(UrlParams.fromInput(body));
|
|
61
61
|
|
|
62
62
|
//#endregion
|