Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
DigiGov-OSS
getNncIdentityClient
Commits
de198bc0
Commit
de198bc0
authored
Jan 13, 2022
by
Panagiotis Skarvelis
Browse files
hackish way to make soap to work on both esm/cjs
parent
92a8f01b
Changes
1
Hide whitespace changes
Inline
Side-by-side
dist/esm/soapClient.js
0 → 100644
View file @
de198bc0
import
thesoap
from
'
soap
'
;
let
soap
=
thesoap
;
try
{
soap
=
require
(
'
soap
'
);
}
catch
(
error
)
{
//my hackish way to make soap work on both esm and cjs
//theshoap on esm is undefined
//On esm require is not defined, however on cjs require can be used.
//So we try to use require and if it fails we use the thesoap module
}
/**
* SOAP client for getNncIdentity
* @class Soap
* @description SOAP client for getNncIdentity
* @param {string} wsdl - The URL of the SOAP service
* @param {string} username
* @param {string} password
* @param {AuditRecord} auditRecord
*/
class
Soap
{
_client
;
_wsdl
;
_username
;
_password
;
_auditRecord
;
constructor
(
wsdl
,
username
,
password
,
auditRecord
)
{
this
.
_wsdl
=
wsdl
;
this
.
_username
=
username
;
this
.
_password
=
password
;
this
.
_auditRecord
=
auditRecord
;
}
async
init
()
{
try
{
const
client
=
await
soap
.
createClientAsync
(
this
.
_wsdl
,
{
wsdl_headers
:
{
'
Authorization
'
:
'
Basic
'
+
Buffer
.
from
(
`
${
this
.
_username
}
:
${
this
.
_password
}
`
).
toString
(
'
base64
'
),
},
});
this
.
_client
=
client
;
return
client
;
}
catch
(
e
)
{
throw
e
;
}
}
async
getIdentity
(
vat
)
{
try
{
const
client
=
await
this
.
init
();
var
options
=
{
hasNonce
:
true
,
actor
:
'
actor
'
};
var
wsSecurity
=
new
soap
.
WSSecurity
(
this
.
_username
,
this
.
_password
,
options
);
client
.
setSecurity
(
wsSecurity
);
const
auditRecord
=
this
.
_auditRecord
;
const
args
=
{
auditRecord
:
auditRecord
,
getNncIdentityInputRecord
:
{
afm
:
vat
}
};
const
result
=
await
client
.
getNncIdentityAsync
(
args
);
return
result
[
0
].
getNncIdentityOutputRecord
;
}
catch
(
e
)
{
throw
e
;
}
}
}
export
default
Soap
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment