@friggframework/api-module-pipedrive 0.11.1 → 1.0.1-canary.36.7e495fb.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/.eslintrc.json +1 -1
- package/CHANGELOG.md +36 -16
- package/LICENSE.md +10 -3
- package/README.md +3 -2
- package/api.js +422 -87
- package/defaultConfig.json +9 -7
- package/definition.js +54 -0
- package/index.js +3 -3
- package/jest-setup.js +1 -1
- package/jest-teardown.js +1 -1
- package/manager.js +13 -10
- package/mocks/apiMock.js +3 -1
- package/models/credential.js +3 -3
- package/models/entity.js +2 -2
- package/package.json +25 -24
- package/specs/openAPI.yaml +11129 -0
- package/test/Api.test.js +7 -7
- package/test/Manager.test.js +2 -2
package/.eslintrc.json
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
|
-
# v0.
|
|
1
|
+
# v0.10.0 (Wed Mar 20 2024)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
:tada: This release contains work from new contributors! :tada:
|
|
4
|
+
|
|
5
|
+
Thanks for all your work!
|
|
6
|
+
|
|
7
|
+
:heart: Nicolas Leal ([@nicolasmelo1](https://github.com/nicolasmelo1))
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
:heart: nmilcoff ([@nmilcoff](https://github.com/nmilcoff))
|
|
10
|
+
|
|
11
|
+
#### 🚀 Enhancement
|
|
6
12
|
|
|
7
13
|
#### 🐛 Bug Fix
|
|
8
14
|
|
|
9
|
-
-
|
|
15
|
+
- correct some bad automated edits, though they are not in relevant
|
|
16
|
+
files ([@MichaelRyanWebber](https://github.com/MichaelRyanWebber))
|
|
10
17
|
- Bump independent versions \[skip ci\] ([@seanspeaks](https://github.com/seanspeaks))
|
|
11
18
|
|
|
12
|
-
#### Authors:
|
|
19
|
+
#### Authors: 4
|
|
13
20
|
|
|
14
21
|
- [@MichaelRyanWebber](https://github.com/MichaelRyanWebber)
|
|
22
|
+
- Nicolas Leal ([@nicolasmelo1](https://github.com/nicolasmelo1))
|
|
23
|
+
- nmilcoff ([@nmilcoff](https://github.com/nmilcoff))
|
|
15
24
|
- Sean Matthews ([@seanspeaks](https://github.com/seanspeaks))
|
|
16
25
|
|
|
17
26
|
---
|
|
@@ -123,16 +132,22 @@ Thank you, Jonathan O'Donnell ([@joncodo](https://github.com/joncodo)), for all
|
|
|
123
132
|
|
|
124
133
|
#### 🐛 Bug Fix
|
|
125
134
|
|
|
126
|
-
- Merge remote-tracking branch 'origin/main' into
|
|
135
|
+
- Merge remote-tracking branch 'origin/main' into
|
|
136
|
+
gitbook-updates [#48](https://github.com/friggframework/frigg/pull/48) ([@seanspeaks](https://github.com/seanspeaks))
|
|
127
137
|
- Bump independent versions \[skip ci\] ([@seanspeaks](https://github.com/seanspeaks))
|
|
128
|
-
- A lot of changes all rolled into
|
|
129
|
-
|
|
138
|
+
- A lot of changes all rolled into
|
|
139
|
+
one [#21](https://github.com/friggframework/frigg/pull/21) ([@seanspeaks](https://github.com/seanspeaks))
|
|
140
|
+
- Updated API modules with support for sls offline, and made sure optional chaining with discriminators was in
|
|
141
|
+
place ([@seanspeaks](https://github.com/seanspeaks))
|
|
130
142
|
- Fixing dependencies across all API Modules ([@seanspeaks](https://github.com/seanspeaks))
|
|
131
|
-
- More import issues (Exports are named objects, imports needed to object
|
|
143
|
+
- More import issues (Exports are named objects, imports needed to object
|
|
144
|
+
destructure) ([@seanspeaks](https://github.com/seanspeaks))
|
|
132
145
|
- Updates to API Modules for proper export/imports ([@seanspeaks](https://github.com/seanspeaks))
|
|
133
|
-
- Merge remote-tracking branch 'origin/main' into
|
|
146
|
+
- Merge remote-tracking branch 'origin/main' into
|
|
147
|
+
simplify-mongoose-models ([@seanspeaks](https://github.com/seanspeaks))
|
|
134
148
|
- Update all api modules to use module-plugin models ([@seanspeaks](https://github.com/seanspeaks))
|
|
135
|
-
- Add READMEs for all packages and
|
|
149
|
+
- Add READMEs for all packages and
|
|
150
|
+
api-modules [#20](https://github.com/friggframework/frigg/pull/20) ([@seanspeaks](https://github.com/seanspeaks))
|
|
136
151
|
- Add READMEs for all packages and api-modules ([@seanspeaks](https://github.com/seanspeaks))
|
|
137
152
|
|
|
138
153
|
#### ⚠️ Pushed to `main`
|
|
@@ -150,7 +165,8 @@ Thank you, Jonathan O'Donnell ([@joncodo](https://github.com/joncodo)), for all
|
|
|
150
165
|
|
|
151
166
|
#### 🐛 Bug Fix
|
|
152
167
|
|
|
153
|
-
- fix modules to
|
|
168
|
+
- fix modules to
|
|
169
|
+
@friggframework [#74](https://github.com/friggframework/frigg/pull/74) ([@sheehantoufiq](https://github.com/sheehantoufiq))
|
|
154
170
|
- Bump independent versions \[skip ci\] ([@seanspeaks](https://github.com/seanspeaks))
|
|
155
171
|
|
|
156
172
|
#### Authors: 2
|
|
@@ -164,9 +180,11 @@ Thank you, Jonathan O'Donnell ([@joncodo](https://github.com/joncodo)), for all
|
|
|
164
180
|
|
|
165
181
|
#### 🐛 Bug Fix
|
|
166
182
|
|
|
167
|
-
- Test environment setup for all
|
|
183
|
+
- Test environment setup for all
|
|
184
|
+
modules [#49](https://github.com/friggframework/frigg/pull/49) ([@seanspeaks](https://github.com/seanspeaks))
|
|
168
185
|
- Test environment setup for all modules ([@seanspeaks](https://github.com/seanspeaks))
|
|
169
|
-
- Merge remote-tracking branch 'origin/main' into
|
|
186
|
+
- Merge remote-tracking branch 'origin/main' into
|
|
187
|
+
gitbook-updates [#48](https://github.com/friggframework/frigg/pull/48) ([@seanspeaks](https://github.com/seanspeaks))
|
|
170
188
|
|
|
171
189
|
#### Authors: 1
|
|
172
190
|
|
|
@@ -178,10 +196,12 @@ Thank you, Jonathan O'Donnell ([@joncodo](https://github.com/joncodo)), for all
|
|
|
178
196
|
|
|
179
197
|
#### 🐛 Bug Fix
|
|
180
198
|
|
|
181
|
-
- version bumped to address tag
|
|
199
|
+
- version bumped to address tag
|
|
200
|
+
issue [#43](https://github.com/friggframework/frigg/pull/43) ([@seanspeaks](https://github.com/seanspeaks))
|
|
182
201
|
- version bumped ([@seanspeaks](https://github.com/seanspeaks))
|
|
183
202
|
- Publish ([@seanspeaks](https://github.com/seanspeaks))
|
|
184
|
-
- Add nx and
|
|
203
|
+
- Add nx and
|
|
204
|
+
licenses [#37](https://github.com/friggframework/frigg/pull/37) ([@seanspeaks](https://github.com/seanspeaks))
|
|
185
205
|
- MIT to all packages ([@seanspeaks](https://github.com/seanspeaks))
|
|
186
206
|
|
|
187
207
|
#### Authors: 1
|
package/LICENSE.md
CHANGED
|
@@ -2,8 +2,15 @@ MIT License
|
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2022 Left Hook Inc.
|
|
4
4
|
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
6
|
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
7
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
8
|
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
9
|
|
|
7
|
-
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or
|
|
10
|
+
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or
|
|
11
|
+
substantial portions of the Software.
|
|
8
12
|
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
14
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
15
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
16
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# pipedrive
|
|
2
|
-
|
|
3
|
-
This is the API Module for pipedrive that allows the [Frigg](https://friggframework.org) code to talk to the pipedrive
|
|
2
|
+
|
|
3
|
+
This is the API Module for pipedrive that allows the [Frigg](https://friggframework.org) code to talk to the pipedrive
|
|
4
|
+
API.
|
|
4
5
|
|
|
5
6
|
Read more on the [Frigg documentation site](https://docs.friggframework.org/api-modules/list/pipedrive
|
package/api.js
CHANGED
|
@@ -1,118 +1,453 @@
|
|
|
1
|
-
const { OAuth2Requester } = require('@friggframework/
|
|
2
|
-
const { get } = require('@friggframework/assertions');
|
|
1
|
+
const { OAuth2Requester, get } = require('@friggframework/core');
|
|
3
2
|
|
|
4
3
|
class Api extends OAuth2Requester {
|
|
5
4
|
constructor(params) {
|
|
6
5
|
super(params);
|
|
6
|
+
this.baseUrl = 'https://api.pipedrive.com/api/v2';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
12
|
-
|
|
13
|
-
this.
|
|
14
|
-
this.client_secret = process.env.PIPEDRIVE_CLIENT_SECRET;
|
|
15
|
-
this.redirect_uri = `${process.env.REDIRECT_URI}/pipedrive`;
|
|
16
|
-
this.scopes = process.env.PIPEDRIVE_SCOPES;
|
|
8
|
+
// OAuth2 configuration
|
|
9
|
+
this.authorizationUri = 'https://oauth.pipedrive.com/oauth/authorize';
|
|
10
|
+
this.tokenUri = 'https://oauth.pipedrive.com/oauth/token';
|
|
11
|
+
this.client_id = get(params, 'client_id', process.env.PIPEDRIVE_CLIENT_ID);
|
|
12
|
+
this.client_secret = get(params, 'client_secret', process.env.PIPEDRIVE_CLIENT_SECRET);
|
|
13
|
+
this.redirect_uri = get(params, 'redirect_uri', process.env.PIPEDRIVE_REDIRECT_URI);
|
|
17
14
|
|
|
18
15
|
this.URLs = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
activityById: (activityId) => `/
|
|
22
|
-
getUser: '/v1/users/me',
|
|
23
|
-
users: '/v1/users',
|
|
24
|
-
deals: '/v1/deals',
|
|
25
|
-
};
|
|
16
|
+
// Activities endpoints
|
|
17
|
+
activities: '/activities',
|
|
18
|
+
activityById: (activityId) => `/activities/${activityId}`,
|
|
26
19
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
// Deals endpoints
|
|
21
|
+
deals: '/deals',
|
|
22
|
+
dealById: (dealId) => `/deals/${dealId}`,
|
|
30
23
|
|
|
31
|
-
|
|
24
|
+
// Products endpoints
|
|
25
|
+
products: '/products',
|
|
26
|
+
productById: (productId) => `/products/${productId}`,
|
|
27
|
+
|
|
28
|
+
// Leads endpoints
|
|
29
|
+
leads: '/leads',
|
|
30
|
+
leadById: (leadId) => `/leads/${leadId}`,
|
|
31
|
+
|
|
32
|
+
// Organizations endpoints
|
|
33
|
+
organizations: '/organizations',
|
|
34
|
+
organizationById: (orgId) => `/organizations/${orgId}`,
|
|
35
|
+
|
|
36
|
+
// Persons endpoints
|
|
37
|
+
persons: '/persons',
|
|
38
|
+
personById: (personId) => `/persons/${personId}`,
|
|
39
|
+
|
|
40
|
+
// Pipelines endpoints
|
|
41
|
+
pipelines: '/pipelines',
|
|
42
|
+
pipelineById: (pipelineId) => `/pipelines/${pipelineId}`,
|
|
43
|
+
|
|
44
|
+
// Stages endpoints
|
|
45
|
+
stages: '/stages',
|
|
46
|
+
stageById: (stageId) => `/stages/${stageId}`,
|
|
47
|
+
|
|
48
|
+
// Users endpoints
|
|
49
|
+
users: '/users',
|
|
50
|
+
userById: (userId) => `/users/${userId}`,
|
|
51
|
+
|
|
52
|
+
// Search endpoints
|
|
53
|
+
itemSearch: '/itemSearch',
|
|
54
|
+
};
|
|
32
55
|
}
|
|
33
56
|
|
|
34
|
-
async
|
|
35
|
-
|
|
36
|
-
return super.setTokens(params);
|
|
57
|
+
async getAuthorizationUri() {
|
|
58
|
+
return `${this.authorizationUri}?client_id=${this.client_id}&redirect_uri=${this.redirect_uri}&response_type=code`;
|
|
37
59
|
}
|
|
38
60
|
|
|
39
|
-
|
|
40
|
-
|
|
61
|
+
// Activities API methods
|
|
62
|
+
async getActivities(options = {}) {
|
|
63
|
+
const query = this._cleanParams({
|
|
64
|
+
filter_id: options.filter_id,
|
|
65
|
+
ids: options.ids,
|
|
66
|
+
owner_id: options.owner_id,
|
|
67
|
+
deal_id: options.deal_id,
|
|
68
|
+
lead_id: options.lead_id,
|
|
69
|
+
person_id: options.person_id,
|
|
70
|
+
org_id: options.org_id,
|
|
71
|
+
done: options.done,
|
|
72
|
+
updated_since: options.updated_since,
|
|
73
|
+
updated_until: options.updated_until,
|
|
74
|
+
sort_by: options.sort_by || 'id',
|
|
75
|
+
sort_direction: options.sort_direction || 'asc',
|
|
76
|
+
include_fields: options.include_fields,
|
|
77
|
+
limit: options.limit || 100,
|
|
78
|
+
cursor: options.cursor
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return this._get({
|
|
82
|
+
url: this.baseUrl + this.URLs.activities,
|
|
83
|
+
query
|
|
84
|
+
});
|
|
41
85
|
}
|
|
42
|
-
|
|
43
|
-
async
|
|
44
|
-
|
|
45
|
-
url: this.
|
|
46
|
-
};
|
|
47
|
-
const res = await this._get(options);
|
|
48
|
-
return res;
|
|
86
|
+
|
|
87
|
+
async getActivityById(activityId) {
|
|
88
|
+
return this._get({
|
|
89
|
+
url: this.baseUrl + this.URLs.activityById(activityId)
|
|
90
|
+
});
|
|
49
91
|
}
|
|
50
|
-
|
|
51
|
-
async
|
|
52
|
-
|
|
53
|
-
url: this.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
92
|
+
|
|
93
|
+
async createActivity(body) {
|
|
94
|
+
return this._post({
|
|
95
|
+
url: this.baseUrl + this.URLs.activities,
|
|
96
|
+
body,
|
|
97
|
+
headers: {
|
|
98
|
+
'Content-Type': 'application/json'
|
|
99
|
+
}
|
|
100
|
+
});
|
|
57
101
|
}
|
|
58
102
|
|
|
59
|
-
async
|
|
60
|
-
|
|
61
|
-
url: this.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return res;
|
|
103
|
+
async updateActivity(activityId, body) {
|
|
104
|
+
return this._put({
|
|
105
|
+
url: this.baseUrl + this.URLs.activityById(activityId),
|
|
106
|
+
body,
|
|
107
|
+
headers: {
|
|
108
|
+
'Content-Type': 'application/json'
|
|
109
|
+
}
|
|
110
|
+
});
|
|
68
111
|
}
|
|
69
112
|
|
|
70
113
|
async deleteActivity(activityId) {
|
|
71
|
-
|
|
72
|
-
url: this.
|
|
73
|
-
};
|
|
74
|
-
const res = await this._delete(options);
|
|
75
|
-
return res;
|
|
114
|
+
return this._delete({
|
|
115
|
+
url: this.baseUrl + this.URLs.activityById(activityId)
|
|
116
|
+
});
|
|
76
117
|
}
|
|
77
118
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
119
|
+
// Deals API methods
|
|
120
|
+
async getDeals(options = {}) {
|
|
121
|
+
const query = this._cleanParams({
|
|
122
|
+
filter_id: options.filter_id,
|
|
123
|
+
ids: options.ids,
|
|
124
|
+
owner_id: options.owner_id,
|
|
125
|
+
stage_id: options.stage_id,
|
|
126
|
+
status: options.status,
|
|
127
|
+
updated_since: options.updated_since,
|
|
128
|
+
updated_until: options.updated_until,
|
|
129
|
+
sort_by: options.sort_by || 'id',
|
|
130
|
+
sort_direction: options.sort_direction || 'asc',
|
|
131
|
+
limit: options.limit || 100,
|
|
132
|
+
cursor: options.cursor
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
return this._get({
|
|
136
|
+
url: this.baseUrl + this.URLs.deals,
|
|
137
|
+
query
|
|
138
|
+
});
|
|
85
139
|
}
|
|
86
140
|
|
|
87
|
-
async
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
141
|
+
async getDealById(dealId) {
|
|
142
|
+
return this._get({
|
|
143
|
+
url: this.baseUrl + this.URLs.dealById(dealId)
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async createDeal(body) {
|
|
148
|
+
return this._post({
|
|
149
|
+
url: this.baseUrl + this.URLs.deals,
|
|
150
|
+
body,
|
|
94
151
|
headers: {
|
|
95
|
-
'Content-Type': 'application/json'
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
const res = await this._post(options);
|
|
99
|
-
return res;
|
|
152
|
+
'Content-Type': 'application/json'
|
|
153
|
+
}
|
|
154
|
+
});
|
|
100
155
|
}
|
|
101
|
-
|
|
102
|
-
async
|
|
103
|
-
|
|
104
|
-
url: this.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
156
|
+
|
|
157
|
+
async updateDeal(dealId, body) {
|
|
158
|
+
return this._put({
|
|
159
|
+
url: this.baseUrl + this.URLs.dealById(dealId),
|
|
160
|
+
body,
|
|
161
|
+
headers: {
|
|
162
|
+
'Content-Type': 'application/json'
|
|
163
|
+
}
|
|
164
|
+
});
|
|
108
165
|
}
|
|
109
166
|
|
|
110
|
-
async
|
|
111
|
-
|
|
112
|
-
url: this.
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
|
|
167
|
+
async deleteDeal(dealId) {
|
|
168
|
+
return this._delete({
|
|
169
|
+
url: this.baseUrl + this.URLs.dealById(dealId)
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Products API methods
|
|
174
|
+
async getProducts(options = {}) {
|
|
175
|
+
const query = this._cleanParams({
|
|
176
|
+
filter_id: options.filter_id,
|
|
177
|
+
ids: options.ids,
|
|
178
|
+
owner_id: options.owner_id,
|
|
179
|
+
updated_since: options.updated_since,
|
|
180
|
+
updated_until: options.updated_until,
|
|
181
|
+
sort_by: options.sort_by || 'id',
|
|
182
|
+
sort_direction: options.sort_direction || 'asc',
|
|
183
|
+
limit: options.limit || 100,
|
|
184
|
+
cursor: options.cursor
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
return this._get({
|
|
188
|
+
url: this.baseUrl + this.URLs.products,
|
|
189
|
+
query
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async getProductById(productId) {
|
|
194
|
+
return this._get({
|
|
195
|
+
url: this.baseUrl + this.URLs.productById(productId)
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async createProduct(body) {
|
|
200
|
+
return this._post({
|
|
201
|
+
url: this.baseUrl + this.URLs.products,
|
|
202
|
+
body,
|
|
203
|
+
headers: {
|
|
204
|
+
'Content-Type': 'application/json'
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
async updateProduct(productId, body) {
|
|
210
|
+
return this._put({
|
|
211
|
+
url: this.baseUrl + this.URLs.productById(productId),
|
|
212
|
+
body,
|
|
213
|
+
headers: {
|
|
214
|
+
'Content-Type': 'application/json'
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async deleteProduct(productId) {
|
|
220
|
+
return this._delete({
|
|
221
|
+
url: this.baseUrl + this.URLs.productById(productId)
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Leads API methods
|
|
226
|
+
async getLeads(options = {}) {
|
|
227
|
+
const query = this._cleanParams({
|
|
228
|
+
filter_id: options.filter_id,
|
|
229
|
+
ids: options.ids,
|
|
230
|
+
owner_id: options.owner_id,
|
|
231
|
+
updated_since: options.updated_since,
|
|
232
|
+
updated_until: options.updated_until,
|
|
233
|
+
sort_by: options.sort_by || 'id',
|
|
234
|
+
sort_direction: options.sort_direction || 'asc',
|
|
235
|
+
limit: options.limit || 100,
|
|
236
|
+
cursor: options.cursor
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
return this._get({
|
|
240
|
+
url: this.baseUrl + this.URLs.leads,
|
|
241
|
+
query
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async getLeadById(leadId) {
|
|
246
|
+
return this._get({
|
|
247
|
+
url: this.baseUrl + this.URLs.leadById(leadId)
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async createLead(body) {
|
|
252
|
+
return this._post({
|
|
253
|
+
url: this.baseUrl + this.URLs.leads,
|
|
254
|
+
body,
|
|
255
|
+
headers: {
|
|
256
|
+
'Content-Type': 'application/json'
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async updateLead(leadId, body) {
|
|
262
|
+
return this._put({
|
|
263
|
+
url: this.baseUrl + this.URLs.leadById(leadId),
|
|
264
|
+
body,
|
|
265
|
+
headers: {
|
|
266
|
+
'Content-Type': 'application/json'
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async deleteLead(leadId) {
|
|
272
|
+
return this._delete({
|
|
273
|
+
url: this.baseUrl + this.URLs.leadById(leadId)
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// Organizations API methods
|
|
278
|
+
async getOrganizations(options = {}) {
|
|
279
|
+
const query = this._cleanParams({
|
|
280
|
+
filter_id: options.filter_id,
|
|
281
|
+
ids: options.ids,
|
|
282
|
+
owner_id: options.owner_id,
|
|
283
|
+
updated_since: options.updated_since,
|
|
284
|
+
updated_until: options.updated_until,
|
|
285
|
+
sort_by: options.sort_by || 'id',
|
|
286
|
+
sort_direction: options.sort_direction || 'asc',
|
|
287
|
+
limit: options.limit || 100,
|
|
288
|
+
cursor: options.cursor
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
return this._get({
|
|
292
|
+
url: this.baseUrl + this.URLs.organizations,
|
|
293
|
+
query
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
async getOrganizationById(orgId) {
|
|
298
|
+
return this._get({
|
|
299
|
+
url: this.baseUrl + this.URLs.organizationById(orgId)
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
async createOrganization(body) {
|
|
304
|
+
return this._post({
|
|
305
|
+
url: this.baseUrl + this.URLs.organizations,
|
|
306
|
+
body,
|
|
307
|
+
headers: {
|
|
308
|
+
'Content-Type': 'application/json'
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
async updateOrganization(orgId, body) {
|
|
314
|
+
return this._put({
|
|
315
|
+
url: this.baseUrl + this.URLs.organizationById(orgId),
|
|
316
|
+
body,
|
|
317
|
+
headers: {
|
|
318
|
+
'Content-Type': 'application/json'
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
async deleteOrganization(orgId) {
|
|
324
|
+
return this._delete({
|
|
325
|
+
url: this.baseUrl + this.URLs.organizationById(orgId)
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Persons API methods
|
|
330
|
+
async getPersons(options = {}) {
|
|
331
|
+
const query = this._cleanParams({
|
|
332
|
+
filter_id: options.filter_id,
|
|
333
|
+
ids: options.ids,
|
|
334
|
+
owner_id: options.owner_id,
|
|
335
|
+
org_id: options.org_id,
|
|
336
|
+
updated_since: options.updated_since,
|
|
337
|
+
updated_until: options.updated_until,
|
|
338
|
+
sort_by: options.sort_by || 'id',
|
|
339
|
+
sort_direction: options.sort_direction || 'asc',
|
|
340
|
+
limit: options.limit || 100,
|
|
341
|
+
cursor: options.cursor
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
return this._get({
|
|
345
|
+
url: this.baseUrl + this.URLs.persons,
|
|
346
|
+
query
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
async getPersonById(personId) {
|
|
351
|
+
return this._get({
|
|
352
|
+
url: this.baseUrl + this.URLs.personById(personId)
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
async createPerson(body) {
|
|
357
|
+
return this._post({
|
|
358
|
+
url: this.baseUrl + this.URLs.persons,
|
|
359
|
+
body,
|
|
360
|
+
headers: {
|
|
361
|
+
'Content-Type': 'application/json'
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
async updatePerson(personId, body) {
|
|
367
|
+
return this._put({
|
|
368
|
+
url: this.baseUrl + this.URLs.personById(personId),
|
|
369
|
+
body,
|
|
370
|
+
headers: {
|
|
371
|
+
'Content-Type': 'application/json'
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
async deletePerson(personId) {
|
|
377
|
+
return this._delete({
|
|
378
|
+
url: this.baseUrl + this.URLs.personById(personId)
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Pipelines API methods
|
|
383
|
+
async getPipelines(options = {}) {
|
|
384
|
+
const query = this._cleanParams(options);
|
|
385
|
+
return this._get({
|
|
386
|
+
url: this.baseUrl + this.URLs.pipelines,
|
|
387
|
+
query
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
async getPipelineById(pipelineId) {
|
|
392
|
+
return this._get({
|
|
393
|
+
url: this.baseUrl + this.URLs.pipelineById(pipelineId)
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Stages API methods
|
|
398
|
+
async getStages(options = {}) {
|
|
399
|
+
const query = this._cleanParams(options);
|
|
400
|
+
return this._get({
|
|
401
|
+
url: this.baseUrl + this.URLs.stages,
|
|
402
|
+
query
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
async getStageById(stageId) {
|
|
407
|
+
return this._get({
|
|
408
|
+
url: this.baseUrl + this.URLs.stageById(stageId)
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// Users API methods
|
|
413
|
+
async getUsers(options = {}) {
|
|
414
|
+
const query = this._cleanParams(options);
|
|
415
|
+
return this._get({
|
|
416
|
+
url: this.baseUrl + this.URLs.users,
|
|
417
|
+
query
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
async getUserById(userId) {
|
|
422
|
+
return this._get({
|
|
423
|
+
url: this.baseUrl + this.URLs.userById(userId)
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
async getCurrentUser() {
|
|
428
|
+
const users = await this.getUsers();
|
|
429
|
+
return users.data && users.data.length > 0 ? users.data[0] : null;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// Search API methods
|
|
433
|
+
async search(options = {}) {
|
|
434
|
+
const query = this._cleanParams(options);
|
|
435
|
+
return this._get({
|
|
436
|
+
url: this.baseUrl + this.URLs.itemSearch,
|
|
437
|
+
query
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// Helper methods
|
|
442
|
+
_cleanParams(params) {
|
|
443
|
+
const cleaned = {};
|
|
444
|
+
Object.keys(params).forEach(key => {
|
|
445
|
+
if (params[key] !== undefined && params[key] !== null) {
|
|
446
|
+
cleaned[key] = params[key];
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
return cleaned;
|
|
116
450
|
}
|
|
117
451
|
}
|
|
452
|
+
|
|
118
453
|
module.exports = { Api };
|