-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: PRO-2395 sequelize integration to backend and property name upd…
…ates for APIKey entity references in backend and frontend components
- Loading branch information
1 parent
df5476a
commit ce1a9a2
Showing
14 changed files
with
339 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
|
||
# build | ||
/build/ | ||
|
||
# misc | ||
.DS_Store | ||
.env.production | ||
|
||
# debug | ||
npm-debug.log* | ||
|
||
.nyc_output | ||
coverage | ||
|
||
.env | ||
config.json | ||
database.sqlite | ||
|
||
package-lock.json | ||
pnpm-lock.yaml | ||
|
||
# Ponder | ||
/indexer/.ponder | ||
/indexer/generated | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ | |
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,6 @@ pnpm-lock.yaml | |
|
||
# Ponder | ||
/indexer/.ponder | ||
/indexer/generated | ||
/indexer/generated | ||
|
||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { Sequelize, DataTypes, Model } from 'sequelize'; | ||
|
||
export class APIKey extends Model { | ||
declare apiKey: string; | ||
declare walletAddress: string; | ||
declare privateKey: string; | ||
declare supportedNetworks: string | null; | ||
declare erc20Paymasters: string | null; | ||
declare multiTokenPaymasters: string | null; | ||
declare multiTokenOracles: string | null; | ||
declare sponsorName: string | null; | ||
declare logoUrl: string | null; | ||
declare transactionLimit: number; | ||
declare noOfTransactionsInAMonth: number | null; | ||
declare indexerEndpoint: string | null; | ||
} | ||
|
||
export function initializeAPIKeyModel(sequelize: Sequelize) { | ||
APIKey.init({ | ||
apiKey: { | ||
type: DataTypes.TEXT, | ||
allowNull: false, | ||
primaryKey: true, | ||
field: 'API_KEY' | ||
}, | ||
walletAddress: { | ||
type: DataTypes.TEXT, | ||
allowNull: false, | ||
field: 'WALLET_ADDRESS' | ||
}, | ||
privateKey: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
field: 'PRIVATE_KEY' | ||
}, | ||
supportedNetworks: { | ||
type: DataTypes.STRING, | ||
allowNull: true, | ||
field: 'SUPPORTED_NETWORKS' | ||
}, | ||
erc20Paymasters: { | ||
type: DataTypes.STRING, | ||
allowNull: true, | ||
field: 'ERC20_PAYMASTERS' | ||
}, | ||
multiTokenPaymasters: { | ||
type: DataTypes.STRING, | ||
allowNull: true, | ||
field: 'MULTI_TOKEN_PAYMASTERS' | ||
}, | ||
multiTokenOracles: { | ||
type: DataTypes.STRING, | ||
allowNull: true, | ||
field: 'MULTI_TOKEN_ORACLES' | ||
}, | ||
sponsorName: { | ||
type: DataTypes.STRING, | ||
allowNull: true, | ||
field: 'SPONSOR_NAME' | ||
}, | ||
logoUrl: { | ||
type: DataTypes.STRING, | ||
allowNull: true, | ||
field: 'LOGO_URL' | ||
}, | ||
transactionLimit: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
field: 'TRANSACTION_LIMIT' | ||
}, | ||
noOfTransactionsInAMonth: { | ||
type: DataTypes.INTEGER, | ||
allowNull: true, | ||
field: 'NO_OF_TRANSACTIONS_IN_A_MONTH' | ||
}, | ||
indexerEndpoint: { | ||
type: DataTypes.STRING, | ||
allowNull: true, | ||
field: 'INDEXER_ENDPOINT' | ||
}, | ||
}, { | ||
tableName: 'api_keys', | ||
sequelize, // passing the `sequelize` instance is required | ||
timestamps: false, // this will deactivate the `createdAt` and `updatedAt` columns | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import fp from "fastify-plugin"; | ||
import { FastifyPluginAsync } from "fastify"; | ||
import { Sequelize } from 'sequelize'; | ||
import sqlite3 from 'sqlite3'; | ||
|
||
const sequelizePlugin: FastifyPluginAsync = async (server) => { | ||
const sequelize = new Sequelize({ | ||
dialect: 'sqlite', | ||
storage: './database.sqlite', | ||
dialectModule: sqlite3 | ||
}); | ||
|
||
server.decorate('sequelize', sequelize); | ||
|
||
server.addHook('onClose', (instance, done) => { | ||
instance.sequelize.close().then(() => done(), done); | ||
}); | ||
}; | ||
|
||
declare module "fastify" { | ||
interface FastifyInstance { | ||
sequelize: Sequelize; | ||
} | ||
} | ||
|
||
export default fp(sequelizePlugin); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Sequelize } from 'sequelize'; | ||
import { APIKey } from '../models/APIKey'; | ||
|
||
export class APIKeyRepository { | ||
private sequelize: Sequelize; | ||
|
||
constructor(sequelize: Sequelize) { | ||
this.sequelize = sequelize; | ||
} | ||
|
||
async findAll(): Promise<APIKey[]> { | ||
const result = await this.sequelize.models.APIKey.findAll(); | ||
return result.map(apiKey => apiKey.get() as APIKey); | ||
} | ||
|
||
async findOneByApiKey(apiKey: string): Promise<APIKey | null> { | ||
const result = await this.sequelize.models.APIKey.findOne({ where: { apiKey: apiKey } }); | ||
return result ? result.get() as APIKey : null; | ||
} | ||
|
||
async findOneByWalletAddress(walletAddress: string): Promise<APIKey | null> { | ||
const result = await this.sequelize.models.APIKey.findOne({ where: { walletAddress: walletAddress } }); | ||
return result ? result.get() as APIKey : null; | ||
} | ||
} |
Oops, something went wrong.