@digital-passports/javascript-sdk
Version:
JavaScript SDK for interacting with the Digital Passport Hub REST API.
54 lines • 1.96 kB
HTML
<html>
<head>
<meta charset="UTF-8">
<title>Digital Passport Hub SDK Raw JS Local Example</title>
<script src="../../dist/javascript-sdk.umd.js"></script>
<style>
body { font-family: sans-serif; margin: 2em; }
#output { white-space: pre; background: #f4f4f4; padding: 1em; border-radius: 4px; }
label { display: block; margin-top: 1em; }
</style>
</head>
<body>
<h1>Digital Passport Hub SDK Raw JavaScript Local Example</h1>
<label>
API Key:
<input id="apiKey" type="text" value="your_api_key" style="width: 300px;">
</label>
<button id="listBtn">List Passports</button>
<button id="createBtn">Create Passport</button>
<div id="output"></div>
<script>
function getSDK() {
var apiKey = document.getElementById('apiKey').value;
const DigitalPassport = window.DigitalPassport.default || window.DigitalPassport;
return new DigitalPassport({ apiKey: apiKey });
}
document.getElementById('listBtn').onclick = async function() {
var dpp = getSDK();
try {
var passports = await dpp.listPassports();
document.getElementById('output').textContent = JSON.stringify(passports, null, 2);
} catch (err) {
document.getElementById('output').textContent = 'Error: ' + err.message;
}
};
document.getElementById('createBtn').onclick = async function() {
var dpp = getSDK();
try {
var passport = await dpp.createPassport({
sku: 'RAWJS-LOCAL-EXAMPLE',
name: 'Raw JS Local Example Product',
materials: [
{ name: 'Vanillium', percentage: 100 }
]
});
document.getElementById('output').textContent = 'Created: ' + JSON.stringify(passport, null, 2);
} catch (err) {
document.getElementById('output').textContent = 'Error: ' + err.message;
}
};
</script>
</body>
</html>