Skip to content

Commit

Permalink
feat: add getHistory to Moralis.Streams
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnoW committed Sep 16, 2022
1 parent b6c7dc1 commit b5f3bc7
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-buses-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@moralisweb3/streams': minor
---

Add Moralis.Streams.getHistory to get all failed webhooks
8 changes: 3 additions & 5 deletions packages/streams/src/MoralisStreams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { updateStream, UpdateStreamOptions } from './methods/update';
import { deleteStream, DeleteStreamOptions } from './methods/delete';
import { GetStreamsOptions, getStreams } from './methods/getAll';
import { makeVerifySignature, VerifySignatureOptions } from './methods/verifySignature';
import { getHistory } from './resolvers/getHistory';

export const BASE_URL = 'https://streams-api.aws-prod-streams-master-1.moralis.io';

Expand All @@ -31,17 +32,14 @@ export class MoralisStreams extends ApiModule {
public readonly endpoints = new Endpoints(this.core, BASE_URL);

public readonly add = (options: CreateStreamOptions) => createStream(this.core)(options);

public readonly update = (options: UpdateStreamOptions) => updateStream(this.core)(options);

public readonly delete = (options: DeleteStreamOptions) => deleteStream(this.core)(options);

public readonly getAll = (options: GetStreamsOptions) => getStreams(this.core)(options);

public readonly setSettings = this.endpoints.createFetcher(setSettings);
public readonly getHistory = this.endpoints.createFetcher(getHistory);

public readonly setSettings = this.endpoints.createFetcher(setSettings);
private readonly _readSettings = this.endpoints.createFetcher(getSettings);

public readonly readSettings = () => this._readSettings({});

public readonly verifySignature = (options: VerifySignatureOptions) => makeVerifySignature(this.core)(options);
Expand Down
143 changes: 123 additions & 20 deletions packages/streams/src/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/

export interface paths {
"/logger": {
get: operations["SetSettings"];
"/history": {
get: operations["GetHistory"];
};
"/settings": {
/** Get the settings for the current project based on the project api-key. */
Expand All @@ -31,16 +31,103 @@ export interface paths {

export interface components {
schemas: {
/** @enum {string} */
LogType: "debug" | "info" | "warn" | "error";
LogModel: {
ILog: {
transaction_hash: string;
/** Format: double */
transaction_index: number;
/** Format: double */
log_index: number;
tag: string;
address: string;
topic0: string;
topic1: string;
topic2: string;
topic3: string;
data: string;
streamId: string;
};
ITransaction: { [key: string]: string };
ITransactionInternal: {
from: string;
to: string;
value: string;
gas: string;
transaction_hash: string;
};
IERC20Transfer: {
transaction_hash: string;
/** Format: double */
transaction_index: number;
/** Format: double */
log_index: number;
tag: string;
contractAddress: string;
from: string;
to: string;
amount: string;
valueWithDecimals: string;
};
IERC20Approval: {
transaction_hash: string;
/** Format: double */
transaction_index: number;
/** Format: double */
log_index: number;
tag: string;
contractAddress: string;
owner: string;
spender: string;
value: string;
valueWithDecimals: string;
};
INFTTransfer: {
transaction_hash: string;
/** Format: double */
transaction_index: number;
/** Format: double */
log_index: number;
tag: string;
contractAddress: string;
from: string;
to: string;
tokenId: string;
};
INFTApproval: {
transaction_hash: string;
/** Format: double */
transaction_index: number;
/** Format: double */
log_index: number;
tag: string;
account: string;
operator: string;
approved: boolean;
};
"WebhookTypes.IWebhook": {
/** Format: double */
block: number;
chainId: string;
logs: components["schemas"]["ILog"][];
txs: components["schemas"]["ITransaction"][];
txsInternal: components["schemas"]["ITransactionInternal"][];
abis: unknown;
/** Format: double */
retries: number;
confirmed: boolean;
erc20Transfers?: components["schemas"]["IERC20Transfer"][];
erc20Approvals?: components["schemas"]["IERC20Approval"][];
nftTransfers?: components["schemas"]["INFTTransfer"][];
nftApprovals?: components["schemas"]["INFTApproval"][];
};
HistoryModel: {
id: string;
date: string;
block: string;
message: string;
type: components["schemas"]["LogType"];
payload: components["schemas"]["WebhookTypes.IWebhook"];
errorMessage: string;
webhookUrl: string;
};
LogsResponse: {
result: components["schemas"]["LogModel"][];
HistoryResponse: {
result: components["schemas"]["HistoryModel"][];
cursor?: string;
};
/** @enum {string} */
Expand Down Expand Up @@ -152,16 +239,19 @@ export interface components {
}

export interface operations {
/** Set the settings for the current project based on the project api-key. */
SetSettings: {
parameters: {};
responses: {
/** No content */
204: never;
GetHistory: {
parameters: {
query: {
limit: number;
cursor?: string;
};
};
requestBody: {
content: {
"application/json": components["schemas"]["SettingsModel"];
responses: {
/** Ok */
200: {
content: {
"application/json": components["schemas"]["HistoryResponse"];
};
};
};
};
Expand All @@ -177,6 +267,19 @@ export interface operations {
};
};
};
/** Set the settings for the current project based on the project api-key. */
SetSettings: {
parameters: {};
responses: {
/** No content */
204: never;
};
requestBody: {
content: {
"application/json": components["schemas"]["SettingsModel"];
};
};
};
/** Get all the evm streams for the current project based on the project api-key. */
GetStreams: {
parameters: {
Expand Down Expand Up @@ -226,7 +329,7 @@ export interface operations {
/** Ok */
200: {
content: {
"application/json": components["schemas"]["StreamsModel"][];
"application/json": components["schemas"]["StreamsModel"];
};
};
};
Expand Down
20 changes: 20 additions & 0 deletions packages/streams/src/resolvers/getHistory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createEndpoint, createEndpointFactory } from '@moralisweb3/api-utils';
import { operations } from '../generated/types';

const name = 'GetHistory';

type Name = typeof name;
type ApiResult = operations[Name]['responses']['200']['content']['application/json'];
type QueryParams = operations[Name]['parameters']['query'];
type ApiParams = QueryParams;
type Params = ApiParams;

export const getHistory = createEndpointFactory(() =>
createEndpoint({
name,
getUrl: () => `/history`,
apiToResult: (data: ApiResult) => data,
resultToJson: (data) => data,
parseParams: (params: Params): ApiParams => params,
}),
);

0 comments on commit b5f3bc7

Please sign in to comment.