Skip to content

Commit 6d87e16

Browse files
added firma_elettronica
1 parent e7103b9 commit 6d87e16

File tree

4 files changed

+155
-66
lines changed

4 files changed

+155
-66
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"test": "tsc && jest -config=jest.config.json --all",
1111
"build": "tsc",
1212
"tag": "git tag `npm view '@altravia/openapi' version`",
13-
"patch": "npm version patch && npm run tag",
14-
"minor": "npm version minor && npm run tag"
13+
"patch": "npm run build && npm version patch && npm run tag",
14+
"minor": "npm run build && npm version minor && npm run tag"
1515
},
1616
"homepage": "https://developers.openapi.it",
1717
"repository": {

src/Services/FirmaDigitale.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,48 @@ export interface Anagrafica {
3939
note?: string
4040
}
4141

42+
export interface FirmaElettronica {
43+
id: string;
44+
filename: string;
45+
title: string;
46+
description: string;
47+
members: FesMemberResponse[];
48+
status: string;
49+
download_link: string;
50+
callback_status: string;
51+
callback: FesCallback;
52+
}
53+
54+
interface FesCallback {
55+
method: string;
56+
field: string;
57+
url: string;
58+
}
59+
60+
interface FesMemberResponse {
61+
firstname: string;
62+
lastname: string;
63+
email: string;
64+
phone: string;
65+
status: string;
66+
createdAt: number;
67+
updatedAt: number;
68+
sign_link: string;
69+
}
70+
71+
interface FesMember {
72+
firstname: string;
73+
lastname: string;
74+
email: string;
75+
phone: string;
76+
signs: Sign[];
77+
}
78+
79+
interface Sign {
80+
page: number;
81+
position: string;
82+
}
83+
4284
export class FirmaDigitale implements Service {
4385
client: AxiosInstance;
4486
readonly service = 'firmaDigitale';
@@ -79,6 +121,35 @@ export class FirmaDigitale implements Service {
79121
return await (await this.client.post(this.url + '/richiesta/' + codProdotto, JSON.stringify(body))).data.data
80122
}
81123

124+
/**
125+
* Firma digitale
126+
*/
127+
async getFirmaElettronica(id: string): Promise<FirmaElettronica> {
128+
return await (await this.client.get(this.url + '/firma_elettronica/' + id )).data.data;
129+
}
130+
131+
async listFirmaElettronica(): Promise<FirmaElettronica[]> {
132+
return await (await this.client.get(this.url + '/firma_elettronica/')).data.data;
133+
}
134+
135+
async createFirmaElettronica(filename: string, content: string, members: FesMember[], callback?: FesCallback, title?: string, description?: string): Promise<FirmaElettronica> {
136+
let body: any = {
137+
filename,
138+
content,
139+
members,
140+
callback
141+
};
142+
143+
if (title) body.title = title;
144+
if (description) body.description = description;
145+
146+
return await (await this.client.post(this.url + '/firma_elettronica/base', JSON.stringify(body))).data.data;
147+
}
148+
149+
async downloadFirmaElettronica(id: string): Promise<string> {
150+
return await (await this.client.get(this.url + '/firma_elettronica/' + id + '/download')).data.content;
151+
}
152+
82153
get url() {
83154
return getBaseUrl(this.environment, this.baseUrl)
84155
}

test/client.test.js

Lines changed: 82 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// import OpenApi from '../dist/index';
2+
const fs = require('fs');
23
let OpenApi = require('../dist/index').default;
34

45
const scopes = [
@@ -129,18 +130,35 @@ const scopes = [
129130
// const piva = await client.pa.findPa('00559720982')
130131
// expect(piva).toBeDefined();
131132
// })
132-
// test('testFD', async function() {
133-
// let client = await OpenApi.init('test', process.env.OPENAPI_USERNAME, process.env.API_KEY, process.env.TOKEN);
134-
// const prodotti = await client.firmaDigitale.getProducts();
135-
// expect(prodotti).toBeDefined();
136133

137-
// const richiesta = await client.firmaDigitale.requestProduct('RINFIR', {})
138-
// expect(richiesta.id).toBeDefined()
134+
test('testFD', async function() {
135+
let client = await OpenApi.init('test', process.env.OPENAPI_USERNAME, process.env.API_KEY, process.env.TOKEN);
136+
// const prodotti = await client.firmaDigitale.getProducts();
137+
// expect(prodotti).toBeDefined();
139138

140-
// const infoRichiesta = await client.firmaDigitale.getRequest(richiesta.id)
141-
// expect(infoRichiesta).toBeDefined()
142-
// console.log(infoRichiesta);
143-
// })
139+
// const richiesta = await client.firmaDigitale.requestProduct('RINFIR', {})
140+
// expect(richiesta.id).toBeDefined()
141+
142+
// const infoRichiesta = await client.firmaDigitale.getRequest(richiesta.id)
143+
// expect(infoRichiesta).toBeDefined()
144+
// console.log(infoRichiesta);
145+
146+
const listaFirmaElettroniche = await client.firmaDigitale.listFirmaElettronica();
147+
expect(listaFirmaElettroniche).toBeDefined();
148+
console.log(listaFirmaElettroniche);
149+
150+
const pdf = await fs.promises.readFile(__dirname + '/resources/testosemplice.pdf')
151+
const newFirmaElettronica = await client.firmaDigitale.createFirmaElettronica('test.pdf', pdf.toString('base64'), [
152+
{
153+
'firstname': 'test',
154+
'lastname': 'test',
155+
'email': 'test@altravia.com',
156+
'phone': '+39321321321',
157+
}
158+
]).catch(e => console.log(e))
159+
160+
expect(newFirmaElettronica).toBeDefined();
161+
})
144162

145163
// test('testMT', async function() {
146164
// let client = await OpenApi.init('test', process.env.OPENAPI_USERNAME, process.env.API_KEY, process.env.TOKEN);
@@ -189,58 +207,58 @@ const scopes = [
189207
// console.log(JSON.stringify(sms, null, 2));
190208
// })
191209

192-
test('testUP', async function() {
193-
let client = await OpenApi.init('test', process.env.OPENAPI_USERNAME, process.env.API_KEY, process.env.TOKEN);
194-
// const list = await client.ufficioPostale.listRaccomandate('NEW')
195-
// expect(list).toBeDefined()
196-
const mitt = {
197-
"titolo": "mr",
198-
"nome": "Simone",
199-
"dug": "SST",
200-
"indirizzo": "Valnerina",
201-
"civico": "1",
202-
"comune": "montefranco",
203-
"cap": "05030",
204-
"provincia": "tr",
205-
"nazione": "Italia",
206-
"email": "s.desantis@altravia.com",
207-
"ragione_sociale": "privato",
208-
"cognome": "xxx"
209-
}
210-
211-
const dest = {
212-
"nome": "Simone",
213-
"cognome": "Desantis",
214-
"co": "Altravia Servizi SRL",
215-
"dug": "piazza",
216-
"indirizzo": "San Giovanni Decollato",
217-
"civico": "6",
218-
"comune": "Terni",
219-
"cap": "05100",
220-
"provincia": "TR",
221-
"nazione": "Italia"
222-
}
223-
224-
// const comuni = await client.ufficioPostale.comuni('00143')
225-
// expect(comuni).toBeDefined()
226-
// console.log(comuni);
227-
228-
// const r = await client.ufficioPostale.createRaccomandata(mitt, [dest], ['Test'], false).catch(e => console.log(e))
229-
// const result = await client.ufficioPostale.confirmRaccomandata(r[0].id).catch(e => console.log(e))
230-
// expect(result).toBeDefined()
231-
// console.log(result);
232-
233-
// const t = await client.ufficioPostale.createTelegramma(mitt, [dest], 'Test', false)
234-
// const resultTelegramma = await client.ufficioPostale.confirmTelegramma(t[0].id).catch(e => console.log(e))
235-
// expect(resultTelegramma).toBeDefined()
236-
// console.log(resultTelegramma);
237-
238-
// const pricing = await client.ufficioPostale.pricing().catch(e => console.log(e))
239-
// expect(pricing).toBeDefined()
240-
// console.log(pricing);
241-
242-
// const dugs = await client.ufficioPostale.listDug().catch(e => console.log(e))
243-
// expect(dugs).toBeDefined()
244-
// console.log(dugs)
245-
})
210+
// test('testUP', async function() {
211+
// let client = await OpenApi.init('test', process.env.OPENAPI_USERNAME, process.env.API_KEY, process.env.TOKEN);
212+
// // const list = await client.ufficioPostale.listRaccomandate('NEW')
213+
// // expect(list).toBeDefined()
214+
// const mitt = {
215+
// "titolo": "mr",
216+
// "nome": "Simone",
217+
// "dug": "SST",
218+
// "indirizzo": "Valnerina",
219+
// "civico": "1",
220+
// "comune": "montefranco",
221+
// "cap": "05030",
222+
// "provincia": "tr",
223+
// "nazione": "Italia",
224+
// "email": "s.desantis@altravia.com",
225+
// "ragione_sociale": "privato",
226+
// "cognome": "xxx"
227+
// }
228+
229+
// const dest = {
230+
// "nome": "Simone",
231+
// "cognome": "Desantis",
232+
// "co": "Altravia Servizi SRL",
233+
// "dug": "piazza",
234+
// "indirizzo": "San Giovanni Decollato",
235+
// "civico": "6",
236+
// "comune": "Terni",
237+
// "cap": "05100",
238+
// "provincia": "TR",
239+
// "nazione": "Italia"
240+
// }
241+
242+
// // const comuni = await client.ufficioPostale.comuni('00143')
243+
// // expect(comuni).toBeDefined()
244+
// // console.log(comuni);
245+
246+
// // const r = await client.ufficioPostale.createRaccomandata(mitt, [dest], ['Test'], false).catch(e => console.log(e))
247+
// // const result = await client.ufficioPostale.confirmRaccomandata(r[0].id).catch(e => console.log(e))
248+
// // expect(result).toBeDefined()
249+
// // console.log(result);
250+
251+
// // const t = await client.ufficioPostale.createTelegramma(mitt, [dest], 'Test', false)
252+
// // const resultTelegramma = await client.ufficioPostale.confirmTelegramma(t[0].id).catch(e => console.log(e))
253+
// // expect(resultTelegramma).toBeDefined()
254+
// // console.log(resultTelegramma);
255+
256+
// // const pricing = await client.ufficioPostale.pricing().catch(e => console.log(e))
257+
// // expect(pricing).toBeDefined()
258+
// // console.log(pricing);
259+
260+
// // const dugs = await client.ufficioPostale.listDug().catch(e => console.log(e))
261+
// // expect(dugs).toBeDefined()
262+
// // console.log(dugs)
263+
// })
246264

test/resources/testosemplice.pdf

2.17 KB
Binary file not shown.

0 commit comments

Comments
 (0)