Skip to content

Commit

Permalink
Highlevel new actions (#11507)
Browse files Browse the repository at this point in the history
* Package updates

* pnpm

* app base request

* pnpm

* Adding request methods

* Create Contact action

* Reusing common props for contacts

* Upsert Contact prop

* Update Contact + contact id query

* Adding missing 'version' header

* Adjustments

* Adding reloadProps to check for correct auth

* Removing gender prop
  • Loading branch information
GTFalcao authored Apr 24, 2024
1 parent 6b93be8 commit aab63d9
Show file tree
Hide file tree
Showing 10 changed files with 296 additions and 21 deletions.
3 changes: 0 additions & 3 deletions components/highlevel_oauth/.gitignore

This file was deleted.

60 changes: 60 additions & 0 deletions components/highlevel_oauth/actions/common/common.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { ConfigurationError } from "@pipedream/platform";
import { parseObjectEntries } from "../../common/utils.mjs";
import app from "../../highlevel_oauth.app.mjs";

export default {
props: {
app: {
...app,
reloadProps: true,
},
name: {
type: "string",
label: "Name",
description: "Full name of the contact, e.g. `Rosan Deo`",
optional: true,
},
email: {
type: "string",
label: "Email",
description: "Email of the contact, e.g. `rosan@deos.com`",
optional: true,
},
phone: {
type: "string",
label: "Phone Number",
description: "Phone number of the contact, e.g. `+1 888-888-8888`",
optional: true,
},
additionalOptions: {
type: "object",
label: "Additional Options",
description:
"Additional parameters to send in the request. [See the documentation](https://highlevel.stoplight.io/docs/integrations/4c8362223c17b-create-contact) for available parameters. Values will be parsed as JSON where applicable.",
optional: true,
},
},
async additionalProps() {
const locationId = this.app.getLocationId();
if (!locationId) {
throw new ConfigurationError("This component requires you to authenticate as a **location**, not as an agency/company. *(`locationId` field is missing from `$auth`)*");
}

return {};
},
methods: {
getData(useLocation = true) {
const {
app, additionalOptions, locationId, ...data
} = this;
return {
app,
...(useLocation && {
locationId: locationId ?? app.getLocationId(),
}),
...data,
...(additionalOptions && parseObjectEntries(additionalOptions)),
};
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import common from "../common/common.mjs";

const {
props: {
app, ...props
},
} = common;

export default {
...common,
key: "highlevel_oauth-create-contact",
name: "Create Contact",
description: "Creates a new contact on HighLevel. [See the documentation](https://highlevel.stoplight.io/docs/integrations/4c8362223c17b-create-contact)",
version: "0.0.1",
type: "action",
props: {
app,
locationId: {
propDefinition: [
app,
"locationId",
],
},
...props,
},
async run({ $ }) {
const {
app, ...data
} = this.getData();
const response = await app.createContact({
$,
data,
});

$.export("$summary", `Successfully created contact (ID: ${response?.contact?.id})`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import common from "../common/common.mjs";

const {
props: {
app, ...props
},
} = common;

export default {
...common,
key: "highlevel_oauth-update-contact",
name: "Update Contact",
description: "Updates a selected contact on HighLevel. [See the documentation](https://highlevel.stoplight.io/docs/integrations/9ce5a739d4fb9-update-contact)",
version: "0.0.1",
type: "action",
props: {
app,
contactId: {
propDefinition: [
app,
"contactId",
],
},
...props,
},
async run({ $ }) {
const {
app,
contactId, ...data

} = this.getData(false);
const response = await app.updateContact({
$,
contactId,
data,
});

$.export("$summary", `Successfully updated contact (ID: ${contactId})`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import common from "../common/common.mjs";

const {
props: {
app, ...props
},
} = common;

export default {
...common,
key: "highlevel_oauth-upsert-contact",
name: "Upsert Contact",
description: "Creates or updates a contact on HighLevel. [See the documentation](https://highlevel.stoplight.io/docs/integrations/f71bbdd88f028-upsert-contact)",
version: "0.0.1",
type: "action",
props: {
app,
locationId: {
propDefinition: [
app,
"locationId",
],
},
...props,
},
async run({ $ }) {
const {
app, ...data
} = this.getData();
const response = await app.upsertContact({
$,
data,
});

$.export("$summary", `Successfully upserted contact (ID: ${response?.contact?.id})`);
return response;
},
};
13 changes: 0 additions & 13 deletions components/highlevel_oauth/app/highlevel_oauth.app.ts

This file was deleted.

22 changes: 22 additions & 0 deletions components/highlevel_oauth/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function optionalParseAsJSON(value) {
try {
return JSON.parse(value);
} catch (e) {
return value;
}
}

export function parseObjectEntries(value) {
const obj = typeof value === "string"
? JSON.parse(value)
: value;
return Object.fromEntries(
Object.entries(obj).map(([
key,
value,
]) => [
key,
optionalParseAsJSON(value),
]),
);
}
87 changes: 87 additions & 0 deletions components/highlevel_oauth/highlevel_oauth.app.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "highlevel_oauth",
propDefinitions: {
locationId: {
type: "string",
label: "Location ID",
description: "If not specified, defaults to the authenticated location.",
optional: true,
},
contactId: {
type: "string",
label: "Contact ID",
description: "Search for a contact or provide a custom contact ID",
useQuery: true,
async options({ query }) {
const { contacts } = await this.searchContacts({
params: {
query,
limit: 100,
locationId: this.getLocationId(),
},
});
return contacts?.map(({
id, name, email,
}) => ({
label: name ?? email ?? id,
value: id,
}));
},
},
},
methods: {
getLocationId() {
return this.$auth.locationId;
},
_baseUrl() {
return "https://services.leadconnectorhq.com";
},
async _makeRequest({
$ = this,
headers,
...otherOpts
}) {
return axios($, {
baseURL: this._baseUrl(),
headers: {
...headers,
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
"Version": "2021-07-28",
},
...otherOpts,
});
},
async createContact(args) {
return this._makeRequest({
method: "POST",
url: "/contacts/",
...args,
});
},
async updateContact({
contactId, ...args
}) {
return this._makeRequest({
method: "PUT",
url: `/contacts/${contactId}`,
...args,
});
},
async upsertContact(args) {
return this._makeRequest({
method: "POST",
url: "/contacts/upsert",
...args,
});
},
async searchContacts(args) {
return this._makeRequest({
url: "/contacts/",
...args,
});
},
},
};
10 changes: 6 additions & 4 deletions components/highlevel_oauth/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"name": "@pipedream/highlevel_oauth",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream HighLevel (OAuth) Components",
"main": "dist/app/highlevel_oauth.app.mjs",
"main": "highlevel_oauth.app.mjs",
"keywords": [
"pipedream",
"highlevel_oauth"
],
"files": ["dist"],
"homepage": "https://pipedream.com/apps/highlevel_oauth",
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.6.2"
}
}
}
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aab63d9

Please sign in to comment.