Skip to content

Commit

Permalink
Merge pull request #850 from MoralisWeb3/chore/regularise-package-names
Browse files Browse the repository at this point in the history
refactor: refactor
  • Loading branch information
sogunshola authored Nov 28, 2022
2 parents c076f6c + c6f49e9 commit 5fe8033
Show file tree
Hide file tree
Showing 86 changed files with 127 additions and 41 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
'^@moralisweb3/api-utils': path.join(__dirname, 'packages/apiUtils/src'),
'^@moralisweb3/test-utils': path.join(__dirname, 'packages/testUtils/src'),
'^@moralisweb3/common-streams-utils': path.join(__dirname, 'packages/common/streamsUtils/src'),
'^@moralisweb3/common-auth-utils': path.join(__dirname, 'packages/common/authUtils/src'),
'^@moralisweb3/common-core': path.join(__dirname, 'packages/common/core/src'),
'^@moralisweb3/(.*)$': path.join(__dirname, 'packages/$1/src'),
},
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"test:watch": "yarn run test --watch",
"lint": "eslint . --ext .js,.ts,.tsx,jsx",
"clean": "rm -rf lib && rm -rf tsconfig.tsbuildinfo && rm -rf tsconfig.build.tsbuildinfo && rm -rf ./node_modules/.cache/nx",
"gen:api-types": "openapi-typescript https://authapi.moralis.io/api-docs-json --output src/generated/types.ts",
"build": "tsc -p tsconfig.build.json",
"dev": "tsc --watch"
},
Expand All @@ -31,6 +30,7 @@
"@moralisweb3/api-utils": "^2.7.4",
"@moralisweb3/common-core": "^2.7.4",
"@moralisweb3/common-evm-utils": "^2.7.4",
"@moralisweb3/common-auth-utils": "^2.7.4",
"@moralisweb3/common-sol-utils": "^2.7.4"
}
}
6 changes: 4 additions & 2 deletions packages/auth/src/Auth.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { ApiModule, Core, CoreProvider } from '@moralisweb3/common-core';
import { makeRequestMessage, RequestMessageOptions } from './methods/requestMessage';
import { makeVerify, VerifyEvmOptions, VerifyOptions, VerifySolOptions } from './methods/verify';
import { VerifyChallengeEvmResponseAdapter } from './operations/evm';
import { VerifyChallengeSolanaResponseAdapter } from './operations/solana';
import {
VerifyChallengeSolanaResponseAdapter,
VerifyChallengeEvmResponseAdapter,
} from '@moralisweb3/common-auth-utils';

export const BASE_URL = 'https://authapi.moralis.io';

Expand Down
2 changes: 0 additions & 2 deletions packages/auth/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Auth } from './Auth';

export * from './Auth';
export * from './operations';

// Export SDK types
export * from './methods/types';
export * from './operations';

export default Auth;
2 changes: 1 addition & 1 deletion packages/auth/src/methods/requestMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Core, { AuthErrorCode, MoralisAuthError } from '@moralisweb3/common-core'
import { EvmAddress, EvmAddressish, EvmChain, EvmChainish } from '@moralisweb3/common-evm-utils';
import { BASE_URL } from '../Auth';
import { AuthNetworkType } from '../utils/AuthNetworkType';
import { requestChallengeSolanaOperation, requestChallengeEvmOperation } from '../operations';
import { requestChallengeSolanaOperation, requestChallengeEvmOperation } from '@moralisweb3/common-auth-utils';

// Imported from Swagger and adjusted for better types for Evm
// TODO: generalize and extend generated types
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/methods/verify.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OperationResolver } from '@moralisweb3/api-utils';
import Core, { AuthErrorCode, MoralisAuthError } from '@moralisweb3/common-core';
import { BASE_URL } from '../Auth';
import { verifyChallengeSolanaOperation, verifyChallengeEvmOperation } from '../operations';
import { verifyChallengeSolanaOperation, verifyChallengeEvmOperation } from '@moralisweb3/common-auth-utils';
import { AuthNetworkType } from '../utils/AuthNetworkType';

export interface VerifyEvmOptions {
Expand Down
5 changes: 5 additions & 0 deletions packages/common/authUtils/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
extends: ['@moralisweb3'],
plugins: ['jest'],
ignorePatterns: ['**/lib/**/*', '**/*.test.ts', '**/dist/**/*', '**/build/**/*', '**/generated/**/*'],
};
1 change: 1 addition & 0 deletions packages/common/authUtils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @moralisweb3/common-auth-utils
4 changes: 4 additions & 0 deletions packages/common/authUtils/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable global-require */
module.exports = {
...require('../../../jest.config'),
};
36 changes: 36 additions & 0 deletions packages/common/authUtils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@moralisweb3/common-auth-utils",
"author": "Moralis",
"version": "2.7.4",
"license": "MIT",
"private": false,
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"sideEffects": false,
"files": [
"lib/*"
],
"scripts": {
"test": "yarn jest --runInBand --detectOpenHandles --forceExit --ci",
"test:coverage": "yarn run test --coverage",
"test:watch": "yarn run test --watch",
"gen:api-types": "openapi-typescript https://authapi.moralis.io/api-docs-json --output src/operations/openapi.ts",
"lint": "eslint . --ext .js,.ts,.tsx,jsx",
"clean": "rm -rf lib && rm -rf tsconfig.tsbuildinfo && rm -rf tsconfig.build.tsbuildinfo && rm -rf ./node_modules/.cache/nx",
"build": "tsc -p tsconfig.build.json",
"dev": "tsc --watch"
},
"devDependencies": {
"eslint-plugin-jest": "^26.8.3",
"jest": "^28.0.3",
"prettier": "^2.5.1",
"typescript": "^4.5.5"
},
"dependencies": {
"@ethersproject/abi": "^5.7.0",
"@moralisweb3/common-core": "^2.7.4",
"@moralisweb3/common-evm-utils": "^2.7.4",
"@moralisweb3/common-sol-utils": "^2.7.4",
"@moralisweb3/streams-typings": "^1.0.5"
}
}
1 change: 1 addition & 0 deletions packages/common/authUtils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './operations';
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Core, Camelize, Operation, DateInput, ResponseAdapter } from '@moralisweb3/common-core';
import { EvmAddress, EvmAddressish, EvmChainish, EvmChainResolver } from '@moralisweb3/common-evm-utils';
import { operations } from '../../generated/types';
import { operations } from '../openapi';

type OperationId = 'requestChallengeEvm';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Camelize, maybe, Operation, ResponseAdapter } from '@moralisweb3/common-core';
import { EvmAddress, EvmChain } from '@moralisweb3/common-evm-utils';
import { operations } from '../../generated/types';
import { operations } from '../openapi';

type OperationId = 'verifyChallengeEvm';

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('operations', () => {
let reader: OpenApiInterfaceReader;

beforeAll(() => {
reader = new OpenApiInterfaceReader('src/generated/types.ts')!;
reader = new OpenApiInterfaceReader('src/operations/openapi.ts')!;
});

for (const operation of operations) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Camelize, Operation, DateInput, ResponseAdapter } from '@moralisweb3/common-core';
import { SolAddress, SolAddressish, SolNetwork, SolNetworkish } from '@moralisweb3/common-sol-utils';
import { operations } from '../../generated/types';
import { operations } from '../openapi';

type OperationId = 'requestChallengeSolana';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Camelize, maybe, Operation, ResponseAdapter } from '@moralisweb3/common-core';
import { SolAddress, SolNetwork } from '@moralisweb3/common-sol-utils';
import { operations } from '../../generated/types';
import { operations } from '../openapi';

type OperationId = 'verifyChallengeSolana';

Expand Down
9 changes: 9 additions & 0 deletions packages/common/authUtils/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./lib/",
"declarationDir": "./lib/",
"rootDir": "./src"
},
"exclude": ["test/**/*", "**/__mocks__/*", "**/test/*", "**/*.test.ts", "integration/**/*"]
}
5 changes: 5 additions & 0 deletions packages/common/authUtils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../../tsconfig.package.json",
"compilerOptions": {},
"include": ["src/**/*", "types/**/*", "integration/**/*"]
}
2 changes: 2 additions & 0 deletions packages/common/streamsUtils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"test": "yarn jest --runInBand --detectOpenHandles --forceExit --ci",
"test:coverage": "yarn run test --coverage",
"test:watch": "yarn run test --watch",
"gen:api-types": "openapi-typescript https://api.moralis-streams.com/api-docs/swagger.json --output src/operations/openapi.ts",
"gen:api-types-beta": "openapi-typescript https://streams-api-stage.aws-prod-streams-master-1.moralis.io/api-docs/swagger.json --output src/operations/openapi.ts",
"lint": "eslint . --ext .js,.ts,.tsx,jsx",
"clean": "rm -rf lib && rm -rf tsconfig.tsbuildinfo && rm -rf tsconfig.build.tsbuildinfo && rm -rf ./node_modules/.cache/nx",
"build": "tsc -p tsconfig.build.json",
Expand Down
1 change: 1 addition & 0 deletions packages/common/streamsUtils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// Export data types
export * from './dataTypes';
export * from './operations';
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('createStreamEvmOperation', () => {
chains: ['0x1'],
abi: null,
advancedOptions: null,
demo: true,
};

const serializedRequest = createStreamEvmOperation.serializeRequest(request, core);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Camelize, Core, Operation } from '@moralisweb3/common-core';
import { EvmChain, EvmChainish } from '@moralisweb3/common-evm-utils';
import { EvmStream } from '@moralisweb3/common-streams-utils';
import { EvmStream } from '../../dataTypes';
import { operations } from '../openapi';

type OperationId = 'CreateStream';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Camelize, Core, Operation } from '@moralisweb3/common-core';
import { EvmStream } from '@moralisweb3/common-streams-utils';
import { EvmStream } from '../../dataTypes';
import { operations } from '../openapi';

type OperationId = 'DeleteStream';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Core, Camelize, Operation } from '@moralisweb3/common-core';
import { EvmStream } from '@moralisweb3/common-streams-utils';
import { EvmStream } from '../../dataTypes';
import { operations } from '../openapi';

type OperationId = 'GetStream';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Core, Camelize, maybe, PaginatedOperation } from '@moralisweb3/common-core';
import { EvmStream } from '@moralisweb3/common-streams-utils';
import { EvmStream } from '../../dataTypes';
import { operations } from '../openapi';

type OperationId = 'GetStreams';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('createStreamEvmOperation', () => {
chains: ['0x1'],
abi: null,
advancedOptions: null,
demo: true,
};

const serializedRequest = updateStreamEvmOperation.serializeRequest(request, core);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Camelize, Core, Operation } from '@moralisweb3/common-core';
import { EvmChain, EvmChainish } from '@moralisweb3/common-evm-utils';
import { EvmStream } from '@moralisweb3/common-streams-utils';
import { EvmStream } from '../../dataTypes';
import { operations } from '../openapi';

type OperationId = 'UpdateStream';
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ export interface components {
*/
StreamsStatus: "active" | "paused" | "error" | "terminated";
/**
* @description The filter object, optional and only used if the type : log
* https://v1docs.moralis.io/moralis-dapp/automatic-transaction-sync/smart-contract-events#event-filters
* @description The filter object for the topic0
* https://docs.moralis.io/docs/filter-streams
* @example {}
*/
StreamsFilter: { [key: string]: unknown };
Expand All @@ -306,7 +306,7 @@ export interface components {
description: string;
/** @description A user-provided tag that will be send along the webhook, the user can use this tag to identify the specific stream if multiple streams are present */
tag: string;
/** @description An Array of topic0's in hex, required if the type : log */
/** @description An Array of topic0's in string-signature format ex: ['FunctionName(address,uint256)'] */
topic0?: string[] | null;
/** @description Include events for all addresses (only applied when abi and topic0 is provided) */
allAddresses?: boolean;
Expand All @@ -320,6 +320,8 @@ export interface components {
advancedOptions?: components["schemas"]["advancedOptions"][] | null;
/** @description The ids of the chains for this stream in hex Ex: ["0x1","0x38"] */
chainIds: string[];
/** @description Indicator if it is a demo stream */
demo?: boolean;
/** @description The unique uuid of the stream */
id: components["schemas"]["UUID"];
/** @description The status of the stream. */
Expand All @@ -345,7 +347,7 @@ export interface components {
description: string;
/** @description A user-provided tag that will be send along the webhook, the user can use this tag to identify the specific stream if multiple streams are present */
tag: string;
/** @description An Array of topic0's in hex, required if the type : log */
/** @description An Array of topic0's in string-signature format ex: ['FunctionName(address,uint256)'] */
topic0?: string[] | null;
/** @description Include events for all addresses (only applied when abi and topic0 is provided) */
allAddresses?: boolean;
Expand All @@ -359,6 +361,8 @@ export interface components {
advancedOptions?: components["schemas"]["advancedOptions"][] | null;
/** @description The ids of the chains for this stream in hex Ex: ["0x1","0x38"] */
chainIds: string[];
/** @description Indicator if it is a demo stream */
demo?: boolean;
/** @description The unique uuid of the stream */
id: components["schemas"]["UUID"];
/** @description The status of the stream. */
Expand All @@ -373,7 +377,7 @@ export interface components {
description: string;
/** @description A user-provided tag that will be send along the webhook, the user can use this tag to identify the specific stream if multiple streams are present */
tag: string;
/** @description An Array of topic0's in hex, required if the type : log */
/** @description An Array of topic0's in string-signature format ex: ['FunctionName(address,uint256)'] */
topic0?: string[] | null;
/** @description Include events for all addresses (only applied when abi and topic0 is provided) */
allAddresses?: boolean;
Expand All @@ -387,6 +391,8 @@ export interface components {
advancedOptions?: components["schemas"]["advancedOptions"][] | null;
/** @description The ids of the chains for this stream in hex Ex: ["0x1","0x38"] */
chainIds: string[];
/** @description Indicator if it is a demo stream */
demo?: boolean;
};
/** @description Make all properties in T optional */
"Partial_streamsTypes.StreamsModelCreate_": {
Expand All @@ -396,7 +402,7 @@ export interface components {
description?: string;
/** @description A user-provided tag that will be send along the webhook, the user can use this tag to identify the specific stream if multiple streams are present */
tag?: string;
/** @description An Array of topic0's in hex, required if the type : log */
/** @description An Array of topic0's in string-signature format ex: ['FunctionName(address,uint256)'] */
topic0?: string[] | null;
/** @description Include events for all addresses (only applied when abi and topic0 is provided) */
allAddresses?: boolean;
Expand All @@ -410,6 +416,8 @@ export interface components {
advancedOptions?: components["schemas"]["advancedOptions"][] | null;
/** @description The ids of the chains for this stream in hex Ex: ["0x1","0x38"] */
chainIds?: string[];
/** @description Indicator if it is a demo stream */
demo?: boolean;
};
"streamsTypes.StreamsStatusUpdate": {
/** @description The status of the stream. */
Expand Down
10 changes: 10 additions & 0 deletions packages/moralis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"./streams-typings": "./lib/streamsTypings/index.js",
"./common-evm-utils": "./lib/commonEvmUtils/index.js",
"./common-sol-utils": "./lib/commonSolUtils/index.js",
"./common-auth-utils": "./lib/commonAuthUtils/index.js",
"./common-streams-utils": "./lib/commonStreamsUtils/index.js",
"./auth": "./lib/auth/index.js",
"./streams": "./lib/streams/index.js"
},
Expand All @@ -57,6 +59,12 @@
"common-sol-utils": [
"lib/commonSolUtils/index.d.ts"
],
"common-auth-utils": [
"lib/commonAuthUtils/index.d.ts"
],
"common-streams-utils": [
"lib/commonStreamsUtils/index.d.ts"
],
"streams": [
"lib/streams/index.d.ts"
],
Expand All @@ -67,6 +75,8 @@
},
"dependencies": {
"@moralisweb3/auth": "^2.7.4",
"@moralisweb3/common-auth-utils": "^2.7.4",
"@moralisweb3/common-streams-utils": "^2.7.4",
"@moralisweb3/common-core": "^2.7.4",
"@moralisweb3/streams": "^2.7.4",
"@moralisweb3/api-utils": "^2.7.4",
Expand Down
1 change: 1 addition & 0 deletions packages/moralis/src/commonAuthUtils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@moralisweb3/common-auth-utils';
1 change: 1 addition & 0 deletions packages/moralis/src/commonStreamsUtils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@moralisweb3/common-streams-utils';
1 change: 1 addition & 0 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"dependencies": {
"@moralisweb3/api-utils": "^2.7.4",
"@moralisweb3/evm-api": "^2.7.4",
"@moralisweb3/common-auth-utils": "^2.7.4",
"@moralisweb3/auth": "^2.7.4",
"@moralisweb3/sol-api": "^2.7.4",
"axios": "^0.27.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/MoralisNextApi/RequestHandlerResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { operations as evmOperations } from 'moralis/common-evm-utils';
import { operations as solOperations } from 'moralis/common-sol-utils';
import { Operation } from 'moralis/common-core';
import { OperationResolver } from '@moralisweb3/api-utils';
import { operations as authOperations, Auth } from '@moralisweb3/auth';
import { operations as authOperations } from '@moralisweb3/common-auth-utils';
import { Auth } from '@moralisweb3/auth';
import { SolApi } from '@moralisweb3/sol-api';
import Moralis from 'moralis';

Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/MoralisNextApi/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiUtilsConfigValues } from '@moralisweb3/api-utils';
import { RequestChallengeEvmRequest, RequestChallengeSolanaRequest } from '@moralisweb3/auth';
import { RequestChallengeEvmRequest, RequestChallengeSolanaRequest } from '@moralisweb3/common-auth-utils';
import { MoralisCoreConfigValues } from 'moralis/common-core';
import type { NextApiRequest, NextApiResponse } from 'next';

Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/auth/MoralisNextAuthProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VerifyChallengeSolanaJSONResponse, VerifyChallengeEvmJSONResponse } from '@moralisweb3/auth';
import { VerifyChallengeSolanaJSONResponse, VerifyChallengeEvmJSONResponse } from '@moralisweb3/common-auth-utils';
import axios from 'axios';
import CredentialsProvider from 'next-auth/providers/credentials';
import { Network } from 'moralis/common-core';
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/hooks/auth/useAuthRequestChallengeEvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
requestChallengeEvmOperation as operation,
RequestChallengeEvmRequest,
RequestChallengeEvmResponse,
} from '@moralisweb3/auth';
} from '@moralisweb3/common-auth-utils';
import { fetcher } from '../../utils/fetcher';
import { FetchParams } from '../types';
import { useCallback } from 'react';
Expand Down
Loading

1 comment on commit 5fe8033

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage

Title Lines Statements Branches Functions
api-utils Coverage: 25%
26.34% (49/186) 19.14% (9/47) 22.85% (8/35)
auth Coverage: 90%
92.77% (77/83) 81.81% (18/22) 90% (18/20)
evm-api Coverage: 100%
100% (79/79) 66.66% (6/9) 100% (47/47)
common-evm-utils Coverage: 64%
65% (938/1443) 19.93% (123/617) 35.89% (201/560)
sol-api Coverage: 96%
96.66% (29/30) 66.66% (6/9) 91.66% (11/12)
common-sol-utils Coverage: 74%
73.77% (135/183) 60% (12/20) 65.67% (44/67)
common-streams-utils Coverage: 93%
93.13% (787/845) 85.96% (196/228) 84.14% (276/328)
streams Coverage: 87%
86.71% (398/459) 67.14% (47/70) 84.52% (71/84)

Please sign in to comment.