@friggframework/api-module-pipedrive 0.11.2 → 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/api.js CHANGED
@@ -1,118 +1,453 @@
1
- const { OAuth2Requester } = require('@friggframework/module-plugin');
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
- this.access_token = get(params, 'access_token', null);
9
- this.refresh_token = get(params, 'refresh_token', null);
10
- this.companyDomain = get(params, 'companyDomain', null);
11
- this.baseURL = () => `${this.companyDomain}/api`;
12
-
13
- this.client_id = process.env.PIPEDRIVE_CLIENT_ID;
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
- activities: '/v1/activities',
20
- activityFields: '/v1/activityFields',
21
- activityById: (activityId) => `/v1/activities/${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
- this.authorizationUri = encodeURI(
28
- `https://oauth.pipedrive.com/oauth/authorize?client_id=${this.client_id}&redirect_uri=${this.redirect_uri}&response_type=code&scope=${this.scopes}`
29
- );
20
+ // Deals endpoints
21
+ deals: '/deals',
22
+ dealById: (dealId) => `/deals/${dealId}`,
30
23
 
31
- this.tokenUri = 'https://oauth.pipedrive.com/oauth/token';
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 setTokens(params) {
35
- await this.setCompanyDomain(params.api_domain);
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
- async setCompanyDomain(companyDomain) {
40
- this.companyDomain = companyDomain;
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
- // ************************** Deals **********************************
43
- async listDeals() {
44
- const options = {
45
- url: this.baseURL() + this.URLs.deals,
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
- // ************************** Activities **********************************
51
- async listActivityFields() {
52
- const options = {
53
- url: this.baseURL() + this.URLs.activityFields,
54
- };
55
- const res = await this._get(options);
56
- return res;
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 listActivities(params) {
60
- const options = {
61
- url: this.baseURL() + this.URLs.activities,
62
- };
63
- if (params.query) {
64
- options.query = params.query;
65
- }
66
- const res = await this._get(options);
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
- const options = {
72
- url: this.baseURL() + this.URLs.activityById(activityId),
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
- async updateActivity(activityId, task) {
79
- const options = {
80
- url: this.baseURL() + this.URLs.activityById(activityId),
81
- body: task,
82
- };
83
- const res = await this._patch(options);
84
- return res;
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 createActivity(params) {
88
- const dealId = get(params, 'dealId', null);
89
- const subject = get(params, 'subject');
90
- const type = get(params, 'type');
91
- const options = {
92
- url: this.baseURL() + this.URLs.activities,
93
- body: { ...params },
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
- // ************************** Users **********************************
102
- async getUser() {
103
- const options = {
104
- url: this.baseURL() + this.URLs.getUser,
105
- };
106
- const res = await this._get(options);
107
- return res;
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 listUsers() {
111
- const options = {
112
- url: this.baseURL() + this.URLs.users,
113
- };
114
- const res = await this._get(options);
115
- return res;
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 };
@@ -1,9 +1,11 @@
1
1
  {
2
- "name": "pipedrive",
3
- "label": "PipeDrive CRM",
4
- "productUrl": "https://pipedrive.com",
5
- "apiDocs": "https://developer.pipedrive.com",
6
- "logoUrl": "https://friggframework.org/assets/img/pipedrive.jpeg",
7
- "categories": ["Sales"],
8
- "description": "Pipedrive"
2
+ "name": "pipedrive",
3
+ "label": "PipeDrive CRM",
4
+ "productUrl": "https://pipedrive.com",
5
+ "apiDocs": "https://developer.pipedrive.com",
6
+ "logoUrl": "https://friggframework.org/assets/img/pipedrive-icon.png",
7
+ "categories": [
8
+ "Sales"
9
+ ],
10
+ "description": "Pipedrive"
9
11
  }
package/definition.js ADDED
@@ -0,0 +1,54 @@
1
+ require('dotenv').config();
2
+ const { Api } = require('./api');
3
+ const { get } = require('@friggframework/core');
4
+ const config = require('./defaultConfig.json');
5
+
6
+ const Definition = {
7
+ API: Api,
8
+ getName: function () {
9
+ return config.name;
10
+ },
11
+ moduleName: config.name,
12
+ modelName: 'Pipedrive',
13
+ requiredAuthMethods: {
14
+ getAuthorizationRequirements: async function (params) {
15
+ return {
16
+ url: await this.api.getAuthUri(),
17
+ type: 'oauth2',
18
+ };
19
+ },
20
+ getToken: async function (api, params) {
21
+ const code = get(params.data, 'code');
22
+ return api.getTokenFromCode(code);
23
+ },
24
+ getEntityDetails: async function (api, callbackParams, tokenResponse, userId) {
25
+ const userDetails = await api.getUser();
26
+ return {
27
+ identifiers: { externalId: userDetails.data.id, user: userId },
28
+ details: { name: userDetails.data.name || userDetails.data.email }
29
+ };
30
+ },
31
+ apiPropertiesToPersist: {
32
+ credential: ['access_token', 'refresh_token', 'companyDomain'],
33
+ entity: []
34
+ },
35
+ getCredentialDetails: async function (api, userId) {
36
+ const userDetails = await api.getUser();
37
+ return {
38
+ identifiers: { externalId: userDetails.data.id, user: userId },
39
+ details: {}
40
+ };
41
+ },
42
+ testAuthRequest: async function (api) {
43
+ return api.getUser();
44
+ }
45
+ },
46
+ env: {
47
+ client_id: process.env.PIPEDRIVE_CLIENT_ID,
48
+ client_secret: process.env.PIPEDRIVE_CLIENT_SECRET,
49
+ scope: process.env.PIPEDRIVE_SCOPE,
50
+ redirect_uri: `${process.env.REDIRECT_URI}/pipedrive`
51
+ }
52
+ };
53
+
54
+ module.exports = { Definition };
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
- const { Api } = require('./api');
2
- const { Credential } = require('./models/credential');
3
- const { Entity } = require('./models/entity');
1
+ const {Api} = require('./api');
2
+ const {Credential} = require('./models/credential');
3
+ const {Entity} = require('./models/entity');
4
4
  const ModuleManager = require('./manager');
5
5
  const Config = require('./defaultConfig');
6
6
 
package/jest-setup.js CHANGED
@@ -1,2 +1,2 @@
1
- const { globalSetup } = require('@friggframework/test-environment');
1
+ const {globalSetup} = require('@friggframework/test');
2
2
  module.exports = globalSetup;
package/jest-teardown.js CHANGED
@@ -1,2 +1,2 @@
1
- const { globalTeardown } = require('@friggframework/test-environment');
1
+ const {globalTeardown} = require('@friggframework/test');
2
2
  module.exports = globalTeardown;
package/manager.js CHANGED
@@ -1,18 +1,20 @@
1
- const _ = require('lodash');
2
- const { Api } = require('./api.js');
3
- const { Entity } = require('./models/entity');
4
- const { Credential } = require('./models/credential');
5
1
  const {
6
2
  ModuleManager,
7
3
  ModuleConstants,
8
- } = require('@friggframework/module-plugin');
9
- const { flushDebugLog, debug } = require('@friggframework/logs');
4
+ flushDebugLog,
5
+ debug
6
+ } = require('@friggframework/core');
7
+ const {Api} = require('./api.js');
8
+ const {Entity} = require('./models/entity');
9
+ const {Credential} = require('./models/credential');
10
10
  const Config = require('./defaultConfig.json');
11
11
 
12
12
  class Manager extends ModuleManager {
13
- static Entity = Entity;
13
+ static
14
+ Entity = Entity;
14
15
 
15
- static Credential = Credential;
16
+ static
17
+ Credential = Credential;
16
18
 
17
19
  constructor(params) {
18
20
  super(params);
@@ -22,10 +24,11 @@ class Manager extends ModuleManager {
22
24
  return Config.name;
23
25
  }
24
26
 
25
- static async getInstance(params) {
27
+ static
28
+ async getInstance(params) {
26
29
  const instance = new this(params);
27
30
 
28
- const apiParams = { delegate: instance };
31
+ const apiParams = {delegate: instance};
29
32
  if (params.entityId) {
30
33
  instance.entity = await instance.entityMO.get(params.entityId);
31
34
  instance.credential = await instance.credentialMO.get(