@orchesty/connector-nutshell 1.0.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +190 -0
  3. package/coverage/clover.xml +129 -0
  4. package/coverage/coverage-final.json +7 -0
  5. package/coverage/lcov-report/base.css +224 -0
  6. package/coverage/lcov-report/block-navigation.js +87 -0
  7. package/coverage/lcov-report/favicon.png +0 -0
  8. package/coverage/lcov-report/index.html +146 -0
  9. package/coverage/lcov-report/prettify.css +1 -0
  10. package/coverage/lcov-report/prettify.js +2 -0
  11. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  12. package/coverage/lcov-report/sorter.js +210 -0
  13. package/coverage/lcov-report/src/Connector/NutshellGetAccountConnector.ts.html +532 -0
  14. package/coverage/lcov-report/src/Connector/NutshellNewAccountConnector.ts.html +754 -0
  15. package/coverage/lcov-report/src/Connector/NutshellNewLeadConnector.ts.html +802 -0
  16. package/coverage/lcov-report/src/Connector/NutshellNewTaskConnector.ts.html +406 -0
  17. package/coverage/lcov-report/src/Connector/index.html +161 -0
  18. package/coverage/lcov-report/src/NutshellApplication.ts.html +304 -0
  19. package/coverage/lcov-report/src/index.html +116 -0
  20. package/coverage/lcov-report/test/dataProvider.ts.html +235 -0
  21. package/coverage/lcov-report/test/index.html +116 -0
  22. package/coverage/lcov.info +184 -0
  23. package/dist/Connector/NutshellGetAccountConnector.d.ts +108 -0
  24. package/dist/Connector/NutshellGetAccountConnector.js +29 -0
  25. package/dist/Connector/NutshellNewAccountConnector.d.ts +179 -0
  26. package/dist/Connector/NutshellNewAccountConnector.js +29 -0
  27. package/dist/Connector/NutshellNewLeadConnector.d.ts +205 -0
  28. package/dist/Connector/NutshellNewLeadConnector.js +29 -0
  29. package/dist/Connector/NutshellNewTaskConnector.d.ts +67 -0
  30. package/dist/Connector/NutshellNewTaskConnector.js +29 -0
  31. package/dist/NutshellApplication.d.ts +16 -0
  32. package/dist/NutshellApplication.js +85 -0
  33. package/dist/package.json +22 -0
  34. package/jest.config.js +13 -0
  35. package/package.json +22 -0
  36. package/src/Connector/NutshellGetAccountConnector.ts +149 -0
  37. package/src/Connector/NutshellNewAccountConnector.ts +223 -0
  38. package/src/Connector/NutshellNewLeadConnector.ts +239 -0
  39. package/src/Connector/NutshellNewTaskConnector.ts +107 -0
  40. package/src/Connector/__tests__/Data/NutshellGetAccountConnector/input.json +8 -0
  41. package/src/Connector/__tests__/Data/NutshellGetAccountConnector/mock.json +37 -0
  42. package/src/Connector/__tests__/Data/NutshellGetAccountConnector/output.json +34 -0
  43. package/src/Connector/__tests__/Data/NutshellNewAccountConnector/input.json +10 -0
  44. package/src/Connector/__tests__/Data/NutshellNewAccountConnector/mock.json +34 -0
  45. package/src/Connector/__tests__/Data/NutshellNewAccountConnector/output.json +30 -0
  46. package/src/Connector/__tests__/Data/NutshellNewLeadConnector/input.json +10 -0
  47. package/src/Connector/__tests__/Data/NutshellNewLeadConnector/mock.json +77 -0
  48. package/src/Connector/__tests__/Data/NutshellNewLeadConnector/output.json +74 -0
  49. package/src/Connector/__tests__/Data/NutshellNewTaskConnector/input.json +11 -0
  50. package/src/Connector/__tests__/Data/NutshellNewTaskConnector/mock.json +22 -0
  51. package/src/Connector/__tests__/Data/NutshellNewTaskConnector/output.json +19 -0
  52. package/src/Connector/__tests__/NutshellGetAccountConnector.ts +17 -0
  53. package/src/Connector/__tests__/NutshellNewAccountConnector.ts +17 -0
  54. package/src/Connector/__tests__/NutshellNewLeadConnector.ts +17 -0
  55. package/src/Connector/__tests__/NutshellNewTaskConnector.ts +17 -0
  56. package/src/NutshellApplication.ts +73 -0
  57. package/test/dataProvider.ts +50 -0
  58. package/tsconfig.json +8 -0
  59. package/tsconfig.prod.json +13 -0
  60. package/tsconfig.prod.tsbuildinfo +1 -0
@@ -0,0 +1,107 @@
1
+ import AConnector from '@orchesty/nodejs-sdk/dist/lib/Connector/AConnector';
2
+ import { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
3
+ import ProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/ProcessDto';
4
+ import crypto from 'crypto';
5
+
6
+ export const NAME = 'nutshell-new-task-connector';
7
+
8
+ export default class NutshellNewTaskConnector extends AConnector {
9
+
10
+ public getName(): string {
11
+ return NAME;
12
+ }
13
+
14
+ public async processAction(dto: ProcessDto<IInput>): Promise<ProcessDto<IOutput>> {
15
+ const appInstall = await this.getApplicationInstallFromProcess(dto);
16
+
17
+ const data = {
18
+ jsonrpc: '2.0',
19
+ method: 'newTask',
20
+ params: dto.getJsonData(),
21
+ id: crypto.randomBytes(4).toString('hex'),
22
+ };
23
+ const req = await this.getApplication().getRequestDto(
24
+ dto,
25
+ appInstall,
26
+ HttpMethods.POST,
27
+ undefined,
28
+ data,
29
+ );
30
+
31
+ const resp = await this.getSender().send<IResponse>(req, [200]);
32
+ const response = resp.getJsonBody();
33
+
34
+ return dto.setNewJsonData(response.result);
35
+ }
36
+
37
+ }
38
+
39
+ interface IResponse {
40
+ result: IOutput;
41
+ id: string;
42
+ jsonrpc: string;
43
+ }
44
+
45
+ export interface IOutput {
46
+ title: string;
47
+ id: number;
48
+ entityType: string;
49
+ rev: string;
50
+ createdTime: string;
51
+ description: string;
52
+ dueTime: string;
53
+ completedTime: null;
54
+ completedUser: null;
55
+ assignee: {
56
+ stub: boolean;
57
+ id: number;
58
+ rev: string;
59
+ entityType: string;
60
+ modifiedTime: string;
61
+ createdTime: string;
62
+ name: string;
63
+ emails: string[];
64
+ isEnabled: boolean;
65
+ isAdministrator: boolean;
66
+ };
67
+ entity: {
68
+ stub: boolean;
69
+ id: number;
70
+ rev: string;
71
+ entityType: string;
72
+ modifiedTime: string;
73
+ createdTime: string;
74
+ name: string;
75
+ regions: string[];
76
+ };
77
+ creator: {
78
+ stub: boolean;
79
+ id: number;
80
+ rev: string;
81
+ entityType: string;
82
+ modifiedTime: string;
83
+ createdTime: string;
84
+ name: string;
85
+ emails: string[];
86
+ isEnabled: boolean;
87
+ isAdministrator: boolean;
88
+ };
89
+
90
+ }
91
+
92
+ export interface IInput {
93
+ task: {
94
+ title: string;
95
+ description?: string;
96
+ dueTime?: string;
97
+ assignee?: {
98
+ entityType?: string;
99
+ id?: number;
100
+ };
101
+ entity?: {
102
+ entityType?: string;
103
+ id?: number;
104
+ };
105
+ };
106
+
107
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "headers": {
3
+ "user": "TestUser"
4
+ },
5
+ "data": {
6
+ "accountId": 116
7
+ }
8
+ }
@@ -0,0 +1,37 @@
1
+ {
2
+ "http": "POST https://app.nutshell.com/api/v1/json",
3
+ "code": 200,
4
+ "body": {
5
+ "result": {
6
+ "id": 116,
7
+ "entityType": "Accounts",
8
+ "rev": "0",
9
+ "modifiedTime": "2022-08-10T15:49:23+0000",
10
+ "createdTime": "2022-08-10T15:49:23+0000",
11
+ "name": "New Account Name",
12
+ "htmlUrl": "https:\/\/app.nutshell.com\/company\/116-new-account-name",
13
+ "htmlUrlPath": "\/company\/116-new-account-name",
14
+ "avatarUrl": "https:\/\/app.nutshell.com\/avatar\/accounts\/116\/346392\/K1K9OUzMRMiFaepwtAneseVXZs-THejW7xPt9zhTSDM.2\/1660146563",
15
+ "accountType": {
16
+ "id": 1,
17
+ "name": "Standard Account"
18
+ },
19
+ "industry": null,
20
+ "creator": null,
21
+ "owner": null,
22
+ "tags": [
23
+ ],
24
+ "lastContactedDate": null,
25
+ "contacts": [
26
+ ],
27
+ "description": null,
28
+ "legacyId": null,
29
+ "notes": [
30
+ ],
31
+ "leads": [
32
+ ]
33
+ },
34
+ "id": "apeye",
35
+ "jsonrpc": "2.0"
36
+ }
37
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "headers": {
3
+ "user": "TestUser"
4
+ },
5
+ "data": {
6
+ "id": 116,
7
+ "entityType": "Accounts",
8
+ "rev": "0",
9
+ "modifiedTime": "2022-08-10T15:49:23+0000",
10
+ "createdTime": "2022-08-10T15:49:23+0000",
11
+ "name": "New Account Name",
12
+ "htmlUrl": "https:\/\/app.nutshell.com\/company\/116-new-account-name",
13
+ "htmlUrlPath": "\/company\/116-new-account-name",
14
+ "avatarUrl": "https:\/\/app.nutshell.com\/avatar\/accounts\/116\/346392\/K1K9OUzMRMiFaepwtAneseVXZs-THejW7xPt9zhTSDM.2\/1660146563",
15
+ "accountType": {
16
+ "id": 1,
17
+ "name": "Standard Account"
18
+ },
19
+ "industry": null,
20
+ "creator": null,
21
+ "owner": null,
22
+ "tags": [
23
+ ],
24
+ "lastContactedDate": null,
25
+ "contacts": [
26
+ ],
27
+ "description": null,
28
+ "legacyId": null,
29
+ "notes": [
30
+ ],
31
+ "leads": [
32
+ ]
33
+ }
34
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "headers": {
3
+ "user": "TestUser"
4
+ },
5
+ "data": {
6
+ "account": {
7
+ "name": "New Account Name"
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "http": "POST https://app.nutshell.com/api/v1/json",
3
+ "code": 200,
4
+ "body": {
5
+ "result": {
6
+ "accountType": {
7
+ "id": 1,
8
+ "name": "Standard Account"
9
+ },
10
+ "avatarUrl": "https://app.nutshell.com/avatar/accounts/116/346392/K1K9OUzMRMiFaepwtAneseVXZs-THejW7xPt9zhTSDM.2/1660146563",
11
+ "contacts": [],
12
+ "createdTime": "2022-08-10T15:49:23+0000",
13
+ "creator": null,
14
+ "description": null,
15
+ "entityType": "Accounts",
16
+ "htmlUrl": "https://app.nutshell.com/company/116-new-account-name",
17
+ "htmlUrlPath": "/company/116-new-account-name",
18
+ "id": 116,
19
+ "industry": null,
20
+ "lastContactedDate": null,
21
+ "leads": [],
22
+ "legacyId": null,
23
+ "modifiedTime": "2022-08-10T15:49:23+0000",
24
+ "name": "New Account Name",
25
+ "notes": [],
26
+ "owner": null,
27
+ "rev": "0",
28
+ "tags": []
29
+ },
30
+ "id": "apeye",
31
+ "jsonrpc": "2.0"
32
+ }
33
+ }
34
+
@@ -0,0 +1,30 @@
1
+ {
2
+ "headers": {
3
+ "user": "TestUser"
4
+ },
5
+ "data": {
6
+ "accountType": {
7
+ "id": 1,
8
+ "name": "Standard Account"
9
+ },
10
+ "avatarUrl": "https://app.nutshell.com/avatar/accounts/116/346392/K1K9OUzMRMiFaepwtAneseVXZs-THejW7xPt9zhTSDM.2/1660146563",
11
+ "contacts": [],
12
+ "createdTime": "2022-08-10T15:49:23+0000",
13
+ "creator": null,
14
+ "description": null,
15
+ "entityType": "Accounts",
16
+ "htmlUrl": "https://app.nutshell.com/company/116-new-account-name",
17
+ "htmlUrlPath": "/company/116-new-account-name",
18
+ "id": 116,
19
+ "industry": null,
20
+ "lastContactedDate": null,
21
+ "leads": [],
22
+ "legacyId": null,
23
+ "modifiedTime": "2022-08-10T15:49:23+0000",
24
+ "name": "New Account Name",
25
+ "notes": [],
26
+ "owner": null,
27
+ "rev": "0",
28
+ "tags": []
29
+ }
30
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "headers": {
3
+ "user": "TestUser"
4
+ },
5
+ "data": {
6
+ "lead": {
7
+ "description": "A great new lead"
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,77 @@
1
+ {
2
+ "http": "POST https://app.nutshell.com/api/v1/json",
3
+ "code": 200,
4
+ "body": {
5
+ "result": {
6
+ "id": 1004,
7
+ "entityType": "Leads",
8
+ "rev": "1",
9
+ "modifiedTime": "2022-08-10T16:18:05+0000",
10
+ "createdTime": "2022-08-10T16:18:05+0000",
11
+ "name": "Lead\u20131001",
12
+ "description": "A great new lead",
13
+ "htmlUrl": "https:\/\/app.nutshell.com\/lead\/1001",
14
+ "htmlUrlPath": "\/lead\/1001",
15
+ "avatarUrl": "https:\/\/app.nutshell.com\/avatar\/leads\/v1\/0\/1\/3\/0",
16
+ "creator": null,
17
+ "primaryAccount": null,
18
+ "milestone": {
19
+ "stub": true,
20
+ "id": 101,
21
+ "rev": "0",
22
+ "entityType": "Milestones",
23
+ "name": "Qualify"
24
+ },
25
+ "stageset": {
26
+ "stub": true,
27
+ "id": 1,
28
+ "entityType": "Stagesets",
29
+ "name": "Default Pipeline"
30
+ },
31
+ "activitiesCount": {
32
+ "0": 0,
33
+ "1": 0,
34
+ "2": 0,
35
+ "-1": 0
36
+ },
37
+ "status": 0,
38
+ "confidence": 25,
39
+ "completion": 0,
40
+ "urgency": "0",
41
+ "isOverdue": false,
42
+ "lastContactedDate": null,
43
+ "market": {
44
+ "stub": true,
45
+ "id": 1,
46
+ "rev": "0",
47
+ "entityType": "Markets",
48
+ "name": "U.S."
49
+ },
50
+ "assignee": null,
51
+ "sources": [],
52
+ "competitors": [],
53
+ "products": [],
54
+ "contacts": [],
55
+ "accounts": [],
56
+ "tags": [],
57
+ "priority": 0,
58
+ "processes": [
59
+ {
60
+ "stub": true,
61
+ "id": 8,
62
+ "rev": "0",
63
+ "entityType": "Processes",
64
+ "name": "Default Pipeline",
65
+ "type": "0",
66
+ "startedTime": "2022-08-10T16:18:05+0000",
67
+ "closedTime": null,
68
+ "currentMilestoneId": "101",
69
+ "processTemplateId": "1"
70
+ }
71
+ ],
72
+ "notes": []
73
+ },
74
+ "id": "7a21312a",
75
+ "jsonrpc": "2.0"
76
+ }
77
+ }
@@ -0,0 +1,74 @@
1
+ {
2
+ "headers": {
3
+ "user": "TestUser"
4
+ },
5
+ "data": {
6
+ "accounts": [],
7
+ "activitiesCount": {
8
+ "0": 0,
9
+ "1": 0,
10
+ "2": 0,
11
+ "-1": 0
12
+ },
13
+ "assignee": null,
14
+ "avatarUrl": "https://app.nutshell.com/avatar/leads/v1/0/1/3/0",
15
+ "competitors": [],
16
+ "completion": 0,
17
+ "confidence": 25,
18
+ "contacts": [],
19
+ "createdTime": "2022-08-10T16:18:05+0000",
20
+ "creator": null,
21
+ "description": "A great new lead",
22
+ "entityType": "Leads",
23
+ "htmlUrl": "https://app.nutshell.com/lead/1001",
24
+ "htmlUrlPath": "/lead/1001",
25
+ "id": 1004,
26
+ "isOverdue": false,
27
+ "lastContactedDate": null,
28
+ "market": {
29
+ "entityType": "Markets",
30
+ "id": 1,
31
+ "name": "U.S.",
32
+ "rev": "0",
33
+ "stub": true
34
+ },
35
+ "milestone": {
36
+ "entityType": "Milestones",
37
+ "id": 101,
38
+ "name": "Qualify",
39
+ "rev": "0",
40
+ "stub": true
41
+ },
42
+ "modifiedTime": "2022-08-10T16:18:05+0000",
43
+ "name": "Lead–1001",
44
+ "notes": [],
45
+ "primaryAccount": null,
46
+ "priority": 0,
47
+ "processes": [
48
+ {
49
+ "closedTime": null,
50
+ "currentMilestoneId": "101",
51
+ "entityType": "Processes",
52
+ "id": 8,
53
+ "name": "Default Pipeline",
54
+ "processTemplateId": "1",
55
+ "rev": "0",
56
+ "startedTime": "2022-08-10T16:18:05+0000",
57
+ "stub": true,
58
+ "type": "0"
59
+ }
60
+ ],
61
+ "products": [],
62
+ "rev": "1",
63
+ "sources": [],
64
+ "stageset": {
65
+ "entityType": "Stagesets",
66
+ "id": 1,
67
+ "name": "Default Pipeline",
68
+ "stub": true
69
+ },
70
+ "status": 0,
71
+ "tags": [],
72
+ "urgency": "0"
73
+ }
74
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "headers": {
3
+ "user": "TestUser"
4
+ },
5
+ "data": {
6
+ "task": {
7
+ "title": "Send product sheet"
8
+ }
9
+ }
10
+ }
11
+
@@ -0,0 +1,22 @@
1
+ {
2
+ "http": "POST https://app.nutshell.com/api/v1/json",
3
+ "code": 200,
4
+ "body": {
5
+ "id": "c172cb2d",
6
+ "jsonrpc": "2.0",
7
+ "result": {
8
+ "assignee": null,
9
+ "completedTime": null,
10
+ "completedUser": null,
11
+ "createdTime": "2022-08-11T07:06:54+0000",
12
+ "creator": null,
13
+ "description": null,
14
+ "dueTime": "2022-08-12T15:00:00+0000",
15
+ "entity": null,
16
+ "entityType": "Tasks",
17
+ "id": 12,
18
+ "rev": "0",
19
+ "title": "Send product sheet"
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "headers": {
3
+ "user": "TestUser"
4
+ },
5
+ "data": {
6
+ "assignee": null,
7
+ "completedTime": null,
8
+ "completedUser": null,
9
+ "createdTime": "2022-08-11T07:06:54+0000",
10
+ "creator": null,
11
+ "description": null,
12
+ "dueTime": "2022-08-12T15:00:00+0000",
13
+ "entity": null,
14
+ "entityType": "Tasks",
15
+ "id": 12,
16
+ "rev": "0",
17
+ "title": "Send product sheet"
18
+ }
19
+ }
@@ -0,0 +1,17 @@
1
+ import { container } from '@orchesty/nodejs-connectors/test/TestAbstract';
2
+ import NodeTester from '@orchesty/nodejs-sdk/dist/test/Testers/NodeTester';
3
+ import init from '../../../test/dataProvider';
4
+ import { NAME as NUTSHELL_GET_ACCOUNT_CONNECTOR } from '../NutshellGetAccountConnector';
5
+
6
+ let tester: NodeTester;
7
+
8
+ describe('Tests for NutshellGetAccountConnector', () => {
9
+ beforeEach(() => {
10
+ tester = new NodeTester(container, __filename);
11
+ init();
12
+ });
13
+
14
+ it('process - ok', async () => {
15
+ await tester.testConnector(NUTSHELL_GET_ACCOUNT_CONNECTOR);
16
+ });
17
+ });
@@ -0,0 +1,17 @@
1
+ import { container } from '@orchesty/nodejs-connectors/test/TestAbstract';
2
+ import NodeTester from '@orchesty/nodejs-sdk/dist/test/Testers/NodeTester';
3
+ import init from '../../../test/dataProvider';
4
+ import { NAME as NUTSHELL_NEW_ACCOUNT_CONNECTOR } from '../NutshellNewAccountConnector';
5
+
6
+ let tester: NodeTester;
7
+
8
+ describe('Tests for NutshellNewAccountConnector', () => {
9
+ beforeEach(() => {
10
+ tester = new NodeTester(container, __filename);
11
+ init();
12
+ });
13
+
14
+ it('process - ok', async () => {
15
+ await tester.testConnector(NUTSHELL_NEW_ACCOUNT_CONNECTOR);
16
+ });
17
+ });
@@ -0,0 +1,17 @@
1
+ import { container } from '@orchesty/nodejs-connectors/test/TestAbstract';
2
+ import NodeTester from '@orchesty/nodejs-sdk/dist/test/Testers/NodeTester';
3
+ import init from '../../../test/dataProvider';
4
+ import { NAME as NUTSHELL_NEW_LEAD_CONNECTOR } from '../NutshellNewLeadConnector';
5
+
6
+ let tester: NodeTester;
7
+
8
+ describe('Tests for NutshellNewLeadConnector', () => {
9
+ beforeEach(() => {
10
+ tester = new NodeTester(container, __filename);
11
+ init();
12
+ });
13
+
14
+ it('process - ok', async () => {
15
+ await tester.testConnector(NUTSHELL_NEW_LEAD_CONNECTOR);
16
+ });
17
+ });
@@ -0,0 +1,17 @@
1
+ import { container } from '@orchesty/nodejs-connectors/test/TestAbstract';
2
+ import NodeTester from '@orchesty/nodejs-sdk/dist/test/Testers/NodeTester';
3
+ import init from '../../../test/dataProvider';
4
+ import { NAME as NUTSHELL_NEW_TASK_CONNECTOR } from '../NutshellNewTaskConnector';
5
+
6
+ let tester: NodeTester;
7
+
8
+ describe('Tests for NutshellNewTaskConnector', () => {
9
+ beforeEach(() => {
10
+ tester = new NodeTester(container, __filename);
11
+ init();
12
+ });
13
+
14
+ it('process - ok', async () => {
15
+ await tester.testConnector(NUTSHELL_NEW_TASK_CONNECTOR);
16
+ });
17
+ });
@@ -0,0 +1,73 @@
1
+ import CoreFormsEnum, { getFormName } from '@orchesty/nodejs-sdk/dist/lib/Application/Base/CoreFormsEnum';
2
+ import { ApplicationInstall } from '@orchesty/nodejs-sdk/dist/lib/Application/Database/ApplicationInstall';
3
+ import Field from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/Field';
4
+ import FieldType from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/FieldType';
5
+ import Form from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/Form';
6
+ import FormStack from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/FormStack';
7
+ import {
8
+ ABasicApplication,
9
+ PASSWORD,
10
+ USER,
11
+ } from '@orchesty/nodejs-sdk/dist/lib/Authorization/Type/Basic/ABasicApplication';
12
+ import RequestDto from '@orchesty/nodejs-sdk/dist/lib/Transport/Curl/RequestDto';
13
+ import { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
14
+ import AProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/AProcessDto';
15
+ import { encode } from '@orchesty/nodejs-sdk/dist/lib/Utils/Base64';
16
+ import { CommonHeaders, JSON_TYPE } from '@orchesty/nodejs-sdk/dist/lib/Utils/Headers';
17
+
18
+ export const NAME = 'nutshell';
19
+
20
+ export default class NutshellApplication extends ABasicApplication {
21
+
22
+ public getDescription(): string {
23
+ return 'Affordable, easy-to-use CRM that helps small-business sales teams win more deals';
24
+ }
25
+
26
+ public getName(): string {
27
+ return NAME;
28
+ }
29
+
30
+ public getPublicName(): string {
31
+ return 'Nutshell';
32
+ }
33
+
34
+ public getLogo(): string {
35
+ return 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDI1LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IlZyc3R2YV8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCIKCSB2aWV3Qm94PSIwIDAgMTAwIDEwMCIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgMTAwIDEwMDsiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgoJLnN0MHtmaWxsOiNGRTU4MDA7fQoJLnN0MXtmaWxsOiNGRkZGRkY7fQo8L3N0eWxlPgo8Zz4KCTxwYXRoIGNsYXNzPSJzdDAiIGQ9Ik0wLjEsMC4xaDk5Ljd2OTkuN0gwLjFWMC4xeiIvPgoJPHBhdGggY2xhc3M9InN0MSIgZD0iTTU1LjUsMjkuMmMtMS4xLDAtMi0xLTEuOS0yLjFjMC0wLjEsMC0wLjIsMC0wLjNsMS40LTcuM2MwLTAuMSwwLTAuMiwwLTAuM2MwLTEuNS0yLjItMS43LTUtMS43cy01LDAuMi01LDEuNwoJCWMwLDAuMSwwLDAuMiwwLDAuM2wxLjQsNy4zYzAuMiwxLjEtMC41LDIuMi0xLjYsMi40Yy0wLjEsMC0wLjIsMC0wLjMsMGMtMTMuNCwwLjUtMjIuOSw0LjktMjIuOSwxMi45djMuMWMwLDAuOCwwLjcsMS41LDEuNSwxLjUKCQljMCwwLDAsMCwwLDBoMjQuNGMxLDAsMS41LDAuNywxLjUsMS41YzAsMC43LTAuNSwxLjMtMS4yLDEuNEwyOS43LDUzYy0wLjcsMC4xLTEuMiwwLjctMS4yLDEuNHY2LjJjMCwxMS45LDkuMywyMS45LDIxLjUsMjEuOQoJCWMxMS45LDAsMjEuNS05LjcsMjEuNS0yMS41di0xM2MwLTAuOCwwLjctMS40LDEuNC0xLjRjMCwwLDAsMCwwLDBoMy45YzAuOCwwLDEuNS0wLjcsMS41LTEuNWMwLDAsMCwwLDAsMHYtMy4xCgkJQzc4LjQsMzQsNjguOSwzMCw1NS41LDI5LjJMNTUuNSwyOS4yeiIvPgo8L2c+Cjwvc3ZnPgo=';
36
+ }
37
+
38
+ public getRequestDto(
39
+ dto: AProcessDto,
40
+ applicationInstall: ApplicationInstall,
41
+ method: HttpMethods,
42
+ url?: string,
43
+ data?: unknown,
44
+ ): Promise<RequestDto> | RequestDto {
45
+ const request = new RequestDto('https://app.nutshell.com/api/v1/json', method, dto);
46
+ request.setHeaders({
47
+ [CommonHeaders.CONTENT_TYPE]: JSON_TYPE,
48
+ [CommonHeaders.ACCEPT]: JSON_TYPE,
49
+ [CommonHeaders.AUTHORIZATION]: `Basic ${this.getToken(applicationInstall)}`,
50
+ });
51
+ if (data) {
52
+ request.setJsonBody(data);
53
+ }
54
+
55
+ return request;
56
+ }
57
+
58
+ public getFormStack(): FormStack {
59
+ const form = new Form(CoreFormsEnum.AUTHORIZATION_FORM, getFormName(CoreFormsEnum.AUTHORIZATION_FORM))
60
+ .addField(new Field(FieldType.TEXT, USER, 'Username', undefined, true))
61
+ .addField(new Field(FieldType.TEXT, PASSWORD, 'API Key', undefined, true));
62
+
63
+ return new FormStack().addForm(form);
64
+ }
65
+
66
+ private getToken(applicationInstall: ApplicationInstall): string {
67
+ return encode(
68
+
69
+ `${applicationInstall.getSettings()[CoreFormsEnum.AUTHORIZATION_FORM][USER]}:${applicationInstall.getSettings()[CoreFormsEnum.AUTHORIZATION_FORM][PASSWORD]}`,
70
+ );
71
+ }
72
+
73
+ }