@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.
Files changed (99) hide show
  1. package/dist/index.d.ts +17 -17
  2. package/dist/index.js +17 -17
  3. package/dist/src/config.d.ts +11 -11
  4. package/dist/src/config.js +9 -12
  5. package/dist/src/errors.d.ts +35 -44
  6. package/dist/src/errors.js +19 -16
  7. package/dist/src/live/ActionsServiceLive.d.ts +3 -3
  8. package/dist/src/live/ActionsServiceLive.js +14 -14
  9. package/dist/src/live/AdaptersServiceLive.d.ts +3 -3
  10. package/dist/src/live/AdaptersServiceLive.js +8 -8
  11. package/dist/src/live/AgentSafesServiceLive.d.ts +3 -3
  12. package/dist/src/live/AgentSafesServiceLive.js +5 -5
  13. package/dist/src/live/AgentWalletsServiceLive.d.ts +3 -3
  14. package/dist/src/live/AgentWalletsServiceLive.js +4 -4
  15. package/dist/src/live/AgentWorkflowsServiceLive.d.ts +3 -3
  16. package/dist/src/live/AgentWorkflowsServiceLive.js +14 -14
  17. package/dist/src/live/AuthServiceLive.d.ts +3 -3
  18. package/dist/src/live/AuthServiceLive.js +7 -7
  19. package/dist/src/live/BookmarksServiceLive.d.ts +3 -3
  20. package/dist/src/live/BookmarksServiceLive.js +20 -20
  21. package/dist/src/live/CodeBlocksServiceLive.d.ts +3 -3
  22. package/dist/src/live/CodeBlocksServiceLive.js +11 -11
  23. package/dist/src/live/CollectionsServiceLive.d.ts +3 -3
  24. package/dist/src/live/CollectionsServiceLive.js +6 -6
  25. package/dist/src/live/ContractsServiceLive.d.ts +3 -3
  26. package/dist/src/live/ContractsServiceLive.js +10 -10
  27. package/dist/src/live/DocsServiceLive.d.ts +3 -3
  28. package/dist/src/live/DocsServiceLive.js +4 -4
  29. package/dist/src/live/GroupsServiceLive.d.ts +3 -3
  30. package/dist/src/live/GroupsServiceLive.js +9 -9
  31. package/dist/src/live/HalServiceLive.d.ts +3 -3
  32. package/dist/src/live/HalServiceLive.js +12 -12
  33. package/dist/src/live/TransactionsServiceLive.d.ts +3 -3
  34. package/dist/src/live/TransactionsServiceLive.js +18 -18
  35. package/dist/src/live/WalletsServiceLive.d.ts +3 -3
  36. package/dist/src/live/WalletsServiceLive.js +18 -18
  37. package/dist/src/live/http.d.ts +6 -6
  38. package/dist/src/live/http.js +15 -15
  39. package/dist/src/schemas/actions.d.ts +179 -339
  40. package/dist/src/schemas/actions.js +80 -76
  41. package/dist/src/schemas/adapters.d.ts +7 -17
  42. package/dist/src/schemas/adapters.js +5 -5
  43. package/dist/src/schemas/agent-wallets.d.ts +98 -222
  44. package/dist/src/schemas/agent-wallets.js +52 -52
  45. package/dist/src/schemas/agent-workflows.d.ts +104 -104
  46. package/dist/src/schemas/agent-workflows.js +53 -49
  47. package/dist/src/schemas/auth.d.ts +35 -64
  48. package/dist/src/schemas/auth.js +16 -16
  49. package/dist/src/schemas/bookmarks.d.ts +98 -216
  50. package/dist/src/schemas/bookmarks.js +55 -51
  51. package/dist/src/schemas/codeblocks.d.ts +149 -308
  52. package/dist/src/schemas/codeblocks.js +72 -67
  53. package/dist/src/schemas/collections.d.ts +120 -232
  54. package/dist/src/schemas/collections.js +48 -44
  55. package/dist/src/schemas/common.d.ts +13 -29
  56. package/dist/src/schemas/common.js +8 -8
  57. package/dist/src/schemas/contracts.d.ts +256 -447
  58. package/dist/src/schemas/contracts.js +92 -103
  59. package/dist/src/schemas/docs.d.ts +12 -29
  60. package/dist/src/schemas/docs.js +9 -9
  61. package/dist/src/schemas/groups.d.ts +74 -74
  62. package/dist/src/schemas/groups.js +32 -32
  63. package/dist/src/schemas/hal.d.ts +109 -217
  64. package/dist/src/schemas/hal.js +44 -42
  65. package/dist/src/schemas/transactions.d.ts +648 -926
  66. package/dist/src/schemas/transactions.js +158 -162
  67. package/dist/src/schemas/wallets.d.ts +577 -731
  68. package/dist/src/schemas/wallets.js +206 -145
  69. package/dist/src/services/ActionsService.d.ts +3 -3
  70. package/dist/src/services/ActionsService.js +2 -2
  71. package/dist/src/services/AdaptersService.d.ts +1 -1
  72. package/dist/src/services/AdaptersService.js +2 -2
  73. package/dist/src/services/AgentSafesService.d.ts +5 -5
  74. package/dist/src/services/AgentSafesService.js +2 -2
  75. package/dist/src/services/AgentWalletsService.d.ts +3 -3
  76. package/dist/src/services/AgentWalletsService.js +2 -2
  77. package/dist/src/services/AgentWorkflowsService.d.ts +11 -11
  78. package/dist/src/services/AgentWorkflowsService.js +6 -2
  79. package/dist/src/services/AuthService.d.ts +5 -5
  80. package/dist/src/services/AuthService.js +2 -2
  81. package/dist/src/services/BookmarksService.d.ts +3 -3
  82. package/dist/src/services/BookmarksService.js +2 -2
  83. package/dist/src/services/CodeBlocksService.d.ts +1 -1
  84. package/dist/src/services/CodeBlocksService.js +2 -2
  85. package/dist/src/services/CollectionsService.d.ts +1 -1
  86. package/dist/src/services/CollectionsService.js +2 -2
  87. package/dist/src/services/ContractsService.d.ts +6 -6
  88. package/dist/src/services/ContractsService.js +2 -2
  89. package/dist/src/services/DocsService.d.ts +2 -2
  90. package/dist/src/services/DocsService.js +2 -2
  91. package/dist/src/services/GroupsService.d.ts +13 -13
  92. package/dist/src/services/GroupsService.js +4 -2
  93. package/dist/src/services/HalService.d.ts +1 -1
  94. package/dist/src/services/HalService.js +2 -2
  95. package/dist/src/services/TransactionsService.d.ts +5 -5
  96. package/dist/src/services/TransactionsService.js +2 -2
  97. package/dist/src/services/WalletsService.d.ts +5 -5
  98. package/dist/src/services/WalletsService.js +2 -2
  99. package/package.json +13 -18
@@ -1,45 +1,45 @@
1
1
  import { ensureServiceError } from "../errors.js";
2
- import { LatestEventTransactions, LatestFunctionTransactions, TransactionQueryResponse } from "../schemas/transactions.js";
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, Function, Layer, Option, Record, pipe } from "effect";
6
- import { HttpClientResponse } from "@effect/platform";
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) => pipe(input, Record.filterMap(Option.liftNullable((v) => v)));
10
- const latestTxParamsToSnakeCaseQuery = (params) => pipe({
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
- called_by: params?.calledBy
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
- getTransaction: (blockchain, txHash) => pipe(client.get(makeUrl(baseUrl, `/v1/transactions/${blockchain}/${txHash}`)), Effect.flatMap(checkStatus), Effect.flatMap(HttpClientResponse.schemaBodyJson(TransactionQueryResponse)), Effect.mapError(ensureServiceError("Failed to get transaction"))),
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(LatestFunctionTransactions)), Effect.mapError(ensureServiceError("Failed to get latest function transactions"))),
36
- getLatestEventTransactions: (blockchain, address, filter, params) => pipe(client.get(makeUrl(baseUrl, `/v1/contracts/${blockchain}/${address}/latest_event_transactions`, {
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(LatestEventTransactions)), Effect.mapError(ensureServiceError("Failed to get latest event transactions")))
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 { HerdConfig } from "../config.js";
1
+ import { HerdConfigService } from "../config.js";
2
2
  import { WalletsService } from "../services/WalletsService.js";
3
3
  import { Layer } from "effect";
4
- import * as _effect_platform_HttpClient10 from "@effect/platform/HttpClient";
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, HerdConfig | _effect_platform_HttpClient10.HttpClient>;
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 { DeployedContracts, TokenActivity, TransactionActivity, WalletOverview } from "../schemas/wallets.js";
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, Function, Layer, Option, Record, pipe } from "effect";
6
- import { HttpClientResponse } from "@effect/platform";
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(WalletOverview)), Effect.mapError(ensureServiceError("Failed to get wallet overview"))),
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(TokenActivity)), Effect.mapError(ensureServiceError("Failed to get token activity"))),
33
+ })), Effect.flatMap(checkStatus), Effect.flatMap(HttpClientResponse.schemaBodyJson(TokenActivitySchema)), Effect.mapError(ensureServiceError("Failed to get token activity"))),
27
34
  getTransactions: (query) => {
28
- const optionalFields = pipe({
35
+ const optionalFields = Record.getSomes(Record.map({
29
36
  from_address: query.fromAddress,
30
37
  to_addresses: query.toAddresses,
31
- before_timestamp: query.beforeBlocknumber !== void 0 ? void 0 : query.beforeTimestamp,
32
- after_timestamp: query.afterBlocknumber !== void 0 ? void 0 : query.afterTimestamp,
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
- }, Record.filterMap(Option.liftNullable(Function.identity)));
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(TransactionActivity)), Effect.mapError(ensureServiceError("Failed to get wallet transactions")));
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
 
@@ -1,16 +1,16 @@
1
- import { HerdConfig } from "../config.js";
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 "@effect/platform";
5
- import * as _effect_platform_HttpClientError0 from "@effect/platform/HttpClientError";
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<_effect_platform_HttpClientError0.HttpClientError, never>;
12
- }, never, HerdConfig | HttpClient.HttpClient>;
13
- declare const handleJsonResponse: <A, I, R>(schema: Schema.Schema<A, I, R>) => (response: HttpClientResponse.HttpClientResponse) => Effect.Effect<A, ServiceError, R>;
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;
@@ -1,7 +1,7 @@
1
- import { HerdConfig } from "../config.js";
1
+ import { HerdConfigService } from "../config.js";
2
2
  import { ServiceError } from "../errors.js";
3
- import { Effect, Either, pipe } from "effect";
4
- import { HttpBody, HttpClient, HttpClientRequest, HttpClientResponse, UrlParams } from "@effect/platform";
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* HerdConfig;
16
+ const config = yield* HerdConfigService;
17
17
  const client = yield* HttpClient.HttpClient;
18
- const { baseUrl, authHeaders } = Either.match(config, {
19
- onLeft: ({ baseUrl: baseUrl$1, oauthAccessToken }) => ({
20
- baseUrl: baseUrl$1,
21
- authHeaders: { Authorization: `Bearer ${oauthAccessToken}` }
18
+ const { baseUrl, authHeaders } = Result.match(config, {
19
+ onFailure: ({ baseUrl: innerBaseUrl, oauthAccessToken }) => ({
20
+ authHeaders: { Authorization: `Bearer ${oauthAccessToken}` },
21
+ baseUrl: innerBaseUrl
22
22
  }),
23
- onRight: ({ baseUrl: baseUrl$1, apiKey }) => ({
24
- baseUrl: baseUrl$1,
25
- authHeaders: { "x-api-key": apiKey }
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.orElse(() => response.text.pipe(Effect.map((text) => text))), Effect.orElseSucceed(() => null), Effect.flatMap((body) => {
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
- status: response.status,
54
- body
53
+ body,
54
+ status: response.status
55
55
  }
56
56
  }));
57
57
  }));
58
58
  };
59
- const jsonBody = (body) => HttpBody.unsafeJson(body);
59
+ const jsonBody = (body) => HttpBody.jsonUnsafe(body);
60
60
  const urlEncodedBody = (body) => HttpBody.urlParams(UrlParams.fromInput(body));
61
61
 
62
62
  //#endregion