Skip to content

Commit

Permalink
Create ssx-core and improve code quality (#26)
Browse files Browse the repository at this point in the history
* Create ssx-core package, populate and update other packages

* Create a main  file to be extended by packages

* Optimize use of try/catch

* Update serverless example login return and make ssx-test-dapp compatible

* Add backwards types compatibility

* Add changelogs

* Add deprecation tags

* Update changelog

* Improve ssx-core docs

* Improve ssx-gnosis-extension's docs

* Improve ssx-react's docs

* Improve ssx-sdk's docs

* Improve ssx-server's docs

* Improve ssx-serverless's docs

* General docs updates

* added support for documentation generation to ssx-core + supporting script

* connect types from ssx-core to relying packages in documentation

* moved eslint config to monorepo

* airbnb-base rules update

* update lint dependencies

* moved .prettierrc to monorepo

* use monorepo eslint

* specify exported files

* Return after middleware response

Co-authored-by: Gregório Granado Magalhães <[email protected]>

* Return response from middleware

Co-authored-by: Sam Gbafa <[email protected]>

* Remove console.error

Co-authored-by: Sam Gbafa <[email protected]>

* Remove console.error

Co-authored-by: Sam Gbafa <[email protected]>

* Remove redundant files

* Remove .npmignore

Co-authored-by: Samuel Gbafa <[email protected]>
Co-authored-by: Gregório Granado Magalhães <[email protected]>
  • Loading branch information
3 people authored Nov 30, 2022
1 parent ffa2132 commit c989838
Show file tree
Hide file tree
Showing 57 changed files with 2,072 additions and 1,698 deletions.
60 changes: 60 additions & 0 deletions .changeset/early-wolves-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
"@spruceid/ssx-core": major
"@spruceid/ssx-gnosis-extension": patch
"@spruceid/ssx-react": patch
"@spruceid/ssx": patch
"@spruceid/ssx-server": patch
"@spruceid/ssx-serverless": patch
---

Refactor code to avoid duplication and improve performance.

## General changes:
- Creates a main `tsconfig` file to be extended by packages;
- Configures `ssx-core`as a new package on the monorepo;
- Removes duplicate `@changesets/cli` dependency.

## @spruceid/ssx-core creation:
- This package was created to held the types definitions and utils functions to all packages. This reduces the amount of duplicated code, prevent circular dependencies, reduces package sizes (tree-shaking during transpilation), and ensures that changes to the API will need a bump to this new package.
- To unify the packages some interfaces/types names were updated:
- `@spruceid/ssx-sdk`: `SSXConfig` -> `SSXClientConfig`;
- `@spruceid/ssx-sdk`: `SSXProviders` -> `SSXClientProviders`;
- `@spruceid/ssx-sdk`: `SSXSession` -> `SSXClientSession`;
- `@spruceid/ssx-server`: `SSXConfig` -> `SSXServerConfig`;
- `@spruceid/ssx-server`: `SSXProviders` -> `SSXServerProviders`;

## @spruceid/ssx changes:
- Adds `@spruceid/ssx-core` as a dependency;
- Removes all types and interfaces declarations. They were moved to `ssx-core`;
- Exports `SSXConfig` (deprecated) and `SSXClientConfig`;
- Exports `SSXProviders` (deprecated) and `SSXClientProviders`;
- Exports `SSXSession` (deprecated) and `SSXClientSession`;
- Removes all utils functions. They were moved to `ssx-core`;
- Optimizes `try/catch` blocks;
- Updates `examples/ssx-test-dapp` to support ENS resolution from `examples/ssx-test-serverless-dynamodb-api`.

## @spruceid/ssx-react changes:
- Updates `ssxConfig?: SSXConfig;` on `SSXProviderProps` to `ssxConfig?: SSXClientConfig;` (non breaking change).

## @spruceid/ssx-gnosis-extension changes:
- Adds `@spruceid/ssx-core` as a dependency;
- Adds types from `ssx-core` to all SSX related variables;
- Optimizes `try/catch` blocks.

## @spruceid/ssx-server changes:
- Adds `@spruceid/ssx-core` as a dependency;
- Removes all types and interfaces declarations. They were moved to `ssx-core`;
- Exports `SSXConfig` (deprecated) and `SSXServerConfig`;
- Exports `SSXProviders` (deprecated) and `SSXServerProviders`;
- Removes all utils functions. They were moved to `ssx-core`;
- Optimizes `try/catch` blocks.

## @spruceid/ssx-serverless changes:
- Adds `@spruceid/ssx-core` as a dependency;
- Removes some types and interfaces declarations. They were moved to `ssx-core`;
- Removes all utils functions. They were moved to `ssx-core`;
- Optimizes `try/catch` blocks;
- Changes axios version to `"^0.27.2"`;
- Updates `examples/ssx-test-serverless-dynamodb-api` to resolve ENS accorddly with the request params and fixes the `/ssx-login` JSON response.


39 changes: 39 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"env": {
"browser": true,
"es2021": true,
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
],
"ignorePatterns": [
"examples/",
"packages/create-ssx-dapp/",
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"project": ["./tsconfig.json", "./packages/*/tsconfig.json"],
},
"plugins": [
"@typescript-eslint",
],
"root": true,
"rules": {
"object-property-newline": "error",
"import/prefer-default-export": "off",
"no-promise-executor-return": "warn",
"no-unused-vars": ["warn", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }],
"no-use-before-define": "warn",
"import/extensions": "off",
"import/no-unresolved": "off",
"max-len": "warn",
"max-classes-per-file": "off",
"no-plusplus": "off",
"no-await-in-loop": "off",
"@typescript-eslint/no-empty-interface": "off",
},
}
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"semi": true,
"singleQuote": true,
"arrowParens": "avoid",
"bracketSameLine": true,
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"endOfLine": "lf"
}
13 changes: 8 additions & 5 deletions examples/ssx-test-dapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,29 @@ function AccountInfo({ address, session }) {
</h2>
{
session?.ens &&
(session?.ens.domain || session?.ens.avatarUrl) ?
(
session?.ens.domain || session?.ens.avatarUrl ||
session?.ens.ensName || session?.ens.ensAvatarUrl
) ?
<div>
<b className='AccountInfo-label'>
ENS
</b>
<br />
<div className='AccountInfo-container'>
{
session.ens.avatarUrl ?
session.ens.avatarUrl || session.ens.ensAvatarUrl ?
<img
className='AccountInfo-avatar'
src={session.ens.avatarUrl}
src={session.ens.avatarUrl ?? session.ens.ensAvatarUrl}
alt='ENS avatar'
/> :
null
}
{
session.ens.domain ?
session.ens.domain || session.ens.ensName ?
<code className='AccountInfo-value'>
{session.ens.domain}
{session.ens.domain || session.ens.ensName}
</code> :
null
}
Expand Down
5 changes: 3 additions & 2 deletions examples/ssx-test-serverless-dynamodb-api/src/libs/siwe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ const signIn: ValidatedEventAPIGatewayProxyEvent<typeof signInSchema> = async (e
event.body.walletAddress,
{
daoLogin: true,
resolveEnsDomain: true,
resolveEnsAvatar: true,
resolveEnsDomain: (event.body.resolveEns as any).domain ?? false,
resolveEnsAvatar: (event.body.resolveEns as any).avatar ?? false,
}
)
.then((response) => formatJSONResponse(200, { ...response }))
.catch(error => formatJSONResponse(500, { error }));
};

Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"clean": "lerna run clean",
"ci": "npm install && npm test",
"test": "lerna run test",
"lint": "eslint . --ignore-path .gitignore --ext .ts,.tsx,.js",
"lint:fix": "yarn lint --fix",
"documentation": "lerna run doc && yarn documentation:reference",
"documentation:reference": "node scripts/build-docs.js",
"bootstrap": "lerna bootstrap",
Expand All @@ -27,6 +29,7 @@
"gnosis": "yarn workspace @spruceid/ssx-gnosis-extension",
"sdk": "yarn workspace @spruceid/ssx",
"react": "yarn workspace @spruceid/ssx-react",
"core": "yarn workspace @spruceid/ssx-core",
"server": "yarn workspace @spruceid/ssx-server",
"serverless": "yarn workspace @spruceid/ssx-serverless",
"test-dapp": "yarn workspace ssx-test-dapp",
Expand All @@ -38,11 +41,14 @@
"devDependencies": {
"@changesets/cli": "^2.25.0",
"concurrently": "^7.3.0",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
"lerna": "^5.1.2",
"nx": "^14.5.4",
"rimraf": "^3.0.2",
"yarn": "^1.22.19",
"typescript": "^4.8.4",
"@changesets/cli": "^2.25.0"
"yarn": "^1.22.19"
}
}
5 changes: 5 additions & 0 deletions packages/ssx-core/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"../../.eslintrc"
]
}
13 changes: 13 additions & 0 deletions packages/ssx-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SSX-Core

SSX-Core is a library made to aggregate types and utils to other SSX packages.

## Installation

You can add SSX-Core from yarn or npm:

```bash
npm install @spruceid/ssx-core
# or
yarn add @spruceid/ssx-core
```
10 changes: 10 additions & 0 deletions packages/ssx-core/api-documenter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-documenter.schema.json",
"outputTarget": "markdown",
"tableOfContents": {
"nonEmptyCategoryNodeNames": ["References", "Interface6"],
"catchAllCategory": "References",
"categorizeByName": true,
"categoryInlineTag": "docCategory"
}
}
Loading

0 comments on commit c989838

Please sign in to comment.