Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/update api types #912

Merged
merged 6 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .changeset/many-points-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
'@moralisweb3/api-utils': patch
'@moralisweb3/auth': patch
'@moralisweb3/client-api-utils': patch
'@moralisweb3/client-evm-api': patch
'@moralisweb3/client-firebase-api-utils': patch
'@moralisweb3/client-firebase-auth-utils': patch
'@moralisweb3/client-firebase-evm-api': patch
'@moralisweb3/client-firebase-evm-auth': patch
'@moralisweb3/client-firebase-sol-api': patch
'@moralisweb3/client-firebase-sol-auth': patch
'@moralisweb3/client-sol-api': patch
'@moralisweb3/codegen': patch
'@moralisweb3/common-auth-utils': patch
'@moralisweb3/common-core': patch
'@moralisweb3/common-evm-utils': patch
'@moralisweb3/common-sol-utils': patch
'@moralisweb3/common-streams-utils': patch
'create-moralis-dapp': patch
'@moralisweb3/evm-api': patch
'@moralisweb3/evm-utils': patch
'moralis': patch
'@moralisweb3/next': patch
'@moralisweb3/parse-server': patch
'@moralisweb3/sol-api': patch
'@moralisweb3/sol-utils': patch
'@moralisweb3/streams': patch
'@moralisweb3/test-utils': patch
---

Update api types to include latest features and fixes of evmApi and streams. This includes:

- removal of deprecated `subdomain` and `providerUrl` params
- evm endpooint for `getMultipleNFTs`
- evm endpoint updated for `getNFTContractTransfers` to include `fromBlock`, `toBlock`, `fromDate` and `toDate` params
- streams support for `getNativeBalances`
3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ packageExtensions:
peerDependencies:
'@babel/core': '*'
'@babel/plugin-transform-react-jsx': '*'
'[email protected]':
peerDependencies:
'@types/node': '*'
'demo-nextjs@*':
peerDependencies:
'@babel-core': '*'
Expand Down
2 changes: 1 addition & 1 deletion demos/parse-server-migration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"@codemirror/language": "^0.20.0",
"@moralisweb3/common-core": "^2.10.1",
"@moralisweb3/parse-server": "2.10.1",
"@types/node": "^18.11.11",
"dotenv": "^16.0.1",
"envalid": "7.3.1",
"express": "^4.18.1",
Expand All @@ -20,6 +19,7 @@
},
"devDependencies": {
"@moralisweb3/eslint-config": "^1.0.1",
"@types/node": "^18.11.11",
"@typescript-eslint/eslint-plugin": "^5.45.1",
"@typescript-eslint/parser": "^5.45.1",
"axios": "^1.2.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/common/authUtils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@
"@moralisweb3/eslint-config": "^1.0.1",
"eslint": "^8.29.0",
"jest": "29.3.1",
"openapi-typescript": "^5.2.0",
"typescript": "^4.9.3"
},
"dependencies": {
"@ethersproject/abi": "^5.7.0",
"@moralisweb3/common-core": "^2.10.1",
"@moralisweb3/common-evm-utils": "^2.10.1",
"@moralisweb3/common-sol-utils": "^2.10.1",
"@moralisweb3/streams-typings": "^1.0.5"
"@moralisweb3/streams-typings": "^1.0.6"
}
}
23 changes: 18 additions & 5 deletions packages/common/authUtils/src/operations/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ export interface components {
*/
notBefore?: string;
/**
* @description List of information or references to information the user wishes to have resolved as part of authentication by the relying party. They are expressed as RFC 3986 URIs separated by `
* - `.
* @description List of information or references to information the user wishes to have resolved as part of authentication by the relying party. They are expressed as RFC 3986 URIs separated by new lines.
* @example [
* "https://docs.moralis.io/"
* ]
Expand Down Expand Up @@ -121,8 +120,23 @@ export interface components {
profileId: string;
};
EvmCompleteChallengeRequestDto: {
/**
* @description Message that needs to be signed by the end user.
* @example defi.finance wants you to sign in with your Ethereum account:
* 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B
*
*
* URI: https://defi.finance
* Version: 1
* Chain ID: 1
* Nonce: Px7Nh1RPzlCLwqgOb
* Issued At: 2022-11-30T10:20:00.262Z
*/
message: string;
/** @example 0x1234567890abcdef0123456789abcdef1234567890abcdef */
/**
* @description EIP-191 compliant signature signed by the Ethereum account address requesting authentication.
* @example 0xa8f89a58bf9b433d3100f9e41ee35b5e31fb8c7cd62547acb113162ec6f2e4140207e2dfbd4e387e1801ebc7f08a9dd105ac1d22b2e2ff0df5fa8b6d9bdcfe491c
*/
signature: string;
};
EvmCompleteChallengeResponseDto: {
Expand Down Expand Up @@ -249,8 +263,7 @@ export interface components {
*/
notBefore?: string;
/**
* @description List of information or references to information the user wishes to have resolved as part of authentication by the relying party. They are expressed as RFC 3986 URIs separated by `
* - `.
* @description List of information or references to information the user wishes to have resolved as part of authentication by the relying party. They are expressed as RFC 3986 URIs separated by new lines.
* @example [
* "https://docs.moralis.io/"
* ]
Expand Down
11 changes: 11 additions & 0 deletions packages/common/evmUtils/src/dataTypes/EvmNft/EvmNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,15 @@ export class EvmNft implements MoralisDataObject {
get amount() {
return this._data.amount;
}

/**
* @returns the token id
* @example
* ```
* nft.tokenId // '1234'
* ```
*/
get tokenId() {
return this._data.tokenId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,18 @@ describe('getNativeBalanceOperation', () => {
address: EvmAddress.create(address, core),
chain: EvmChain.create(chain, core),
toBlock: 123,
providerUrl: 'https://provider.com/url',
};

const serializedRequest = getNativeBalanceOperation.serializeRequest(request, core);

expect(serializedRequest.address).toBe(address);
expect(serializedRequest.chain).toBe(chain);
expect(serializedRequest.providerUrl).toBe(request.providerUrl);
expect(serializedRequest.toBlock).toBe(request.toBlock);
expect(serializedRequest.providerUrl).toBe(request.providerUrl);

const deserializedRequest = getNativeBalanceOperation.deserializeRequest(serializedRequest, core);

expect((deserializedRequest.address as EvmAddress).lowercase).toBe(address);
expect((deserializedRequest.chain as EvmChain).apiHex).toBe(chain);
expect(deserializedRequest.toBlock).toBe(request.toBlock);
expect(deserializedRequest.providerUrl).toBe(request.providerUrl);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const getNativeBalanceOperation: Operation<
groupName: 'balance',
urlPathPattern: '/{address}/balance',
urlPathParamNames: ['address'],
urlSearchParamNames: ['chain', 'providerUrl', 'toBlock'],
urlSearchParamNames: ['chain', 'toBlock'],

getRequestUrlParams,
serializeRequest,
Expand All @@ -53,7 +53,6 @@ export const getNativeBalanceOperation: Operation<
function getRequestUrlParams(request: GetNativeBalanceRequest, core: Core) {
return {
chain: EvmChainResolver.resolve(request.chain, core).apiHex,
providerUrl: request.providerUrl,
to_block: maybe(request.toBlock, String),
address: EvmAddress.create(request.address, core).checksum,
};
Expand All @@ -68,7 +67,6 @@ function deserializeResponse(jsonResponse: GetNativeBalanceJSONResponse) {
function serializeRequest(request: GetNativeBalanceRequest, core: Core) {
return {
chain: EvmChainResolver.resolve(request.chain, core).apiHex,
providerUrl: request.providerUrl,
toBlock: request.toBlock,
address: EvmAddress.create(request.address, core).lowercase,
};
Expand All @@ -77,7 +75,6 @@ function serializeRequest(request: GetNativeBalanceRequest, core: Core) {
function deserializeRequest(jsonRequest: GetNativeBalanceJSONRequest, core: Core): GetNativeBalanceRequest {
return {
chain: EvmChain.create(jsonRequest.chain, core),
providerUrl: jsonRequest.providerUrl,
toBlock: jsonRequest.toBlock,
address: EvmAddress.create(jsonRequest.address, core),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@ describe('getBlockOperation', () => {
const request: Required<GetBlockRequest> = {
blockNumberOrHash: '0x123',
chain: EvmChain.create(chain, core),
subdomain: 'some-subdomain',
};

const serializedRequest = getBlockOperation.serializeRequest(request, core);

expect(serializedRequest.blockNumberOrHash).toBe(request.blockNumberOrHash);
expect(serializedRequest.chain).toBe(chain);
expect(serializedRequest.subdomain).toBe(request.subdomain);

const deserializedRequest = getBlockOperation.deserializeRequest(serializedRequest, core);

expect((deserializedRequest.chain as EvmChain).apiHex).toBe(chain);
expect(deserializedRequest.blockNumberOrHash).toBe(request.blockNumberOrHash);
expect(deserializedRequest.subdomain).toBe(request.subdomain);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const getBlockOperation: Operation<
isNullable: true,
urlPathPattern: '/block/{blockNumberOrHash}',
urlPathParamNames: ['blockNumberOrHash'],
urlSearchParamNames: ['chain', 'subdomain'],
urlSearchParamNames: ['chain'],

getRequestUrlParams,
serializeRequest,
Expand All @@ -52,7 +52,6 @@ export const getBlockOperation: Operation<
function getRequestUrlParams(request: GetBlockRequest, core: Core) {
return {
chain: EvmChainResolver.resolve(request.chain, core).apiHex,
subdomain: request.subdomain,
blockNumberOrHash: request.blockNumberOrHash,
};
}
Expand Down Expand Up @@ -116,15 +115,13 @@ function deserializeResponse(jsonResponse: GetBlockJSONResponse, request: GetBlo
function serializeRequest(request: GetBlockRequest, core: Core) {
return {
chain: EvmChainResolver.resolve(request.chain, core).apiHex,
subdomain: request.subdomain,
blockNumberOrHash: request.blockNumberOrHash,
};
}

function deserializeRequest(jsonRequest: GetBlockJSONRequest, core: Core): GetBlockRequest {
return {
chain: EvmChain.create(jsonRequest.chain, core),
subdomain: jsonRequest.subdomain,
blockNumberOrHash: jsonRequest.blockNumberOrHash,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ describe('getDateToBlockOperation', () => {
const request: Required<GetDateToBlockRequest> = {
chain: EvmChain.create(chain, core),
date: new Date(date),
providerUrl: 'https://provider.com/url',
};

const serializedRequest = getDateToBlockOperation.serializeRequest(request, core);

expect(serializedRequest.chain).toBe(chain);
expect(serializedRequest.providerUrl).toBe(request.providerUrl);
expect(serializedRequest.date).toBe(date);

const deserializedRequest = getDateToBlockOperation.deserializeRequest(serializedRequest, core);

expect((deserializedRequest.chain as EvmChain).apiHex).toBe(chain);
expect((deserializedRequest.date as Date).toISOString()).toBe(date);
expect(deserializedRequest.providerUrl).toBe(request.providerUrl);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const getDateToBlockOperation: Operation<
id: 'getDateToBlock',
groupName: 'block',
urlPathPattern: '/dateToBlock',
urlSearchParamNames: ['chain', 'providerUrl', 'date'],
urlSearchParamNames: ['chain', 'date'],

getRequestUrlParams,
serializeRequest,
Expand All @@ -52,7 +52,6 @@ export const getDateToBlockOperation: Operation<
function getRequestUrlParams(request: GetDateToBlockRequest, core: Core) {
return {
chain: EvmChainResolver.resolve(request.chain, core).apiHex,
providerUrl: request.providerUrl,
date: new Date(request.date).toISOString(),
};
}
Expand All @@ -67,15 +66,13 @@ function deserializeResponse(jsonResponse: GetDateToBlockJSONResponse) {
function serializeRequest(request: GetDateToBlockRequest, core: Core) {
return {
chain: EvmChainResolver.resolve(request.chain, core).apiHex,
providerUrl: request.providerUrl,
date: new Date(request.date).toISOString(),
};
}

function deserializeRequest(jsonRequest: GetDateToBlockJSONRequest, core: Core): GetDateToBlockRequest {
return {
chain: EvmChain.create(jsonRequest.chain, core),
providerUrl: jsonRequest.providerUrl,
date: new Date(jsonRequest.date),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ describe('getPairReservesOperation', () => {
toBlock: '123',
toDate: new Date(toDate),
pairAddress: EvmAddress.create(address, core),
providerUrl: 'https://provider.com/url',
};

const serializedRequest = getPairReservesOperation.serializeRequest(request, core);

expect(serializedRequest.pairAddress).toBe(address);
expect(serializedRequest.chain).toBe(chain);
expect(serializedRequest.providerUrl).toBe(request.providerUrl);
expect(serializedRequest.toBlock).toBe(request.toBlock);
expect(serializedRequest.toDate).toBe(toDate);

Expand All @@ -36,6 +34,5 @@ describe('getPairReservesOperation', () => {
expect((deserializedRequest.chain as EvmChain).apiHex).toBe(chain);
expect(deserializedRequest.toBlock).toBe(request.toBlock);
expect((deserializedRequest.toDate as Date | undefined)?.toISOString()).toBe(toDate);
expect(deserializedRequest.providerUrl).toBe(request.providerUrl);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const getPairReservesOperation: Operation<
groupName: 'defi',
urlPathPattern: '/{pairAddress}/reserves',
urlPathParamNames: ['pairAddress'],
urlSearchParamNames: ['chain', 'toBlock', 'toDate', 'providerUrl'],
urlSearchParamNames: ['chain', 'toBlock', 'toDate'],

getRequestUrlParams,
serializeRequest,
Expand All @@ -57,7 +57,6 @@ function getRequestUrlParams(request: GetPairReservesRequest, core: Core) {
pairAddress: EvmAddress.create(request.pairAddress, core).lowercase,
to_block: request.toBlock,
to_date: request.toDate ? new Date(request.toDate).toISOString() : undefined,
provider_url: request.providerUrl,
};
}

Expand All @@ -66,7 +65,6 @@ function serializeRequest(request: GetPairReservesRequest, core: Core) {
chain: EvmChainResolver.resolve(request.chain, core).apiHex,
toBlock: request.toBlock,
toDate: request.toDate ? new Date(request.toDate).toISOString() : undefined,
providerUrl: request.providerUrl,
pairAddress: EvmAddress.create(request.pairAddress, core).lowercase,
};
}
Expand All @@ -76,7 +74,6 @@ function deserializeRequest(jsonRequest: GetPairReservesJSONRequest, core: Core)
chain: EvmChain.create(jsonRequest.chain, core),
toBlock: jsonRequest.toBlock,
toDate: jsonRequest.toDate ? new Date(jsonRequest.toDate) : undefined,
providerUrl: jsonRequest.providerUrl,
pairAddress: EvmAddress.create(jsonRequest.pairAddress, core),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,15 @@ describe('getContractEventsOperation', () => {
toDate: new Date(toDate),
fromDate: new Date(fromDate),
address: EvmAddress.create(address, core),
subdomain: 'subdomain',
limit: 100,
offset: 0,
topic: 'topic0',
providerUrl: 'https://provider.com/url',
};

const serializedRequest = getContractEventsOperation.serializeRequest(request, core);

expect(serializedRequest.address).toBe(address);
expect(serializedRequest.chain).toBe(chain);
expect(serializedRequest.providerUrl).toBe(request.providerUrl);
expect(serializedRequest.subdomain).toBe(request.subdomain);
expect(serializedRequest.limit).toBe(request.limit);
expect(serializedRequest.offset).toBe(request.offset);
expect(serializedRequest.topic).toBe(request.topic);
Expand All @@ -58,8 +54,6 @@ describe('getContractEventsOperation', () => {
expect(deserializedRequest.toBlock).toBe(request.toBlock);
expect((deserializedRequest.fromDate as Date | undefined)?.toISOString()).toBe(fromDate);
expect((deserializedRequest.toDate as Date | undefined)?.toISOString()).toBe(toDate);
expect(deserializedRequest.providerUrl).toBe(request.providerUrl);
expect(deserializedRequest.subdomain).toBe(request.subdomain);
expect(deserializedRequest.limit).toBe(request.limit);
expect(deserializedRequest.offset).toBe(request.offset);
expect(deserializedRequest.topic).toBe(request.topic);
Expand Down
Loading