@brifle/brifle-sdk 0.0.5 → 0.2.0
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/dist/api/api.js +79 -0
- package/dist/cjs/api/api.d.ts +6 -0
- package/dist/cjs/endpoints/v1/content.d.ts +16 -1
- package/dist/cjs/endpoints/v1/requests/content.d.ts +31 -2
- package/dist/cjs/endpoints/v1/requests/mailbox.d.ts +2 -0
- package/dist/cjs/endpoints/v1/responses/content.d.ts +35 -22
- package/dist/cjs/endpoints/v1/responses/status.d.ts +8 -0
- package/dist/cjs/endpoints/v1/status.d.ts +16 -0
- package/dist/cjs/index.js +68 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/endpoints/v1/accounts.js +32 -0
- package/dist/endpoints/v1/apiResponse.js +64 -0
- package/dist/endpoints/v1/authentication.js +43 -0
- package/dist/endpoints/v1/content.js +131 -0
- package/dist/endpoints/v1/mailbox.js +55 -0
- package/dist/endpoints/v1/requests/authentication.js +1 -0
- package/dist/endpoints/v1/requests/content.js +1 -0
- package/dist/endpoints/v1/requests/mailbox.js +1 -0
- package/dist/endpoints/v1/requests/signatures.js +1 -0
- package/dist/endpoints/v1/responses/accounts.js +1 -0
- package/dist/endpoints/v1/responses/authentication.js +1 -0
- package/dist/endpoints/v1/responses/content.js +1 -0
- package/dist/endpoints/v1/responses/mailbox.js +1 -0
- package/dist/endpoints/v1/responses/signatures.js +1 -0
- package/dist/endpoints/v1/responses/status.js +1 -0
- package/dist/endpoints/v1/responses/tenant.js +1 -0
- package/dist/endpoints/v1/signatures.js +55 -0
- package/dist/endpoints/v1/status.js +27 -0
- package/dist/endpoints/v1/tenant.js +49 -0
- package/dist/esm/api/api.d.ts +6 -0
- package/dist/esm/endpoints/v1/content.d.ts +16 -1
- package/dist/esm/endpoints/v1/requests/content.d.ts +31 -2
- package/dist/esm/endpoints/v1/requests/mailbox.d.ts +2 -0
- package/dist/esm/endpoints/v1/responses/content.d.ts +35 -22
- package/dist/esm/endpoints/v1/responses/status.d.ts +8 -0
- package/dist/esm/endpoints/v1/status.d.ts +16 -0
- package/dist/esm/index.mjs +68 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/index.d.ts +109 -23
- package/dist/index.js +18 -0
- package/dist/types/api/api.d.ts +6 -0
- package/dist/types/endpoints/v1/content.d.ts +16 -1
- package/dist/types/endpoints/v1/requests/content.d.ts +31 -2
- package/dist/types/endpoints/v1/requests/mailbox.d.ts +2 -0
- package/dist/types/endpoints/v1/responses/content.d.ts +35 -22
- package/dist/types/endpoints/v1/responses/status.d.ts +8 -0
- package/dist/types/endpoints/v1/status.d.ts +16 -0
- package/package.json +2 -1
package/dist/api/api.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { AuthenticationEndpoints } from "../endpoints/v1/authentication";
|
|
2
|
+
import { ContentEndpoints } from "../endpoints/v1/content";
|
|
3
|
+
import { SignaturesEndpoint } from "../endpoints/v1/signatures";
|
|
4
|
+
import { MailboxEndpoints } from "../endpoints/v1/mailbox";
|
|
5
|
+
import { TenantsEndpoints } from "../endpoints/v1/tenant";
|
|
6
|
+
import { AccountsEndpoints } from "../endpoints/v1/accounts";
|
|
7
|
+
import { StatusEndpoint } from "../endpoints/v1/status";
|
|
8
|
+
var ENDPOINTS;
|
|
9
|
+
(function (ENDPOINTS) {
|
|
10
|
+
ENDPOINTS["SANDBOX"] = "https://sandbox-api.brifle.de";
|
|
11
|
+
ENDPOINTS["PRODUCTION"] = "https://api.brifle.de";
|
|
12
|
+
})(ENDPOINTS || (ENDPOINTS = {}));
|
|
13
|
+
class ApiV1 {
|
|
14
|
+
constructor(endpoint) {
|
|
15
|
+
if (endpoint.endsWith("/")) {
|
|
16
|
+
this.endpoint = endpoint.slice(0, -1);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
this.endpoint = endpoint;
|
|
20
|
+
}
|
|
21
|
+
this.apiState = {};
|
|
22
|
+
}
|
|
23
|
+
static get sandbox() {
|
|
24
|
+
return new ApiV1(ENDPOINTS.SANDBOX);
|
|
25
|
+
}
|
|
26
|
+
static get production() {
|
|
27
|
+
return new ApiV1(ENDPOINTS.PRODUCTION);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* gets an instance of the AuthenticationEndpoints
|
|
31
|
+
* @returns AuthenticationEndpoints
|
|
32
|
+
*/
|
|
33
|
+
authentication() {
|
|
34
|
+
return new AuthenticationEndpoints(this);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* gets an instance of the ContentEndpoints
|
|
38
|
+
* @returns ContentEndpoints
|
|
39
|
+
*/
|
|
40
|
+
content() {
|
|
41
|
+
return new ContentEndpoints(this);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* gets an instance of the SignatureEndpoints
|
|
45
|
+
* @returns ContentEndpoints
|
|
46
|
+
*/
|
|
47
|
+
signature() {
|
|
48
|
+
return new SignaturesEndpoint(this);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* gets an instance of the TenantsEndpoints
|
|
52
|
+
* @returns TenantsEndpoints
|
|
53
|
+
*/
|
|
54
|
+
tenants() {
|
|
55
|
+
return new TenantsEndpoints(this);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* gets an instance of the AccountsEndpoints
|
|
59
|
+
* @returns AccountsEndpoints
|
|
60
|
+
*/
|
|
61
|
+
accounts() {
|
|
62
|
+
return new AccountsEndpoints(this);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* gets an instance of the MailboxEndpoints
|
|
66
|
+
* @returns MailboxEndpoints
|
|
67
|
+
*/
|
|
68
|
+
mailbox() {
|
|
69
|
+
return new MailboxEndpoints(this);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* gets an instance of the StatusEndpoint
|
|
73
|
+
* @returns StatusEndpoint
|
|
74
|
+
*/
|
|
75
|
+
status() {
|
|
76
|
+
return new StatusEndpoint(this);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export { ApiV1 };
|
package/dist/cjs/api/api.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { SignaturesEndpoint } from "../endpoints/v1/signatures";
|
|
|
4
4
|
import { MailboxEndpoints } from "../endpoints/v1/mailbox";
|
|
5
5
|
import { TenantsEndpoints } from "../endpoints/v1/tenant";
|
|
6
6
|
import { AccountsEndpoints } from "../endpoints/v1/accounts";
|
|
7
|
+
import { StatusEndpoint } from "../endpoints/v1/status";
|
|
7
8
|
declare class ApiV1 {
|
|
8
9
|
readonly endpoint: string;
|
|
9
10
|
readonly apiState: ApiV1State;
|
|
@@ -40,6 +41,11 @@ declare class ApiV1 {
|
|
|
40
41
|
* @returns MailboxEndpoints
|
|
41
42
|
*/
|
|
42
43
|
mailbox(): MailboxEndpoints;
|
|
44
|
+
/**
|
|
45
|
+
* gets an instance of the StatusEndpoint
|
|
46
|
+
* @returns StatusEndpoint
|
|
47
|
+
*/
|
|
48
|
+
status(): StatusEndpoint;
|
|
43
49
|
}
|
|
44
50
|
export interface ApiV1State {
|
|
45
51
|
auth_token?: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ApiResponse } from "./apiResponse";
|
|
2
|
-
import { CheckReceiverResponse, ContentActionsResponse, ContentResponse, SendContentResponse } from "./responses/content";
|
|
2
|
+
import { CheckReceiverResponse, ContentActionsResponse, ContentResponse, CoverLetterOverviewResponse, SendContentResponse } from "./responses/content";
|
|
3
3
|
import { ApiV1 } from "../../api/api";
|
|
4
4
|
import { ReceiverRequest, SendContentRequest } from "./requests/content";
|
|
5
5
|
declare class ContentEndpoints {
|
|
@@ -38,5 +38,20 @@ declare class ContentEndpoints {
|
|
|
38
38
|
* @returns
|
|
39
39
|
*/
|
|
40
40
|
sendContent(tenantId: string, request: SendContentRequest): Promise<ApiResponse<SendContentResponse>>;
|
|
41
|
+
/**
|
|
42
|
+
* list all cover letters for a tenant
|
|
43
|
+
* @param tenantId - The tenant id
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
listCoverLetters(tenantId: string): Promise<ApiResponse<CoverLetterOverviewResponse>>;
|
|
47
|
+
/**
|
|
48
|
+
* get the content of a cover letter
|
|
49
|
+
* @param tenantId - The tenant id
|
|
50
|
+
* @param type - The type of the cover letter (custom | default)
|
|
51
|
+
* @param name - The name of the cover letter
|
|
52
|
+
* @param encoding - The encoding of the cover letter (base64 | pdf)
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
getCoverLetterContent(tenantId: string, type: 'custom' | 'default', name: string, encoding: 'base64' | 'pdf'): Promise<import("axios").AxiosResponse<Blob, any>>;
|
|
41
56
|
}
|
|
42
57
|
export { ContentEndpoints };
|
|
@@ -9,6 +9,17 @@ interface ReceiverRequest {
|
|
|
9
9
|
last_name?: string;
|
|
10
10
|
full_name?: string;
|
|
11
11
|
date_of_birth?: string;
|
|
12
|
+
postal_address?: PostalAddress;
|
|
13
|
+
}
|
|
14
|
+
interface PostalAddress {
|
|
15
|
+
city: string;
|
|
16
|
+
country: string;
|
|
17
|
+
date_of_birth?: string;
|
|
18
|
+
first_name: string;
|
|
19
|
+
house_number: string;
|
|
20
|
+
last_name: string;
|
|
21
|
+
postcode: string;
|
|
22
|
+
street: string;
|
|
12
23
|
}
|
|
13
24
|
interface BirthInformation {
|
|
14
25
|
birth_name?: string;
|
|
@@ -17,7 +28,7 @@ interface BirthInformation {
|
|
|
17
28
|
nationality?: string;
|
|
18
29
|
given_names?: string;
|
|
19
30
|
last_name?: string;
|
|
20
|
-
|
|
31
|
+
postal_address?: string;
|
|
21
32
|
}
|
|
22
33
|
interface PaymentDetails {
|
|
23
34
|
amount: number;
|
|
@@ -35,6 +46,7 @@ interface SendContentRequest {
|
|
|
35
46
|
type: 'application/pdf';
|
|
36
47
|
content: string;
|
|
37
48
|
}[];
|
|
49
|
+
fallback?: FallbackOptions;
|
|
38
50
|
payment_info?: {
|
|
39
51
|
details?: PaymentDetails;
|
|
40
52
|
payable: boolean;
|
|
@@ -47,4 +59,21 @@ interface SendContentRequest {
|
|
|
47
59
|
}[];
|
|
48
60
|
};
|
|
49
61
|
}
|
|
50
|
-
|
|
62
|
+
interface FallbackOptions {
|
|
63
|
+
enabled_physical_delivery: boolean;
|
|
64
|
+
paper_mail: {
|
|
65
|
+
recipient: {
|
|
66
|
+
address_line1: string;
|
|
67
|
+
address_line2?: string;
|
|
68
|
+
address_line3?: string;
|
|
69
|
+
postal_code: string;
|
|
70
|
+
city: string;
|
|
71
|
+
country: string;
|
|
72
|
+
};
|
|
73
|
+
test_mode: {
|
|
74
|
+
email: string;
|
|
75
|
+
enabled: boolean;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export type { SendContentRequest, ReceiverRequest, BirthInformation, PaymentDetails, FallbackOptions };
|
|
@@ -19,14 +19,16 @@ interface ContentMeta {
|
|
|
19
19
|
size: number;
|
|
20
20
|
subject: string;
|
|
21
21
|
type: string;
|
|
22
|
+
size_responsive?: number;
|
|
22
23
|
}
|
|
23
24
|
interface ContentResponse {
|
|
24
|
-
content:
|
|
25
|
-
content: string;
|
|
26
|
-
type: string;
|
|
27
|
-
};
|
|
25
|
+
content: Content[];
|
|
28
26
|
meta: ContentMeta;
|
|
29
27
|
}
|
|
28
|
+
interface Content {
|
|
29
|
+
content: string;
|
|
30
|
+
type: string;
|
|
31
|
+
}
|
|
30
32
|
interface ContentActionsPaymentResponse {
|
|
31
33
|
details: {
|
|
32
34
|
amount: number;
|
|
@@ -39,30 +41,41 @@ interface ContentActionsPaymentResponse {
|
|
|
39
41
|
};
|
|
40
42
|
link: string;
|
|
41
43
|
}
|
|
44
|
+
interface CoverLetterOverviewItem {
|
|
45
|
+
type: string;
|
|
46
|
+
name: string;
|
|
47
|
+
display_name: string;
|
|
48
|
+
}
|
|
49
|
+
interface CoverLetterOverviewResponse {
|
|
50
|
+
cover_letters: CoverLetterOverviewItem[];
|
|
51
|
+
}
|
|
52
|
+
interface EmbbededSignatureResponse {
|
|
53
|
+
id: string;
|
|
54
|
+
created_by: string;
|
|
55
|
+
created_date: string;
|
|
56
|
+
document_signature_id: string;
|
|
57
|
+
due_date: string;
|
|
58
|
+
field_name: string;
|
|
59
|
+
history?: string;
|
|
60
|
+
purpose: string;
|
|
61
|
+
request_date: string;
|
|
62
|
+
requested_to: string;
|
|
63
|
+
signature_date: string;
|
|
64
|
+
signed_by: string;
|
|
65
|
+
signed_for: string;
|
|
66
|
+
value: string;
|
|
67
|
+
status: 'pending' | 'signed' | 'rejected';
|
|
68
|
+
}
|
|
42
69
|
interface ContentActionsSignatureResponse {
|
|
43
70
|
document_signatures: {
|
|
44
71
|
signature_ids: string[];
|
|
45
72
|
signature_reference: string;
|
|
46
73
|
};
|
|
47
|
-
embedded_signatures:
|
|
48
|
-
created_by: string;
|
|
49
|
-
created_date: string;
|
|
50
|
-
document_signature_id: string;
|
|
51
|
-
due_date: string;
|
|
52
|
-
field_name: string;
|
|
53
|
-
history?: string;
|
|
54
|
-
purpose: string;
|
|
55
|
-
request_date: string;
|
|
56
|
-
requested_to: string;
|
|
57
|
-
signature_date: string;
|
|
58
|
-
signed_by: string;
|
|
59
|
-
signed_for: string;
|
|
60
|
-
value: string;
|
|
61
|
-
}[];
|
|
74
|
+
embedded_signatures: EmbbededSignatureResponse[];
|
|
62
75
|
signature_reference: string;
|
|
63
76
|
}
|
|
64
77
|
interface ContentActionsResponse {
|
|
65
|
-
payments: ContentActionsPaymentResponse
|
|
66
|
-
signatures: ContentActionsSignatureResponse
|
|
78
|
+
payments: ContentActionsPaymentResponse;
|
|
79
|
+
signatures: ContentActionsSignatureResponse;
|
|
67
80
|
}
|
|
68
|
-
export type { SendContentResponse, CheckReceiverResponse, ContentMeta, ContentResponse, ContentActionsResponse };
|
|
81
|
+
export type { EmbbededSignatureResponse, Content, CoverLetterOverviewResponse, CoverLetterOverviewItem, ContentActionsSignatureResponse, ContentActionsPaymentResponse, SendContentResponse, CheckReceiverResponse, ContentMeta, ContentResponse, ContentActionsResponse };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ApiV1 } from "../../api/api";
|
|
2
|
+
import { ApiResponse } from "./apiResponse";
|
|
3
|
+
import { StatusResponse } from "./responses/status";
|
|
4
|
+
declare class StatusEndpoint {
|
|
5
|
+
private endpoint;
|
|
6
|
+
private readonly VERSION;
|
|
7
|
+
private state;
|
|
8
|
+
constructor(api: ApiV1);
|
|
9
|
+
private getPath;
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @returns the
|
|
13
|
+
*/
|
|
14
|
+
getStatus(): Promise<ApiResponse<StatusResponse>>;
|
|
15
|
+
}
|
|
16
|
+
export { StatusEndpoint };
|
package/dist/cjs/index.js
CHANGED
|
@@ -199,6 +199,42 @@ class ContentEndpoints {
|
|
|
199
199
|
return ApiResponse.errorAxios(error);
|
|
200
200
|
});
|
|
201
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* list all cover letters for a tenant
|
|
204
|
+
* @param tenantId - The tenant id
|
|
205
|
+
* @returns
|
|
206
|
+
*/
|
|
207
|
+
listCoverLetters(tenantId) {
|
|
208
|
+
const path = this.getPath(`cover_letters/${tenantId}/list`);
|
|
209
|
+
return axios.get(path, {
|
|
210
|
+
headers: {
|
|
211
|
+
"Authorization": `Bearer ${this.state.auth_token}`
|
|
212
|
+
}
|
|
213
|
+
})
|
|
214
|
+
.then((response) => {
|
|
215
|
+
return ApiResponse.success(response.data);
|
|
216
|
+
})
|
|
217
|
+
.catch((error) => {
|
|
218
|
+
return ApiResponse.errorAxios(error);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* get the content of a cover letter
|
|
223
|
+
* @param tenantId - The tenant id
|
|
224
|
+
* @param type - The type of the cover letter (custom | default)
|
|
225
|
+
* @param name - The name of the cover letter
|
|
226
|
+
* @param encoding - The encoding of the cover letter (base64 | pdf)
|
|
227
|
+
* @returns
|
|
228
|
+
*/
|
|
229
|
+
getCoverLetterContent(tenantId, type, name, encoding) {
|
|
230
|
+
const path = this.getPath(`cover_letter/${tenantId}/${type}/${name}/${encoding}`);
|
|
231
|
+
return axios.get(path, {
|
|
232
|
+
headers: {
|
|
233
|
+
"Authorization": `Bearer ${this.state.auth_token}`
|
|
234
|
+
},
|
|
235
|
+
responseType: 'blob'
|
|
236
|
+
});
|
|
237
|
+
}
|
|
202
238
|
}
|
|
203
239
|
|
|
204
240
|
class SignaturesEndpoint {
|
|
@@ -384,6 +420,31 @@ class AccountsEndpoints {
|
|
|
384
420
|
}
|
|
385
421
|
}
|
|
386
422
|
|
|
423
|
+
class StatusEndpoint {
|
|
424
|
+
constructor(api) {
|
|
425
|
+
this.VERSION = "v1";
|
|
426
|
+
this.endpoint = api.endpoint;
|
|
427
|
+
this.state = api.apiState;
|
|
428
|
+
}
|
|
429
|
+
getPath(path) {
|
|
430
|
+
return `${this.endpoint}/${this.VERSION}/status/${path}`;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
*
|
|
434
|
+
* @returns the
|
|
435
|
+
*/
|
|
436
|
+
getStatus() {
|
|
437
|
+
const path = this.getPath("");
|
|
438
|
+
return axios.get(path)
|
|
439
|
+
.then((response) => {
|
|
440
|
+
return ApiResponse.success(response.data);
|
|
441
|
+
})
|
|
442
|
+
.catch((error) => {
|
|
443
|
+
return ApiResponse.errorAxios(error);
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
387
448
|
var ENDPOINTS;
|
|
388
449
|
(function (ENDPOINTS) {
|
|
389
450
|
ENDPOINTS["SANDBOX"] = "https://sandbox-api.brifle.de";
|
|
@@ -447,6 +508,13 @@ class ApiV1 {
|
|
|
447
508
|
mailbox() {
|
|
448
509
|
return new MailboxEndpoints(this);
|
|
449
510
|
}
|
|
511
|
+
/**
|
|
512
|
+
* gets an instance of the StatusEndpoint
|
|
513
|
+
* @returns StatusEndpoint
|
|
514
|
+
*/
|
|
515
|
+
status() {
|
|
516
|
+
return new StatusEndpoint(this);
|
|
517
|
+
}
|
|
450
518
|
}
|
|
451
519
|
|
|
452
520
|
exports.AccountsEndpoints = AccountsEndpoints;
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { ApiResponse } from "./apiResponse";
|
|
3
|
+
class AccountsEndpoints {
|
|
4
|
+
constructor(api) {
|
|
5
|
+
this.VERSION = "v1";
|
|
6
|
+
this.endpoint = api.endpoint;
|
|
7
|
+
this.state = api.apiState;
|
|
8
|
+
}
|
|
9
|
+
getPath(path) {
|
|
10
|
+
return `${this.endpoint}/${this.VERSION}/accounts/${path}`;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Gets a tenant by its ID
|
|
14
|
+
*/
|
|
15
|
+
getById(accountId) {
|
|
16
|
+
const path = this.getPath(`${accountId}`);
|
|
17
|
+
console.log(path, path);
|
|
18
|
+
return axios.get(path, {
|
|
19
|
+
headers: {
|
|
20
|
+
"Authorization": `Bearer ${this.state.auth_token}`,
|
|
21
|
+
"Content-Type": "application/json"
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
.then((response) => {
|
|
25
|
+
return ApiResponse.success(response.data);
|
|
26
|
+
})
|
|
27
|
+
.catch((error) => {
|
|
28
|
+
return ApiResponse.errorAxios(error);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export { AccountsEndpoints };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export class ApiResponse {
|
|
2
|
+
constructor(data, error) {
|
|
3
|
+
this._data = data;
|
|
4
|
+
this._error = error;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* create a success response from data
|
|
8
|
+
* @param data - The data to return
|
|
9
|
+
*/
|
|
10
|
+
static success(data) {
|
|
11
|
+
return new ApiResponse(data);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* create an error response from an AxiosError
|
|
15
|
+
* @param error - The AxiosError object
|
|
16
|
+
*/
|
|
17
|
+
static error(error) {
|
|
18
|
+
return new ApiResponse(undefined, error);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* create an error response from an AxiosError
|
|
22
|
+
* @param error - The AxiosError object
|
|
23
|
+
*/
|
|
24
|
+
static errorAxios(error) {
|
|
25
|
+
const response = error.response;
|
|
26
|
+
if (response === undefined) {
|
|
27
|
+
return ApiResponse.error({
|
|
28
|
+
code: 50000,
|
|
29
|
+
message: "Unknown error",
|
|
30
|
+
status: 500
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
const data = response.data;
|
|
34
|
+
return ApiResponse.error({
|
|
35
|
+
code: data.code,
|
|
36
|
+
message: data.message,
|
|
37
|
+
status: response.status
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* check if the response is a success
|
|
42
|
+
*/
|
|
43
|
+
get isSuccess() {
|
|
44
|
+
return this._data !== undefined;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* check if the response is an error
|
|
48
|
+
*/
|
|
49
|
+
get isError() {
|
|
50
|
+
return this._error !== undefined;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* get the data from the response
|
|
54
|
+
*/
|
|
55
|
+
get data() {
|
|
56
|
+
return this._data;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* get the error from the response
|
|
60
|
+
*/
|
|
61
|
+
get error() {
|
|
62
|
+
return this._error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ApiResponse } from "./apiResponse";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
class AuthenticationEndpoints {
|
|
4
|
+
constructor(api) {
|
|
5
|
+
this.VERSION = "v1";
|
|
6
|
+
this.endpoint = api.endpoint;
|
|
7
|
+
this.state = api.apiState;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* builds the full path
|
|
11
|
+
* @param path - The path to the endpoint, e.g. "authentication/login"
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
getPath(path) {
|
|
15
|
+
return `${this.endpoint}/${this.VERSION}/auth/${path}`;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* login to the API
|
|
19
|
+
* @param loginRequest - The login request object
|
|
20
|
+
* @returns the login response object
|
|
21
|
+
*/
|
|
22
|
+
login(loginRequest) {
|
|
23
|
+
const path = this.getPath("login");
|
|
24
|
+
// axios.post(path, loginRequest)
|
|
25
|
+
return axios.post(path, loginRequest)
|
|
26
|
+
.then((response) => {
|
|
27
|
+
return ApiResponse.success(response.data);
|
|
28
|
+
}).then((response) => {
|
|
29
|
+
var _a, _b, _c, _d, _e;
|
|
30
|
+
const at = (_a = response.data) === null || _a === void 0 ? void 0 : _a.access_token;
|
|
31
|
+
this.state.auth_token = at;
|
|
32
|
+
const expire_in = ((_c = (_b = response.data) === null || _b === void 0 ? void 0 : _b.expires_in) !== null && _c !== void 0 ? _c : 0) * 1000;
|
|
33
|
+
const issue_time = new Date((_e = (_d = response.data) === null || _d === void 0 ? void 0 : _d.created_at) !== null && _e !== void 0 ? _e : new Date()).getMilliseconds();
|
|
34
|
+
const expires_milli = issue_time + expire_in;
|
|
35
|
+
this.state.auth_token_expire_date = new Date(expires_milli);
|
|
36
|
+
return response;
|
|
37
|
+
})
|
|
38
|
+
.catch((error) => {
|
|
39
|
+
return ApiResponse.errorAxios(error);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export { AuthenticationEndpoints };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { ApiResponse } from "./apiResponse";
|
|
3
|
+
class ContentEndpoints {
|
|
4
|
+
constructor(api) {
|
|
5
|
+
this.VERSION = "v1";
|
|
6
|
+
this.endpoint = api.endpoint;
|
|
7
|
+
this.state = api.apiState;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* builds the full path
|
|
11
|
+
* @param path - The path to the endpoint, e.g. "authentication/login"
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
getPath(path) {
|
|
15
|
+
return `${this.endpoint}/${this.VERSION}/content/${path}`;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* get the content of a document
|
|
19
|
+
* @param documentId - The id of the document
|
|
20
|
+
* @returns the content of the document
|
|
21
|
+
*/
|
|
22
|
+
getContent(documentId) {
|
|
23
|
+
const path = this.getPath(`document/${documentId}`);
|
|
24
|
+
return axios.get(path, {
|
|
25
|
+
headers: {
|
|
26
|
+
"Authorization": `Bearer ${this.state.auth_token}`
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
.then((response) => {
|
|
30
|
+
return ApiResponse.success(response.data);
|
|
31
|
+
})
|
|
32
|
+
.catch((error) => {
|
|
33
|
+
return ApiResponse.errorAxios(error);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* get the actions of a document
|
|
38
|
+
* @param documentId - The id of the document
|
|
39
|
+
* @returns the actions of the document
|
|
40
|
+
*/
|
|
41
|
+
getContentActions(documentId) {
|
|
42
|
+
const path = this.getPath(`document/${documentId}/actions`);
|
|
43
|
+
return axios.get(path, {
|
|
44
|
+
headers: {
|
|
45
|
+
"Authorization": `Bearer ${this.state.auth_token}`
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
.then((response) => {
|
|
49
|
+
return ApiResponse.success(response.data);
|
|
50
|
+
})
|
|
51
|
+
.catch((error) => {
|
|
52
|
+
return ApiResponse.errorAxios(error);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* checks if a receiver is existing in Brifle
|
|
57
|
+
* @param receiver - The receiver object to check
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
checkReceiver(receiver) {
|
|
61
|
+
const path = this.getPath(`receiver/check`);
|
|
62
|
+
return axios.post(path, receiver, {
|
|
63
|
+
headers: {
|
|
64
|
+
"Authorization": `Bearer ${this.state.auth_token}`
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
.then((response) => {
|
|
68
|
+
return ApiResponse.success(response.data);
|
|
69
|
+
})
|
|
70
|
+
.catch((error) => {
|
|
71
|
+
return ApiResponse.errorAxios(error);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* send a content to a receiver
|
|
76
|
+
* @param tenantId - The tenant id of the receiver
|
|
77
|
+
* @param request - The request object to send
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
80
|
+
sendContent(tenantId, request) {
|
|
81
|
+
const path = this.getPath(`send/${tenantId}`);
|
|
82
|
+
return axios.post(path, request, {
|
|
83
|
+
headers: {
|
|
84
|
+
"Authorization": `Bearer ${this.state.auth_token}`
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
.then((response) => {
|
|
88
|
+
return ApiResponse.success(response.data);
|
|
89
|
+
})
|
|
90
|
+
.catch((error) => {
|
|
91
|
+
return ApiResponse.errorAxios(error);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* list all cover letters for a tenant
|
|
96
|
+
* @param tenantId - The tenant id
|
|
97
|
+
* @returns
|
|
98
|
+
*/
|
|
99
|
+
listCoverLetters(tenantId) {
|
|
100
|
+
const path = this.getPath(`cover_letters/${tenantId}/list`);
|
|
101
|
+
return axios.get(path, {
|
|
102
|
+
headers: {
|
|
103
|
+
"Authorization": `Bearer ${this.state.auth_token}`
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
.then((response) => {
|
|
107
|
+
return ApiResponse.success(response.data);
|
|
108
|
+
})
|
|
109
|
+
.catch((error) => {
|
|
110
|
+
return ApiResponse.errorAxios(error);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* get the content of a cover letter
|
|
115
|
+
* @param tenantId - The tenant id
|
|
116
|
+
* @param type - The type of the cover letter (custom | default)
|
|
117
|
+
* @param name - The name of the cover letter
|
|
118
|
+
* @param encoding - The encoding of the cover letter (base64 | pdf)
|
|
119
|
+
* @returns
|
|
120
|
+
*/
|
|
121
|
+
getCoverLetterContent(tenantId, type, name, encoding) {
|
|
122
|
+
const path = this.getPath(`cover_letter/${tenantId}/${type}/${name}/${encoding}`);
|
|
123
|
+
return axios.get(path, {
|
|
124
|
+
headers: {
|
|
125
|
+
"Authorization": `Bearer ${this.state.auth_token}`
|
|
126
|
+
},
|
|
127
|
+
responseType: 'blob'
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
export { ContentEndpoints };
|