Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into return-data
Browse files Browse the repository at this point in the history
  • Loading branch information
whilefoo committed Apr 15, 2024
1 parent de23301 commit d448698
Show file tree
Hide file tree
Showing 33 changed files with 1,956 additions and 346 deletions.
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"Libsodium",
"ciphertext",
"tweetnacl",
"typeguards"
"typeguards",
"Numberish"
]
}
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
X25519_PRIVATE_KEY=
NFT_MINTER_PRIVATE_KEY=
SUPABASE_URL=
SUPABASE_ANON_KEY=
SUPABASE_KEY=
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"plugins": ["@typescript-eslint", "sonarjs"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:sonarjs/recommended"],
"ignorePatterns": ["**/*.js"],
"ignorePatterns": ["**/*.js", "src/adapters/supabase/types/database.ts"],
"rules": {
"prefer-arrow-callback": ["warn", { "allowNamedFunctions": true }],
"func-style": ["warn", "declaration", { "allowArrowFunctions": false }],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/jest-testing.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Run Jest testing suite
on:
workflow_dispatch:
pull_request_target:
pull_request:
types: [opened, synchronize]

env:
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Publish Package

on:
workflow_dispatch:
push:
branches:
- main

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v4
with:
release-type: node
package-name: "@ubiquibot/permit-generation"
default-branch: main
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.10.0'
registry-url: https://registry.npmjs.org/
- run: |
yarn install --immutable --immutable-cache --check-cache
yarn pack
yarn publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ node_modules
.env
static/dist
/coverage
junit.xml
junit.xml
dist
3 changes: 2 additions & 1 deletion knip.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { KnipConfig } from "knip";

const config: KnipConfig = {
entry: ["build/index.ts"],
entry: ["src/main.ts"],
project: ["src/**/*.ts"],
ignore: [],
ignoreBinaries: ["publish"],
ignoreExportsUsedInFile: true,
ignoreDependencies: ["ts-node"],
jest: {
Expand Down
30 changes: 24 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "@ubiquibot/permit-generation",
"version": "1.0.0",
"description": "Template repository with TypeScript support.",
"main": "src/index.ts",
"version": "1.0.2",
"description": "ECR20 / ECR721 permit generation for automated payments.",
"author": "Ubiquity DAO",
"license": "MIT",
"engines": {
Expand All @@ -16,7 +15,8 @@
"knip": "knip",
"knip-ci": "knip --no-exit-code --reporter json",
"prepare": "husky install",
"test": "jest"
"test": "jest",
"build": "rollup -c"
},
"keywords": [
"typescript",
Expand All @@ -31,7 +31,7 @@
"@octokit/rest": "^20.0.2",
"@octokit/webhooks": "^13.1.0",
"@sinclair/typebox": "^0.32.5",
"@supabase/supabase-js": "^2.39.7",
"@supabase/supabase-js": "2.42.0",
"@uniswap/permit2-sdk": "^1.2.0",
"dotenv": "^16.4.4",
"ethers": "6.11.1",
Expand All @@ -43,6 +43,13 @@
"@cspell/dict-node": "^4.0.3",
"@cspell/dict-software-terms": "^3.3.18",
"@cspell/dict-typescript": "^3.1.2",
"@jest/globals": "29.7.0",
"@jest/types": "29.6.3",
"@rollup/plugin-commonjs": "25.0.7",
"@rollup/plugin-json": "6.1.0",
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-terser": "0.4.4",
"@rollup/plugin-yaml": "4.1.2",
"@types/libsodium-wrappers": "^0.7.8",
"@types/node": "^20.11.19",
"@typescript-eslint/eslint-plugin": "^7.0.1",
Expand All @@ -57,6 +64,9 @@
"lint-staged": "^15.2.2",
"npm-run-all": "^4.1.5",
"prettier": "^3.2.5",
"rollup": "4.14.0",
"rollup-plugin-dts-bundle-generator": "1.4.0",
"rollup-plugin-typescript2": "0.36.0",
"ts-jest": "29.1.2",
"ts-node": "10.9.2",
"tsx": "^4.7.1",
Expand All @@ -75,5 +85,13 @@
"extends": [
"@commitlint/config-conventional"
]
}
},
"files": [
"dist/*",
"README.md",
"package.json"
],
"module": "dist/index.esm.js",
"main": "dist/index.js",
"typings": "dist/index.d.ts"
}
16 changes: 16 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import typescript from "rollup-plugin-typescript2";
import yaml from "@rollup/plugin-yaml";
import { generateDtsBundle } from "rollup-plugin-dts-bundle-generator";
import nodeResolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import terser from "@rollup/plugin-terser";

export default {
input: "src/index.ts",
output: {
dir: "dist",
format: "cjs",
},
plugins: [nodeResolve(), commonjs(), typescript(), yaml(), json(), generateDtsBundle(), terser()],
};
27 changes: 8 additions & 19 deletions src/adapters/supabase/helpers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,30 @@ export class User extends Super {
super(supabase, context);
}

async getUsernameById(userId: number) {
const { data, error } = await this.supabase.from("users").select("username").eq("user_id", userId).single();
async getUserById(userId: number) {
const { data, error } = await this.supabase.from("users").select("*").eq("id", userId).single();
if (error) {
console.error(FAILED_TO_GET_USER, { userId, error });
throw error;
}

console.log(SUCCESSFULLY_FETCHED_USER, { userId, username: data?.username });
return data?.username;
}

async getUserIdByUsername(username: string) {
const { data, error } = await this.supabase.from("users").select("user_id").eq("username", username).single();
if (error) {
console.error(FAILED_TO_GET_USER, { username, error });
throw error;
}

console.log(SUCCESSFULLY_FETCHED_USER, { username, userId: data?.user_id });
return data?.user_id;
console.log(SUCCESSFULLY_FETCHED_USER, { userId, ...data });
return data;
}

async getUserIdByWallet(wallet: string) {
const { data, error } = await this.supabase.from("wallets").select("user_id").eq("address", wallet).single();
const { data, error } = await this.supabase.from("wallets").select("id").eq("address", wallet).single();
if (error) {
console.error(FAILED_TO_GET_USER, { wallet, error });
throw error;
}

console.log(SUCCESSFULLY_FETCHED_USER, { wallet, userId: data?.user_id });
return data?.user_id;
console.log(SUCCESSFULLY_FETCHED_USER, { wallet, userId: data?.id });
return data?.id.toString();
}

async upsertUser(userId: number, username: string) {
const { error } = await this.supabase.from("users").upsert({ user_id: userId, username }).select();
const { error } = await this.supabase.from("users").upsert({ id: userId, username }).select();
if (error) {
console.error("Failed to upsert user", { userId, username, error });
throw error;
Expand Down
40 changes: 11 additions & 29 deletions src/adapters/supabase/helpers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,31 @@ export class Wallet extends Super {
}

async getWalletByUserId(userId: number) {
const { data, error } = await this.supabase.from("wallets").select("address").eq("user_id", userId).single();
const { data, error } = await this.supabase.from("users").select("wallets(*)").eq("id", userId).single();
if (error) {
console.error("Failed to get wallet", { userId, error });
throw error;
}

console.info("Successfully fetched wallet", { userId, address: data.address });
return data.address;
console.info("Successfully fetched wallet", { userId, address: data.wallets?.address });
return data.wallets?.address;
}

async getWalletByUsername(username: string) {
const { data, error } = await this.supabase.from("users").select("id").eq("username", username).single();
if (error) {
console.error("Failed to get user", { username, error });
throw error;
}

const userId = data?.id;

if (!userId) {
console.error("Failed to get user", { username });
throw new Error("User not found");
}

const { data: walletData, error: walletError } = await this.supabase.from("wallets").select("address").eq("user_id", userId).single();
async upsertWallet(userId: number, address: string) {
const { error: walletError, data } = await this.supabase.from("wallets").upsert([{ address }]).select().single();

if (walletError) {
console.error("Failed to get wallet", { userId, error });
console.error("Failed to upsert wallet", { userId, address, walletError });
throw walletError;
}

console.info("Successfully fetched wallet", { userId, address: walletData?.address });

return walletData?.address as `0x${string}` | undefined;
}
const { error: userError } = await this.supabase.from("users").upsert([{ id: userId, wallet_id: data.id }]);

async upsertWallet(userId: number, address: string) {
const { error } = await this.supabase.from("wallets").upsert([{ user_id: userId.toString(), address }]);
if (error) {
console.error("Failed to upsert wallet", { userId, address, error });
throw error;
if (userError) {
console.error("Failed to upsert user with new wallet", { userId, address, userError });
throw userError;
}

console.info("Successfully upserted wallet", { userId, address });
console.info("Successfully upsert wallet", { userId, address });
}
}
Loading

0 comments on commit d448698

Please sign in to comment.