Skip to content
Open
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
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) {
// if queries.json is missing or invalid, keep as null
queries = null;
}

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

export const examples = {credentials};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"scripts": {
"check": "node test/safe-mode-check.js",
"extract": "node test/safe-mode-check.js extract",
"publish": "eleventy",
"build": "eleventy",
"serve": "wrangler pages dev _site/ --compatibility-date=2025-04-02",
"watch": "eleventy --watch",
"test": "npm run lint && npm run test-node",
"test-node": "cross-env NODE_ENV=test mocha --preserve-symlinks -t 10000 test/*.spec.js",
"lint": "eslint ."
Expand All @@ -33,7 +34,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/credential-handler/vc-examples"
"url": "git+https://github.com/credential-handler/vc-examples.git"
},
"engines": {
"node": ">=18"
Expand Down
14 changes: 14 additions & 0 deletions src/credentials/index.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
layout: false
permalink: credentials/index.json
---
{
{% for example in examples %}
{{ example[0] | json }}: {
"credential": "{{ example[0] | append: '/credential.json' }}",
"queries": "{{ example[0] | append: '/queries.json' }}",
"image": "{{ example[0] | append: '/image.png' }}"
}
{% if forloop.last == false %},{% endif %}
{% endfor %}
}