@verdocs/js-sdk 1.0.25 → 1.0.26
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/HTTP/Endpoint.d.ts +70 -0
- package/HTTP/Endpoint.js +98 -0
- package/HTTP/Transport.d.ts +3 -2
- package/HTTP/Transport.js +3 -2
- package/HTTP/index.d.ts +1 -0
- package/HTTP/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An Endpoint is a specific connection and authorization session for calling the Verdocs APIs. Where the global Transport is generally used
|
|
3
|
+
* to simpliy standard-user operations, Endpoints can be used for isolated session tasks. For instance, ephemeral signing sessions may be
|
|
4
|
+
* created independently of a caller's status as an authenticated user. In that case, an Endpoint can be created and authenticated, used
|
|
5
|
+
* for calls related to signing operations, then discarded once signing is complete.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { AxiosInstance } from 'axios';
|
|
10
|
+
export declare class Endpoint {
|
|
11
|
+
baseURL: string;
|
|
12
|
+
endpoint: AxiosInstance;
|
|
13
|
+
requestLoggerId: number | null;
|
|
14
|
+
/**
|
|
15
|
+
* Create a new Endpoint to call Verdocs services.
|
|
16
|
+
*
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import {Endpoint} from '@verdocs/js-sdk/HTTP';
|
|
19
|
+
*
|
|
20
|
+
* console.log('Current timeout', Transport.getEndpoint().defaults.timeout);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
constructor({ baseURL }: {
|
|
24
|
+
baseURL?: string;
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Set the timeout for API calls in milliseconds. 2000-4000ms is recommended for most purposes. 3000ms is the default.
|
|
28
|
+
*
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import {Endpoint} from '@verdocs/js-sdk/HTTP';
|
|
31
|
+
*
|
|
32
|
+
* const endpoint = new Endpoint();
|
|
33
|
+
* endpoint.setTimeout(3000);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
setTimeout(timeout: number): void;
|
|
37
|
+
/**
|
|
38
|
+
* Set the Client ID for Verdocs API calls.
|
|
39
|
+
*
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import {Endpoint} from '@verdocs/js-sdk/HTTP';
|
|
42
|
+
*
|
|
43
|
+
* const endpoint = new Endpoint();
|
|
44
|
+
* endpoint.setClientID('1234);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
setClientID(clientID: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Set the auth token that will be used for Verdocs API calls.
|
|
50
|
+
*
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import {Endpoint} from '@verdocs/js-sdk/HTTP';
|
|
53
|
+
*
|
|
54
|
+
* const endpoint = new Endpoint();
|
|
55
|
+
* endpoint.setAuthorization(accessToken);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
setAuthorization(accessToken: string | null): void;
|
|
59
|
+
/**
|
|
60
|
+
* Enable or disable request logging. This may expose sensitive data in the console log, so it should only be used for debugging.
|
|
61
|
+
*
|
|
62
|
+
* ```typescript
|
|
63
|
+
* import {Endpoint} from '@verdocs/js-sdk/HTTP';
|
|
64
|
+
*
|
|
65
|
+
* const endpoint = new Endpoint();
|
|
66
|
+
* endpoint.logRequests(true);
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
logRequests(enable: boolean): void;
|
|
70
|
+
}
|
package/HTTP/Endpoint.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An Endpoint is a specific connection and authorization session for calling the Verdocs APIs. Where the global Transport is generally used
|
|
3
|
+
* to simpliy standard-user operations, Endpoints can be used for isolated session tasks. For instance, ephemeral signing sessions may be
|
|
4
|
+
* created independently of a caller's status as an authenticated user. In that case, an Endpoint can be created and authenticated, used
|
|
5
|
+
* for calls related to signing operations, then discarded once signing is complete.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import axios from 'axios';
|
|
10
|
+
var requestLogger = function (r) {
|
|
11
|
+
// tslint:disable-next-line
|
|
12
|
+
console.log("[JS-SDK] ".concat(r.method.toUpperCase(), " ").concat(r.baseURL).concat(r.url), r.data ? JSON.stringify(r.data) : '');
|
|
13
|
+
return r;
|
|
14
|
+
};
|
|
15
|
+
var Endpoint = /** @class */ (function () {
|
|
16
|
+
/**
|
|
17
|
+
* Create a new Endpoint to call Verdocs services.
|
|
18
|
+
*
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import {Endpoint} from '@verdocs/js-sdk/HTTP';
|
|
21
|
+
*
|
|
22
|
+
* console.log('Current timeout', Transport.getEndpoint().defaults.timeout);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function Endpoint(_a) {
|
|
26
|
+
var baseURL = _a.baseURL;
|
|
27
|
+
this.requestLoggerId = null;
|
|
28
|
+
this.baseURL = baseURL || 'https://api.verdocs.com/';
|
|
29
|
+
this.endpoint = axios.create({
|
|
30
|
+
baseURL: this.baseURL,
|
|
31
|
+
timeout: 6000,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Set the timeout for API calls in milliseconds. 2000-4000ms is recommended for most purposes. 3000ms is the default.
|
|
36
|
+
*
|
|
37
|
+
* ```typescript
|
|
38
|
+
* import {Endpoint} from '@verdocs/js-sdk/HTTP';
|
|
39
|
+
*
|
|
40
|
+
* const endpoint = new Endpoint();
|
|
41
|
+
* endpoint.setTimeout(3000);
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
Endpoint.prototype.setTimeout = function (timeout) {
|
|
45
|
+
this.endpoint.defaults.timeout = timeout;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Set the Client ID for Verdocs API calls.
|
|
49
|
+
*
|
|
50
|
+
* ```typescript
|
|
51
|
+
* import {Endpoint} from '@verdocs/js-sdk/HTTP';
|
|
52
|
+
*
|
|
53
|
+
* const endpoint = new Endpoint();
|
|
54
|
+
* endpoint.setClientID('1234);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
Endpoint.prototype.setClientID = function (clientID) {
|
|
58
|
+
this.endpoint.defaults.headers['X-Client-ID'] = clientID;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Set the auth token that will be used for Verdocs API calls.
|
|
62
|
+
*
|
|
63
|
+
* ```typescript
|
|
64
|
+
* import {Endpoint} from '@verdocs/js-sdk/HTTP';
|
|
65
|
+
*
|
|
66
|
+
* const endpoint = new Endpoint();
|
|
67
|
+
* endpoint.setAuthorization(accessToken);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
Endpoint.prototype.setAuthorization = function (accessToken) {
|
|
71
|
+
if (accessToken) {
|
|
72
|
+
this.endpoint.defaults.headers.Authorization = "Bearer ".concat(accessToken);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
delete this.endpoint.defaults.headers.Authorization;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Enable or disable request logging. This may expose sensitive data in the console log, so it should only be used for debugging.
|
|
80
|
+
*
|
|
81
|
+
* ```typescript
|
|
82
|
+
* import {Endpoint} from '@verdocs/js-sdk/HTTP';
|
|
83
|
+
*
|
|
84
|
+
* const endpoint = new Endpoint();
|
|
85
|
+
* endpoint.logRequests(true);
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
Endpoint.prototype.logRequests = function (enable) {
|
|
89
|
+
if (enable && this.requestLoggerId === null) {
|
|
90
|
+
this.requestLoggerId = this.endpoint.interceptors.request.use(requestLogger);
|
|
91
|
+
}
|
|
92
|
+
else if (!enable && this.requestLoggerId !== null) {
|
|
93
|
+
this.endpoint.interceptors.request.eject(this.requestLoggerId);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
return Endpoint;
|
|
97
|
+
}());
|
|
98
|
+
export { Endpoint };
|
package/HTTP/Transport.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The Transport
|
|
3
|
-
* its configuration settings are shared for all callers.
|
|
2
|
+
* The Transport is a global singleton used to call Verdocs APIs. There can only be one Transport per application, and
|
|
3
|
+
* its configuration settings are shared for all callers. This is a simplified form of the Endpoint class where most
|
|
4
|
+
* tasks such as general session-token-management are handled automatically for the caller.
|
|
4
5
|
*
|
|
5
6
|
* @module
|
|
6
7
|
*/
|
package/HTTP/Transport.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The Transport
|
|
3
|
-
* its configuration settings are shared for all callers.
|
|
2
|
+
* The Transport is a global singleton used to call Verdocs APIs. There can only be one Transport per application, and
|
|
3
|
+
* its configuration settings are shared for all callers. This is a simplified form of the Endpoint class where most
|
|
4
|
+
* tasks such as general session-token-management are handled automatically for the caller.
|
|
4
5
|
*
|
|
5
6
|
* @module
|
|
6
7
|
*/
|
package/HTTP/index.d.ts
CHANGED
package/HTTP/index.js
CHANGED