Skip to content

Commit d468a1b

Browse files
migrate to ecosystem wallets and pnpm (#127)
* integrate ecosystem wallets * streamline login functions; fix ecosystem env vars * add changeset * remove exports for in-app wallets * upgrade thirdweb sdk * upgrade thirdweb sdk * add changeset * remove duplicate changeset * fix email login * use ecosystem details on redirect auth * fix electron app social auth * fix comment * use ecosystem wallets for email upsert check * Migrate from npm to pnpm (#131) * Switch npm to pnpm * Update READMEs and dockerfile * Install pnpm in workflows * fix electron example * fix for typescript and vite * update root package.json to use workspace * move package dependencies to workspace * move more to catalog * fix react example * fix generate command * fix dev commands * add electron example deps to workspace * move api deps to workspace * fix * move magicswap example to workspace * fix local dependency linking * Fix for examples * re-add react optimize --------- Co-authored-by: Alec Ananian <[email protected]> --------- Co-authored-by: Wyatt Mufson <[email protected]>
1 parent 83ce381 commit d468a1b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+14840
-22106
lines changed

.changeset/rotten-garlics-provide.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@treasure-dev/tdk-react": major
3+
"@treasure-dev/tdk-core": major
4+
---
5+
6+
Migrated from in-app wallets to ecosystem wallets

.github/workflows/deploy-api.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,22 @@ jobs:
6565
uses: actions/checkout@v4
6666
with:
6767
fetch-depth: 0
68+
- name: Install pnpm
69+
uses: pnpm/action-setup@v4
70+
with:
71+
version: 9
6872
- name: Set up Node.js
6973
uses: actions/setup-node@v4
7074
with:
7175
node-version: 20
7276
- name: Install dependencies
73-
run: npm ci
77+
run: pnpm install --frozen-lockfile
7478
- name: Build packages
7579
run: |
76-
npm run build:auth
77-
npm run build:core
80+
pnpm build:auth
81+
pnpm build:core
7882
- name: Build code
79-
run: npm run build:api
83+
run: pnpm build:api
8084
- name: Create Sentry release
8185
uses: getsentry/action-release@v1
8286
env:

.github/workflows/pr.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@ jobs:
66
steps:
77
- name: Check out repo
88
uses: actions/checkout@v4
9+
- name: Install pnpm
10+
uses: pnpm/action-setup@v4
11+
with:
12+
version: 9
913
- name: Set up Node.js
1014
uses: actions/setup-node@v4
1115
with:
1216
node-version: 20
1317
- name: Install dependencies
14-
run: npm ci
18+
run: pnpm install --frozen-lockfile
1519
- name: Generate code
16-
run: npm run generate
20+
run: pnpm generate
1721
- name: Lint code
18-
run: npm run lint
22+
run: pnpm lint
1923
- name: Analyze code
20-
run: npm run knip
24+
run: pnpm knip
2125
- name: Test code
22-
run: npm test
26+
run: pnpm test
2327
- name: Build code
24-
run: npm run build
28+
run: pnpm build

.github/workflows/release.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,21 @@ jobs:
1111
steps:
1212
- name: Check out repo
1313
uses: actions/checkout@v4
14+
- name: Install pnpm
15+
uses: pnpm/action-setup@v4
16+
with:
17+
version: 9
1418
- name: Set up Node.js
1519
uses: actions/setup-node@v4
1620
with:
1721
node-version: 20
1822
- name: Install dependencies
19-
run: npm ci
23+
run: pnpm install --frozen-lockfile
2024
- name: Create release PR or publish to npm
2125
uses: changesets/action@v1
2226
with:
23-
version: npm run package:version
24-
publish: npm run package:publish
27+
version: pnpm package:version
28+
publish: pnpm package:publish
2529
env:
2630
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2731
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
npx lint-staged && npm run knip
1+
npx lint-staged && pnpm knip

.lintstagedrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"*": "npm run fix"
2+
"*": "pnpm fix"
33
}

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,28 @@ SDK for the Treasure ecosystem
2727
Install dependencies:
2828

2929
```bash
30-
npm install
30+
pnpm install
3131
```
3232

3333
Open the `README.md` files for the apps and examples you are contributing to and follow the instructions to finish configuring the packages.
3434

3535
Start watch mode for base workspaces:
3636

3737
```bash
38-
npm run dev
38+
pnpm dev
3939
```
4040

4141
Start any example apps:
4242

4343
```bash
4444
$ cd examples/connect-react
45-
$ npm run dev
45+
$ pnpm dev
4646
```
4747

4848
### Contributing
4949

5050
Before creating a PR, add a [changeset](https://github.com/changesets/changesets/blob/main/docs/intro-to-using-changesets.md) to your commit:
5151

5252
```bash
53-
npm run package:changeset
53+
pnpm package:changeset
5454
```

apps/api/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ THIRDWEB_CLIENT_ID=
1010
THIRDWEB_ENGINE_URL=
1111
THIRDWEB_ENGINE_ACCESS_TOKEN=
1212
THIRDWEB_SECRET_KEY=
13+
THIRDWEB_ECOSYSTEM_ID=ecosystem.treasure
14+
THIRDWEB_ECOSYSTEM_PARTNER_ID=
15+
TREASURE_AUTH_KMS_KEY=
1316
TROVE_API_URL=https://trove-api-dev.treasure.lol
1417
TROVE_API_KEY=
1518
ENGINE_MAINTENANCE_MODE_ENABLED=false

apps/api/Dockerfile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,22 @@ RUN apk update && \
1212
# Copy application code
1313
COPY . .
1414

15-
# Install dependencies
16-
RUN npm install --include=dev
15+
# Install pnpm
16+
RUN npm install -g pnpm
17+
18+
# Install dependencies including dev dependencies
19+
RUN pnpm install --prod=false
1720

1821
# Build packages
19-
RUN npm run build:auth
20-
RUN npm run build:core
22+
RUN pnpm build:auth
23+
RUN pnpm build:core
2124

2225
# Build application
23-
RUN npm run build:api
26+
RUN pnpm build:api
2427

2528
# Remove development dependencies
26-
RUN npm prune --omit=dev
29+
RUN pnpm prune --prod
2730

2831
# Start the server
2932
EXPOSE 8080
30-
CMD [ "npm", "run", "start:api" ]
33+
CMD [ "pnpm", "start:api" ]

apps/api/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Backend server powering the Treasure Development Kit
1313
Install dependencies:
1414

1515
```bash
16-
npm install
16+
pnpm install
1717
```
1818

1919
Create `.env` file based on example and fill in with relevant environment variables:
@@ -25,25 +25,25 @@ cp .env.example .env
2525
Generate database client:
2626

2727
```bash
28-
npm run generate
28+
pnpm generate
2929
```
3030

3131
Create initial tables in database:
3232

3333
```bash
34-
npm run db:migrate
34+
pnpm db:migrate
3535
```
3636

3737
Seed database with development values:
3838

3939
```bash
40-
npm run db:seed
40+
pnpm db:seed
4141
```
4242

4343
Start server:
4444

4545
```bash
46-
npm run dev
46+
pnpm dev
4747
```
4848

4949
## Deployment

apps/api/package.json

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,38 @@
44
"type": "module",
55
"scripts": {
66
"typecheck": "tsc --noEmit",
7-
"build": "npm run generate && npm run typecheck && tsup",
7+
"build": "pnpm generate && pnpm typecheck && tsup",
88
"generate": "prisma generate",
9-
"dev": "npm run generate && tsup --watch --onSuccess 'npm run start'",
9+
"dev": "pnpm generate && tsup --watch --onSuccess 'pnpm start'",
1010
"start": "node ./dist/index.js",
1111
"db:seed": "tsx ./prisma/seed.ts",
12-
"db:seed:dev": "npm run db:seed dev",
13-
"db:seed:prod": "npm run db:seed prod",
12+
"db:seed:dev": "pnpm db:seed dev",
13+
"db:seed:prod": "pnpm db:seed prod",
1414
"db:migrate": "prisma migrate dev"
1515
},
1616
"dependencies": {
17-
"@aws-sdk/client-secrets-manager": "^3.507.0",
18-
"@fastify/cors": "^10.0.0",
19-
"@fastify/swagger": "^9.0.0",
20-
"@fastify/swagger-ui": "^5.0.1",
21-
"@fastify/type-provider-typebox": "^5.0.0",
22-
"@prisma/client": "^5.3.0",
23-
"@sentry/node": "^8.7.0",
24-
"@sinclair/typebox": "^0.33.7",
25-
"@thirdweb-dev/engine": "^0.0.15",
26-
"@treasure-dev/auth": "*",
27-
"@treasure-dev/tdk-core": "*",
28-
"@wagmi/core": "^2.9.1",
29-
"abitype": "^1.0.5",
30-
"dotenv": "^16.3.1",
31-
"fastify": "^5.0.0",
32-
"pino": "^9.4.0",
33-
"pino-pretty": "^11.2.2",
34-
"thirdweb": "^5.48.1",
35-
"viem": "^2.5.0"
17+
"@aws-sdk/client-secrets-manager": "catalog:",
18+
"@fastify/cors": "catalog:",
19+
"@fastify/swagger": "catalog:",
20+
"@fastify/swagger-ui": "catalog:",
21+
"@fastify/type-provider-typebox": "catalog:",
22+
"@prisma/client": "catalog:",
23+
"@sentry/node": "catalog:",
24+
"@sinclair/typebox": "catalog:",
25+
"@thirdweb-dev/engine": "catalog:",
26+
"@treasure-dev/auth": "workspace:*",
27+
"@treasure-dev/tdk-core": "workspace:*",
28+
"@wagmi/core": "catalog:",
29+
"abitype": "catalog:",
30+
"dotenv": "catalog:",
31+
"fastify": "catalog:",
32+
"pino": "catalog:",
33+
"pino-pretty": "catalog:",
34+
"thirdweb": "catalog:",
35+
"viem": "catalog:"
3636
},
3737
"devDependencies": {
38-
"prisma": "^5.3.0"
38+
"prisma": "catalog:"
3939
},
4040
"engines": {
4141
"node": ">=20"

apps/api/src/routes/auth.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ import {
2323
} from "../schema";
2424
import type { TdkApiContext } from "../types";
2525
import { USER_PROFILE_SELECT_FIELDS, USER_SELECT_FIELDS } from "../utils/db";
26-
import { transformUserProfileResponseFields } from "../utils/user";
26+
import {
27+
parseThirdwebUserEmail,
28+
transformUserProfileResponseFields,
29+
} from "../utils/user";
2730

2831
export const authRoutes =
2932
({
3033
auth,
3134
thirdwebAuth,
3235
db,
36+
env,
3337
client,
3438
engine,
3539
}: TdkApiContext): FastifyPluginAsync =>
@@ -117,18 +121,23 @@ export const authRoutes =
117121
// Look up any associated user details in the embedded wallet
118122
const thirdwebUser = await getUser({
119123
client,
124+
ecosystem: {
125+
id: env.THIRDWEB_ECOSYSTEM_ID,
126+
partnerId: env.THIRDWEB_ECOSYSTEM_PARTNER_ID,
127+
},
120128
walletAddress: adminAddress,
121129
});
122-
if (thirdwebUser?.email) {
123-
user = await db.user.update({
124-
where: {
125-
id: user.id,
126-
},
127-
data: {
128-
email: thirdwebUser.email,
129-
},
130-
select: USER_SELECT_FIELDS,
131-
});
130+
if (thirdwebUser) {
131+
const email = parseThirdwebUserEmail(thirdwebUser);
132+
if (email) {
133+
user = await db.user.update({
134+
where: {
135+
id: user.id,
136+
},
137+
data: { email },
138+
select: USER_SELECT_FIELDS,
139+
});
140+
}
132141
}
133142
}
134143
}

apps/api/src/utils/env.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { type Static, Type } from "@sinclair/typebox";
66
import { AssertError, Value } from "@sinclair/typebox/value";
77
import "dotenv/config";
88

9+
import { DEFAULT_TDK_ECOSYSTEM_ID } from "@treasure-dev/tdk-core";
910
import { log } from "./log";
1011

1112
// Parse local environment variables
@@ -31,6 +32,11 @@ const envSchema = Type.Object({
3132
THIRDWEB_ENGINE_URL: Type.String(),
3233
THIRDWEB_ENGINE_ACCESS_TOKEN: Type.String(),
3334
THIRDWEB_SECRET_KEY: Type.String(),
35+
THIRDWEB_ECOSYSTEM_ID: Type.TemplateLiteral(
36+
[Type.Literal("ecosystem."), Type.String()],
37+
{ default: DEFAULT_TDK_ECOSYSTEM_ID },
38+
),
39+
THIRDWEB_ECOSYSTEM_PARTNER_ID: Type.String(),
3440
TREASURE_AUTH_KMS_KEY: Type.String(),
3541
TROVE_API_URL: Type.String({ default: "https://trove-api.treasure.lol" }),
3642
TROVE_API_KEY: Type.String(),

apps/api/src/utils/user.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { UserProfile } from "@prisma/client";
2+
import type { GetUserResult } from "thirdweb";
23

34
export const transformUserProfileResponseFields = (
45
profile: Partial<UserProfile>,
@@ -10,3 +11,23 @@ export const transformUserProfileResponseFields = (
1011
testnetFaucetLastUsedAt:
1112
profile.testnetFaucetLastUsedAt?.toISOString() ?? null,
1213
});
14+
15+
export const parseThirdwebUserEmail = (user: GetUserResult) => {
16+
if (user.email) {
17+
return user.email;
18+
}
19+
20+
const profileEmail = user.profiles.find(({ type }) => type === "email")
21+
?.details.email;
22+
if (profileEmail) {
23+
return profileEmail;
24+
}
25+
26+
for (const profile of user.profiles) {
27+
if (profile.details.email) {
28+
return profile.details.email;
29+
}
30+
}
31+
32+
return undefined;
33+
};

examples/connect-core/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
VITE_TDK_API_URL=http://localhost:8080
22
VITE_TDK_CLIENT_ID=
3+
VITE_TDK_ECOSYSTEM_ID=ecosystem.treasure
4+
VITE_TDK_ECOSYSTEM_PARTNER_ID=
35
VITE_TDK_BACKEND_WALLET=

examples/connect-core/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Example showing how vanilla JS/TS front-ends can interact with the Treasure Deve
1212
Install dependencies:
1313

1414
```bash
15-
npm install
15+
pnpm install
1616
```
1717

1818
Create `.env` file based on example and fill in with relevant environment variables:
@@ -24,5 +24,5 @@ cp .env.example .env
2424
Start server:
2525

2626
```bash
27-
npm run dev
27+
pnpm dev
2828
```

0 commit comments

Comments
 (0)