@elumixor/digisigner 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -0
- package/dist/digi-signer.d.ts +10 -0
- package/dist/digi-signer.test.d.ts +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +84 -0
- package/dist/types.d.ts +36 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# @elumixor/digisigner
|
|
2
|
+
|
|
3
|
+
TypeScript wrapper for the DigiSigner API - a simple and efficient way to add electronic signatures to your documents.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @elumixor/digisigner
|
|
9
|
+
# or
|
|
10
|
+
bun add @elumixor/digisigner
|
|
11
|
+
# or
|
|
12
|
+
yarn add @elumixor/digisigner
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { DigiSigner } from "@elumixor/digisigner";
|
|
19
|
+
|
|
20
|
+
// Initialize the client
|
|
21
|
+
const signer = new DigiSigner(process.env.DIGISIGNER_API_KEY);
|
|
22
|
+
|
|
23
|
+
// Upload a document
|
|
24
|
+
const document = await signer.uploadDocument(pdfBuffer, "contract.pdf");
|
|
25
|
+
|
|
26
|
+
// Send signature request
|
|
27
|
+
const signature = await signer.sendSignatureRequest({
|
|
28
|
+
documentId: document.document_id,
|
|
29
|
+
signers: [
|
|
30
|
+
{ email: "john@example.com", name: "John Doe" },
|
|
31
|
+
{ email: "jane@example.com", name: "Jane Smith" },
|
|
32
|
+
],
|
|
33
|
+
fields: [
|
|
34
|
+
{
|
|
35
|
+
type: "signature",
|
|
36
|
+
page: 0,
|
|
37
|
+
x: 100,
|
|
38
|
+
y: 100,
|
|
39
|
+
width: 200,
|
|
40
|
+
height: 50,
|
|
41
|
+
signer_id: 0,
|
|
42
|
+
required: true,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
subject: "Please sign this document",
|
|
46
|
+
message: "Please review and sign the attached document.",
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
console.log(signature.signing_urls); // { "john@example.com": "https://...", "jane@example.com": "https://..." }
|
|
50
|
+
|
|
51
|
+
// Check signature status
|
|
52
|
+
const status = await signer.getSignatureStatus(signature.signature_request_id);
|
|
53
|
+
console.log(status.status); // "pending", "completed", etc.
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## API
|
|
57
|
+
|
|
58
|
+
### `DigiSigner`
|
|
59
|
+
|
|
60
|
+
Main client class for interacting with the DigiSigner API.
|
|
61
|
+
|
|
62
|
+
#### Constructor
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
new DigiSigner(apiKey: string)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### Methods
|
|
69
|
+
|
|
70
|
+
##### `uploadDocument(buffer: Buffer, filename: string): Promise<DigiSignerDocument>`
|
|
71
|
+
|
|
72
|
+
Upload a PDF document to DigiSigner.
|
|
73
|
+
|
|
74
|
+
##### `sendSignatureRequest(request: DigiSignerSignatureRequest): Promise<DigiSignerSignature>`
|
|
75
|
+
|
|
76
|
+
Send a signature request for a document.
|
|
77
|
+
|
|
78
|
+
##### `getSignatureStatus(signatureRequestId: string): Promise<DigiSignerSignatureStatus>`
|
|
79
|
+
|
|
80
|
+
Get the status of a signature request.
|
|
81
|
+
|
|
82
|
+
## Types
|
|
83
|
+
|
|
84
|
+
All TypeScript types are exported:
|
|
85
|
+
|
|
86
|
+
- `DigiSignerSigner`
|
|
87
|
+
- `DigiSignerField`
|
|
88
|
+
- `DigiSignerSignatureRequest`
|
|
89
|
+
- `DigiSignerDocument`
|
|
90
|
+
- `DigiSignerSignature`
|
|
91
|
+
- `DigiSignerSignatureStatus`
|
|
92
|
+
|
|
93
|
+
## Getting an API Key
|
|
94
|
+
|
|
95
|
+
1. Sign up at [DigiSigner](https://www.digisigner.com/)
|
|
96
|
+
2. Navigate to API Settings
|
|
97
|
+
3. Generate your API key
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
ISC
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DigiSignerDocument, DigiSignerSignature, DigiSignerSignatureRequest, DigiSignerSignatureStatus } from "./types";
|
|
2
|
+
export declare class DigiSigner {
|
|
3
|
+
private readonly apiKey;
|
|
4
|
+
constructor(apiKey: string);
|
|
5
|
+
private request;
|
|
6
|
+
private createFormData;
|
|
7
|
+
uploadDocument(buffer: Buffer, filename: string): Promise<DigiSignerDocument>;
|
|
8
|
+
sendSignatureRequest(request: DigiSignerSignatureRequest): Promise<DigiSignerSignature>;
|
|
9
|
+
getSignatureStatus(signatureRequestId: string): Promise<DigiSignerSignatureStatus>;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// src/digi-signer.ts
|
|
2
|
+
var DIGISIGNER_API_URL = "https://api.digisigner.com/v1";
|
|
3
|
+
|
|
4
|
+
class DigiSigner {
|
|
5
|
+
apiKey;
|
|
6
|
+
constructor(apiKey) {
|
|
7
|
+
if (!apiKey)
|
|
8
|
+
throw new Error("DigiSigner API key is required");
|
|
9
|
+
this.apiKey = apiKey;
|
|
10
|
+
}
|
|
11
|
+
async request(method, endpoint, body) {
|
|
12
|
+
const response = await fetch(`${DIGISIGNER_API_URL}${endpoint}`, {
|
|
13
|
+
method,
|
|
14
|
+
headers: {
|
|
15
|
+
Authorization: `Token ${this.apiKey}`,
|
|
16
|
+
"Content-Type": "application/json"
|
|
17
|
+
},
|
|
18
|
+
body: body ? JSON.stringify(body) : undefined
|
|
19
|
+
});
|
|
20
|
+
if (!response.ok) {
|
|
21
|
+
const error = await response.text();
|
|
22
|
+
throw new Error(`DigiSigner API error: ${response.status} ${error}`);
|
|
23
|
+
}
|
|
24
|
+
return response.json();
|
|
25
|
+
}
|
|
26
|
+
createFormData(buffer, filename) {
|
|
27
|
+
const formData = new FormData;
|
|
28
|
+
const uint8Array = new Uint8Array(buffer);
|
|
29
|
+
const blob = new Blob([uint8Array], { type: "application/pdf" });
|
|
30
|
+
formData.append("file", blob, filename);
|
|
31
|
+
return formData;
|
|
32
|
+
}
|
|
33
|
+
async uploadDocument(buffer, filename) {
|
|
34
|
+
const formData = this.createFormData(buffer, filename);
|
|
35
|
+
const response = await fetch(`${DIGISIGNER_API_URL}/documents`, {
|
|
36
|
+
method: "POST",
|
|
37
|
+
headers: {
|
|
38
|
+
Authorization: `Token ${this.apiKey}`
|
|
39
|
+
},
|
|
40
|
+
body: formData
|
|
41
|
+
});
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
const error = await response.text();
|
|
44
|
+
throw new Error(`DigiSigner upload error: ${response.status} ${error}`);
|
|
45
|
+
}
|
|
46
|
+
return await response.json();
|
|
47
|
+
}
|
|
48
|
+
async sendSignatureRequest(request) {
|
|
49
|
+
const signers = request.signers.map((signer, index) => ({
|
|
50
|
+
email: signer.email,
|
|
51
|
+
name: signer.name,
|
|
52
|
+
role: signer.role ?? `Signer ${index + 1}`,
|
|
53
|
+
order: index + 1
|
|
54
|
+
}));
|
|
55
|
+
const fields = request.fields.map((field) => ({
|
|
56
|
+
type: field.type,
|
|
57
|
+
page: field.page,
|
|
58
|
+
rectangle: {
|
|
59
|
+
x: field.x,
|
|
60
|
+
y: field.y,
|
|
61
|
+
width: field.width,
|
|
62
|
+
height: field.height
|
|
63
|
+
},
|
|
64
|
+
signer: field.signer_id,
|
|
65
|
+
label: field.label,
|
|
66
|
+
required: field.required ?? true
|
|
67
|
+
}));
|
|
68
|
+
const payload = {
|
|
69
|
+
document_id: request.documentId,
|
|
70
|
+
signers,
|
|
71
|
+
fields,
|
|
72
|
+
subject: request.subject,
|
|
73
|
+
message: request.message,
|
|
74
|
+
send_emails: true
|
|
75
|
+
};
|
|
76
|
+
return this.request("POST", "/signature_requests", payload);
|
|
77
|
+
}
|
|
78
|
+
async getSignatureStatus(signatureRequestId) {
|
|
79
|
+
return this.request("GET", `/signature_requests/${signatureRequestId}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export {
|
|
83
|
+
DigiSigner
|
|
84
|
+
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface DigiSignerSigner {
|
|
2
|
+
email: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
role?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface DigiSignerField {
|
|
7
|
+
type: "signature" | "text" | "date" | "checkbox";
|
|
8
|
+
page: number;
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
signer_id: number;
|
|
14
|
+
label?: string;
|
|
15
|
+
required?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface DigiSignerSignatureRequest {
|
|
18
|
+
documentId: string;
|
|
19
|
+
signers: DigiSignerSigner[];
|
|
20
|
+
fields: DigiSignerField[];
|
|
21
|
+
subject?: string;
|
|
22
|
+
message?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface DigiSignerDocument {
|
|
25
|
+
document_id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
}
|
|
28
|
+
export interface DigiSignerSignature {
|
|
29
|
+
signature_request_id: string;
|
|
30
|
+
signing_urls: Record<string, string>;
|
|
31
|
+
status: string;
|
|
32
|
+
}
|
|
33
|
+
export interface DigiSignerSignatureStatus {
|
|
34
|
+
status: string;
|
|
35
|
+
signed_document_url?: string;
|
|
36
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elumixor/digisigner",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "TypeScript wrapper for DigiSigner API",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/elumixor/digisigner.git"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"./dist"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "bun run build:bundle && bun run build:declaration",
|
|
16
|
+
"build:bundle": "bun build ./src/index.ts --outdir ./dist",
|
|
17
|
+
"build:declaration": "tsc --project tsconfig.json",
|
|
18
|
+
"lint": "biome check .",
|
|
19
|
+
"lint:fix": "biome check --write .",
|
|
20
|
+
"format": "biome format --write .",
|
|
21
|
+
"test": "bun test",
|
|
22
|
+
"release:patch": "npm version patch -m \"Release v%s\" && git push --tags",
|
|
23
|
+
"release:minor": "npm version minor -m \"Release v%s\" && git push --tags",
|
|
24
|
+
"release:major": "npm version major -m \"Release v%s\" && git push --tags"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"digisigner",
|
|
28
|
+
"esignature",
|
|
29
|
+
"document-signing",
|
|
30
|
+
"api-wrapper",
|
|
31
|
+
"typescript"
|
|
32
|
+
],
|
|
33
|
+
"author": "",
|
|
34
|
+
"license": "ISC",
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@biomejs/biome": "^2.3.10",
|
|
37
|
+
"@types/bun": "^1.3.1",
|
|
38
|
+
"typescript": "^5.7.2"
|
|
39
|
+
}
|
|
40
|
+
}
|