docstron 1.0.0
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/.env.example +2 -0
- package/LICENSE +21 -0
- package/README.md +789 -0
- package/check-connection.js +107 -0
- package/examples/basic-usage.js +91 -0
- package/examples/complete-workflow.js +160 -0
- package/examples/generate-pdf.js +325 -0
- package/examples/invoice-template.js +187 -0
- package/examples/manage-applications.js +114 -0
- package/examples/quick-generate.js +101 -0
- package/index.js +13 -0
- package/lib/Docstron.js +55 -0
- package/lib/constants.js +7 -0
- package/lib/resources/Applications.js +110 -0
- package/lib/resources/Documents.js +173 -0
- package/lib/resources/Templates.js +97 -0
- package/lib/utils/errors.js +38 -0
- package/lib/utils/httpClient.js +68 -0
- package/package.json +42 -0
- package/test/test.js +213 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
require('dotenv').config();
|
|
2
|
+
const Docstron = require('../index');
|
|
3
|
+
|
|
4
|
+
async function createInvoiceTemplate() {
|
|
5
|
+
const apiKey = process.env.DOCSTRON_API_KEY;
|
|
6
|
+
const appId = process.env.DOCSTRON_APP_ID;
|
|
7
|
+
|
|
8
|
+
if (!apiKey || !appId) {
|
|
9
|
+
console.error('❌ Missing credentials. Please check your .env file.');
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const client = new Docstron(apiKey);
|
|
14
|
+
|
|
15
|
+
const invoiceHTML = `
|
|
16
|
+
<!DOCTYPE html>
|
|
17
|
+
<html>
|
|
18
|
+
<head>
|
|
19
|
+
<meta charset="UTF-8">
|
|
20
|
+
<style>
|
|
21
|
+
body {
|
|
22
|
+
font-family: 'Arial', sans-serif;
|
|
23
|
+
max-width: 800px;
|
|
24
|
+
margin: 0 auto;
|
|
25
|
+
padding: 40px;
|
|
26
|
+
color: #333;
|
|
27
|
+
}
|
|
28
|
+
.header {
|
|
29
|
+
text-align: center;
|
|
30
|
+
border-bottom: 3px solid #4a90e2;
|
|
31
|
+
padding-bottom: 20px;
|
|
32
|
+
margin-bottom: 30px;
|
|
33
|
+
}
|
|
34
|
+
.header h1 {
|
|
35
|
+
color: #4a90e2;
|
|
36
|
+
margin: 0;
|
|
37
|
+
}
|
|
38
|
+
.info-section {
|
|
39
|
+
display: flex;
|
|
40
|
+
justify-content: space-between;
|
|
41
|
+
margin-bottom: 30px;
|
|
42
|
+
}
|
|
43
|
+
.info-box {
|
|
44
|
+
flex: 1;
|
|
45
|
+
}
|
|
46
|
+
.info-box h3 {
|
|
47
|
+
color: #4a90e2;
|
|
48
|
+
border-bottom: 2px solid #e0e0e0;
|
|
49
|
+
padding-bottom: 5px;
|
|
50
|
+
}
|
|
51
|
+
table {
|
|
52
|
+
width: 100%;
|
|
53
|
+
border-collapse: collapse;
|
|
54
|
+
margin: 20px 0;
|
|
55
|
+
}
|
|
56
|
+
th {
|
|
57
|
+
background: #4a90e2;
|
|
58
|
+
color: white;
|
|
59
|
+
padding: 12px;
|
|
60
|
+
text-align: left;
|
|
61
|
+
}
|
|
62
|
+
td {
|
|
63
|
+
padding: 10px;
|
|
64
|
+
border-bottom: 1px solid #e0e0e0;
|
|
65
|
+
}
|
|
66
|
+
.total-section {
|
|
67
|
+
text-align: right;
|
|
68
|
+
margin-top: 20px;
|
|
69
|
+
}
|
|
70
|
+
.total {
|
|
71
|
+
font-size: 24px;
|
|
72
|
+
font-weight: bold;
|
|
73
|
+
color: #4a90e2;
|
|
74
|
+
}
|
|
75
|
+
.footer {
|
|
76
|
+
margin-top: 40px;
|
|
77
|
+
text-align: center;
|
|
78
|
+
color: #666;
|
|
79
|
+
font-size: 12px;
|
|
80
|
+
border-top: 1px solid #e0e0e0;
|
|
81
|
+
padding-top: 20px;
|
|
82
|
+
}
|
|
83
|
+
</style>
|
|
84
|
+
</head>
|
|
85
|
+
<body>
|
|
86
|
+
<div class="header">
|
|
87
|
+
<h1>INVOICE</h1>
|
|
88
|
+
<p>Invoice #{{invoice_number}}</p>
|
|
89
|
+
<p>Date: {{invoice_date}}</p>
|
|
90
|
+
</div>
|
|
91
|
+
|
|
92
|
+
<div class="info-section">
|
|
93
|
+
<div class="info-box">
|
|
94
|
+
<h3>From:</h3>
|
|
95
|
+
<p><strong>{{company_name}}</strong></p>
|
|
96
|
+
<p>{{company_address}}</p>
|
|
97
|
+
<p>{{company_email}}</p>
|
|
98
|
+
</div>
|
|
99
|
+
<div class="info-box">
|
|
100
|
+
<h3>Bill To:</h3>
|
|
101
|
+
<p><strong>{{customer_name}}</strong></p>
|
|
102
|
+
<p>{{customer_address}}</p>
|
|
103
|
+
<p>{{customer_email}}</p>
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
<table>
|
|
108
|
+
<thead>
|
|
109
|
+
<tr>
|
|
110
|
+
<th>Description</th>
|
|
111
|
+
<th>Quantity</th>
|
|
112
|
+
<th>Rate</th>
|
|
113
|
+
<th>Amount</th>
|
|
114
|
+
</tr>
|
|
115
|
+
</thead>
|
|
116
|
+
<tbody>
|
|
117
|
+
<tr>
|
|
118
|
+
<td>{{item_description}}</td>
|
|
119
|
+
<td>{{item_quantity}}</td>
|
|
120
|
+
<td>{{item_rate}}</td>
|
|
121
|
+
<td>{{item_amount}}</td>
|
|
122
|
+
</tr>
|
|
123
|
+
</tbody>
|
|
124
|
+
</table>
|
|
125
|
+
|
|
126
|
+
<div class="total-section">
|
|
127
|
+
<p><strong>Subtotal:</strong> {{subtotal}}</p>
|
|
128
|
+
<p><strong>Tax ({{tax_rate}}%):</strong> {{tax_amount}}</p>
|
|
129
|
+
<p class="total">Total: {{total_amount}}</p>
|
|
130
|
+
</div>
|
|
131
|
+
|
|
132
|
+
<div class="footer">
|
|
133
|
+
<p>{{footer_text}}</p>
|
|
134
|
+
<p>Payment due within 30 days</p>
|
|
135
|
+
</div>
|
|
136
|
+
</body>
|
|
137
|
+
</html>
|
|
138
|
+
`;
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
const template = await client.templates.create({
|
|
142
|
+
application_id: appId,
|
|
143
|
+
name: 'Professional Invoice Template - ' + Date.now(),
|
|
144
|
+
content: invoiceHTML,
|
|
145
|
+
is_active: true,
|
|
146
|
+
extra_css: `
|
|
147
|
+
@page{
|
|
148
|
+
margin: 2cm;
|
|
149
|
+
@bottom-center {
|
|
150
|
+
content: "Page " counter(page) " of " counter(pages);
|
|
151
|
+
font-size: 10px;
|
|
152
|
+
color: #666;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
`
|
|
156
|
+
});
|
|
157
|
+
console.log('✅ Invoice template created!');
|
|
158
|
+
console.log('Template ID:', template.template_id);
|
|
159
|
+
console.log('\nYou can now use this template to generate invoices with your data.');
|
|
160
|
+
console.log('\nExample data structure:');
|
|
161
|
+
console.log(JSON.stringify({
|
|
162
|
+
invoice_number: 'INV-2025-001',
|
|
163
|
+
invoice_date: '2025-11-08',
|
|
164
|
+
company_name: 'Acme Corporation',
|
|
165
|
+
company_address: '123 Business St, City, State 12345',
|
|
166
|
+
company_email: 'billing@acme.com',
|
|
167
|
+
customer_name: 'John Doe',
|
|
168
|
+
customer_address: '456 Customer Ave, City, State 67890',
|
|
169
|
+
customer_email: 'john@example.com',
|
|
170
|
+
item_description: 'Web Development Services',
|
|
171
|
+
item_quantity: '40 hours',
|
|
172
|
+
item_rate: '$100/hr',
|
|
173
|
+
item_amount: '$4,000.00',
|
|
174
|
+
subtotal: '$4,000.00',
|
|
175
|
+
tax_rate: '10',
|
|
176
|
+
tax_amount: '$400.00',
|
|
177
|
+
total_amount: '$4,400.00',
|
|
178
|
+
footer_text: 'Thank you for your business!'
|
|
179
|
+
}, null, 2));
|
|
180
|
+
|
|
181
|
+
} catch (error) {
|
|
182
|
+
console.error('❌ Error:', error.message);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
createInvoiceTemplate();
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
require('dotenv').config();
|
|
2
|
+
const Docstron = require('../index');
|
|
3
|
+
|
|
4
|
+
async function manageApplicationsExample() {
|
|
5
|
+
const apiKey = process.env.DOCSTRON_API_KEY;
|
|
6
|
+
|
|
7
|
+
if (!apiKey) {
|
|
8
|
+
console.error('❌ Missing DOCSTRON_API_KEY. Please check your .env file.');
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const client = new Docstron(apiKey);
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
console.log('🏢 Application Management Examples\n');
|
|
16
|
+
console.log('='.repeat(50));
|
|
17
|
+
|
|
18
|
+
// Example 1: List all applications
|
|
19
|
+
console.log('\n📃 Example 1: List all applications... \n');
|
|
20
|
+
const allApps = await client.applications.list();
|
|
21
|
+
console.log(`✅ Found ${allApps.length} application(s)`);
|
|
22
|
+
allApps.forEach((apps, index) => {
|
|
23
|
+
console.log(` ${index + 1}. ${apps.name} (${apps.app_id})`);
|
|
24
|
+
console.log(` Status: ${apps.is_active ? 'Active' : 'Inactive'}`);
|
|
25
|
+
console.log(` Created: ${apps.created_at}`);
|
|
26
|
+
});
|
|
27
|
+
console.log('');
|
|
28
|
+
|
|
29
|
+
// Example 2: Create a new application
|
|
30
|
+
console.log('📝 Example 2: Create a new application... \n');
|
|
31
|
+
const newApp = await client.applications.create({
|
|
32
|
+
name: 'Test Application - ' + Date.now(),
|
|
33
|
+
description: 'Created by Node SDK for testing purposes',
|
|
34
|
+
is_active: true
|
|
35
|
+
});
|
|
36
|
+
console.log('✅ Application Created!');
|
|
37
|
+
console.log(' App ID:', newApp.app_id);
|
|
38
|
+
console.log(' Name:', newApp.name);
|
|
39
|
+
console.log(' Description:', newApp.description);
|
|
40
|
+
console.log(' Status:', newApp.is_active ? 'Active' : 'Inactive');
|
|
41
|
+
console.log(' Created:', newApp.created_at);
|
|
42
|
+
console.log('');
|
|
43
|
+
|
|
44
|
+
// Example 3: Get specific application details
|
|
45
|
+
console.log('📖 Example 3: Get application details... \n');
|
|
46
|
+
const appDetails = await client.applications.get(newApp.app_id);
|
|
47
|
+
console.log('✅ Applicaiton details retrieved');
|
|
48
|
+
console.log(' Name:', appDetails.name);
|
|
49
|
+
console.log(' Description:', appDetails.description);
|
|
50
|
+
console.log(' Status:', appDetails.is_active ? 'Active' : 'Inactive');
|
|
51
|
+
console.log(' Created:', appDetails.created_at);
|
|
52
|
+
console.log('');
|
|
53
|
+
|
|
54
|
+
// Example 4: Update application
|
|
55
|
+
console.log('✏️ Example 4: Update application...\n');
|
|
56
|
+
const updatedApp = await client.applications.update(newApp.app_id, {
|
|
57
|
+
name: 'Updated Test Application',
|
|
58
|
+
description: 'Updated description',
|
|
59
|
+
is_active: true
|
|
60
|
+
});
|
|
61
|
+
console.log('✅ Application updated!');
|
|
62
|
+
console.log(' New Name:', updatedApp.name);
|
|
63
|
+
console.log(' New Description:', updatedApp.description);
|
|
64
|
+
console.log(' Updated At:', updatedApp.updated_at);
|
|
65
|
+
console.log('');
|
|
66
|
+
|
|
67
|
+
// Example 5: Deactivate application
|
|
68
|
+
console.log('🔒 Example 5: Deactivate application...\n');
|
|
69
|
+
const deactivated = await client.applications.update(newApp.app_id, {
|
|
70
|
+
is_active: false
|
|
71
|
+
});
|
|
72
|
+
console.log('✅ Application deactivated!');
|
|
73
|
+
console.log(' Status:', deactivated.is_active ? 'Active' : 'Inactive');
|
|
74
|
+
console.log('');
|
|
75
|
+
|
|
76
|
+
// Example 6: Get only active applications
|
|
77
|
+
console.log('📋 Example 6: List active applications only...\n');
|
|
78
|
+
const activeApps = await client.applications.listActive();
|
|
79
|
+
console.log(`✅ Found ${activeApps.length} active application(s):`);
|
|
80
|
+
activeApps.forEach((app, index) => {
|
|
81
|
+
console.log(` ${index + 1}. ${app.name} (${app.app_id})`);
|
|
82
|
+
});
|
|
83
|
+
console.log('');
|
|
84
|
+
|
|
85
|
+
// Example 7: Get only inactive applications
|
|
86
|
+
console.log('📋 Example 7: List inactive applications only...\n');
|
|
87
|
+
const inactiveApps = await client.applications.listInactive();
|
|
88
|
+
console.log(`✅ Found ${inactiveApps.length} inactive application(s):`);
|
|
89
|
+
inactiveApps.forEach((app, index) => {
|
|
90
|
+
console.log(` ${index + 1}. ${app.name} (${app.app_id})`);
|
|
91
|
+
});
|
|
92
|
+
console.log('');
|
|
93
|
+
|
|
94
|
+
// Example 8: Delete application (cleanup)
|
|
95
|
+
console.log('🗑️ Example 8: Delete test application...\n');
|
|
96
|
+
await client.applications.delete(newApp.app_id);
|
|
97
|
+
console.log('✅ Application deleted successfully!');
|
|
98
|
+
console.log('');
|
|
99
|
+
|
|
100
|
+
console.log('='.repeat(50));
|
|
101
|
+
console.log('🎉 All application management examples completed!\n');
|
|
102
|
+
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error('\n❌ Error:', error.message);
|
|
105
|
+
if (error.name === 'ValidationError') {
|
|
106
|
+
console.error('Validation errors:');
|
|
107
|
+
error.errors?.forEach(err => {
|
|
108
|
+
console.error(` - ${err.field}: ${err.message}`);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
manageApplicationsExample();
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
require('dotenv').config();
|
|
2
|
+
const Docstron = require('../index');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
async function quickGenerateExample() {
|
|
7
|
+
const apiKey = process.env.DOCSTRON_API_KEY;
|
|
8
|
+
const appId = process.env.DOCSTRON_APP_ID;
|
|
9
|
+
|
|
10
|
+
if (!apiKey) {
|
|
11
|
+
console.error('❌ Missing DOCSTRON_API_KEY. Please check your .env file.');
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const client = new Docstron(apiKey);
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
console.log('⚡ Quick Generate PDF Examples\n');
|
|
19
|
+
console.log('='.repeat(50));
|
|
20
|
+
|
|
21
|
+
// Example 1: Quick generate without saving template
|
|
22
|
+
console.log('\n📄 Example 1: Quick generate (no template save)...');
|
|
23
|
+
const doc1 = await client.documents.quickGenerate({
|
|
24
|
+
html: `
|
|
25
|
+
<html>
|
|
26
|
+
<head>
|
|
27
|
+
<style>
|
|
28
|
+
body { font-family: Arial; padding: 40px; }
|
|
29
|
+
h1 { color: #3498db; }
|
|
30
|
+
</style>
|
|
31
|
+
</head>
|
|
32
|
+
<body>
|
|
33
|
+
<h1>Hello {{name}}!</h1>
|
|
34
|
+
<p>This is a quick PDF generated on {{date}}</p>
|
|
35
|
+
<p>Message: {{message}}</p>
|
|
36
|
+
</body>
|
|
37
|
+
</html>
|
|
38
|
+
`,
|
|
39
|
+
data: {
|
|
40
|
+
name: 'World',
|
|
41
|
+
date: new Date().toLocaleDateString(),
|
|
42
|
+
message: 'No template needed!'
|
|
43
|
+
},
|
|
44
|
+
response_type: 'document_id'
|
|
45
|
+
});
|
|
46
|
+
console.log('✅ PDF generated!');
|
|
47
|
+
console.log(' Document ID:', doc1.document_id);
|
|
48
|
+
console.log(' Download URL:', doc1.download_url);
|
|
49
|
+
|
|
50
|
+
/*
|
|
51
|
+
// Example 2: Quick generate with extra CSS
|
|
52
|
+
console.log('\n📄 Example 2: Quick generate with custom CSS...');
|
|
53
|
+
const doc2 = await client.documents.quickGenerate({
|
|
54
|
+
html: '<h1>Styled PDF</h1><p>This has custom page margins</p>',
|
|
55
|
+
data: {},
|
|
56
|
+
extra_css: '@page { margin: 3cm; } h1 { color: #e74c3c; }',
|
|
57
|
+
response_type: 'document_id'
|
|
58
|
+
});
|
|
59
|
+
console.log('✅ PDF generated with custom styling!');
|
|
60
|
+
console.log(' Document ID:', doc2.document_id);
|
|
61
|
+
|
|
62
|
+
// Example 3: Quick generate and save as template
|
|
63
|
+
if (appId) {
|
|
64
|
+
console.log('\n📄 Example 3: Quick generate and save as template...');
|
|
65
|
+
const doc3 = await client.documents.quickGenerate({
|
|
66
|
+
html: '<h1>Receipt</h1><p>Amount: {{amount}}</p>',
|
|
67
|
+
data: { amount: '$99.99' },
|
|
68
|
+
response_type: 'document_id',
|
|
69
|
+
save_template: true,
|
|
70
|
+
application_id: appId
|
|
71
|
+
});
|
|
72
|
+
console.log('✅ PDF generated and template saved!');
|
|
73
|
+
console.log(' Document ID:', doc3.document_id);
|
|
74
|
+
console.log(' Template ID:', doc3.template_id);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Example 4: Quick generate with password protection
|
|
78
|
+
console.log('\n📄 Example 4: Password-protected PDF...');
|
|
79
|
+
const doc4 = await client.documents.quickGenerate({
|
|
80
|
+
html: '<h1>Confidential</h1><p>This PDF is password protected</p>',
|
|
81
|
+
data: {},
|
|
82
|
+
response_type: 'document_id',
|
|
83
|
+
password: 'SecurePass123!'
|
|
84
|
+
});
|
|
85
|
+
console.log('✅ Password-protected PDF generated!');
|
|
86
|
+
console.log(' Document ID:', doc4.document_id);
|
|
87
|
+
console.log(' Password: SecurePass123!');
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
console.log('\n' + '='.repeat(50));
|
|
91
|
+
console.log('🎉 Quick generate examples completed!\n');
|
|
92
|
+
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error('\n❌ Error:', error.message);
|
|
95
|
+
if (error.statusCode) {
|
|
96
|
+
console.error('Status Code:', error.statusCode);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
quickGenerateExample();
|
package/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const Docstron = require('./lib/Docstron');
|
|
2
|
+
const {
|
|
3
|
+
DocstronError,
|
|
4
|
+
ValidationError,
|
|
5
|
+
AuthenticationError,
|
|
6
|
+
NotFoundError
|
|
7
|
+
} = require('./lib/utils/errors');
|
|
8
|
+
|
|
9
|
+
module.exports = Docstron;
|
|
10
|
+
module.exports.DocstronError = DocstronError;
|
|
11
|
+
module.exports.ValidationError = ValidationError;
|
|
12
|
+
module.exports.AuthenticationError = AuthenticationError;
|
|
13
|
+
module.exports.NotFoundError = NotFoundError;
|
package/lib/Docstron.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const HttpClient = require('./utils/httpClient');
|
|
2
|
+
const Templates = require('./resources/Templates');
|
|
3
|
+
const Documents = require('./resources/Documents');
|
|
4
|
+
const Applications = require('./resources/Applications');
|
|
5
|
+
const { DEFAULT_BASE_URL } = require('./constants');
|
|
6
|
+
|
|
7
|
+
class Docstron {
|
|
8
|
+
/**
|
|
9
|
+
* Create new Docstron client
|
|
10
|
+
* @param {string} apiKey - Your Docstron API key
|
|
11
|
+
* @param {Object} [Options] - Configuration options
|
|
12
|
+
* @param {string} [Options.baseURL] - Custom base URL
|
|
13
|
+
*/
|
|
14
|
+
constructor(apiKey, options = {}) {
|
|
15
|
+
if (!apiKey) {
|
|
16
|
+
throw new Error('API key is required');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
this.apiKey = apiKey;
|
|
20
|
+
this.baseURL = options.baseURL || DEFAULT_BASE_URL;
|
|
21
|
+
|
|
22
|
+
const httpClient = new HttpClient(this.apiKey, this.baseURL);
|
|
23
|
+
|
|
24
|
+
// v0.1.0 - Templates Only
|
|
25
|
+
this.templates = new Templates(httpClient);
|
|
26
|
+
|
|
27
|
+
// v0.2.0 - Documents
|
|
28
|
+
this.documents = new Documents(httpClient);
|
|
29
|
+
|
|
30
|
+
// v0.3.0 - Applications
|
|
31
|
+
this.applications = new Applications(httpClient);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get the current SDK version
|
|
36
|
+
* @returns {string} version number
|
|
37
|
+
*/
|
|
38
|
+
static getVersion() {
|
|
39
|
+
return '0.3.0';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Check which features are available
|
|
44
|
+
* @returns {Object} Available features
|
|
45
|
+
*/
|
|
46
|
+
static getFeatures() {
|
|
47
|
+
return {
|
|
48
|
+
templates: true, // v0.1.0+
|
|
49
|
+
documents: true, // v0.2.0+
|
|
50
|
+
applications: true // v0.3.0+
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = Docstron;
|
package/lib/constants.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
class Applications {
|
|
2
|
+
constructor(httpClient) {
|
|
3
|
+
this.http = httpClient;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Create a new application
|
|
8
|
+
* @param {Object} params - Application parameters
|
|
9
|
+
* @param {string} [params.name] - Application name
|
|
10
|
+
* @param {string} [params.description] - Application description
|
|
11
|
+
* @param {boolean} [params.is_active=true] - Whether the application is active
|
|
12
|
+
* @returns {Promise<Object>} Craeted application
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
async create(params) {
|
|
16
|
+
this._validateCreateParams(params);
|
|
17
|
+
|
|
18
|
+
const response = await this.http.post('/v1/applications', params);
|
|
19
|
+
return response.data;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Get an application by id
|
|
24
|
+
* @param {string} appId - Application ID
|
|
25
|
+
* @returns {Promise<Object>} Application details
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
async get(appId) {
|
|
29
|
+
if (!appId) {
|
|
30
|
+
throw new Error('Applicaiton ID is required.');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const response = await this.http.get(`/v1/applications/${appId}`);
|
|
34
|
+
return response.data;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Update an application
|
|
39
|
+
* @param {string} appId - The application ID
|
|
40
|
+
* @param {Object} params - Application parameters
|
|
41
|
+
* @param {string} [params.name] - New applicatio name
|
|
42
|
+
* @param {string} [params.description] - New description
|
|
43
|
+
* @param {boolean} [params.is_active] - New active status
|
|
44
|
+
* @returns {Promise<Object>} Updated application
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
async update(appId, params) {
|
|
48
|
+
if (!appId) {
|
|
49
|
+
throw new Error('Applicaiton ID is required');
|
|
50
|
+
}
|
|
51
|
+
if (!params || Object.keys(params).length === 0) {
|
|
52
|
+
throw new Error('At least one parameter is required to update');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const response = await this.http.put(`/v1/applications/${appId}`, params);
|
|
56
|
+
return response.data;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Delete an application
|
|
61
|
+
* @param {string} appId - The application ID
|
|
62
|
+
* @return {Promise<Object>} Deletion confirmation
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
async delete(appId) {
|
|
66
|
+
if (!appId) {
|
|
67
|
+
throw new Error('Application ID is required');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const response = await this.http.delete(`/v1/applications/${appId}`);
|
|
71
|
+
return response.data;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* List all applications
|
|
76
|
+
* @returns {Promise<Array>} List of all applications
|
|
77
|
+
*/
|
|
78
|
+
async list() {
|
|
79
|
+
const response = await this.http.get('/v1/applications');
|
|
80
|
+
return response.data;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Get active applications only
|
|
85
|
+
* @returns {Promise<Array>} List of active applications
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
async listActive() {
|
|
89
|
+
const allApps = await this.list();
|
|
90
|
+
return allApps.filter(app => app.is_active === true);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get inactive applications only
|
|
95
|
+
* @returns {Promise<Array>} List of inactive applications
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
async listInactive() {
|
|
99
|
+
const allApps = await this.list();
|
|
100
|
+
return allApps.filter(app => app.is_active === false);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
_validateCreateParams(params) {
|
|
104
|
+
if (!params.name) {
|
|
105
|
+
throw new Error('name is required');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
module.exports = Applications;
|