-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
10 changed files
with
296 additions
and
21 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)), | ||
}; | ||
}, | ||
}, | ||
}; |
38 changes: 38 additions & 0 deletions
38
components/highlevel_oauth/actions/create-contact/create-contact.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
41 changes: 41 additions & 0 deletions
41
components/highlevel_oauth/actions/update-contact/update-contact.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
38 changes: 38 additions & 0 deletions
38
components/highlevel_oauth/actions/upsert-contact/upsert-contact.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
]), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.