@pipedream/easybroker 0.0.1 → 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.
@@ -0,0 +1,83 @@
1
+ import easybroker from "../../easybroker.app.mjs";
2
+ import { ConfigurationError } from "@pipedream/platform";
3
+
4
+ export default {
5
+ key: "easybroker-create-contact-request",
6
+ name: "Create Contact Request",
7
+ description: "Creates or updates a new lead in EasyBroker that is interested in the provided property. [See the documentation](https://dev.easybroker.com/reference/post_contact-requests)",
8
+ version: "0.0.1",
9
+ type: "action",
10
+ annotations: {
11
+ destructiveHint: false,
12
+ openWorldHint: true,
13
+ readOnlyHint: false,
14
+ },
15
+ props: {
16
+ easybroker,
17
+ source: {
18
+ type: "string",
19
+ label: "Source",
20
+ description: "The source of the contact request. Example: `mydomain.com`",
21
+ },
22
+ propertyId: {
23
+ propDefinition: [
24
+ easybroker,
25
+ "propertyId",
26
+ ],
27
+ description: "The ID of the property to create the contact request for",
28
+ optional: true,
29
+ },
30
+ name: {
31
+ type: "string",
32
+ label: "Name",
33
+ description: "The name of the contact making the request",
34
+ },
35
+ email: {
36
+ type: "string",
37
+ label: "Email",
38
+ description: "The email address of the contact making the request",
39
+ },
40
+ phone: {
41
+ type: "string",
42
+ label: "Phone",
43
+ description: "The phone number of the contact making the request",
44
+ optional: true,
45
+ },
46
+ message: {
47
+ type: "string",
48
+ label: "Message",
49
+ description: "The message from the contact making the request. Example: `I'm interested in the property.`",
50
+ },
51
+ },
52
+ async run({ $ }) {
53
+ if (this.propertyId && (!this.email && !this.phone && !this.name)) {
54
+ throw new ConfigurationError("You must provide at least the **Email**, **Phone**, or **Name** field when creating a contact request for a specific property.");
55
+ }
56
+
57
+ if (!this.propertyId && !this.name) {
58
+ throw new ConfigurationError("You must provide the **Name** field when creating a contact request for a general lead.");
59
+ }
60
+
61
+ if (!this.propertyId && !this.email && !this.phone) {
62
+ throw new ConfigurationError("You must provide either the **Email** or **Phone** field when creating a contact request for a general lead.");
63
+ }
64
+
65
+ if (!this.propertyId && !this.message) {
66
+ throw new ConfigurationError("You must provide the **Message** field when creating a contact request for a general lead.");
67
+ }
68
+
69
+ const response = await this.easybroker.createContactRequest({
70
+ $,
71
+ data: {
72
+ source: this.source,
73
+ property_id: this.propertyId,
74
+ name: this.name,
75
+ email: this.email,
76
+ phone: this.phone,
77
+ message: this.message,
78
+ },
79
+ });
80
+ $.export("$summary", "Successfully created contact request.");
81
+ return response;
82
+ },
83
+ };
@@ -0,0 +1,31 @@
1
+ import easybroker from "../../easybroker.app.mjs";
2
+
3
+ export default {
4
+ key: "easybroker-get-contact",
5
+ name: "Get Contact",
6
+ description: "Get details of a contact. [See the documentation](https://dev.easybroker.com/reference/get_contacts-contact-id)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ annotations: {
10
+ destructiveHint: false,
11
+ openWorldHint: true,
12
+ readOnlyHint: true,
13
+ },
14
+ props: {
15
+ easybroker,
16
+ contactId: {
17
+ propDefinition: [
18
+ easybroker,
19
+ "contactId",
20
+ ],
21
+ },
22
+ },
23
+ async run({ $ }) {
24
+ const response = await this.easybroker.getContact({
25
+ $,
26
+ contactId: this.contactId,
27
+ });
28
+ $.export("$summary", `Successfully retrieved contact with ID ${this.contactId}`);
29
+ return response;
30
+ },
31
+ };
@@ -0,0 +1,31 @@
1
+ import easybroker from "../../easybroker.app.mjs";
2
+
3
+ export default {
4
+ key: "easybroker-get-property",
5
+ name: "Get Property",
6
+ description: "Get details of a property. [See the documentation](https://dev.easybroker.com/reference/get_properties-property-id)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ annotations: {
10
+ destructiveHint: false,
11
+ openWorldHint: true,
12
+ readOnlyHint: true,
13
+ },
14
+ props: {
15
+ easybroker,
16
+ propertyId: {
17
+ propDefinition: [
18
+ easybroker,
19
+ "propertyId",
20
+ ],
21
+ },
22
+ },
23
+ async run({ $ }) {
24
+ const response = await this.easybroker.getProperty({
25
+ $,
26
+ propertyId: this.propertyId,
27
+ });
28
+ $.export("$summary", `Successfully retrieved property with ID ${this.propertyId}`);
29
+ return response;
30
+ },
31
+ };
@@ -0,0 +1,67 @@
1
+ import easybroker from "../../easybroker.app.mjs";
2
+
3
+ export default {
4
+ key: "easybroker-list-contact-requests",
5
+ name: "List Contact Requests",
6
+ description: "List all contact requests. [See the documentation](https://dev.easybroker.com/reference/get_contact-requests)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ annotations: {
10
+ destructiveHint: false,
11
+ openWorldHint: true,
12
+ readOnlyHint: true,
13
+ },
14
+ props: {
15
+ easybroker,
16
+ propertyId: {
17
+ propDefinition: [
18
+ easybroker,
19
+ "propertyId",
20
+ ],
21
+ description: "The ID of a property to retrieve the contact requests for",
22
+ optional: true,
23
+ },
24
+ happenedAfter: {
25
+ type: "string",
26
+ label: "Happened After",
27
+ description: "Get contact requests created after the given date. Example: `2025-03-01T23:26:53.402Z`",
28
+ optional: true,
29
+ },
30
+ happenedBefore: {
31
+ type: "string",
32
+ label: "Happened Before",
33
+ description: "Get contact requests created before the given date. Example: `2025-03-01T23:26:53.402Z`",
34
+ optional: true,
35
+ },
36
+ limit: {
37
+ type: "integer",
38
+ label: "Limit",
39
+ description: "The maximum number of contact requests to return",
40
+ optional: true,
41
+ max: 50,
42
+ },
43
+ page: {
44
+ type: "integer",
45
+ label: "Page",
46
+ description: "The page number to return",
47
+ optional: true,
48
+ default: 1,
49
+ },
50
+ },
51
+ async run({ $ }) {
52
+ const response = await this.easybroker.listContactRequests({
53
+ $,
54
+ params: {
55
+ property_id: this.propertyId,
56
+ happened_after: this.happenedAfter,
57
+ happened_before: this.happenedBefore,
58
+ limit: this.limit,
59
+ page: this.page,
60
+ },
61
+ });
62
+ $.export("$summary", `Successfully listed ${response?.content?.length} contact request${response?.content?.length === 1
63
+ ? ""
64
+ : "s"}.`);
65
+ return response;
66
+ },
67
+ };
@@ -1,11 +1,102 @@
1
+ import { axios } from "@pipedream/platform";
2
+
1
3
  export default {
2
4
  type: "app",
3
5
  app: "easybroker",
4
- propDefinitions: {},
6
+ propDefinitions: {
7
+ propertyId: {
8
+ type: "string",
9
+ label: "Property ID",
10
+ description: "The ID of the property to get",
11
+ async options({ page }) {
12
+ const { content } = await this.listProperties({
13
+ params: {
14
+ page: page + 1,
15
+ },
16
+ });
17
+ return content?.map(({
18
+ public_id: value, title: label,
19
+ }) => ({
20
+ label,
21
+ value,
22
+ })) || [];
23
+ },
24
+ },
25
+ contactId: {
26
+ type: "string",
27
+ label: "Contact ID",
28
+ description: "The ID of the contact to get",
29
+ async options({ page }) {
30
+ const { content } = await this.listContacts({
31
+ params: {
32
+ page: page + 1,
33
+ },
34
+ });
35
+ return content?.map(({
36
+ id: value, full_name: label,
37
+ }) => ({
38
+ label,
39
+ value,
40
+ })) || [];
41
+ },
42
+ },
43
+ },
5
44
  methods: {
6
- // this.$auth contains connected account data
7
- authKeys() {
8
- console.log(Object.keys(this.$auth));
45
+ _baseUrl() {
46
+ return "https://api.easybroker.com/v1";
47
+ },
48
+ _makeRequest({
49
+ $ = this, path, ...opts
50
+ }) {
51
+ return axios($, {
52
+ url: `${this._baseUrl()}${path}`,
53
+ headers: {
54
+ "x-authorization": `${this.$auth.api_key}`,
55
+ "Accept": "application/json",
56
+ },
57
+ ...opts,
58
+ });
59
+ },
60
+ getProperty({
61
+ propertyId, ...opts
62
+ }) {
63
+ return this._makeRequest({
64
+ path: `/properties/${propertyId}`,
65
+ ...opts,
66
+ });
67
+ },
68
+ getContact({
69
+ contactId, ...opts
70
+ }) {
71
+ return this._makeRequest({
72
+ path: `/contacts/${contactId}`,
73
+ ...opts,
74
+ });
75
+ },
76
+ listProperties(opts = {}) {
77
+ return this._makeRequest({
78
+ path: "/properties",
79
+ ...opts,
80
+ });
81
+ },
82
+ listContacts(opts = {}) {
83
+ return this._makeRequest({
84
+ path: "/contacts",
85
+ ...opts,
86
+ });
87
+ },
88
+ listContactRequests(opts = {}) {
89
+ return this._makeRequest({
90
+ path: "/contact_requests",
91
+ ...opts,
92
+ });
93
+ },
94
+ createContactRequest(opts = {}) {
95
+ return this._makeRequest({
96
+ method: "POST",
97
+ path: "/contact_requests",
98
+ ...opts,
99
+ });
9
100
  },
10
101
  },
11
- };
102
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/easybroker",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "Pipedream EasyBroker Components",
5
5
  "main": "easybroker.app.mjs",
6
6
  "keywords": [
@@ -11,5 +11,8 @@
11
11
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
12
12
  "publishConfig": {
13
13
  "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "@pipedream/platform": "^3.1.1"
14
17
  }
15
18
  }
@@ -0,0 +1,36 @@
1
+ import easybroker from "../../easybroker.app.mjs";
2
+ import {
3
+ DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, ConfigurationError,
4
+ } from "@pipedream/platform";
5
+
6
+ export default {
7
+ props: {
8
+ easybroker,
9
+ db: "$.service.db",
10
+ timer: {
11
+ type: "$.interface.timer",
12
+ default: {
13
+ intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
14
+ },
15
+ },
16
+ },
17
+ methods: {
18
+ _getLastCreated() {
19
+ return this.db.get("lastCreated");
20
+ },
21
+ _setLastCreated(lastCreated) {
22
+ this.db.set("lastCreated", lastCreated);
23
+ },
24
+ processEvents() {
25
+ throw new ConfigurationError("processEvents must be implemented");
26
+ },
27
+ },
28
+ hooks: {
29
+ async deploy() {
30
+ await this.processEvents(10);
31
+ },
32
+ },
33
+ async run() {
34
+ await this.processEvents();
35
+ },
36
+ };
@@ -0,0 +1,61 @@
1
+ import common from "../common/base-polling.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "easybroker-new-contact-created",
6
+ name: "New Contact Created",
7
+ description: "Emit new event when a new contact is created. [See the documentation](https://dev.easybroker.com/reference/get_contacts)",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ async processEvents(max) {
14
+ const lastCreated = this._getLastCreated();
15
+ let maxCreated = lastCreated;
16
+ let page = 1;
17
+ let contacts = [];
18
+ let hasMore = true;
19
+
20
+ do {
21
+ const {
22
+ content, pagination,
23
+ } = await this.easybroker.listContacts({
24
+ params: {
25
+ page,
26
+ limit: 50,
27
+ },
28
+ });
29
+ for (const contact of content) {
30
+ if (!lastCreated || Date.parse(contact.created_at) > Date.parse(lastCreated)) {
31
+ contacts.push(contact);
32
+ if (!maxCreated || Date.parse(contact.created_at) > Date.parse(maxCreated)) {
33
+ maxCreated = contact.created_at;
34
+ }
35
+ }
36
+ }
37
+ hasMore = pagination.next_page !== null;
38
+ page++;
39
+ } while (hasMore);
40
+
41
+ if (maxCreated) {
42
+ this._setLastCreated(maxCreated);
43
+ }
44
+
45
+ if (max && contacts.length >= max) {
46
+ contacts = contacts.slice(-1 * max);
47
+ }
48
+
49
+ for (const contact of contacts) {
50
+ this.$emit(contact, this.generateMeta(contact));
51
+ }
52
+ },
53
+ generateMeta(contact) {
54
+ return {
55
+ id: contact.id,
56
+ summary: `New Contact: ${contact.full_name}`,
57
+ ts: Date.parse(contact.created_at),
58
+ };
59
+ },
60
+ },
61
+ };
@@ -0,0 +1,65 @@
1
+ import common from "../common/base-polling.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "easybroker-new-contact-request-created",
6
+ name: "New Contact Request Created",
7
+ description: "Emit new event when a new contact request is created. [See the documentation](https://dev.easybroker.com/reference/get_contact-requests)",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ async processEvents(max) {
14
+ const lastCreated = this._getLastCreated();
15
+ let maxCreated = lastCreated;
16
+ let page = 1;
17
+ let contactRequests = [];
18
+ let done = false, hasMore = true;
19
+
20
+ do {
21
+ const {
22
+ content, pagination,
23
+ } = await this.easybroker.listContactRequests({
24
+ params: {
25
+ page,
26
+ limit: 50,
27
+ happened_after: lastCreated,
28
+ },
29
+ });
30
+ for (const contactRequest of content) {
31
+ if (!lastCreated || Date.parse(contactRequest.happened_at) > Date.parse(lastCreated)) {
32
+ contactRequests.push(contactRequest);
33
+ if (!maxCreated || Date.parse(contactRequest.happened_at) > Date.parse(maxCreated)) {
34
+ maxCreated = contactRequest.happened_at;
35
+ }
36
+ if (max && contactRequests.length >= max) {
37
+ done = true;
38
+ break;
39
+ }
40
+ } else {
41
+ done = true;
42
+ break;
43
+ }
44
+ }
45
+ hasMore = pagination.next_page !== null;
46
+ page++;
47
+ } while (hasMore && !done);
48
+
49
+ if (maxCreated) {
50
+ this._setLastCreated(maxCreated);
51
+ }
52
+
53
+ for (const contactRequest of contactRequests) {
54
+ this.$emit(contactRequest, this.generateMeta(contactRequest));
55
+ }
56
+ },
57
+ generateMeta(contactRequest) {
58
+ return {
59
+ id: contactRequest.id,
60
+ summary: `New Contact Request: ${contactRequest.name || contactRequest.id}`,
61
+ ts: Date.parse(contactRequest.happened_at),
62
+ };
63
+ },
64
+ },
65
+ };