@verdocs/js-sdk 1.1.1 → 1.1.2
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 +6 -4
- package/Documents/Documents.js +2 -2
- package/Documents/Types.d.ts +11 -10
- package/Users/Auth.d.ts +3 -1
- 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,13 @@ 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[]>;
|
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
|
})];
|
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
|
}
|
package/Users/Auth.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { IAuthenticateAppRequest,
|
|
1
|
+
import { IAuthenticateAppRequest, IAuthenticateUserRequest, TokenValidationRequest, UpdateEmailRequest } from './Types';
|
|
2
|
+
import { IAuthenticateResponse, TokenValidationResponse, UpdateEmailResponse, UpdatePasswordResponse } from './Types';
|
|
3
|
+
import { UpdatePasswordRequest } from './Types';
|
|
2
4
|
/**
|
|
3
5
|
* Authenticate to Verdocs via user/password authentication
|
|
4
6
|
*
|
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
|
-
};
|