@verdocs/js-sdk 1.1.1 → 1.1.5
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/Documents/Documents.d.ts +8 -4
- package/Documents/Documents.js +16 -2
- package/Documents/Types.d.ts +11 -10
- package/HTTP/VerdocsEndpoint.d.ts +13 -2
- package/HTTP/VerdocsEndpoint.js +16 -4
- package/Users/Auth.d.ts +17 -1
- package/Users/Auth.js +52 -0
- package/Utils/Token.d.ts +20 -0
- package/Utils/Token.js +67 -0
- package/Utils/index.d.ts +1 -1
- package/Utils/index.js +1 -1
- package/package.json +1 -1
- package/Utils/AtoB.d.ts +0 -1
- package/Utils/AtoB.js +0 -33
package/Documents/Documents.d.ts
CHANGED
|
@@ -138,11 +138,15 @@ export declare const getSummary: (page: number) => Promise<IDocumentsSummary>;
|
|
|
138
138
|
* ```
|
|
139
139
|
*/
|
|
140
140
|
export declare const searchDocuments: (params: any) => Promise<IDocumentsSearchResult>;
|
|
141
|
+
export interface ISigningSessionResult {
|
|
142
|
+
recipient: IRecipient;
|
|
143
|
+
session: ISigningSession;
|
|
144
|
+
signerToken: string;
|
|
145
|
+
}
|
|
141
146
|
/**
|
|
142
147
|
* Get a signing session for a document.
|
|
143
148
|
*/
|
|
144
|
-
export declare const getSigningSession: (params: ISigningSessionRequest) => Promise<
|
|
145
|
-
recipient: IRecipient;
|
|
146
|
-
session: ISigningSession;
|
|
147
|
-
}>;
|
|
149
|
+
export declare const getSigningSession: (params: ISigningSessionRequest) => Promise<ISigningSessionResult>;
|
|
148
150
|
export declare const getDocumentRecipients: (documentId: string) => Promise<IRecipient[]>;
|
|
151
|
+
export declare const getDocument: (documentId: string) => Promise<IDocument>;
|
|
152
|
+
export declare const getDocumentFile: (documentId: string, envelopeDocumentId: string) => Promise<string>;
|
package/Documents/Documents.js
CHANGED
|
@@ -35,7 +35,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
import { getEndpoint } from '../HTTP/Transport';
|
|
38
|
-
import {
|
|
38
|
+
import { decodeAccessTokenBody } from '../Utils/Token';
|
|
39
39
|
/**
|
|
40
40
|
* Get a summary of currently active documents.
|
|
41
41
|
*
|
|
@@ -79,7 +79,7 @@ export var getSigningSession = function (params) { return __awaiter(void 0, void
|
|
|
79
79
|
var _a, _b;
|
|
80
80
|
// Avoiding a jsonwebtoken dependency here - we don't actually need the whole library
|
|
81
81
|
var signerToken = ((_a = r.headers) === null || _a === void 0 ? void 0 : _a.signer_token) || '';
|
|
82
|
-
var session =
|
|
82
|
+
var session = decodeAccessTokenBody(signerToken);
|
|
83
83
|
getEndpoint().setAuthorization((_b = r.headers) === null || _b === void 0 ? void 0 : _b.signer_token);
|
|
84
84
|
return { recipient: r.data, session: session, signerToken: signerToken };
|
|
85
85
|
})];
|
|
@@ -92,3 +92,17 @@ export var getDocumentRecipients = function (documentId) { return __awaiter(void
|
|
|
92
92
|
.then(function (r) { return r.data; })];
|
|
93
93
|
});
|
|
94
94
|
}); };
|
|
95
|
+
export var getDocument = function (documentId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
96
|
+
return __generator(this, function (_a) {
|
|
97
|
+
return [2 /*return*/, getEndpoint()
|
|
98
|
+
.api.get("/documents/".concat(documentId))
|
|
99
|
+
.then(function (r) { return r.data; })];
|
|
100
|
+
});
|
|
101
|
+
}); };
|
|
102
|
+
export var getDocumentFile = function (documentId, envelopeDocumentId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
103
|
+
return __generator(this, function (_a) {
|
|
104
|
+
return [2 /*return*/, getEndpoint()
|
|
105
|
+
.api.get("/documents/".concat(documentId, "/envelope_documents/").concat(envelopeDocumentId, "?file=true"))
|
|
106
|
+
.then(function (r) { return r.data; })];
|
|
107
|
+
});
|
|
108
|
+
}); };
|
package/Documents/Types.d.ts
CHANGED
|
@@ -27,16 +27,17 @@ export interface ISigningSessionRequest {
|
|
|
27
27
|
inviteCode: string;
|
|
28
28
|
}
|
|
29
29
|
export interface ISigningSession {
|
|
30
|
-
profile_id:
|
|
31
|
-
document_id:
|
|
32
|
-
role:
|
|
33
|
-
email:
|
|
30
|
+
profile_id: string;
|
|
31
|
+
document_id: string;
|
|
32
|
+
role: string;
|
|
33
|
+
email: string;
|
|
34
34
|
access_key: {
|
|
35
|
-
id:
|
|
36
|
-
type:
|
|
35
|
+
id: string;
|
|
36
|
+
type: string;
|
|
37
37
|
};
|
|
38
|
-
iss:
|
|
39
|
-
aud:
|
|
40
|
-
exp:
|
|
41
|
-
iat:
|
|
38
|
+
iss: string;
|
|
39
|
+
aud: string;
|
|
40
|
+
exp: number;
|
|
41
|
+
iat: number;
|
|
42
|
+
[key: string]: any;
|
|
42
43
|
}
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { AxiosInstance } from 'axios';
|
|
11
11
|
export declare class VerdocsEndpoint {
|
|
12
|
-
baseURL: string;
|
|
13
12
|
api: AxiosInstance;
|
|
14
13
|
requestLoggerId: number | null;
|
|
15
14
|
/**
|
|
@@ -21,8 +20,9 @@ export declare class VerdocsEndpoint {
|
|
|
21
20
|
* console.log('Current timeout', Transport.getEndpoint().defaults.timeout);
|
|
22
21
|
* ```
|
|
23
22
|
*/
|
|
24
|
-
constructor({ baseURL }?: {
|
|
23
|
+
constructor({ baseURL, timeout }?: {
|
|
25
24
|
baseURL?: string;
|
|
25
|
+
timeout?: number;
|
|
26
26
|
});
|
|
27
27
|
/**
|
|
28
28
|
* Set the timeout for API calls in milliseconds. 2000-4000ms is recommended for most purposes. 3000ms is the default.
|
|
@@ -57,6 +57,17 @@ export declare class VerdocsEndpoint {
|
|
|
57
57
|
* ```
|
|
58
58
|
*/
|
|
59
59
|
setAuthorization(accessToken: string | null): void;
|
|
60
|
+
/**
|
|
61
|
+
* Set the base URL for API calls. May also be set via the constructor.
|
|
62
|
+
*
|
|
63
|
+
* ```typescript
|
|
64
|
+
* import {Endpoint} from '@verdocs/js-sdk/HTTP';
|
|
65
|
+
*
|
|
66
|
+
* const endpoint = new Endpoint();
|
|
67
|
+
* endpoint.setBaseURL('https://api.verdocs.com');
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
setBaseURL(url: string): void;
|
|
60
71
|
/**
|
|
61
72
|
* Enable or disable request logging. This may expose sensitive data in the console log, so it should only be used for debugging.
|
|
62
73
|
*
|
package/HTTP/VerdocsEndpoint.js
CHANGED
|
@@ -24,12 +24,11 @@ var VerdocsEndpoint = /** @class */ (function () {
|
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
26
|
function VerdocsEndpoint(_a) {
|
|
27
|
-
var _b = _a === void 0 ? {} : _a, baseURL = _b.baseURL;
|
|
27
|
+
var _b = _a === void 0 ? {} : _a, baseURL = _b.baseURL, timeout = _b.timeout;
|
|
28
28
|
this.requestLoggerId = null;
|
|
29
|
-
this.baseURL = baseURL || 'https://api.verdocs.com/';
|
|
30
29
|
this.api = axios.create({
|
|
31
|
-
baseURL:
|
|
32
|
-
timeout: 6000,
|
|
30
|
+
baseURL: baseURL || 'https://api.verdocs.com',
|
|
31
|
+
timeout: timeout || 6000,
|
|
33
32
|
});
|
|
34
33
|
}
|
|
35
34
|
/**
|
|
@@ -76,6 +75,19 @@ var VerdocsEndpoint = /** @class */ (function () {
|
|
|
76
75
|
delete this.api.defaults.headers.Authorization;
|
|
77
76
|
}
|
|
78
77
|
};
|
|
78
|
+
/**
|
|
79
|
+
* Set the base URL for API calls. May also be set via the constructor.
|
|
80
|
+
*
|
|
81
|
+
* ```typescript
|
|
82
|
+
* import {Endpoint} from '@verdocs/js-sdk/HTTP';
|
|
83
|
+
*
|
|
84
|
+
* const endpoint = new Endpoint();
|
|
85
|
+
* endpoint.setBaseURL('https://api.verdocs.com');
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
VerdocsEndpoint.prototype.setBaseURL = function (url) {
|
|
89
|
+
this.api.defaults.baseURL = url;
|
|
90
|
+
};
|
|
79
91
|
/**
|
|
80
92
|
* Enable or disable request logging. This may expose sensitive data in the console log, so it should only be used for debugging.
|
|
81
93
|
*
|
package/Users/Auth.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IActiveSession, IAuthenticateAppRequest, IAuthenticateUserRequest, TokenValidationRequest, UpdateEmailRequest } from './Types';
|
|
2
|
+
import { IAuthenticateResponse, TokenValidationResponse, UpdateEmailResponse, UpdatePasswordResponse } from './Types';
|
|
3
|
+
import { UpdatePasswordRequest } from './Types';
|
|
4
|
+
import { ISigningSession } from '../Documents/Types';
|
|
2
5
|
/**
|
|
3
6
|
* Authenticate to Verdocs via user/password authentication
|
|
4
7
|
*
|
|
@@ -77,3 +80,16 @@ export declare const updatePassword: (params: UpdatePasswordRequest) => Promise<
|
|
|
77
80
|
* ```
|
|
78
81
|
*/
|
|
79
82
|
export declare const updateEmail: (params: UpdateEmailRequest) => Promise<UpdateEmailResponse>;
|
|
83
|
+
export declare type TSession = IActiveSession | ISigningSession | null;
|
|
84
|
+
/**
|
|
85
|
+
* Parses and sets the active session, optionally persisting (brower-only, persists to localStorage).
|
|
86
|
+
*/
|
|
87
|
+
export declare const setSession: (source: string, token: string | null, persist?: boolean) => TSession;
|
|
88
|
+
/**
|
|
89
|
+
* Load a session from localStorage
|
|
90
|
+
*/
|
|
91
|
+
export declare const loadSession: (source: string) => IActiveSession | ISigningSession | null;
|
|
92
|
+
/**
|
|
93
|
+
* End the active session.
|
|
94
|
+
*/
|
|
95
|
+
export declare const endSession: (source: string, persist?: boolean) => null;
|
package/Users/Auth.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getEndpoint } from '../HTTP/Transport';
|
|
2
|
+
import { decodeAccessTokenBody } from '../Utils/Token';
|
|
2
3
|
/**
|
|
3
4
|
* Authenticate to Verdocs via user/password authentication
|
|
4
5
|
*
|
|
@@ -101,3 +102,54 @@ export var updateEmail = function (params) {
|
|
|
101
102
|
.api.put('/user/update_email', params)
|
|
102
103
|
.then(function (r) { return r.data; });
|
|
103
104
|
};
|
|
105
|
+
var clearSession = function (source, persist) {
|
|
106
|
+
getEndpoint().setAuthorization(null);
|
|
107
|
+
if (persist) {
|
|
108
|
+
localStorage.removeItem(source);
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Parses and sets the active session, optionally persisting (brower-only, persists to localStorage).
|
|
114
|
+
*/
|
|
115
|
+
export var setSession = function (source, token, persist) {
|
|
116
|
+
if (persist === void 0) { persist = false; }
|
|
117
|
+
if (token === null) {
|
|
118
|
+
return clearSession(source, persist);
|
|
119
|
+
}
|
|
120
|
+
var session = decodeAccessTokenBody(token || '');
|
|
121
|
+
if (session === null || (session.exp && session.exp * 1000 < new Date().getTime())) {
|
|
122
|
+
return clearSession(source, persist);
|
|
123
|
+
}
|
|
124
|
+
if (persist) {
|
|
125
|
+
localStorage.setItem(source, token);
|
|
126
|
+
}
|
|
127
|
+
getEndpoint().setAuthorization(token);
|
|
128
|
+
return session;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Load a session from localStorage
|
|
132
|
+
*/
|
|
133
|
+
export var loadSession = function (source) {
|
|
134
|
+
var token = localStorage.getItem(source);
|
|
135
|
+
if (!token) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
var session = decodeAccessTokenBody(token);
|
|
139
|
+
if (!session) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
if (session.exp && session.exp * 1000 < new Date().getTime()) {
|
|
143
|
+
localStorage.removeItem(source);
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
getEndpoint().setAuthorization(token);
|
|
147
|
+
return session;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* End the active session.
|
|
151
|
+
*/
|
|
152
|
+
export var endSession = function (source, persist) {
|
|
153
|
+
if (persist === void 0) { persist = false; }
|
|
154
|
+
return clearSession(source, persist);
|
|
155
|
+
};
|
package/Utils/Token.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ISigningSession } from '../Documents/Types';
|
|
2
|
+
import { IActiveSession } from '../Users/Types';
|
|
3
|
+
/**
|
|
4
|
+
* Simplified, Node/Browser-safe alternative to atob() for base64 decoding.
|
|
5
|
+
* Modified from https://github.com/MaxArt2501/base64-js/blob/master/base64.js
|
|
6
|
+
*/
|
|
7
|
+
export declare const AtoB: (str: string) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Decode the body of a JWT. This helper may allow front-end applications to avoid a dependency on `jsonwebtoken` in
|
|
10
|
+
* many cases. Note that this should only be used for true JWTs. Opaque tokens will cause this to throw.
|
|
11
|
+
*/
|
|
12
|
+
export declare const decodeTokenBody: (token: string) => any;
|
|
13
|
+
/**
|
|
14
|
+
* Decode the body of an Verdocs access token. Note that raw tokens contain namespaced fields, e.g.
|
|
15
|
+
* `https://verdocs.com/profile_id`. To make these tokens easier to use in front-end code, this name-spacing
|
|
16
|
+
* will be removed. Note that user and signing sessions have different access token formats. The calling
|
|
17
|
+
* application should distinguish between the two based on the context of the authenticated session, or by
|
|
18
|
+
* the presence of the `document_id` field, which will only be present for signing sessions.
|
|
19
|
+
*/
|
|
20
|
+
export declare const decodeAccessTokenBody: (token: string) => IActiveSession | ISigningSession | null;
|
package/Utils/Token.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/* tslint:disable:no-bitwise */
|
|
2
|
+
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
3
|
+
// Regular expression to check formal correctness of base64 encoded strings
|
|
4
|
+
var b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
|
|
5
|
+
/**
|
|
6
|
+
* Simplified, Node/Browser-safe alternative to atob() for base64 decoding.
|
|
7
|
+
* Modified from https://github.com/MaxArt2501/base64-js/blob/master/base64.js
|
|
8
|
+
*/
|
|
9
|
+
export var AtoB = function (str) {
|
|
10
|
+
// atob can work with strings with whitespaces, even inside the encoded part,
|
|
11
|
+
// but only \t, \n, \f, \r and ' ', which can be stripped.
|
|
12
|
+
str = String(str).replace(/[\t\n\f\r ]+/g, '');
|
|
13
|
+
if (!b64re.test(str))
|
|
14
|
+
throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
|
|
15
|
+
// Adding the padding if missing, for semplicity
|
|
16
|
+
str += '=='.slice(2 - (str.length & 3));
|
|
17
|
+
var bitmap;
|
|
18
|
+
var result = '';
|
|
19
|
+
var r1;
|
|
20
|
+
var r2;
|
|
21
|
+
var i = 0;
|
|
22
|
+
for (; i < str.length;) {
|
|
23
|
+
bitmap =
|
|
24
|
+
(b64.indexOf(str.charAt(i++)) << 18) |
|
|
25
|
+
(b64.indexOf(str.charAt(i++)) << 12) |
|
|
26
|
+
((r1 = b64.indexOf(str.charAt(i++))) << 6) |
|
|
27
|
+
(r2 = b64.indexOf(str.charAt(i++)));
|
|
28
|
+
result +=
|
|
29
|
+
r1 === 64
|
|
30
|
+
? String.fromCharCode((bitmap >> 16) & 255)
|
|
31
|
+
: r2 === 64
|
|
32
|
+
? String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255)
|
|
33
|
+
: String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255, bitmap & 255);
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Decode the body of a JWT. This helper may allow front-end applications to avoid a dependency on `jsonwebtoken` in
|
|
39
|
+
* many cases. Note that this should only be used for true JWTs. Opaque tokens will cause this to throw.
|
|
40
|
+
*/
|
|
41
|
+
export var decodeTokenBody = function (token) { return JSON.parse(AtoB((token || '').split('.')[1] || '')); };
|
|
42
|
+
/**
|
|
43
|
+
* Decode the body of an Verdocs access token. Note that raw tokens contain namespaced fields, e.g.
|
|
44
|
+
* `https://verdocs.com/profile_id`. To make these tokens easier to use in front-end code, this name-spacing
|
|
45
|
+
* will be removed. Note that user and signing sessions have different access token formats. The calling
|
|
46
|
+
* application should distinguish between the two based on the context of the authenticated session, or by
|
|
47
|
+
* the presence of the `document_id` field, which will only be present for signing sessions.
|
|
48
|
+
*/
|
|
49
|
+
export var decodeAccessTokenBody = function (token) {
|
|
50
|
+
var decoded;
|
|
51
|
+
try {
|
|
52
|
+
decoded = decodeTokenBody(token);
|
|
53
|
+
if (decoded === null) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
Object.keys(decoded).forEach(function (key) {
|
|
61
|
+
if (typeof key === 'string' && key.startsWith('https://verdocs.com/')) {
|
|
62
|
+
decoded[key.replace('https://verdocs.com/', '')] = decoded[key];
|
|
63
|
+
delete decoded[key];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return decoded;
|
|
67
|
+
};
|
package/Utils/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * as Token from './Token';
|
|
2
2
|
export * as DateTime from './DateTime';
|
package/Utils/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * as Token from './Token';
|
|
2
2
|
export * as DateTime from './DateTime';
|
package/package.json
CHANGED
package/Utils/AtoB.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const AtoB: (str: string) => string;
|
package/Utils/AtoB.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/* tslint:disable:no-bitwise */
|
|
2
|
-
// Modified from https://github.com/MaxArt2501/base64-js/blob/master/base64.js
|
|
3
|
-
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
4
|
-
// Regular expression to check formal correctness of base64 encoded strings
|
|
5
|
-
var b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
|
|
6
|
-
export var AtoB = function (str) {
|
|
7
|
-
// atob can work with strings with whitespaces, even inside the encoded part,
|
|
8
|
-
// but only \t, \n, \f, \r and ' ', which can be stripped.
|
|
9
|
-
str = String(str).replace(/[\t\n\f\r ]+/g, '');
|
|
10
|
-
if (!b64re.test(str))
|
|
11
|
-
throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
|
|
12
|
-
// Adding the padding if missing, for semplicity
|
|
13
|
-
str += '=='.slice(2 - (str.length & 3));
|
|
14
|
-
var bitmap;
|
|
15
|
-
var result = '';
|
|
16
|
-
var r1;
|
|
17
|
-
var r2;
|
|
18
|
-
var i = 0;
|
|
19
|
-
for (; i < str.length;) {
|
|
20
|
-
bitmap =
|
|
21
|
-
(b64.indexOf(str.charAt(i++)) << 18) |
|
|
22
|
-
(b64.indexOf(str.charAt(i++)) << 12) |
|
|
23
|
-
((r1 = b64.indexOf(str.charAt(i++))) << 6) |
|
|
24
|
-
(r2 = b64.indexOf(str.charAt(i++)));
|
|
25
|
-
result +=
|
|
26
|
-
r1 === 64
|
|
27
|
-
? String.fromCharCode((bitmap >> 16) & 255)
|
|
28
|
-
: r2 === 64
|
|
29
|
-
? String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255)
|
|
30
|
-
: String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255, bitmap & 255);
|
|
31
|
-
}
|
|
32
|
-
return result;
|
|
33
|
-
};
|