@brifle/brifle-sdk 0.0.4 → 0.1.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 +18 -0
- package/dist/cjs/endpoints/v1/accounts.d.ts +15 -0
- package/dist/cjs/endpoints/v1/requests/content.d.ts +19 -1
- package/dist/cjs/endpoints/v1/requests/mailbox.d.ts +2 -0
- package/dist/cjs/endpoints/v1/responses/accounts.d.ts +8 -0
- package/dist/cjs/endpoints/v1/responses/content.d.ts +27 -22
- package/dist/cjs/endpoints/v1/responses/status.d.ts +8 -0
- package/dist/cjs/endpoints/v1/responses/tenant.d.ts +12 -0
- package/dist/cjs/endpoints/v1/status.d.ts +16 -0
- package/dist/cjs/endpoints/v1/tenant.d.ts +19 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +125 -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 +95 -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 +18 -0
- package/dist/esm/endpoints/v1/accounts.d.ts +15 -0
- package/dist/esm/endpoints/v1/requests/content.d.ts +19 -1
- package/dist/esm/endpoints/v1/requests/mailbox.d.ts +2 -0
- package/dist/esm/endpoints/v1/responses/accounts.d.ts +8 -0
- package/dist/esm/endpoints/v1/responses/content.d.ts +27 -22
- package/dist/esm/endpoints/v1/responses/status.d.ts +8 -0
- package/dist/esm/endpoints/v1/responses/tenant.d.ts +12 -0
- package/dist/esm/endpoints/v1/status.d.ts +16 -0
- package/dist/esm/endpoints/v1/tenant.d.ts +19 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.mjs +124 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/index.d.ts +132 -23
- package/dist/index.js +18 -0
- package/dist/types/api/api.d.ts +18 -0
- package/dist/types/endpoints/v1/accounts.d.ts +15 -0
- package/dist/types/endpoints/v1/requests/content.d.ts +19 -1
- package/dist/types/endpoints/v1/requests/mailbox.d.ts +2 -0
- package/dist/types/endpoints/v1/responses/accounts.d.ts +8 -0
- package/dist/types/endpoints/v1/responses/content.d.ts +27 -22
- package/dist/types/endpoints/v1/responses/status.d.ts +8 -0
- package/dist/types/endpoints/v1/responses/tenant.d.ts +12 -0
- package/dist/types/endpoints/v1/status.d.ts +16 -0
- package/dist/types/endpoints/v1/tenant.d.ts +19 -0
- package/dist/types/index.d.ts +4 -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
|
@@ -2,6 +2,9 @@ import { AuthenticationEndpoints } from "../endpoints/v1/authentication";
|
|
|
2
2
|
import { ContentEndpoints } from "../endpoints/v1/content";
|
|
3
3
|
import { SignaturesEndpoint } from "../endpoints/v1/signatures";
|
|
4
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";
|
|
5
8
|
declare class ApiV1 {
|
|
6
9
|
readonly endpoint: string;
|
|
7
10
|
readonly apiState: ApiV1State;
|
|
@@ -23,11 +26,26 @@ declare class ApiV1 {
|
|
|
23
26
|
* @returns ContentEndpoints
|
|
24
27
|
*/
|
|
25
28
|
signature(): SignaturesEndpoint;
|
|
29
|
+
/**
|
|
30
|
+
* gets an instance of the TenantsEndpoints
|
|
31
|
+
* @returns TenantsEndpoints
|
|
32
|
+
*/
|
|
33
|
+
tenants(): TenantsEndpoints;
|
|
34
|
+
/**
|
|
35
|
+
* gets an instance of the AccountsEndpoints
|
|
36
|
+
* @returns AccountsEndpoints
|
|
37
|
+
*/
|
|
38
|
+
accounts(): AccountsEndpoints;
|
|
26
39
|
/**
|
|
27
40
|
* gets an instance of the MailboxEndpoints
|
|
28
41
|
* @returns MailboxEndpoints
|
|
29
42
|
*/
|
|
30
43
|
mailbox(): MailboxEndpoints;
|
|
44
|
+
/**
|
|
45
|
+
* gets an instance of the StatusEndpoint
|
|
46
|
+
* @returns StatusEndpoint
|
|
47
|
+
*/
|
|
48
|
+
status(): StatusEndpoint;
|
|
31
49
|
}
|
|
32
50
|
export interface ApiV1State {
|
|
33
51
|
auth_token?: string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ApiV1 } from "../../api/api";
|
|
2
|
+
import { AccountInfo } from "./responses/accounts";
|
|
3
|
+
import { ApiResponse } from "./apiResponse";
|
|
4
|
+
declare class AccountsEndpoints {
|
|
5
|
+
private endpoint;
|
|
6
|
+
private readonly VERSION;
|
|
7
|
+
private state;
|
|
8
|
+
constructor(api: ApiV1);
|
|
9
|
+
private getPath;
|
|
10
|
+
/**
|
|
11
|
+
* Gets a tenant by its ID
|
|
12
|
+
*/
|
|
13
|
+
getById(accountId: string): Promise<ApiResponse<AccountInfo>>;
|
|
14
|
+
}
|
|
15
|
+
export { AccountsEndpoints };
|
|
@@ -35,6 +35,7 @@ interface SendContentRequest {
|
|
|
35
35
|
type: 'application/pdf';
|
|
36
36
|
content: string;
|
|
37
37
|
}[];
|
|
38
|
+
fallback?: FallbackOptions;
|
|
38
39
|
payment_info?: {
|
|
39
40
|
details?: PaymentDetails;
|
|
40
41
|
payable: boolean;
|
|
@@ -47,4 +48,21 @@ interface SendContentRequest {
|
|
|
47
48
|
}[];
|
|
48
49
|
};
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
+
interface FallbackOptions {
|
|
52
|
+
enabled_physical_delivery: boolean;
|
|
53
|
+
paper_mail: {
|
|
54
|
+
recipient: {
|
|
55
|
+
address_line1: string;
|
|
56
|
+
address_line2?: string;
|
|
57
|
+
address_line3?: string;
|
|
58
|
+
postal_code: string;
|
|
59
|
+
city: string;
|
|
60
|
+
country: string;
|
|
61
|
+
};
|
|
62
|
+
test_mode: {
|
|
63
|
+
email: string;
|
|
64
|
+
enabled: boolean;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
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,33 @@ interface ContentActionsPaymentResponse {
|
|
|
39
41
|
};
|
|
40
42
|
link: string;
|
|
41
43
|
}
|
|
44
|
+
interface EmbbededSignatureResponse {
|
|
45
|
+
id: string;
|
|
46
|
+
created_by: string;
|
|
47
|
+
created_date: string;
|
|
48
|
+
document_signature_id: string;
|
|
49
|
+
due_date: string;
|
|
50
|
+
field_name: string;
|
|
51
|
+
history?: string;
|
|
52
|
+
purpose: string;
|
|
53
|
+
request_date: string;
|
|
54
|
+
requested_to: string;
|
|
55
|
+
signature_date: string;
|
|
56
|
+
signed_by: string;
|
|
57
|
+
signed_for: string;
|
|
58
|
+
value: string;
|
|
59
|
+
status: 'pending' | 'signed' | 'rejected';
|
|
60
|
+
}
|
|
42
61
|
interface ContentActionsSignatureResponse {
|
|
43
62
|
document_signatures: {
|
|
44
63
|
signature_ids: string[];
|
|
45
64
|
signature_reference: string;
|
|
46
65
|
};
|
|
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
|
-
}[];
|
|
66
|
+
embedded_signatures: EmbbededSignatureResponse[];
|
|
62
67
|
signature_reference: string;
|
|
63
68
|
}
|
|
64
69
|
interface ContentActionsResponse {
|
|
65
|
-
payments: ContentActionsPaymentResponse
|
|
66
|
-
signatures: ContentActionsSignatureResponse
|
|
70
|
+
payments: ContentActionsPaymentResponse;
|
|
71
|
+
signatures: ContentActionsSignatureResponse;
|
|
67
72
|
}
|
|
68
|
-
export type { SendContentResponse, CheckReceiverResponse, ContentMeta, ContentResponse, ContentActionsResponse };
|
|
73
|
+
export type { EmbbededSignatureResponse, Content, 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 };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ApiV1 } from "../../api/api";
|
|
2
|
+
import { Tenant, TenantsResponse } from "./responses/tenant";
|
|
3
|
+
import { ApiResponse } from "./apiResponse";
|
|
4
|
+
declare class TenantsEndpoints {
|
|
5
|
+
private endpoint;
|
|
6
|
+
private readonly VERSION;
|
|
7
|
+
private state;
|
|
8
|
+
constructor(api: ApiV1);
|
|
9
|
+
private getPath;
|
|
10
|
+
/**
|
|
11
|
+
* Gets a tenant by its ID
|
|
12
|
+
*/
|
|
13
|
+
getById(tenantId: string): Promise<ApiResponse<Tenant>>;
|
|
14
|
+
/**
|
|
15
|
+
* Gets all tenants owned by the account id
|
|
16
|
+
*/
|
|
17
|
+
getMy(): Promise<ApiResponse<TenantsResponse>>;
|
|
18
|
+
}
|
|
19
|
+
export { TenantsEndpoints };
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -12,3 +12,7 @@ export * from "./endpoints/v1/signatures";
|
|
|
12
12
|
export * from "./endpoints/v1/mailbox";
|
|
13
13
|
export * from "./endpoints/v1/requests/mailbox";
|
|
14
14
|
export * from "./endpoints/v1/responses/mailbox";
|
|
15
|
+
export * from "./endpoints/v1/tenant";
|
|
16
|
+
export * from "./endpoints/v1/responses/tenant";
|
|
17
|
+
export * from "./endpoints/v1/accounts";
|
|
18
|
+
export * from "./endpoints/v1/responses/accounts";
|
package/dist/cjs/index.js
CHANGED
|
@@ -307,6 +307,108 @@ class MailboxEndpoints {
|
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
+
class TenantsEndpoints {
|
|
311
|
+
constructor(api) {
|
|
312
|
+
this.VERSION = "v1";
|
|
313
|
+
this.endpoint = api.endpoint;
|
|
314
|
+
this.state = api.apiState;
|
|
315
|
+
}
|
|
316
|
+
getPath(path) {
|
|
317
|
+
return `${this.endpoint}/${this.VERSION}/tenants/${path}`;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Gets a tenant by its ID
|
|
321
|
+
*/
|
|
322
|
+
getById(tenantId) {
|
|
323
|
+
const path = this.getPath(`id/${tenantId}`);
|
|
324
|
+
return axios.get(path, {
|
|
325
|
+
headers: {
|
|
326
|
+
"Authorization": `Bearer ${this.state.auth_token}`,
|
|
327
|
+
"Content-Type": "application/json"
|
|
328
|
+
}
|
|
329
|
+
})
|
|
330
|
+
.then((response) => {
|
|
331
|
+
return ApiResponse.success(response.data);
|
|
332
|
+
})
|
|
333
|
+
.catch((error) => {
|
|
334
|
+
return ApiResponse.errorAxios(error);
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Gets all tenants owned by the account id
|
|
339
|
+
*/
|
|
340
|
+
getMy() {
|
|
341
|
+
const path = this.getPath(`my`);
|
|
342
|
+
return axios.get(path, {
|
|
343
|
+
headers: {
|
|
344
|
+
"Authorization": `Bearer ${this.state.auth_token}`,
|
|
345
|
+
"Content-Type": "application/json"
|
|
346
|
+
}
|
|
347
|
+
})
|
|
348
|
+
.then((response) => {
|
|
349
|
+
return ApiResponse.success(response.data);
|
|
350
|
+
})
|
|
351
|
+
.catch((error) => {
|
|
352
|
+
return ApiResponse.errorAxios(error);
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
class AccountsEndpoints {
|
|
358
|
+
constructor(api) {
|
|
359
|
+
this.VERSION = "v1";
|
|
360
|
+
this.endpoint = api.endpoint;
|
|
361
|
+
this.state = api.apiState;
|
|
362
|
+
}
|
|
363
|
+
getPath(path) {
|
|
364
|
+
return `${this.endpoint}/${this.VERSION}/accounts/${path}`;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Gets a tenant by its ID
|
|
368
|
+
*/
|
|
369
|
+
getById(accountId) {
|
|
370
|
+
const path = this.getPath(`${accountId}`);
|
|
371
|
+
console.log(path, path);
|
|
372
|
+
return axios.get(path, {
|
|
373
|
+
headers: {
|
|
374
|
+
"Authorization": `Bearer ${this.state.auth_token}`,
|
|
375
|
+
"Content-Type": "application/json"
|
|
376
|
+
}
|
|
377
|
+
})
|
|
378
|
+
.then((response) => {
|
|
379
|
+
return ApiResponse.success(response.data);
|
|
380
|
+
})
|
|
381
|
+
.catch((error) => {
|
|
382
|
+
return ApiResponse.errorAxios(error);
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
class StatusEndpoint {
|
|
388
|
+
constructor(api) {
|
|
389
|
+
this.VERSION = "v1";
|
|
390
|
+
this.endpoint = api.endpoint;
|
|
391
|
+
this.state = api.apiState;
|
|
392
|
+
}
|
|
393
|
+
getPath(path) {
|
|
394
|
+
return `${this.endpoint}/${this.VERSION}/status/${path}`;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
*
|
|
398
|
+
* @returns the
|
|
399
|
+
*/
|
|
400
|
+
getStatus() {
|
|
401
|
+
const path = this.getPath("");
|
|
402
|
+
return axios.get(path)
|
|
403
|
+
.then((response) => {
|
|
404
|
+
return ApiResponse.success(response.data);
|
|
405
|
+
})
|
|
406
|
+
.catch((error) => {
|
|
407
|
+
return ApiResponse.errorAxios(error);
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
310
412
|
var ENDPOINTS;
|
|
311
413
|
(function (ENDPOINTS) {
|
|
312
414
|
ENDPOINTS["SANDBOX"] = "https://sandbox-api.brifle.de";
|
|
@@ -349,6 +451,20 @@ class ApiV1 {
|
|
|
349
451
|
signature() {
|
|
350
452
|
return new SignaturesEndpoint(this);
|
|
351
453
|
}
|
|
454
|
+
/**
|
|
455
|
+
* gets an instance of the TenantsEndpoints
|
|
456
|
+
* @returns TenantsEndpoints
|
|
457
|
+
*/
|
|
458
|
+
tenants() {
|
|
459
|
+
return new TenantsEndpoints(this);
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* gets an instance of the AccountsEndpoints
|
|
463
|
+
* @returns AccountsEndpoints
|
|
464
|
+
*/
|
|
465
|
+
accounts() {
|
|
466
|
+
return new AccountsEndpoints(this);
|
|
467
|
+
}
|
|
352
468
|
/**
|
|
353
469
|
* gets an instance of the MailboxEndpoints
|
|
354
470
|
* @returns MailboxEndpoints
|
|
@@ -356,12 +472,21 @@ class ApiV1 {
|
|
|
356
472
|
mailbox() {
|
|
357
473
|
return new MailboxEndpoints(this);
|
|
358
474
|
}
|
|
475
|
+
/**
|
|
476
|
+
* gets an instance of the StatusEndpoint
|
|
477
|
+
* @returns StatusEndpoint
|
|
478
|
+
*/
|
|
479
|
+
status() {
|
|
480
|
+
return new StatusEndpoint(this);
|
|
481
|
+
}
|
|
359
482
|
}
|
|
360
483
|
|
|
484
|
+
exports.AccountsEndpoints = AccountsEndpoints;
|
|
361
485
|
exports.ApiResponse = ApiResponse;
|
|
362
486
|
exports.ApiV1 = ApiV1;
|
|
363
487
|
exports.AuthenticationEndpoints = AuthenticationEndpoints;
|
|
364
488
|
exports.ContentEndpoints = ContentEndpoints;
|
|
365
489
|
exports.MailboxEndpoints = MailboxEndpoints;
|
|
366
490
|
exports.SignaturesEndpoint = SignaturesEndpoint;
|
|
491
|
+
exports.TenantsEndpoints = TenantsEndpoints;
|
|
367
492
|
//# sourceMappingURL=index.js.map
|
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 };
|