Skip to content

Commit

Permalink
fix(app): allow ceramicHost to be configured on instantiation of cera…
Browse files Browse the repository at this point in the history
…mic db

- add start:ceramic script to root-level start script
- add ceramicHost as a constructor parameter
for CeramicDatabase
- add Ceramic community node url in example env files
- add information on CERAMIC_CLIENT_URL to app and schemas READMEs
  • Loading branch information
shavinac committed May 9, 2022
1 parent c4a188f commit 3969ec5
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/.env-example.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# .env
NEXT_PUBLIC_DPOPP_GOOGLE_CLIENT_ID=MY-APP-ID.apps.googleusercontent.com
NEXT_PUBLIC_DPOPP_IAM_URL=http://example.com/api/
NEXT_PUBLIC_DPOPP_INFURA_KEY=YOUR_INFURA_KEY
NEXT_PUBLIC_DPOPP_INFURA_KEY=YOUR_INFURA_KEY
NEXT_PUBLIC_CERAMIC_CLIENT_URL=https://ceramic-clay.3boxlabs.com
2 changes: 2 additions & 0 deletions app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ This will be the web app allowing users to interact with their dpopp.
```bash
yarn start
```

Set the `NEXT_PUBLIC_CERAMIC_CLIENT_URL` environment variable to change the Ceramic node to run against - the Ceramic host defaults to `http://localhost:7007` if not provided.
7 changes: 5 additions & 2 deletions app/context/userContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ export const UserContextProvider = ({ children }: { children: any }) => {
break;
}
case "connected": {
const ceramicDatabaseInstance = new CeramicDatabase(viewerConnection.selfID.did);
const ceramicDatabaseInstance = new CeramicDatabase(
viewerConnection.selfID.did,
process.env.NEXT_PUBLIC_CERAMIC_CLIENT_URL
);
setCeramicDatabase(ceramicDatabaseInstance);
fetchPassport(ceramicDatabaseInstance);
break;
Expand Down Expand Up @@ -202,7 +205,7 @@ export const UserContextProvider = ({ children }: { children: any }) => {
}, [passport]);

const fetchPassport = (database: CeramicDatabase): void => {
console.log("attempting to fetch from ceramic...");
console.log("attempting to fetch from ceramic...", database.ceramicClient._apiUrl);
setIsLoadingPassport(true);
database
.getPassport()
Expand Down
4 changes: 2 additions & 2 deletions database-client/src/ceramicClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export class CeramicDatabase implements DataStorageBase {
model: DataModel<ModelTypes>;
store: DIDDataStore<ModelTypes>;

constructor(did?: CeramicDID) {
constructor(did?: CeramicDID, ceramicHost?: string) {
// Create the Ceramic instance and inject the DID
const ceramic = new CeramicClient(CERAMIC_CLIENT_URL);
const ceramic = new CeramicClient(ceramicHost ?? CERAMIC_CLIENT_URL);
ceramic.setDID(did);

// Create the loader, model and store
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
"build:identity": "yarn workspace @dpopp/identity build",
"build:iam": "yarn workspace @dpopp/iam build",
"build:app": "yarn workspace @dpopp/app build",
"start": "concurrently --kill-others \"yarn start:iam\" \"yarn start:app\"",
"start": "concurrently --kill-others \"yarn start:iam\" \"yarn start:app\" \"yarn start:ceramic\"",
"start:iam": "yarn workspace @dpopp/iam start",
"start:app": "yarn workspace @dpopp/app start",
"start:ceramic": "yarn ceramic daemon",
"prod:start:iam": "yarn workspace @dpopp/iam prod:start",
"app": "yarn workspace @dpopp/app",
"schemas": "yarn workspace @dpopp/schemas",
Expand Down
2 changes: 2 additions & 0 deletions schemas/.env-example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SEED="YOUR_BASE16_SEED_HERE"
CERAMIC_CLIENT_URL=https://ceramic-clay.3boxlabs.com
2 changes: 2 additions & 0 deletions schemas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Runs the `create-model.mjs` script.
This is only needed to make changes to the model used by the app.
A hex-encoded 32-byte `SEED` environment variable must be present to create a key DID for the model when running the script.

Set the `CERAMIC_CLIENT_URL` environment variable to change the Ceramic node to run against - the scripts will default to `http://localhost:7007` if not provided.

## License

Apache-2.0 OR MIT
2 changes: 1 addition & 1 deletion schemas/scripts/publish-model.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"definitions":{"Passport":"kjzl6cwe1jw145yjj8f4b6fjnzud3uy29utvqx7eqr7xb98kq90rrkuzbljvo1y","VerifiableCredential":"kjzl6cwe1jw147g1cb2awlanpocmy9mso0ln8u9buq3twsl8mkoao8hwylenwgc"},"schemas":{"VerifiableCredential":"ceramic://k3y52l7qbv1frxt4r2b1c9cg96mv6hh2id8u6a16sdibm00jiyyfjot4x58udmo74","Passport":"ceramic://k3y52l7qbv1fry01bkrdj4brb3dcem3galtugf7p6uf770lnalof3n6mo3pqetam8"},"tiles":{}}
{"definitions":{"Passport":"kjzl6cwe1jw14b5pv8zucigpz0sc2lh9z5l0ztdrvqw5y1xt2tvz8cjt34bkub9","VerifiableCredential":"kjzl6cwe1jw147bsnnxvupgywgr0tyi7tesgle7e4427hw2dn8sp9dnsltvey1n"},"schemas":{"Passport":"ceramic://k3y52l7qbv1frygm3lu9o9qra3nid11t6vuj0mas2m1mmlywh0fop5tgrxf060000","VerifiableCredential":"ceramic://k3y52l7qbv1frxunk7h39a05iup0s5sheycsgi8ozxme1s3tl37modhalv38d05q8"},"tiles":{}}
3 changes: 3 additions & 0 deletions schemas/scripts/publish-model.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { readFile, writeFile } from "node:fs/promises";
import { CeramicClient } from "@ceramicnetwork/http-client";
import { ModelManager } from "@glazed/devtools";

import dotenv from "dotenv";
dotenv.config();

// Connect to the local Ceramic node
const CERAMIC_CLIENT_URL =
process.env.CERAMIC_CLIENT_URL || "http://localhost:7007";
Expand Down

0 comments on commit 3969ec5

Please sign in to comment.