Skip to content

Commit

Permalink
export global AutogramSDK
Browse files Browse the repository at this point in the history
  • Loading branch information
pomali committed Nov 16, 2024
1 parent 8567bc6 commit e26de59
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 4 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,25 @@ const { content, issuedBy, signedBy } = await client.sign(
true
);
```

## Usage on web

```html
<script src="dist/index.global.js"></script>
<script>
const client = new AutogramSDK.FullClient();
const { content, issuedBy, signedBy } = await client.sign(
{
content: "hello world",
filename: "hello.txt",
},
{
level: "XAdES_BASELINE_B",
container: "ASiC_E",
},
"text/plain",
true
);
</script>
```
File renamed without changes.
57 changes: 57 additions & 0 deletions demo2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Autogram SDK</title>
</head>
<body>
<h1>Welcome to Autogram SDK</h1>
<p>This is a basic HTML template.</p>
<!-- <script src="dist/demo.global.js" type="module"></script> -->
<script src="dist/index.global.js"></script>
<script>
async function main() {
const client = new AutogramSDK.FullClient();
const filePicker = document.createElement("input");
filePicker.type = "file";
filePicker.addEventListener("change", async (e) => {
const file = filePicker.files?.[0];
if (!file) return;

const signedObject = await client.sign(
{
content: await file.text(),
filename: file.name,
},
{
level: "XAdES_BASELINE_B",
container: "ASiC_E",
},
file.type,
true
);

console.log(signedObject);

const a = document.createElement("a");
const blob = new Blob([signedObject.content], {
type: "text/plain",
});
const url = URL.createObjectURL(blob);
a.href = url;
a.download = `${file.name}.asice`;
a.text = `Download ${a.download}`;
document.body.appendChild(a);
});

document.body.appendChild(filePicker);
}

main().then(
() => console.log("done"),
(err) => console.error(err)
);
</script>
</body>
</html>
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "autogram-sdk",
"version": "0.0.0",
"version": "0.0.2",
"description": "SDK for Autogram signer ",
"main": "dist/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsup src/index.ts src/demo.ts --minify --dts --format cjs,esm,iife --out-dir dist",
"build": "tsup src/index.ts src/demo.ts",
"build:watch": "npm run build -- --watch",
"build:release": "NODE_ENV=production rm -r dist && npm run build -- --env.NODE_ENV production",
"generate-autogram-api-types": "npx openapi-typescript http://localhost:37200/docs/server.yml --output src/autogram-api/lib/autogram-api.generated.ts && npx prettier --write src/autogram-api/lib/autogram-api.generated.ts",
Expand Down
6 changes: 6 additions & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import { defineConfig } from "tsup";

export default defineConfig({
platform: "browser",
minify: true,
dts: true,
sourcemap: true,
format: ["cjs", "esm", "iife"],
outDir: "dist",
esbuildOptions(options, context) {
options.loader = {
...options.loader,
".css": "text",
};
options.globalName = "AutogramSDK";
return options;
},
});

0 comments on commit e26de59

Please sign in to comment.