Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
*.log
*.sw[nop]
*~
Expand All @@ -7,8 +8,8 @@
TAGS
dist
node_modules
package-lock.json
_site/
vocabs/**/vocabulary.*
!vocabs/**/vocabulary.yml
.DS_Store
.wrangler/
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,41 @@ All local example context files are added as static contexts mapped to their
future publication URLs via
[jsonld-document-loader](https://github.com/digitalbazaar/jsonld-document-loader).

To host the generated examples index locally for testing, run:

```sh
npm run watch # in one shell environment
npm run serve # in another shell environment
```

The `watch` command will monitor file changes and rebuild the site via Eleventy.
The `serve` command will host the generated site at `http://localhost:8788/` and
also takes the `_headers` and `_redirects` files into account.

### Production

The production environment is managed via [Cloudflare Pages](https://pages.cloudflare.com/)
and managed via the [Wrangler CLI](https://developers.cloudflare.com/workers/wrangler/).

To publish into production--even on a preview branch, run:

```sh
npm run delpoy
```

The `wrangler.toml` file contains the configuration for the Cloudflare Pages
deployment and sets the `NODE_ENV` environment variable to `production` for
production.

A Linked Data Platform (LDP) Basic Container document of the contents of the
`./credentials/` directory is generated and uses the `NODE_ENV` variable to
generate the absolute URLs in the JSON-LD.

The production LDP index is at
`https://examples.vcplayground.org/credentials/index.jsonld`. It is primarily
intended for use by [VC Viewer](https://github.com/digitalbazaar/vc-viewer), but
may be useful for other applications as well.

## Usage

### Add / Update a Verifiable Credential
Expand Down
33 changes: 33 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,42 @@
* Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
*/
import {fileURLToPath} from 'node:url';
import fs from 'node:fs/promises';
import path from 'node:path';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

export const contextsDir = path.resolve(__dirname, '..', 'contexts');
export const credentialsDir = path.resolve(__dirname, '..', 'credentials');

const entries = await fs.readdir(credentialsDir, {withFileTypes: true});
const credentialDirs = entries.filter(e => e.isDirectory()).map(d => d.name);

const credentials = {};
for(const dirName of credentialDirs) {
const dirPath = path.join(credentialsDir, dirName);
const credentialJsonPath = path.join(dirPath, 'credential.json');
const queriesJsonPath = path.join(dirPath, 'queries.json');

let credential = null;
let queries = null;

try {
const credText = await fs.readFile(credentialJsonPath, 'utf8');
credential = JSON.parse(credText);
} catch(e) {
throw new Error(`Failed to read/parse ${credentialJsonPath}: ${e.message}`);
}

try {
const queriesText = await fs.readFile(queriesJsonPath, 'utf8');
queries = JSON.parse(queriesText);
} catch(e) {

Check failure on line 35 in lib/index.js

View workflow job for this annotation

GitHub Actions / lint (20.x)

'e' is defined but never used
// if queries.json is missing or invalid, keep as null
queries = null;
}

credentials[dirName] = {credential, queries};
}

export const examples = {credentials};
Loading
Loading