diff --git a/.github/workflows/close-external-prs.yml b/.github/workflows/close-external-prs.yml index 27da95a6d7dc..f2a4b28f9202 100644 --- a/.github/workflows/close-external-prs.yml +++ b/.github/workflows/close-external-prs.yml @@ -26,6 +26,7 @@ jobs: close: runs-on: ubuntu-latest # OWNER / MEMBER / COLLABORATOR are trusted; everyone else gets auto-closed. + # CONTRIBUTOR means they have a merged PR here before, so they keep their PRs open. # Bots (dependabot, AP automation) and the "keep-open" label are exempt. # Add the "keep-open" label to a PR to reopen it for review (selective reopen, tldraw-style). if: > @@ -33,6 +34,7 @@ jobs: github.event.pull_request.author_association != 'OWNER' && github.event.pull_request.author_association != 'MEMBER' && github.event.pull_request.author_association != 'COLLABORATOR' && + github.event.pull_request.author_association != 'CONTRIBUTOR' && github.event.pull_request.user.type != 'Bot' && !contains(github.event.pull_request.labels.*.name, 'keep-open') steps: diff --git a/bun.lock b/bun.lock index dccd1c7d1f51..858d8f303d32 100644 --- a/bun.lock +++ b/bun.lock @@ -162,7 +162,7 @@ }, "packages/core/shared": { "name": "@activepieces/shared", - "version": "0.150.0", + "version": "0.151.0", "dependencies": { "@activepieces/core-execution": "workspace:*", "@activepieces/core-formula": "workspace:*", @@ -187,7 +187,7 @@ }, "packages/core/utils": { "name": "@activepieces/core-utils", - "version": "0.6.0", + "version": "0.6.1", "dependencies": { "deepmerge-ts": "7.1.0", "ipaddr.js": "2.3.0", @@ -4305,7 +4305,7 @@ }, "packages/pieces/community/hubspot": { "name": "@activepieces/piece-hubspot", - "version": "0.8.10", + "version": "0.9.0", "dependencies": { "@activepieces/core-piece-types": "workspace:*", "@activepieces/core-utils": "workspace:*", @@ -7996,7 +7996,7 @@ }, "packages/pieces/community/sendgrid": { "name": "@activepieces/piece-sendgrid", - "version": "0.5.6", + "version": "0.5.7", "dependencies": { "@activepieces/core-piece-types": "workspace:*", "@activepieces/core-utils": "workspace:*", diff --git a/docs/install/reference/breaking-changes.mdx b/docs/install/reference/breaking-changes.mdx index 0e911bdcfbca..f903c9201357 100644 --- a/docs/install/reference/breaking-changes.mdx +++ b/docs/install/reference/breaking-changes.mdx @@ -167,7 +167,6 @@ Nothing, and no new configuration: the key is derived from a secret your instanc Rolling back costs at most the codes issued after the deploy: the older build cannot read those, so whoever holds one asks for a fresh code. Nothing is rewritten and nothing is deleted, so no cleanup is needed either way. - ## 0.87.0 ### What has changed? diff --git a/packages/core/shared/package.json b/packages/core/shared/package.json index 7d56925d6f9e..3926a64a2316 100644 --- a/packages/core/shared/package.json +++ b/packages/core/shared/package.json @@ -1,6 +1,6 @@ { "name": "@activepieces/shared", - "version": "0.150.0", + "version": "0.151.0", "type": "commonjs", "sideEffects": false, "main": "./dist/src/index.js", diff --git a/packages/core/shared/src/lib/ee/agent/agent.ts b/packages/core/shared/src/lib/ee/agent/agent.ts index f5f3c8ad5025..5c3748b23c93 100644 --- a/packages/core/shared/src/lib/ee/agent/agent.ts +++ b/packages/core/shared/src/lib/ee/agent/agent.ts @@ -103,7 +103,6 @@ const DraftAgentResponse = AgentDraftFields.extend({ modelName: Nullable(z.string().max(MAX_AGENT_NAME_LENGTH)), }) -const AgentTemplate = AgentDraftFields.extend({ id: z.string() }) const DraftAgentRequest = z.object({ projectId: ApId, @@ -127,7 +126,6 @@ export { AgentConfig, AgentIcon, AgentVisibility, - AgentTemplate, CreateAgentRequest, DEFAULT_AGENT_MAX_STEPS, DraftAgentRequest, @@ -151,7 +149,6 @@ export { export type Agent = z.infer export type AgentSummary = z.infer export type AgentConfig = z.infer -export type AgentTemplate = z.infer export type CreateAgentRequest = z.infer export type DraftAgentRequest = z.infer export type AgentDraftFields = z.infer diff --git a/packages/pieces/community/hubspot/package.json b/packages/pieces/community/hubspot/package.json index ea80751a6c8f..c61a9359c2ff 100644 --- a/packages/pieces/community/hubspot/package.json +++ b/packages/pieces/community/hubspot/package.json @@ -1,6 +1,6 @@ { "name": "@activepieces/piece-hubspot", - "version": "0.8.10", + "version": "0.9.0", "main": "./dist/src/index.js", "types": "./dist/src/index.d.ts", "dependencies": { diff --git a/packages/pieces/community/hubspot/src/index.ts b/packages/pieces/community/hubspot/src/index.ts index 0524a4c938a8..cba24d2935df 100644 --- a/packages/pieces/community/hubspot/src/index.ts +++ b/packages/pieces/community/hubspot/src/index.ts @@ -1,5 +1,5 @@ import { createCustomApiCallAction } from '@activepieces/pieces-common'; -import { OAuth2PropertyValue, PieceAuth, createPiece } from '@activepieces/pieces-framework'; +import { createPiece } from '@activepieces/pieces-framework'; import { PieceCategory } from '@activepieces/pieces-framework'; import { hubSpotListsAddContactAction } from './lib/actions/add-contact-to-list-action'; import { newCompanyTrigger } from './lib/triggers/new-company'; @@ -69,12 +69,12 @@ import { createBlogPostAction } from './lib/actions/create-blog-post'; import { createPageAction } from './lib/actions/create-page'; import { getPageAction } from './lib/actions/get-page'; import { deletePageAction } from './lib/actions/delete-page'; -import { hubspotAuth } from './lib/auth'; +import { getHubspotAccessToken, hubspotAuth } from './lib/auth'; export const hubspot = createPiece({ displayName: 'HubSpot', description: 'Powerful CRM that offers tools for sales, customer service, and marketing automation.', - minimumSupportedRelease: '0.5.0', + minimumSupportedRelease: '0.86.4', logoUrl: 'https://cdn.activepieces.com/pieces/hubspot.png', authors: ['Salem-Alaa', 'kishanprmr', 'MoShizzle', 'khaledmashaly', 'abuaboud'], categories: [PieceCategory.SALES_AND_CRM], @@ -128,7 +128,7 @@ export const hubspot = createPiece({ baseUrl: () => 'https://api.hubapi.com', auth: hubspotAuth, authMapping: async (auth) => ({ - Authorization: `Bearer ${(auth).access_token}`, + Authorization: `Bearer ${getHubspotAccessToken(auth)}`, }), }), ], diff --git a/packages/pieces/community/hubspot/src/lib/actions/add-contact-to-list-action.ts b/packages/pieces/community/hubspot/src/lib/actions/add-contact-to-list-action.ts index 1cb6984f7287..3d21db7b4ecc 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/add-contact-to-list-action.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/add-contact-to-list-action.ts @@ -1,6 +1,6 @@ import { staticListsDropdown } from '../common/props'; import { createAction, Property } from '@activepieces/pieces-framework'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { AuthenticationType, httpClient, HttpMethod } from '@activepieces/pieces-common'; export const hubSpotListsAddContactAction = createAction({ @@ -30,7 +30,7 @@ export const hubSpotListsAddContactAction = createAction({ }, authentication: { type: AuthenticationType.BEARER_TOKEN, - token: context.auth.access_token, + token: getHubspotAccessToken(context.auth), }, }) diff --git a/packages/pieces/community/hubspot/src/lib/actions/add-contact-to-workflow.ts b/packages/pieces/community/hubspot/src/lib/actions/add-contact-to-workflow.ts index 9f4f865959a0..77f689c0e27a 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/add-contact-to-workflow.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/add-contact-to-workflow.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from "@activepieces/pieces-framework"; import { workflowIdDropdown } from "../common/props"; import { AuthenticationType, httpClient, HttpMethod } from "@activepieces/pieces-common"; @@ -28,7 +28,7 @@ export const addContactToWorkflowAction = createAction({ url: `https://api.hubapi.com/automation/v2/workflows/${workflowId}/enrollments/contacts/${contactEmail}`, authentication: { type: AuthenticationType.BEARER_TOKEN, - token: context.auth.access_token, + token: getHubspotAccessToken(context.auth), }, }) diff --git a/packages/pieces/community/hubspot/src/lib/actions/create-associations.ts b/packages/pieces/community/hubspot/src/lib/actions/create-associations.ts index d6fe6bf13a27..2d56b01d47f4 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/create-associations.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/create-associations.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { fromObjectTypeAssociationDropdown, @@ -49,7 +49,7 @@ export const createAssociationsAction = createAction({ async run(context) { const { fromObjectId, fromObjectType, toObjectType, associationType } = context.propsValue; - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); if(context.propsValue.toObjectIds === undefined) { throw new Error('Please provide To Object IDs'); diff --git a/packages/pieces/community/hubspot/src/lib/actions/create-blog-post.ts b/packages/pieces/community/hubspot/src/lib/actions/create-blog-post.ts index 035179c8892a..6250c953ed06 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/create-blog-post.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/create-blog-post.ts @@ -1,5 +1,5 @@ import { AuthenticationType, httpClient, HttpMethod } from '@activepieces/pieces-common'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { blogAuthorDropdown, blogUrlDropdown } from '../common/props'; import { createBlogPostOutputSchema } from '../output-schemas'; @@ -62,7 +62,7 @@ export const createBlogPostAction = createAction({ const createdPost = await httpClient.sendRequest>({ method: HttpMethod.POST, url: 'https://api.hubapi.com/content/api/v2/blog-posts', - authentication: { type: AuthenticationType.BEARER_TOKEN, token: context.auth.access_token }, + authentication: { type: AuthenticationType.BEARER_TOKEN, token: getHubspotAccessToken(context.auth) }, body: { blog_author_id: authorId, content_group_id: contentGroupId, @@ -80,7 +80,7 @@ export const createBlogPostAction = createAction({ await httpClient.sendRequest({ method: HttpMethod.POST, url: `https://api.hubapi.com/content/api/v2/blog-posts/${createdPost.body['id']}/publish-action`, - authentication: { type: AuthenticationType.BEARER_TOKEN, token: context.auth.access_token }, + authentication: { type: AuthenticationType.BEARER_TOKEN, token: getHubspotAccessToken(context.auth) }, body: { action: 'schedule-publish', }, @@ -90,7 +90,7 @@ export const createBlogPostAction = createAction({ const postDetails = await httpClient.sendRequest({ method: HttpMethod.GET, url: `https://api.hubapi.com/content/api/v2/blog-posts/${createdPost.body['id']}`, - authentication: { type: AuthenticationType.BEARER_TOKEN, token: context.auth.access_token }, + authentication: { type: AuthenticationType.BEARER_TOKEN, token: getHubspotAccessToken(context.auth) }, }); return postDetails.body diff --git a/packages/pieces/community/hubspot/src/lib/actions/create-company.ts b/packages/pieces/community/hubspot/src/lib/actions/create-company.ts index 8eeb033a5b00..232901a1e270 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/create-company.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/create-company.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { getDefaultPropertiesForObject, standardObjectDynamicProperties, standardObjectPropertiesDropdown} from '../common/props'; import { OBJECT_TYPE } from '../common/constants'; @@ -43,7 +43,7 @@ export const createCompanyAction = createAction({ companyProperties[key] = Array.isArray(value) ? value.join(';') : value; }); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const createdCompany = await client.crm.companies.basicApi.create({ properties: companyProperties, diff --git a/packages/pieces/community/hubspot/src/lib/actions/create-contact.ts b/packages/pieces/community/hubspot/src/lib/actions/create-contact.ts index a46c89b9a43a..00ab2f2d9e35 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/create-contact.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/create-contact.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { MarkdownVariant } from '@activepieces/pieces-framework'; @@ -44,7 +44,7 @@ export const createContactAction = createAction({ contactProperties[key] = Array.isArray(value) ? value.join(';') : value; }); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const createdContact = await client.crm.contacts.basicApi.create({ properties: contactProperties, diff --git a/packages/pieces/community/hubspot/src/lib/actions/create-custom-object.ts b/packages/pieces/community/hubspot/src/lib/actions/create-custom-object.ts index e570a411636b..5cac12e133e3 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/create-custom-object.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/create-custom-object.ts @@ -1,6 +1,6 @@ import { createAction, Property } from '@activepieces/pieces-framework'; import { MarkdownVariant } from '@activepieces/pieces-framework'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { customObjectDropdown, customObjectDynamicProperties, @@ -61,7 +61,7 @@ export const createCustomObjectAction = createAction({ customObjectProperties[key] = Array.isArray(value) ? value.join(';') : value; }); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const createdCustomObject = await client.crm.objects.basicApi.create(customObjectType, { properties: customObjectProperties, diff --git a/packages/pieces/community/hubspot/src/lib/actions/create-deal.ts b/packages/pieces/community/hubspot/src/lib/actions/create-deal.ts index a200a62cfa00..703508738bbf 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/create-deal.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/create-deal.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { Property, createAction } from '@activepieces/pieces-framework'; @@ -75,7 +75,7 @@ export const createDealAction = createAction({ dealProperties[key] = Array.isArray(value) ? value.join(';') : value; }); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const createdDeal = await client.crm.deals.basicApi.create({ properties: dealProperties, diff --git a/packages/pieces/community/hubspot/src/lib/actions/create-line-item.ts b/packages/pieces/community/hubspot/src/lib/actions/create-line-item.ts index 2eb82ac4c829..b2c8c958d1d0 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/create-line-item.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/create-line-item.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { getDefaultPropertiesForObject, @@ -58,7 +58,7 @@ export const createLineItemAction = createAction({ lineItemProperties[key] = Array.isArray(value) ? value.join(';') : value; }); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const createdLineItem = await client.crm.lineItems.basicApi.create({ associations: [], diff --git a/packages/pieces/community/hubspot/src/lib/actions/create-or-update-contact.ts b/packages/pieces/community/hubspot/src/lib/actions/create-or-update-contact.ts index 08f847765d67..2f011058130d 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/create-or-update-contact.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/create-or-update-contact.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { Client } from '@hubspot/api-client'; @@ -36,7 +36,7 @@ export const createOrUpdateContactAction = createAction({ contactProperties[key] = Array.isArray(value) ? value.join(';') : value; }); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const searchResponse = await client.crm.contacts.searchApi.doSearch({ limit: 1, diff --git a/packages/pieces/community/hubspot/src/lib/actions/create-page.ts b/packages/pieces/community/hubspot/src/lib/actions/create-page.ts index 8c8259a81f9b..f9a1d667a2c7 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/create-page.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/create-page.ts @@ -1,5 +1,5 @@ import { AuthenticationType, httpClient, HttpMethod } from '@activepieces/pieces-common'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { pageType } from '../common/props'; import { pageOutputSchema } from '../output-schemas'; @@ -90,7 +90,7 @@ export const createPageAction = createAction({ url, authentication: { type: AuthenticationType.BEARER_TOKEN, - token: context.auth.access_token, + token: getHubspotAccessToken(context.auth), }, body: { htmlTitle: pageTitle, @@ -110,7 +110,7 @@ export const createPageAction = createAction({ url: `https://api.hubapi.com/content/api/v2/pages/${createdPage.body.id}/publish-action`, authentication: { type: AuthenticationType.BEARER_TOKEN, - token: context.auth.access_token, + token: getHubspotAccessToken(context.auth), }, body: { action: 'schedule-publish' }, }); @@ -119,7 +119,7 @@ export const createPageAction = createAction({ const pageDetails = await httpClient.sendRequest({ method: HttpMethod.GET, url: `${url}/${createdPage.body.id}`, - authentication: { type: AuthenticationType.BEARER_TOKEN, token: context.auth.access_token }, + authentication: { type: AuthenticationType.BEARER_TOKEN, token: getHubspotAccessToken(context.auth) }, }); return pageDetails.body; diff --git a/packages/pieces/community/hubspot/src/lib/actions/create-product.ts b/packages/pieces/community/hubspot/src/lib/actions/create-product.ts index b9c84084fbad..701ffe58bdec 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/create-product.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/create-product.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { getDefaultPropertiesForObject, @@ -51,7 +51,7 @@ export const createProductAction = createAction({ productProperties[key] = Array.isArray(value) ? value.join(';') : value; }); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const createdProduct = await client.crm.products.basicApi.create({ properties: productProperties, diff --git a/packages/pieces/community/hubspot/src/lib/actions/create-ticket.ts b/packages/pieces/community/hubspot/src/lib/actions/create-ticket.ts index 31763a86ba62..4260c65521d2 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/create-ticket.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/create-ticket.ts @@ -2,7 +2,7 @@ import { createAction, Property } from '@activepieces/pieces-framework'; import { Client } from '@hubspot/api-client'; import { MarkdownVariant } from '@activepieces/pieces-framework'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { getDefaultPropertiesForObject, pipelineDropdown, pipelineStageDropdown, standardObjectDynamicProperties, standardObjectPropertiesDropdown } from '../common/props'; import { OBJECT_TYPE } from '../common/constants'; import { crmObjectOutputSchema } from '../output-schemas'; @@ -73,7 +73,7 @@ export const createTicketAction = createAction({ ticketProperties[key] = Array.isArray(value) ? value.join(';') : value; }); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const createdTicket = await client.crm.tickets.basicApi.create({ properties: ticketProperties, diff --git a/packages/pieces/community/hubspot/src/lib/actions/delete-page.ts b/packages/pieces/community/hubspot/src/lib/actions/delete-page.ts index 2ad55d4a546c..793bae2c34fc 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/delete-page.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/delete-page.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { Client } from '@hubspot/api-client'; import { pageType } from '../common/props'; @@ -21,7 +21,7 @@ export const deletePageAction = createAction({ }, async run(context) { const { pageId, pageType } = context.propsValue; - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); if (pageType === 'site_page') { return await client.cms.pages.sitePagesApi.archive(pageId); diff --git a/packages/pieces/community/hubspot/src/lib/actions/find-associations.ts b/packages/pieces/community/hubspot/src/lib/actions/find-associations.ts index a4a49e50e101..42711561f206 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/find-associations.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/find-associations.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { fromObjectTypeAssociationDropdown } from '../common/props'; import { OBJECT_TYPE } from '../common/constants'; @@ -36,7 +36,7 @@ export const findAssociationsAction = createAction({ async run(context) { const { fromObjectId, fromObjectType, toObjectType } = context.propsValue; - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const results = []; const limit = 100; diff --git a/packages/pieces/community/hubspot/src/lib/actions/find-company.ts b/packages/pieces/community/hubspot/src/lib/actions/find-company.ts index a13aac05ea6b..3556d422a1c7 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/find-company.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/find-company.ts @@ -1,5 +1,5 @@ import { MarkdownVariant } from '@activepieces/pieces-framework'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { getDefaultPropertiesForObject, @@ -85,7 +85,7 @@ export const findCompanyAction = createAction({ }); } - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const defaultCompanyProperties = getDefaultPropertiesForObject(OBJECT_TYPE.COMPANY); diff --git a/packages/pieces/community/hubspot/src/lib/actions/find-contact.ts b/packages/pieces/community/hubspot/src/lib/actions/find-contact.ts index be5eebc52ec0..1934bb5c3d87 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/find-contact.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/find-contact.ts @@ -1,7 +1,7 @@ import { MarkdownVariant } from '@activepieces/pieces-framework'; import { createAction, Property } from '@activepieces/pieces-framework'; import { Client } from '@hubspot/api-client'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { getDefaultPropertiesForObject, standardObjectPropertiesDropdown } from '../common/props'; import { OBJECT_TYPE, MAX_SEARCH_PAGE_SIZE } from '../common/constants'; import { FilterOperatorEnum } from '../common/types'; @@ -83,7 +83,7 @@ export const findContactAction = createAction({ }); } - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const defaultContactProperties = getDefaultPropertiesForObject(OBJECT_TYPE.CONTACT); diff --git a/packages/pieces/community/hubspot/src/lib/actions/find-custom-object.ts b/packages/pieces/community/hubspot/src/lib/actions/find-custom-object.ts index 436873823017..8d8df7eb16be 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/find-custom-object.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/find-custom-object.ts @@ -1,7 +1,7 @@ import { MarkdownVariant } from '@activepieces/pieces-framework'; import { createAction, Property } from '@activepieces/pieces-framework'; import { Client } from '@hubspot/api-client'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { customObjectDropdown, customObjectPropertiesDropdown } from '../common/props'; import { FilterOperatorEnum } from '../common/types'; import { MAX_SEARCH_PAGE_SIZE } from '../common/constants'; @@ -91,7 +91,7 @@ export const findCustomObjectAction = createAction({ }); } - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const response = await client.crm.objects.searchApi.doSearch(customObjectType, { limit: MAX_SEARCH_PAGE_SIZE, diff --git a/packages/pieces/community/hubspot/src/lib/actions/find-deal.ts b/packages/pieces/community/hubspot/src/lib/actions/find-deal.ts index e99efc636b1f..a956469c342a 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/find-deal.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/find-deal.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { getDefaultPropertiesForObject, standardObjectPropertiesDropdown } from '../common/props'; import { OBJECT_TYPE, MAX_SEARCH_PAGE_SIZE } from '../common/constants'; @@ -83,7 +83,7 @@ export const findDealAction = createAction({ }); } - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const defaultDealProperties = getDefaultPropertiesForObject(OBJECT_TYPE.DEAL); diff --git a/packages/pieces/community/hubspot/src/lib/actions/find-line-item.ts b/packages/pieces/community/hubspot/src/lib/actions/find-line-item.ts index b9d9b9073bee..97facc8d65ca 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/find-line-item.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/find-line-item.ts @@ -1,7 +1,7 @@ import { MarkdownVariant } from '@activepieces/pieces-framework'; import { createAction, Property } from '@activepieces/pieces-framework'; import { Client } from '@hubspot/api-client'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { getDefaultPropertiesForObject, standardObjectPropertiesDropdown } from '../common/props'; import { OBJECT_TYPE, MAX_SEARCH_PAGE_SIZE } from '../common/constants'; import { FilterOperatorEnum } from '../common/types'; @@ -83,7 +83,7 @@ export const findLineItemAction = createAction({ }); } - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const defaultLineItemProperties = getDefaultPropertiesForObject(OBJECT_TYPE.LINE_ITEM); diff --git a/packages/pieces/community/hubspot/src/lib/actions/find-product.ts b/packages/pieces/community/hubspot/src/lib/actions/find-product.ts index fa25a354b624..e79342080454 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/find-product.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/find-product.ts @@ -1,5 +1,5 @@ import { MarkdownVariant } from '@activepieces/pieces-framework'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { getDefaultPropertiesForObject, standardObjectPropertiesDropdown @@ -84,7 +84,7 @@ export const findProductAction = createAction({ }); } - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const defaultProductProperties = getDefaultPropertiesForObject(OBJECT_TYPE.PRODUCT); diff --git a/packages/pieces/community/hubspot/src/lib/actions/find-ticket.ts b/packages/pieces/community/hubspot/src/lib/actions/find-ticket.ts index e14094796374..23e15b9c4250 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/find-ticket.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/find-ticket.ts @@ -1,7 +1,7 @@ import { MarkdownVariant } from '@activepieces/pieces-framework'; import { createAction, Property } from '@activepieces/pieces-framework'; import { Client } from '@hubspot/api-client'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { getDefaultPropertiesForObject, standardObjectPropertiesDropdown } from '../common/props'; import { OBJECT_TYPE, MAX_SEARCH_PAGE_SIZE } from '../common/constants'; import { FilterOperatorEnum } from '../common/types'; @@ -83,7 +83,7 @@ export const findTicketAction = createAction({ }); } - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const defaultTicketProperties = getDefaultPropertiesForObject(OBJECT_TYPE.TICKET); diff --git a/packages/pieces/community/hubspot/src/lib/actions/get-company.ts b/packages/pieces/community/hubspot/src/lib/actions/get-company.ts index c2d07f90a2b0..71ddd886b48c 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/get-company.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/get-company.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { getDefaultPropertiesForObject, @@ -45,7 +45,7 @@ export const getCompanyAction = createAction({ const defaultCompanyProperties = getDefaultPropertiesForObject(OBJECT_TYPE.COMPANY); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const companyDetails = await client.crm.companies.basicApi.getById(companyId, [ ...defaultCompanyProperties, diff --git a/packages/pieces/community/hubspot/src/lib/actions/get-contact.ts b/packages/pieces/community/hubspot/src/lib/actions/get-contact.ts index ea19434d4b14..f89abdbd006d 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/get-contact.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/get-contact.ts @@ -2,7 +2,7 @@ import { createAction, Property } from '@activepieces/pieces-framework'; import { Client } from '@hubspot/api-client'; import { MarkdownVariant } from '@activepieces/pieces-framework'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { getDefaultPropertiesForObject, standardObjectPropertiesDropdown } from '../common/props'; import { OBJECT_TYPE } from '../common/constants'; import { crmObjectOutputSchema } from '../output-schemas'; @@ -43,7 +43,7 @@ export const getContactAction = createAction({ const defaultContactProperties = getDefaultPropertiesForObject(OBJECT_TYPE.CONTACT); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const contactDetails = await client.crm.contacts.basicApi.getById(contactId, [ ...defaultContactProperties, diff --git a/packages/pieces/community/hubspot/src/lib/actions/get-custom-object.ts b/packages/pieces/community/hubspot/src/lib/actions/get-custom-object.ts index 722e0a307357..83048f63585c 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/get-custom-object.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/get-custom-object.ts @@ -2,7 +2,7 @@ import { createAction, Property } from '@activepieces/pieces-framework'; import { Client } from '@hubspot/api-client'; import { MarkdownVariant } from '@activepieces/pieces-framework'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { customObjectDropdown, customObjectPropertiesDropdown } from '../common/props'; import { crmObjectOutputSchema } from '../output-schemas'; @@ -50,7 +50,7 @@ export const getCustomObjectAction = createAction({ propertiesToRetrieve = []; } - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const customObjectDetails = await client.crm.objects.basicApi.getById( customObjectType, diff --git a/packages/pieces/community/hubspot/src/lib/actions/get-deal.ts b/packages/pieces/community/hubspot/src/lib/actions/get-deal.ts index 7407303b82ec..e070af89905d 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/get-deal.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/get-deal.ts @@ -2,7 +2,7 @@ import { createAction, Property } from '@activepieces/pieces-framework'; import { Client } from '@hubspot/api-client'; import { MarkdownVariant } from '@activepieces/pieces-framework'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { getDefaultPropertiesForObject, standardObjectPropertiesDropdown } from '../common/props'; import { OBJECT_TYPE } from '../common/constants'; import { crmObjectOutputSchema } from '../output-schemas'; @@ -43,7 +43,7 @@ export const getDealAction = createAction({ const defaultDealProperties = getDefaultPropertiesForObject(OBJECT_TYPE.DEAL); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const dealDetails = await client.crm.deals.basicApi.getById(dealId, [ ...defaultDealProperties, diff --git a/packages/pieces/community/hubspot/src/lib/actions/get-line-item.ts b/packages/pieces/community/hubspot/src/lib/actions/get-line-item.ts index c591c88f5fc9..299f662bad6f 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/get-line-item.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/get-line-item.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { MarkdownVariant } from '@activepieces/pieces-framework'; import { getDefaultPropertiesForObject, standardObjectPropertiesDropdown } from '../common/props'; @@ -41,7 +41,7 @@ export const getLineItemAction = createAction({ const additionalPropertiesToRetrieve = context.propsValue.additionalPropertiesToRetrieve ?? []; const defaultLineItemProperties = getDefaultPropertiesForObject(OBJECT_TYPE.LINE_ITEM); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const lineItemDetails = await client.crm.lineItems.basicApi.getById(lineItemId, [ ...defaultLineItemProperties, diff --git a/packages/pieces/community/hubspot/src/lib/actions/get-owner-by-email.ts b/packages/pieces/community/hubspot/src/lib/actions/get-owner-by-email.ts index 44a9b7c34e59..b9c15e8a93ca 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/get-owner-by-email.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/get-owner-by-email.ts @@ -1,5 +1,5 @@ import { createAction, Property } from '@activepieces/pieces-framework'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { Client } from '@hubspot/api-client'; import { getOwnerByEmailOutputSchema } from '../output-schemas'; @@ -24,7 +24,7 @@ export const getOwnerByEmailAction = createAction({ }, async run(context) { const { email } = context.propsValue; - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const response = await client.crm.owners.ownersApi.getPage(email); return response; diff --git a/packages/pieces/community/hubspot/src/lib/actions/get-owner-by-id.ts b/packages/pieces/community/hubspot/src/lib/actions/get-owner-by-id.ts index 37042c3dfdde..678e8f112d89 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/get-owner-by-id.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/get-owner-by-id.ts @@ -1,5 +1,5 @@ import { createAction, Property } from '@activepieces/pieces-framework'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { Client } from '@hubspot/api-client'; import { getOwnerByIdOutputSchema } from '../output-schemas'; @@ -20,7 +20,7 @@ export const getOwnerByIdAction = createAction({ }, async run(context) { const { ownerId } = context.propsValue; - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const response = await client.crm.owners.ownersApi.getById(Number(ownerId)); return response; diff --git a/packages/pieces/community/hubspot/src/lib/actions/get-page.ts b/packages/pieces/community/hubspot/src/lib/actions/get-page.ts index 4ffc8d53eb64..032d3963df56 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/get-page.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/get-page.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { Client } from '@hubspot/api-client'; import { pageType } from '../common/props'; @@ -27,7 +27,7 @@ export const getPageAction = createAction({ }, async run(context) { const { pageId, pageType } = context.propsValue; - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); if (pageType === 'site_page') { return await client.cms.pages.sitePagesApi.getById(pageId); diff --git a/packages/pieces/community/hubspot/src/lib/actions/get-pipeline-stage-details.ts b/packages/pieces/community/hubspot/src/lib/actions/get-pipeline-stage-details.ts index a7c733420952..13ce708e672e 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/get-pipeline-stage-details.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/get-pipeline-stage-details.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { Client } from '@hubspot/api-client'; import { pipelineStageDetailsOutputSchema } from '../output-schemas'; @@ -44,7 +44,7 @@ export const getPipelineStageDetailsAction = createAction({ const pipelineId = context.propsValue.pipelineId; const stageId = context.propsValue.stageId; - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const response = await client.crm.pipelines.pipelineStagesApi.getById( objectType, diff --git a/packages/pieces/community/hubspot/src/lib/actions/get-product.ts b/packages/pieces/community/hubspot/src/lib/actions/get-product.ts index a84545c5d9b6..4d7ea7feef42 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/get-product.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/get-product.ts @@ -2,7 +2,7 @@ import { createAction, Property } from '@activepieces/pieces-framework'; import { Client } from '@hubspot/api-client'; import { MarkdownVariant } from '@activepieces/pieces-framework'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { getDefaultPropertiesForObject, standardObjectPropertiesDropdown } from '../common/props'; import { OBJECT_TYPE } from '../common/constants'; import { crmObjectOutputSchema } from '../output-schemas'; @@ -43,7 +43,7 @@ export const getProductAction = createAction({ const defaultProductProperties = getDefaultPropertiesForObject(OBJECT_TYPE.PRODUCT); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const productDetails = await client.crm.products.basicApi.getById(productId, [ ...defaultProductProperties, diff --git a/packages/pieces/community/hubspot/src/lib/actions/get-ticket.ts b/packages/pieces/community/hubspot/src/lib/actions/get-ticket.ts index 4b07632684d0..bb15acf34173 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/get-ticket.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/get-ticket.ts @@ -4,7 +4,7 @@ import { Client } from '@hubspot/api-client'; import { MarkdownVariant } from '@activepieces/pieces-framework'; import { getDefaultPropertiesForObject, standardObjectPropertiesDropdown } from '../common/props'; import { OBJECT_TYPE } from '../common/constants'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { crmObjectOutputSchema } from '../output-schemas'; export const getTicketAction = createAction({ @@ -43,7 +43,7 @@ export const getTicketAction = createAction({ const defaultTicketProperties = getDefaultPropertiesForObject(OBJECT_TYPE.TICKET); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const ticketDetails = await client.crm.tickets.basicApi.getById(ticketId, [ ...defaultTicketProperties, diff --git a/packages/pieces/community/hubspot/src/lib/actions/remove-associations.ts b/packages/pieces/community/hubspot/src/lib/actions/remove-associations.ts index 661675967ffb..27d9d99d33bc 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/remove-associations.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/remove-associations.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { fromObjectTypeAssociationDropdown, @@ -49,7 +49,7 @@ export const removeAssociationsAction = createAction({ async run(context) { const { fromObjectId, fromObjectType, toObjectType, associationType } = context.propsValue; - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); if(context.propsValue.toObjectIds === undefined) { throw new Error('Please provide To Object IDs'); diff --git a/packages/pieces/community/hubspot/src/lib/actions/remove-contact-from-list.ts b/packages/pieces/community/hubspot/src/lib/actions/remove-contact-from-list.ts index ed79878eb0e5..994bfea75593 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/remove-contact-from-list.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/remove-contact-from-list.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { staticListsDropdown } from '../common/props'; import { HttpMethod } from '@activepieces/pieces-common'; @@ -27,7 +27,7 @@ export const removeContactFromListAction = createAction({ async run(context) { const { listId, email } = context.propsValue; - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const contact = await client.crm.contacts.searchApi.doSearch({ limit: 1, diff --git a/packages/pieces/community/hubspot/src/lib/actions/remove-email-subscription.ts b/packages/pieces/community/hubspot/src/lib/actions/remove-email-subscription.ts index a3361b9bea8f..8defb9373cce 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/remove-email-subscription.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/remove-email-subscription.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { AuthenticationType, httpClient, HttpMethod } from '@activepieces/pieces-common'; import { createAction, Property } from '@activepieces/pieces-framework'; @@ -25,7 +25,7 @@ export const removeEmailSubscriptionAction = createAction({ url: `https://api.hubapi.com/email/public/v1/subscriptions/${email}`, authentication: { type: AuthenticationType.BEARER_TOKEN, - token: context.auth.access_token, + token: getHubspotAccessToken(context.auth), }, body: { unsubscribeFromAll: true, diff --git a/packages/pieces/community/hubspot/src/lib/actions/update-company.ts b/packages/pieces/community/hubspot/src/lib/actions/update-company.ts index 572675447377..ce252834aad2 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/update-company.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/update-company.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { @@ -57,7 +57,7 @@ export const updateCompanyAction = createAction({ companyProperties[key] = Array.isArray(value) ? value.join(';') : value; }); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const updatedCompany = await client.crm.companies.basicApi.update(companyId, { properties: companyProperties, diff --git a/packages/pieces/community/hubspot/src/lib/actions/update-contact.ts b/packages/pieces/community/hubspot/src/lib/actions/update-contact.ts index c2f5ca193046..c2d9a0a4c6c8 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/update-contact.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/update-contact.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { getDefaultPropertiesForObject, @@ -57,7 +57,7 @@ export const updateContactAction = createAction({ contactProperties[key] = Array.isArray(value) ? value.join(';') : value; }); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const updatedContact = await client.crm.contacts.basicApi.update(contactId, { properties: contactProperties, diff --git a/packages/pieces/community/hubspot/src/lib/actions/update-custom-object.ts b/packages/pieces/community/hubspot/src/lib/actions/update-custom-object.ts index b7911e019864..fbc544d78885 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/update-custom-object.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/update-custom-object.ts @@ -1,6 +1,6 @@ import { createAction, Property } from '@activepieces/pieces-framework'; import { MarkdownVariant } from '@activepieces/pieces-framework'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { customObjectDropdown, customObjectDynamicProperties, @@ -67,7 +67,7 @@ export const updateCustomObjectAction = createAction({ customObjectProperties[key] = Array.isArray(value) ? value.join(';') : value; }); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const updatedCustomObject = await client.crm.objects.basicApi.update( customObjectType, diff --git a/packages/pieces/community/hubspot/src/lib/actions/update-deal.ts b/packages/pieces/community/hubspot/src/lib/actions/update-deal.ts index 1be47f83e6e4..4044dd5c31a0 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/update-deal.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/update-deal.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { Property, @@ -92,7 +92,7 @@ export const updateDealAction = createAction({ dealProperties[key] = Array.isArray(value) ? value.join(';') : value; }); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const updatedDeal = await client.crm.deals.basicApi.update(dealId, { properties: dealProperties, diff --git a/packages/pieces/community/hubspot/src/lib/actions/update-line-item.ts b/packages/pieces/community/hubspot/src/lib/actions/update-line-item.ts index 6c8a01b83092..9eb6924c23f7 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/update-line-item.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/update-line-item.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { getDefaultPropertiesForObject, @@ -71,7 +71,7 @@ export const updateLineItemAction = createAction({ lineItemProperties[key] = Array.isArray(value) ? value.join(';') : value; }); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const createdLineItem = await client.crm.lineItems.basicApi.update(lineItemId, { properties: lineItemProperties, diff --git a/packages/pieces/community/hubspot/src/lib/actions/update-product.ts b/packages/pieces/community/hubspot/src/lib/actions/update-product.ts index b8d43c900457..354e787babfc 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/update-product.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/update-product.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createAction, Property } from '@activepieces/pieces-framework'; import { getDefaultPropertiesForObject, @@ -57,7 +57,7 @@ export const updateProductAction = createAction({ productProperties[key] = Array.isArray(value) ? value.join(';') : value; }); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const updatedProduct = await client.crm.products.basicApi.update(productId, { properties: productProperties, diff --git a/packages/pieces/community/hubspot/src/lib/actions/update-ticket.ts b/packages/pieces/community/hubspot/src/lib/actions/update-ticket.ts index a96dd2731b1b..db18b86d6b60 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/update-ticket.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/update-ticket.ts @@ -2,7 +2,7 @@ import { createAction, Property } from '@activepieces/pieces-framework'; import { Client } from '@hubspot/api-client'; import { MarkdownVariant } from '@activepieces/pieces-framework'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { getDefaultPropertiesForObject, pipelineDropdown, pipelineStageDropdown, standardObjectDynamicProperties, standardObjectPropertiesDropdown } from '../common/props'; import { OBJECT_TYPE } from '../common/constants'; import { crmObjectOutputSchema } from '../output-schemas'; @@ -91,7 +91,7 @@ export const updateTicketAction = createAction({ ticketProperties[key] = Array.isArray(value) ? value.join(';') : value; }); - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const updatedTicket = await client.crm.tickets.basicApi.update(ticketId,{ properties: ticketProperties, diff --git a/packages/pieces/community/hubspot/src/lib/actions/upload-file.ts b/packages/pieces/community/hubspot/src/lib/actions/upload-file.ts index b6713f7c3c9e..4a8caedb342f 100644 --- a/packages/pieces/community/hubspot/src/lib/actions/upload-file.ts +++ b/packages/pieces/community/hubspot/src/lib/actions/upload-file.ts @@ -1,8 +1,7 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, HubspotAuthValue, hubspotAuth } from '../auth'; import { createAction, DropdownOption, - PiecePropValueSchema, Property, } from '@activepieces/pieces-framework'; import { Client } from '@hubspot/api-client'; @@ -32,8 +31,8 @@ export const uploadFileAction = createAction({ }; } - const authValue = auth as PiecePropValueSchema; - const client = new Client({ accessToken: authValue.access_token }); + const authValue = auth as HubspotAuthValue; + const client = new Client({ accessToken: getHubspotAccessToken(authValue) }); const limit = 100; const options: DropdownOption[] = []; @@ -91,7 +90,7 @@ export const uploadFileAction = createAction({ }, async run(context) { const { accessLevel, fileName, folderId, file } = context.propsValue; - const client = new Client({ accessToken: context.auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(context.auth) }); const response = await client.files.filesApi.upload( { diff --git a/packages/pieces/community/hubspot/src/lib/auth.ts b/packages/pieces/community/hubspot/src/lib/auth.ts index 0f0c5e9cca52..dc1b8229031e 100644 --- a/packages/pieces/community/hubspot/src/lib/auth.ts +++ b/packages/pieces/community/hubspot/src/lib/auth.ts @@ -1,39 +1,83 @@ -import { PieceAuth } from '@activepieces/pieces-framework'; +import { AppConnectionType, AppConnectionValueForAuthProperty, PieceAuth } from '@activepieces/pieces-framework'; +import { AuthenticationType, HttpMethod, httpClient } from '@activepieces/pieces-common'; -export const hubspotAuth = PieceAuth.OAuth2({ - authUrl: 'https://app.hubspot.com/oauth/authorize', - tokenUrl: 'https://api.hubapi.com/oauth/v1/token', - required: true, - scope: [ - 'crm.lists.read', - 'crm.lists.write', - 'crm.objects.companies.read', - 'crm.objects.companies.write', - 'crm.objects.contacts.read', - 'crm.objects.contacts.write', - 'crm.objects.custom.read', - 'crm.objects.custom.write', - 'crm.objects.deals.read', - 'crm.objects.deals.write', - 'crm.objects.line_items.read', - 'crm.objects.owners.read', - 'crm.objects.leads.read', - 'crm.objects.leads.write', - 'crm.schemas.companies.read', - 'crm.schemas.contacts.read', - 'crm.schemas.custom.read', - 'crm.schemas.deals.read', - 'crm.schemas.line_items.read', - 'automation', - 'e-commerce', - 'tickets', - 'content', - 'settings.currencies.read', - 'settings.users.read', - 'settings.users.teams.read', - 'files', - 'forms', - 'scheduler.meetings.meeting-link.read' - // 'business_units_view.read' - ], -}); +export const hubspotAuth = [ + PieceAuth.OAuth2({ + authUrl: 'https://app.hubspot.com/oauth/authorize', + tokenUrl: 'https://api.hubapi.com/oauth/v1/token', + required: true, + scope: [ + 'crm.lists.read', + 'crm.lists.write', + 'crm.objects.companies.read', + 'crm.objects.companies.write', + 'crm.objects.contacts.read', + 'crm.objects.contacts.write', + 'crm.objects.custom.read', + 'crm.objects.custom.write', + 'crm.objects.deals.read', + 'crm.objects.deals.write', + 'crm.objects.line_items.read', + 'crm.objects.owners.read', + 'crm.objects.leads.read', + 'crm.objects.leads.write', + 'crm.schemas.companies.read', + 'crm.schemas.contacts.read', + 'crm.schemas.custom.read', + 'crm.schemas.deals.read', + 'crm.schemas.line_items.read', + 'automation', + 'e-commerce', + 'tickets', + 'content', + 'settings.currencies.read', + 'settings.users.read', + 'settings.users.teams.read', + 'files', + 'forms', + 'scheduler.meetings.meeting-link.read' + // 'business_units_view.read' + ], + }), + PieceAuth.CustomAuth({ + displayName: 'Private App Access Token', + description: `In HubSpot, go to **Development > Legacy Apps** in the left sidebar, create (or open) a private app, and on the **Scopes** tab grant the scopes for the actions you plan to use. They group roughly as: + - **Contacts, companies & deals** — \`crm.objects.contacts.read\`, \`crm.objects.contacts.write\`, \`crm.objects.companies.read\`, \`crm.objects.companies.write\`, \`crm.objects.deals.read\`, \`crm.objects.deals.write\`, \`crm.objects.line_items.read\`, \`crm.schemas.contacts.read\`, \`crm.schemas.companies.read\`, \`crm.schemas.deals.read\`, \`crm.schemas.line_items.read\` + - **Lists & custom objects** — \`crm.lists.read\`, \`crm.lists.write\`, \`crm.objects.custom.read\`, \`crm.objects.custom.write\`, \`crm.schemas.custom.read\` + - **Leads & owners** — \`crm.objects.leads.read\`, \`crm.objects.leads.write\`, \`crm.objects.owners.read\` + - **Tickets & e-commerce** — \`tickets\`, \`e-commerce\` + - **Content, files & forms** — \`content\`, \`files\`, \`forms\` + - **Workflows & meeting links** — \`automation\`, \`scheduler.meetings.meeting-link.read\` + - **Account settings** — \`settings.currencies.read\`, \`settings.users.read\`, \`settings.users.teams.read\` + +Then copy the **Access Token** from the **Auth** tab and paste it below. Private app tokens never expire.`, + required: true, + props: { + access_token: PieceAuth.SecretText({ + displayName: 'Private App Access Token', + description: 'The access token generated for your HubSpot private app.', + required: true, + }), + }, + validate: async ({ auth }) => { + try { + await httpClient.sendRequest({ + method: HttpMethod.GET, + url: 'https://api.hubapi.com/account-info/v3/details', + authentication: { + type: AuthenticationType.BEARER_TOKEN, + token: auth.access_token, + }, + }); + return { valid: true }; + } catch { + return { valid: false, error: 'Invalid Private App Access Token.' }; + } + }, + }), +]; + +export type HubspotAuthValue = AppConnectionValueForAuthProperty; + +export const getHubspotAccessToken = (auth: HubspotAuthValue): string => + auth.type === AppConnectionType.CUSTOM_AUTH ? auth.props.access_token:auth.access_token; diff --git a/packages/pieces/community/hubspot/src/lib/common/props.ts b/packages/pieces/community/hubspot/src/lib/common/props.ts index 21252b32c68d..bccf53481f51 100644 --- a/packages/pieces/community/hubspot/src/lib/common/props.ts +++ b/packages/pieces/community/hubspot/src/lib/common/props.ts @@ -1,8 +1,6 @@ import { DropdownOption, DynamicPropsValue, - OAuth2PropertyValue, - PiecePropValueSchema, Property, } from '@activepieces/pieces-framework'; import { @@ -24,7 +22,7 @@ import { STANDARD_OBJECT_TYPES, } from './constants'; import { Client } from '@hubspot/api-client'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, HubspotAuthValue, hubspotAuth } from '../auth'; const buildEmptyList = ({ placeholder }: { placeholder: string }) => { return { @@ -261,11 +259,11 @@ function createPropertyDefinition(property: HubspotProperty, propertyDisplayName } async function retrieveObjectProperties( - auth: PiecePropValueSchema, + auth: HubspotAuthValue, objectType: string, excludedProperties: string[] = [], ) { - const client = new Client({ accessToken: auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(auth) }); // Fetch property groups const propertyGroups = await client.crm.properties.groupsApi.getAll(objectType); @@ -296,12 +294,12 @@ async function retrieveObjectProperties( props[property.name] = await createReferencedPropertyDefinition( property, propertyDisplayName, - auth.access_token, + getHubspotAccessToken(auth), ); continue; } if (property.name === 'hs_shared_user_ids') { - const userOptions = await fetchUsersOptions(auth.access_token); + const userOptions = await fetchUsersOptions(getHubspotAccessToken(auth)); props[property.name] = Property.StaticMultiSelectDropdown({ displayName: propertyDisplayName, required: false, @@ -313,7 +311,7 @@ async function retrieveObjectProperties( continue; } if (['hs_shared_team_ids', 'hs_attributed_team_ids'].includes(property.name)) { - const teamOptions = await fetchTeamsOptions(auth.access_token); + const teamOptions = await fetchTeamsOptions(getHubspotAccessToken(auth)); props[property.name] = Property.StaticMultiSelectDropdown({ displayName: propertyDisplayName, required: false, @@ -325,7 +323,7 @@ async function retrieveObjectProperties( continue; } if (property.name === 'deal_currency_code') { - const currencyOptions = await fetchCurrenciesOptions(auth.access_token); + const currencyOptions = await fetchCurrenciesOptions(getHubspotAccessToken(auth)); props[property.name] = Property.StaticDropdown({ displayName: propertyDisplayName, required: false, @@ -338,7 +336,7 @@ async function retrieveObjectProperties( } if (property.name === 'hs_all_assigned_business_unit_ids') { // TO DO : Add business unit options - // const businessUnitOptions = await fetchBusinessUnitsOptions(authValue.access_token); + // const businessUnitOptions = await fetchBusinessUnitsOptions(getHubspotAccessToken(authValue)); // props[property.name] = Property.StaticMultiSelectDropdown({ // displayName: propertyDisplayName, // required: false, @@ -367,8 +365,8 @@ export const standardObjectDynamicProperties = (objectType: string, excludedProp // if (typeof createIfNotExists === "boolean" && createIfNotExists === false) { // return {}; // } - const authValue = auth as PiecePropValueSchema; - return await retrieveObjectProperties(authValue, objectType, excludedProperties); + + return await retrieveObjectProperties(auth, objectType, excludedProperties); }, }); @@ -381,8 +379,8 @@ export const customObjectDynamicProperties = Property.DynamicProperties({ if (!auth || !customObjectType) { return {}; } - const authValue = auth as PiecePropValueSchema; - return await retrieveObjectProperties(authValue, customObjectType as unknown as string); + + return await retrieveObjectProperties(auth, customObjectType as unknown as string); }, }); @@ -404,8 +402,7 @@ export const standardObjectPropertiesDropdown = ( placeholder: 'Please connect your account.', }); } - const authValue = auth as PiecePropValueSchema; - const client = new Client({ accessToken: authValue.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(auth) }); // Fetch all properties for the given object type const allProperties = await client.crm.properties.coreApi.getAll(params.objectType); @@ -456,9 +453,8 @@ export const customObjectPropertiesDropdown = ( if (!auth || !customObjectType) { return {}; } - const authValue = auth as PiecePropValueSchema; - const client = new Client({ accessToken: authValue.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(auth) }); // Fetch all properties for the given object type const allProperties = await client.crm.properties.coreApi.getAll( @@ -513,7 +509,7 @@ export const workflowIdDropdown = Property.Dropdown({ }); } - const token = (auth as OAuth2PropertyValue).access_token; + const token = getHubspotAccessToken(auth); const workflowsResponse = await httpClient.sendRequest<{ workflows: WorkflowResponse[]; }>({ @@ -556,8 +552,7 @@ export const pipelineDropdown = (params: DropdownParams) => }); } - const authValue = auth as PiecePropValueSchema; - const client = new Client({ accessToken: authValue.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(auth) }); const pipelinesResponse = await client.crm.pipelines.pipelinesApi.getAll(params.objectType); @@ -588,8 +583,7 @@ export const pipelineStageDropdown = (params: DropdownParams) => }); } - const authValue = auth as PiecePropValueSchema; - const client = new Client({ accessToken: authValue.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(auth) }); const pipelineStagesResponse = await client.crm.pipelines.pipelineStagesApi.getAll( params.objectType, @@ -624,8 +618,7 @@ export const productDropdown = (params: DropdownParams) => }); } - const authValue = auth as PiecePropValueSchema; - const client = new Client({ accessToken: authValue.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(auth) }); const options: DropdownOption[] = []; @@ -661,8 +654,7 @@ export const customObjectDropdown = Property.Dropdown({ }); } - const authValue = auth as PiecePropValueSchema; - const client = new Client({ accessToken: authValue.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(auth) }); const customObjectsResponse = await client.crm.schemas.coreApi.getAll(); @@ -692,7 +684,6 @@ export const staticListsDropdown = Property.Dropdown({ }); } - const authValue = auth as PiecePropValueSchema; const options: DropdownOption[] = []; let offset = 0; @@ -703,7 +694,7 @@ export const staticListsDropdown = Property.Dropdown({ method: HttpMethod.GET, authentication: { type: AuthenticationType.BEARER_TOKEN, - token: authValue.access_token, + token: getHubspotAccessToken(auth), }, queryParams: { count: '100', @@ -748,8 +739,7 @@ export const fromObjectTypeAssociationDropdown = (params: DropdownParams) => }); } - const authValue = auth as PiecePropValueSchema; - const client = new Client({ accessToken: authValue.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(auth) }); const customObjectsResponse = await client.crm.schemas.coreApi.getAll(); @@ -779,8 +769,7 @@ export const associationTypeDropdown = Property.Dropdown({ }); } - const authValue = auth as PiecePropValueSchema; - const client = new Client({ accessToken: authValue.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(auth) }); const associationLabels = await client.crm.associations.v4.schema.definitionsApi.getAll( fromObjectType as string, toObjectType as string, @@ -814,8 +803,7 @@ export const toObjectIdsDropdown = (params: DropdownParams) => }); } - const authValue = auth as PiecePropValueSchema; - const client = new Client({ accessToken: authValue.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(auth) }); const limit = 100; const options: DropdownOption[] = []; @@ -872,8 +860,7 @@ export const formDropdown = Property.Dropdown({ }); } - const authValue = auth as PiecePropValueSchema; - const client = new Client({ accessToken: authValue.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(auth) }); const limit = 100; const options: DropdownOption[] = []; @@ -907,12 +894,11 @@ export const blogUrlDropdown = Property.Dropdown({ return { disabled: true, options: [], placeholder: 'Please connect your account.' }; } - const authValue = auth as PiecePropValueSchema; const response = await httpClient.sendRequest({ method: HttpMethod.GET, url: 'https://api.hubapi.com/content/api/v2/blogs', - authentication: { type: AuthenticationType.BEARER_TOKEN, token: authValue.access_token }, + authentication: { type: AuthenticationType.BEARER_TOKEN, token: getHubspotAccessToken(auth) }, queryParams: { limit: '100', }, @@ -940,9 +926,7 @@ export const blogAuthorDropdown = Property.Dropdown({ return { disabled: true, options: [], placeholder: 'Please connect your account.' }; } - const authValue = auth as PiecePropValueSchema; - - const client = new Client({ accessToken: authValue.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(auth) }); const options: DropdownOption[] = []; diff --git a/packages/pieces/community/hubspot/src/lib/triggers/deal-stage-updated.ts b/packages/pieces/community/hubspot/src/lib/triggers/deal-stage-updated.ts index 0d5e602e9e8b..54b9d003bb16 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/deal-stage-updated.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/deal-stage-updated.ts @@ -1,5 +1,4 @@ import { - PiecePropValueSchema, Property, TriggerStrategy, createTrigger, @@ -9,7 +8,7 @@ import { DedupeStrategy, Polling, pollingHelper } from '@activepieces/pieces-com import dayjs from 'dayjs'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { getDefaultPropertiesForObject, @@ -22,6 +21,8 @@ import { isNil } from '@activepieces/pieces-framework'; import { MarkdownVariant } from '@activepieces/pieces-framework'; import { Client } from '@hubspot/api-client'; import { FilterOperatorEnum } from '../common/types'; +import { crmObjectOutputSchema } from '../output-schemas'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; type Props = { additionalPropertiesToRetrieve?: string | string[]; @@ -29,12 +30,10 @@ type Props = { stageId?: string; }; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; -import { crmObjectOutputSchema } from '../output-schemas'; const polling: Polling, Props> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { - const client = new Client({ accessToken: auth.access_token, numberOfApiCallRetries: 3 }); + const client = new Client({ accessToken: getHubspotAccessToken(auth), numberOfApiCallRetries: 3 }); const additionalProperties = propsValue.additionalPropertiesToRetrieve ?? []; const defaultDealProperties = getDefaultPropertiesForObject(OBJECT_TYPE.DEAL); diff --git a/packages/pieces/community/hubspot/src/lib/triggers/email-subscriptions-timeline.ts b/packages/pieces/community/hubspot/src/lib/triggers/email-subscriptions-timeline.ts index b8c24514ebf8..b43c5f17b0b2 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/email-subscriptions-timeline.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/email-subscriptions-timeline.ts @@ -7,11 +7,10 @@ import { pollingHelper, QueryParams, } from '@activepieces/pieces-common'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { AppConnectionValueForAuthProperty, createTrigger, - PiecePropValueSchema, TriggerStrategy, } from '@activepieces/pieces-framework'; import { newEmailSubscriptionsTimelineTriggerOutputSchema } from '../output-schemas'; @@ -39,7 +38,7 @@ const polling: Polling, Re queryParams: qs, authentication: { type: AuthenticationType.BEARER_TOKEN, - token: auth.access_token, + token: getHubspotAccessToken(auth), }, }); hasMore = response.body.hasMore; diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-blog-article.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-blog-article.ts index 129f271d71d4..5cfc416120a5 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-blog-article.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-blog-article.ts @@ -7,7 +7,7 @@ import { pollingHelper, QueryParams, } from '@activepieces/pieces-common'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createTrigger, @@ -16,6 +16,7 @@ import { } from '@activepieces/pieces-framework'; import dayjs from 'dayjs'; import { newBlogArticleTriggerOutputSchema } from '../output-schemas'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; type Props = { articleState: string; @@ -29,7 +30,6 @@ type ListBlogPostsResponse = { }; }; }; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; const polling: Polling, Props> = { strategy: DedupeStrategy.TIMEBASED, @@ -60,7 +60,7 @@ const polling: Polling, Pr method: HttpMethod.GET, url: 'https://api.hubapi.com/cms/v3/blogs/posts', queryParams: qs, - authentication: { type: AuthenticationType.BEARER_TOKEN, token: auth.access_token }, + authentication: { type: AuthenticationType.BEARER_TOKEN, token: getHubspotAccessToken(auth) }, }); after = response.body.paging?.next?.after; diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-company-property-change.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-company-property-change.ts index 0819917d5f9a..b2092fc49c55 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-company-property-change.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-company-property-change.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createTrigger, AppConnectionValueForAuthProperty, @@ -22,7 +22,7 @@ type Props = { const polling: Polling, Props> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { - const client = new Client({ accessToken: auth.access_token, numberOfApiCallRetries: 3 }); + const client = new Client({ accessToken: getHubspotAccessToken(auth), numberOfApiCallRetries: 3 }); const propertyToCheck = propsValue.propertyName as string; diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-company.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-company.ts index 30e1a82d8e50..0c7165cce255 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-company.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-company.ts @@ -1,4 +1,4 @@ -import { PiecePropValueSchema, Property, createTrigger } from '@activepieces/pieces-framework'; +import {Property, createTrigger } from '@activepieces/pieces-framework'; import { TriggerStrategy } from '@activepieces/pieces-framework'; import { DedupeStrategy, Polling, pollingHelper } from '@activepieces/pieces-common'; @@ -7,20 +7,22 @@ import dayjs from 'dayjs'; import { isNil } from '@activepieces/pieces-framework'; import { MarkdownVariant } from '@activepieces/pieces-framework'; import { OBJECT_TYPE, MAX_SEARCH_PAGE_SIZE, MAX_SEARCH_TOTAL_RESULTS } from '../common/constants'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { Client } from '@hubspot/api-client'; import { FilterOperatorEnum } from '../common/types'; +import { crmObjectOutputSchema } from '../output-schemas'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; + + type Props = { additionalPropertiesToRetrieve?: string | string[]; }; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; -import { crmObjectOutputSchema } from '../output-schemas'; const polling: Polling, Props> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { - const client = new Client({ accessToken: auth.access_token, numberOfApiCallRetries: 3 }); + const client = new Client({ accessToken: getHubspotAccessToken(auth), numberOfApiCallRetries: 3 }); const additionalProperties = propsValue.additionalPropertiesToRetrieve ?? []; const defaultCompanyProperties = getDefaultPropertiesForObject(OBJECT_TYPE.COMPANY); diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-contact-in-list.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-contact-in-list.ts index 51c126b43a21..0bc1d5ef4749 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-contact-in-list.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-contact-in-list.ts @@ -1,9 +1,8 @@ import { DedupeStrategy, Polling, pollingHelper } from '@activepieces/pieces-common'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, HubspotAuthValue, hubspotAuth } from '../auth'; import { createTrigger, DropdownOption, - PiecePropValueSchema, Property, TriggerStrategy, } from '@activepieces/pieces-framework'; @@ -13,13 +12,13 @@ import { getDefaultPropertiesForObject, standardObjectPropertiesDropdown } from import { OBJECT_TYPE } from '../common/constants'; import dayjs from 'dayjs'; import { newContactInListTriggerOutputSchema } from '../output-schemas'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; type Props = { listId: string; additionalPropertiesToRetrieve?: string | string[]; }; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; const polling: Polling, Props> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { @@ -29,7 +28,7 @@ const polling: Polling, Pr const defaultContactProperties = getDefaultPropertiesForObject(OBJECT_TYPE.CONTACT); const propertiesToRetrieve = [...defaultContactProperties, ...additionalProperties]; - const client = new Client({ accessToken: auth.access_token }); + const client = new Client({ accessToken: getHubspotAccessToken(auth) }); const isTestMode = lastFetchEpochMS === 0; let listMembers = []; @@ -113,8 +112,8 @@ export const newContactInListTrigger = createTrigger({ }; } - const authValue = auth as PiecePropValueSchema; - const client = new Client({ accessToken: authValue.access_token }); + const authValue = auth as HubspotAuthValue; + const client = new Client({ accessToken: getHubspotAccessToken(authValue) }); let offset = 0; let hasMore = true; const options: DropdownOption[] = []; diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-contact-property-change.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-contact-property-change.ts index c6159c23362c..bb0e76637b55 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-contact-property-change.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-contact-property-change.ts @@ -1,7 +1,6 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createTrigger, - PiecePropValueSchema, TriggerStrategy, } from '@activepieces/pieces-framework'; import { standardObjectPropertiesDropdown } from '../common/props'; @@ -13,17 +12,17 @@ import { chunk } from '@activepieces/pieces-framework'; import { Client } from '@hubspot/api-client'; import dayjs from 'dayjs'; import { FilterOperatorEnum } from '../common/types'; +import { crmObjectOutputSchema } from '../output-schemas'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; type Props = { propertyName?: string | string[]; }; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; -import { crmObjectOutputSchema } from '../output-schemas'; const polling: Polling, Props> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { - const client = new Client({ accessToken: auth.access_token, numberOfApiCallRetries: 3 }); + const client = new Client({ accessToken: getHubspotAccessToken(auth), numberOfApiCallRetries: 3 }); const propertyToCheck = propsValue.propertyName as string; diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-contact.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-contact.ts index 9bc9a2bd580a..3c82d1039cbb 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-contact.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-contact.ts @@ -1,4 +1,4 @@ -import { PiecePropValueSchema, Property, createTrigger } from '@activepieces/pieces-framework'; +import { Property, createTrigger } from '@activepieces/pieces-framework'; import { TriggerStrategy } from '@activepieces/pieces-framework'; import { DedupeStrategy, Polling, pollingHelper } from '@activepieces/pieces-common'; @@ -7,20 +7,20 @@ import dayjs from 'dayjs'; import { isNil } from '@activepieces/pieces-framework'; import { MarkdownVariant } from '@activepieces/pieces-framework'; import { OBJECT_TYPE, MAX_SEARCH_PAGE_SIZE, MAX_SEARCH_TOTAL_RESULTS } from '../common/constants'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { Client } from '@hubspot/api-client'; import { FilterOperatorEnum } from '../common/types'; import { crmObjectOutputSchema } from '../output-schemas'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; type Props = { additionalPropertiesToRetrieve?: string | string[]; }; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; const polling: Polling, Props> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { - const client = new Client({ accessToken: auth.access_token, numberOfApiCallRetries: 3 }); + const client = new Client({ accessToken: getHubspotAccessToken(auth), numberOfApiCallRetries: 3 }); const additionalProperties = propsValue.additionalPropertiesToRetrieve ?? []; const defaultContactProperties = getDefaultPropertiesForObject(OBJECT_TYPE.CONTACT); diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-custom-object-property-change.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-custom-object-property-change.ts index 7525e3f46f63..1fbccdb88584 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-custom-object-property-change.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-custom-object-property-change.ts @@ -1,8 +1,7 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createTrigger, DynamicPropsValue, - PiecePropValueSchema, TriggerStrategy, } from '@activepieces/pieces-framework'; import { @@ -18,17 +17,17 @@ import dayjs from 'dayjs'; import { FilterOperatorEnum } from '../common/types'; import { MAX_SEARCH_PAGE_SIZE, MAX_SEARCH_TOTAL_RESULTS } from '../common/constants'; import { crmObjectOutputSchema } from '../output-schemas'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; type Props = { customObjectType?: string; propertyName?: DynamicPropsValue; }; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; const polling: Polling, Props> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { - const client = new Client({ accessToken: auth.access_token, numberOfApiCallRetries: 3 }); + const client = new Client({ accessToken: getHubspotAccessToken(auth), numberOfApiCallRetries: 3 }); const customObjectType = propsValue.customObjectType as string; const propertyToCheck = propsValue.propertyName?.['values'] as string; diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-custom-object.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-custom-object.ts index c28efaefced3..d79239ad1981 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-custom-object.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-custom-object.ts @@ -1,9 +1,8 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { DedupeStrategy, Polling, pollingHelper } from '@activepieces/pieces-common'; import { createTrigger, DynamicPropsValue, - PiecePropValueSchema, Property, TriggerStrategy, } from '@activepieces/pieces-framework'; @@ -15,17 +14,17 @@ import { FilterOperatorEnum } from '../common/types'; import { MAX_SEARCH_PAGE_SIZE, MAX_SEARCH_TOTAL_RESULTS } from '../common/constants'; import dayjs from 'dayjs'; import { crmObjectOutputSchema } from '../output-schemas'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; type Props = { customObjectType?: string; additionalPropertiesToRetrieve?: DynamicPropsValue; }; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; const polling: Polling, Props> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { - const client = new Client({ accessToken: auth.access_token, numberOfApiCallRetries: 3 }); + const client = new Client({ accessToken: getHubspotAccessToken(auth), numberOfApiCallRetries: 3 }); const customObjectType = propsValue.customObjectType as string; const additionalPropertiesToRetrieve = propsValue.additionalPropertiesToRetrieve?.['values']; diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-deal-property-change.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-deal-property-change.ts index 85cf21a3f8e6..e3aa13caa591 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-deal-property-change.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-deal-property-change.ts @@ -1,7 +1,6 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createTrigger, - PiecePropValueSchema, TriggerStrategy, } from '@activepieces/pieces-framework'; import { standardObjectPropertiesDropdown } from '../common/props'; @@ -13,17 +12,17 @@ import { chunk } from '@activepieces/pieces-framework'; import { Client } from '@hubspot/api-client'; import dayjs from 'dayjs'; import { FilterOperatorEnum } from '../common/types'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; type Props = { propertyName?: string | string[]; }; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; import { crmObjectOutputSchema } from '../output-schemas'; const polling: Polling, Props> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { - const client = new Client({ accessToken: auth.access_token, numberOfApiCallRetries: 3 }); + const client = new Client({ accessToken: getHubspotAccessToken(auth), numberOfApiCallRetries: 3 }); const propertyToCheck = propsValue.propertyName as string; diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-deal.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-deal.ts index 18ee46396759..a663b2a7cff8 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-deal.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-deal.ts @@ -1,26 +1,26 @@ -import { PiecePropValueSchema, Property, createTrigger } from '@activepieces/pieces-framework'; +import { Property, createTrigger } from '@activepieces/pieces-framework'; import { TriggerStrategy } from '@activepieces/pieces-framework'; import { DedupeStrategy, Polling, pollingHelper } from '@activepieces/pieces-common'; import { getDefaultPropertiesForObject, standardObjectPropertiesDropdown } from '../common/props'; import dayjs from 'dayjs'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { isNil } from '@activepieces/pieces-framework'; import { MarkdownVariant } from '@activepieces/pieces-framework'; import { OBJECT_TYPE, MAX_SEARCH_PAGE_SIZE, MAX_SEARCH_TOTAL_RESULTS } from '../common/constants'; import { Client } from '@hubspot/api-client'; import { FilterOperatorEnum } from '../common/types'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; type Props = { additionalPropertiesToRetrieve?: string | string[]; }; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; import { crmObjectOutputSchema } from '../output-schemas'; const polling: Polling, Props> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { - const client = new Client({ accessToken: auth.access_token, numberOfApiCallRetries: 3 }); + const client = new Client({ accessToken: getHubspotAccessToken(auth), numberOfApiCallRetries: 3 }); const additionalProperties = propsValue.additionalPropertiesToRetrieve ?? []; const defaultProductProperties = getDefaultPropertiesForObject(OBJECT_TYPE.DEAL); diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-email-event.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-email-event.ts index 912491e4da03..a9b3b52cf26c 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-email-event.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-email-event.ts @@ -7,13 +7,13 @@ import { pollingHelper, QueryParams, } from '@activepieces/pieces-common'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createTrigger, - PiecePropValueSchema, Property, TriggerStrategy, } from '@activepieces/pieces-framework'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; type Props = { eventType?: string; @@ -25,7 +25,6 @@ type EmailEventResponse = { offset: string; }; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; const polling: Polling, Props> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { @@ -49,7 +48,7 @@ const polling: Polling, Pr queryParams: qs, authentication: { type: AuthenticationType.BEARER_TOKEN, - token: auth.access_token, + token: getHubspotAccessToken(auth), }, }); hasMore = response.body.hasMore; diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-engagement.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-engagement.ts index 5303a46da8c7..f30ec285eb00 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-engagement.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-engagement.ts @@ -7,13 +7,13 @@ import { pollingHelper, QueryParams, } from '@activepieces/pieces-common'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createTrigger, - PiecePropValueSchema, Property, TriggerStrategy, } from '@activepieces/pieces-framework'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; type Props = { eventType?: string; @@ -25,7 +25,6 @@ type EngagementResponse = { offset: string; }; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; const polling: Polling, Props> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { @@ -41,7 +40,7 @@ const polling: Polling, Pr queryParams: qs, authentication: { type: AuthenticationType.BEARER_TOKEN, - token: auth.access_token, + token: getHubspotAccessToken(auth), }, }); hasMore = response.body.hasMore; diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-form-submission.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-form-submission.ts index 61848239b65a..67575baee0a3 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-form-submission.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-form-submission.ts @@ -1,4 +1,4 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, HubspotAuthValue, hubspotAuth } from '../auth'; import { AuthenticationType, DedupeStrategy, @@ -10,12 +10,12 @@ import { } from '@activepieces/pieces-common'; import { createTrigger, - PiecePropValueSchema, TriggerStrategy, Property, } from '@activepieces/pieces-framework'; import { formDropdown } from '../common/props'; import { newFormSubmissionTriggerOutputSchema } from '../output-schemas'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; type Props = { formId: string; @@ -42,11 +42,10 @@ type FormField = { fieldType: string; }; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; const polling: Polling, Props> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { - const authValue = auth as PiecePropValueSchema; + const authValue = auth as HubspotAuthValue; const formId = propsValue.formId; const submissions = []; @@ -62,7 +61,7 @@ const polling: Polling, Pr queryParams: qs, authentication: { type: AuthenticationType.BEARER_TOKEN, - token: authValue.access_token, + token: getHubspotAccessToken(authValue), }, }); after = response.body.paging?.next?.after; @@ -74,7 +73,7 @@ const polling: Polling, Pr url: `https://api.hubapi.com/forms/v2/fields/${formId}`, authentication: { type: AuthenticationType.BEARER_TOKEN, - token: authValue.access_token, + token: getHubspotAccessToken(authValue), }, }); diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-line-item.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-line-item.ts index af8a02a12b12..6ea35eccbc9f 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-line-item.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-line-item.ts @@ -1,8 +1,7 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { DedupeStrategy, Polling, pollingHelper } from '@activepieces/pieces-common'; import { createTrigger, - PiecePropValueSchema, Property, TriggerStrategy, } from '@activepieces/pieces-framework'; @@ -13,17 +12,17 @@ import { OBJECT_TYPE, MAX_SEARCH_PAGE_SIZE, MAX_SEARCH_TOTAL_RESULTS } from '../ import { Client } from '@hubspot/api-client'; import { FilterOperatorEnum } from '../common/types'; import dayjs from 'dayjs'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; type Props = { additionalPropertiesToRetrieve?: string | string[]; }; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; import { crmObjectOutputSchema } from '../output-schemas'; const polling: Polling, Props> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { - const client = new Client({ accessToken: auth.access_token, numberOfApiCallRetries: 3 }); + const client = new Client({ accessToken: getHubspotAccessToken(auth), numberOfApiCallRetries: 3 }); // Extract properties once to avoid recomputation const additionalProperties = propsValue.additionalPropertiesToRetrieve ?? []; diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-or-updated-company.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-or-updated-company.ts index 185be052de77..cef306429834 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-or-updated-company.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-or-updated-company.ts @@ -1,9 +1,8 @@ import { isNil } from '@activepieces/pieces-framework'; import { MarkdownVariant } from '@activepieces/pieces-framework'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createTrigger, - PiecePropValueSchema, Property, TriggerStrategy, } from '@activepieces/pieces-framework'; @@ -14,12 +13,12 @@ import { Client } from '@hubspot/api-client'; import { FilterOperatorEnum } from '../common/types'; import dayjs from 'dayjs'; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; import { crmObjectOutputSchema } from '../output-schemas'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; const polling: Polling,{ additionalPropertiesToRetrieve?: string[] | string }> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { - const client = new Client({ accessToken: auth.access_token, numberOfApiCallRetries: 3 }); + const client = new Client({ accessToken: getHubspotAccessToken(auth), numberOfApiCallRetries: 3 }); // Extract properties once to avoid recomputation const additionalProperties = propsValue.additionalPropertiesToRetrieve ?? []; diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-or-updated-contact.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-or-updated-contact.ts index 1e3c6b8eaa41..a271b029116d 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-or-updated-contact.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-or-updated-contact.ts @@ -1,9 +1,8 @@ import { isNil } from '@activepieces/pieces-framework'; import { MarkdownVariant } from '@activepieces/pieces-framework'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createTrigger, - PiecePropValueSchema, Property, TriggerStrategy, } from '@activepieces/pieces-framework'; @@ -14,12 +13,12 @@ import { Client } from '@hubspot/api-client'; import { FilterOperatorEnum } from '../common/types'; import dayjs from 'dayjs'; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; import { crmObjectOutputSchema } from '../output-schemas'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; const polling: Polling,{ additionalPropertiesToRetrieve?: string[] | string }> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { - const client = new Client({ accessToken: auth.access_token, numberOfApiCallRetries: 3 }); + const client = new Client({ accessToken: getHubspotAccessToken(auth), numberOfApiCallRetries: 3 }); // Extract properties once to avoid recomputation const additionalProperties = propsValue.additionalPropertiesToRetrieve ?? []; diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-or-updated-line-item.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-or-updated-line-item.ts index 3aa2744d7d05..2e81eb49d636 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-or-updated-line-item.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-or-updated-line-item.ts @@ -1,9 +1,8 @@ import { isNil } from '@activepieces/pieces-framework'; import { MarkdownVariant } from '@activepieces/pieces-framework'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createTrigger, - PiecePropValueSchema, Property, TriggerStrategy, } from '@activepieces/pieces-framework'; @@ -14,12 +13,12 @@ import { Client } from '@hubspot/api-client'; import { FilterOperatorEnum } from '../common/types'; import dayjs from 'dayjs'; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; import { crmObjectOutputSchema } from '../output-schemas'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; const polling: Polling,{ additionalPropertiesToRetrieve?: string[] | string }> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { - const client = new Client({ accessToken: auth.access_token, numberOfApiCallRetries: 3 }); + const client = new Client({ accessToken: getHubspotAccessToken(auth), numberOfApiCallRetries: 3 }); // Extract properties once to avoid recomputation const additionalProperties = propsValue.additionalPropertiesToRetrieve ?? []; diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-or-updated-product.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-or-updated-product.ts index fe17f4426b93..448080825e32 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-or-updated-product.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-or-updated-product.ts @@ -1,9 +1,8 @@ import { isNil } from '@activepieces/pieces-framework'; import { MarkdownVariant } from '@activepieces/pieces-framework'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createTrigger, - PiecePropValueSchema, Property, TriggerStrategy, } from '@activepieces/pieces-framework'; @@ -14,12 +13,12 @@ import { Client } from '@hubspot/api-client'; import { FilterOperatorEnum } from '../common/types'; import dayjs from 'dayjs'; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; import { crmObjectOutputSchema } from '../output-schemas'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; const polling: Polling,{ additionalPropertiesToRetrieve?: string[] | string }> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { - const client = new Client({ accessToken: auth.access_token, numberOfApiCallRetries: 3 }); + const client = new Client({ accessToken: getHubspotAccessToken(auth), numberOfApiCallRetries: 3 }); // Extract properties once to avoid recomputation const additionalProperties = propsValue.additionalPropertiesToRetrieve ?? []; diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-product.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-product.ts index 10ed94914c74..4f05f36c7d11 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-product.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-product.ts @@ -1,8 +1,7 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { DedupeStrategy, Polling, pollingHelper } from '@activepieces/pieces-common'; import { createTrigger, - PiecePropValueSchema, Property, TriggerStrategy, } from '@activepieces/pieces-framework'; @@ -13,17 +12,17 @@ import { OBJECT_TYPE, MAX_SEARCH_PAGE_SIZE, MAX_SEARCH_TOTAL_RESULTS } from '../ import { Client } from '@hubspot/api-client'; import { FilterOperatorEnum } from '../common/types'; import dayjs from 'dayjs'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; type Props = { additionalPropertiesToRetrieve?: string | string[]; }; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; import { crmObjectOutputSchema } from '../output-schemas'; const polling: Polling, Props> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { - const client = new Client({ accessToken: auth.access_token, numberOfApiCallRetries: 3 }); + const client = new Client({ accessToken: getHubspotAccessToken(auth), numberOfApiCallRetries: 3 }); // Extract properties once to avoid recomputation const additionalProperties = propsValue.additionalPropertiesToRetrieve ?? []; diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-task.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-task.ts index 3da18a72929a..b885f35dcdd4 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-task.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-task.ts @@ -1,8 +1,8 @@ -import { PiecePropValueSchema, Property, createTrigger } from '@activepieces/pieces-framework'; +import { Property, createTrigger } from '@activepieces/pieces-framework'; import { TriggerStrategy } from '@activepieces/pieces-framework'; import { DedupeStrategy, Polling, pollingHelper } from '@activepieces/pieces-common'; import dayjs from 'dayjs'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { isNil } from '@activepieces/pieces-framework'; import { MarkdownVariant } from '@activepieces/pieces-framework'; import { OBJECT_TYPE, MAX_SEARCH_PAGE_SIZE, MAX_SEARCH_TOTAL_RESULTS } from '../common/constants'; @@ -10,17 +10,17 @@ import { getDefaultPropertiesForObject, standardObjectPropertiesDropdown } from import { Client } from '@hubspot/api-client'; import { FilterOperatorEnum } from '../common/types'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; type Props = { additionalPropertiesToRetrieve?: string | string[]; }; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; import { crmObjectOutputSchema } from '../output-schemas'; const polling: Polling, Props> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { - const client = new Client({ accessToken: auth.access_token, numberOfApiCallRetries: 3 }); + const client = new Client({ accessToken: getHubspotAccessToken(auth), numberOfApiCallRetries: 3 }); const additionalProperties = propsValue.additionalPropertiesToRetrieve ?? []; const defaultTaskProperties = getDefaultPropertiesForObject(OBJECT_TYPE.TASK); diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-ticket-property-change.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-ticket-property-change.ts index 00f082c0558a..7980a26a3ca9 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-ticket-property-change.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-ticket-property-change.ts @@ -1,7 +1,6 @@ -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { createTrigger, - PiecePropValueSchema, TriggerStrategy, } from '@activepieces/pieces-framework'; import { standardObjectPropertiesDropdown } from '../common/props'; @@ -13,17 +12,17 @@ import { chunk } from '@activepieces/pieces-framework'; import { Client } from '@hubspot/api-client'; import dayjs from 'dayjs'; import { FilterOperatorEnum } from '../common/types'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; type Props = { propertyName?: string | string[]; }; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; import { crmObjectOutputSchema } from '../output-schemas'; const polling: Polling, Props> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { - const client = new Client({ accessToken: auth.access_token, numberOfApiCallRetries: 3 }); + const client = new Client({ accessToken: getHubspotAccessToken(auth), numberOfApiCallRetries: 3 }); const propertyToCheck = propsValue.propertyName as string; diff --git a/packages/pieces/community/hubspot/src/lib/triggers/new-ticket.ts b/packages/pieces/community/hubspot/src/lib/triggers/new-ticket.ts index 91bed067625d..be44f5f315ac 100644 --- a/packages/pieces/community/hubspot/src/lib/triggers/new-ticket.ts +++ b/packages/pieces/community/hubspot/src/lib/triggers/new-ticket.ts @@ -1,26 +1,26 @@ -import { PiecePropValueSchema, Property, createTrigger } from '@activepieces/pieces-framework'; +import { Property, createTrigger } from '@activepieces/pieces-framework'; import { TriggerStrategy } from '@activepieces/pieces-framework'; import { DedupeStrategy, Polling, pollingHelper } from '@activepieces/pieces-common'; import { getDefaultPropertiesForObject, standardObjectPropertiesDropdown } from '../common/props'; import dayjs from 'dayjs'; -import { hubspotAuth } from '../auth'; +import { getHubspotAccessToken, hubspotAuth } from '../auth'; import { isNil } from '@activepieces/pieces-framework'; import { MarkdownVariant } from '@activepieces/pieces-framework'; import { OBJECT_TYPE, MAX_SEARCH_PAGE_SIZE, MAX_SEARCH_TOTAL_RESULTS } from '../common/constants'; import { Client } from '@hubspot/api-client'; import { FilterOperatorEnum } from '../common/types'; +import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; type Props = { additionalPropertiesToRetrieve?: string | string[]; }; -import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework'; import { crmObjectOutputSchema } from '../output-schemas'; const polling: Polling, Props> = { strategy: DedupeStrategy.TIMEBASED, async items({ auth, propsValue, lastFetchEpochMS }) { - const client = new Client({ accessToken: auth.access_token, numberOfApiCallRetries: 3 }); + const client = new Client({ accessToken: getHubspotAccessToken(auth), numberOfApiCallRetries: 3 }); const additionalProperties = propsValue.additionalPropertiesToRetrieve ?? []; const defaultTicketProperties = getDefaultPropertiesForObject(OBJECT_TYPE.TICKET); diff --git a/packages/server/api/src/app/ee/agent/agent-controller.ts b/packages/server/api/src/app/ee/agent/agent-controller.ts index fad25f6eb0ef..d2778d262e20 100644 --- a/packages/server/api/src/app/ee/agent/agent-controller.ts +++ b/packages/server/api/src/app/ee/agent/agent-controller.ts @@ -1,5 +1,5 @@ import { ActivepiecesError, ApId, assertNotNullOrUndefined, ErrorCode, Permission, SeekPage, UserId } from '@activepieces/core-utils' -import { Agent, AgentSummary, AgentTemplate, ApplicationEventName, CreateAgentRequest, DraftAgentRequest, DraftAgentResponse, ListAgentsRequest, PrincipalType, SERVICE_KEY_SECURITY_OPENAPI, UpdateAgentRequest } from '@activepieces/shared' +import { Agent, AgentSummary, ApplicationEventName, CreateAgentRequest, DraftAgentRequest, DraftAgentResponse, ListAgentsRequest, PrincipalType, SERVICE_KEY_SECURITY_OPENAPI, UpdateAgentRequest } from '@activepieces/shared' import { FastifyRequest } from 'fastify' import { FastifyPluginAsyncZod } from 'fastify-type-provider-zod' import { StatusCodes } from 'http-status-codes' @@ -7,14 +7,12 @@ import { z } from 'zod' import { ProjectResourceType } from '../../core/security/authorization/common' import { securityAccess } from '../../core/security/authorization/fastify-security' import { applicationEvents } from '../../helper/application-events' -import { paginationHelper } from '../../helper/pagination/pagination-utils' import { securityHelper } from '../../helper/security-helper' import { assertCreditsAndAppSumoNotExceeded } from '../../platform/billing-provider' import { agentDraftAi } from './agent-draft-ai' import { AgentEntity } from './agent-entity' import { agentHelpers } from './agent-helpers' import { agentAudit, agentRedaction, agentService } from './agent-service' -import { AGENT_TEMPLATES } from './agent-templates' export const DRAFTS_PER_MINUTE = 20 @@ -44,10 +42,6 @@ export const agentController: FastifyPluginAsyncZod = async (app) => { }) }) - app.get('/templates', ListTemplatesRoute, async (): Promise> => { - return paginationHelper.createPage([...AGENT_TEMPLATES], null) - }) - app.post('/draft', DraftAgentRoute, async (request): Promise => { const platformId = request.principal.platform.id await assertCreditsAndAppSumoNotExceeded({ platformId, log: request.log }) @@ -168,20 +162,6 @@ const ListAgentsRoute = { }, } -const ListTemplatesRoute = { - config: { - security: securityAccess.publicPlatform([PrincipalType.USER, PrincipalType.SERVICE]), - }, - schema: { - tags: ['agents'], - security: [SERVICE_KEY_SECURITY_OPENAPI], - description: 'List the starter agents, none of which need a connection', - response: { - [StatusCodes.OK]: SeekPage(AgentTemplate), - }, - }, -} - const DraftAgentRoute = { config: { security: securityAccess.project( diff --git a/packages/server/api/src/app/ee/agent/agent-templates.ts b/packages/server/api/src/app/ee/agent/agent-templates.ts deleted file mode 100644 index dfbfea8ad960..000000000000 --- a/packages/server/api/src/app/ee/agent/agent-templates.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { AgentIcon, AgentTemplate, ColorName } from '@activepieces/shared' - -export const AGENT_TEMPLATES: readonly AgentTemplate[] = [ - { - id: 'launch-copy', - displayName: 'Launch copy', - description: 'Writes the announcement, in two versions, in your voice.', - icon: AgentIcon.SPARKLES, - color: ColorName.PURPLE, - instructions: 'You draft launch copy. If you were given no sample of the writing you should match, ask for one rather than inventing a house voice. Keep posts under 120 words, lead with what changed for the reader, and never invent a metric, a customer quote, or a release date. Always return two options with one line on how they differ.', - }, - { - id: 'research-analyst', - displayName: 'Research analyst', - description: 'Searches, reads, and returns a brief with sources.', - icon: AgentIcon.SEARCH, - color: ColorName.BLUE, - instructions: 'You research a question and return a short brief. Search before you answer, read more than one source, and say which claim came from where. If you cannot search, say so plainly and work only from what you were given, marking every claim you could not verify. Lead with the answer, then the evidence, then what is still uncertain. If the sources disagree, say so rather than picking one silently.', - }, - { - id: 'support-triage', - displayName: 'Support triage', - description: 'Reads a ticket, tags severity, and drafts the first reply.', - icon: AgentIcon.MESSAGE, - color: ColorName.ORANGE, - instructions: 'You triage incoming support tickets. Decide severity from customer impact, not from tone. Summarise the problem in one sentence, list what you would need to reproduce it, and draft a first reply that acknowledges the specific issue rather than thanking them for their patience. Never promise a fix date.', - }, - { - id: 'meeting-follow-up', - displayName: 'Meeting follow-up', - description: 'Turns notes into decisions, owners, and next steps.', - icon: AgentIcon.CALENDAR, - color: ColorName.GREEN, - instructions: 'You turn meeting notes into a follow-up. Separate decisions from discussion, and give every action an owner and a date. If an action has no owner in the notes, list it as unassigned rather than guessing. Keep it short enough to read on a phone.', - }, - { - id: 'sales-prospecting', - displayName: 'Sales prospecting', - description: 'Researches a lead and writes an opener worth answering.', - icon: AgentIcon.USERS, - color: ColorName.CYAN, - instructions: 'You research a lead and write a first-touch email. Find something specific and recent about their company, and open with that rather than with your product. Three sentences, one question, no adjectives about yourself. If you cannot search, or cannot find anything specific, say so instead of writing a generic opener.', - }, - { - id: 'content-repurposer', - displayName: 'Content repurposer', - description: 'Turns one long piece into posts for each channel.', - icon: AgentIcon.FILE, - color: ColorName.PINK, - instructions: 'You repurpose one long piece of content into shorter ones. Pull the ideas that stand alone, and rewrite each for its channel rather than truncating the original. Keep the author\'s claims exactly as they made them. Say which section each piece came from.', - }, - { - id: 'data-cleanup', - displayName: 'Data cleanup', - description: 'Flags duplicates and inconsistent formatting in a list.', - icon: AgentIcon.CHART, - color: ColorName.YELLOW, - instructions: 'You review messy records and report what needs fixing. Flag inconsistent formatting and likely duplicates rather than changing or merging anything yourself, and list every problem so it can be reviewed in one pass. When two records conflict, show both and ask which wins. Never delete or rewrite a record.', - }, - { - id: 'onboarding-buddy', - displayName: 'Onboarding buddy', - description: 'Answers new-hire questions from your own docs.', - icon: AgentIcon.BOOK, - color: ColorName.LAVENDER, - instructions: 'You answer questions from new team members. Answer from the documents you are given, quote the part you used, and link it. If you were given no documents, ask for them rather than answering from general knowledge. If the docs do not cover the question, say that and suggest who to ask rather than guessing at an answer that sounds plausible.', - }, -] diff --git a/packages/server/api/test/integration/ee/agent/agent-controller.test.ts b/packages/server/api/test/integration/ee/agent/agent-controller.test.ts index 19fc88091f9b..06b260e6f823 100644 --- a/packages/server/api/test/integration/ee/agent/agent-controller.test.ts +++ b/packages/server/api/test/integration/ee/agent/agent-controller.test.ts @@ -6,7 +6,6 @@ import { db } from '../../../helpers/db' import { mockAndSaveAIProvider } from '../../../helpers/mocks' import { createMemberContext, createTestContext, TestContext } from '../../../helpers/test-context' import { DRAFTS_PER_MINUTE } from '../../../../src/app/ee/agent/agent-controller' -import { AGENT_TEMPLATES } from '../../../../src/app/ee/agent/agent-templates' import { setupTestEnvironment, teardownTestEnvironment } from '../../../helpers/test-setup' let app: FastifyInstance @@ -521,89 +520,10 @@ describe('agent permissions', () => { }) }) -describe('agent templates', () => { - it('serves starter agents with no ai provider and no connections configured', async () => { - const ctx = await context() - - const response = await ctx.get('/v1/agents/templates') - - expect(response.statusCode).toBe(StatusCodes.OK) - const templates = response.json().data - expect(templates.length).toBe(AGENT_TEMPLATES.length) - expect(new Set(templates.map((t: { id: string }) => t.id)).size).toBe(templates.length) - for (const template of templates) { - expect(template.instructions.length).toBeGreaterThan(0) - } - }) - - it.each(AGENT_TEMPLATES.map((template) => [template.id, template]))( - 'creates and publishes the %s starter, with only what the template carries', - async (_id, template) => { - const ctx = await context() - - const created = await ctx.post('/v1/agents', { - projectId: ctx.project.id, - displayName: template.displayName, - description: template.description, - icon: template.icon, - color: template.color, - draft: { instructions: template.instructions }, - }) - - expect(created.statusCode).toBe(StatusCodes.CREATED) - expect(created.json().description).toBe(template.description) - expect(created.json().draft.maxSteps).toBe(DEFAULT_AGENT_MAX_STEPS) - expect((await ctx.post(`/v1/agents/${created.json().id}/publish`)).statusCode).toBe(StatusCodes.OK) - }) - - it('tells the caller to connect a provider, rather than naming an internal entity', async () => { - const ctx = await context() - - const drafted = await ctx.post('/v1/agents/draft', { projectId: ctx.project.id, prompt: 'watch competitor pricing' }) - - expect(drafted.statusCode).toBe(StatusCodes.CONFLICT) - expect(drafted.body).toContain('Connect an AI provider') - expect(drafted.body).not.toContain('ChatAiProvider') - }) - - it('rate limits one caller without blocking another on the same platform', async () => { - const owner = await context() - const colleague = await createMemberContext(app, owner, { projectRole: DefaultProjectRole.EDITOR }) - const draft = (ctx: TestContext) => ctx.post('/v1/agents/draft', { projectId: owner.project.id, prompt: 'watch competitor pricing' }) - - const responses = [] - for (let attempt = 0; attempt <= DRAFTS_PER_MINUTE; attempt++) { - responses.push(await draft(owner)) - } - - expect(responses[responses.length - 1].body).toContain(`above the limit of ${DRAFTS_PER_MINUTE}`) - expect((await draft(colleague)).body).not.toContain('above the limit') - }) - - it('refuses a draft prompt longer than the endpoint is meant to take', async () => { - const ctx = await context() - - const response = await ctx.post('/v1/agents/draft', { projectId: ctx.project.id, prompt: 'a'.repeat(MAX_DRAFT_PROMPT_LENGTH + 1) }) - - expect(response.statusCode).toBe(StatusCodes.BAD_REQUEST) - }) - - it('refuses to draft for a project the caller cannot write', async () => { - const owner = await context() - const viewer = await createMemberContext(app, owner, { projectRole: DefaultProjectRole.VIEWER }) - - const response = await viewer.post('/v1/agents/draft', { projectId: owner.project.id, prompt: 'anything' }) - - expect(response.statusCode).toBe(StatusCodes.FORBIDDEN) - }) - -}) - describe('agent routes coexist with the chat routes already on /v1/agents', () => { it('does not swallow the static sibling routes with /:id', async () => { const ctx = await createTestContext(app, { plan: { agentsEnabled: true, chatEnabled: true } }) - expect((await ctx.get('/v1/agents/templates')).statusCode).toBe(StatusCodes.OK) expect((await ctx.get('/v1/agents/memory')).statusCode).toBe(StatusCodes.OK) expect((await ctx.get('/v1/agents/conversations')).statusCode).toBe(StatusCodes.OK) }) @@ -627,7 +547,6 @@ describe('agent feature gate', () => { expect((await ctx.get(`/v1/agents/${agent.id}`)).statusCode).toBe(StatusCodes.PAYMENT_REQUIRED) expect((await ctx.post(`/v1/agents/${agent.id}`, { displayName: 'x' })).statusCode).toBe(StatusCodes.PAYMENT_REQUIRED) expect((await ctx.post(`/v1/agents/${agent.id}/publish`)).statusCode).toBe(StatusCodes.PAYMENT_REQUIRED) - expect((await ctx.get('/v1/agents/templates')).statusCode).toBe(StatusCodes.PAYMENT_REQUIRED) expect((await ctx.post('/v1/agents/draft', { projectId: ctx.project.id, prompt: 'x' })).statusCode).toBe(StatusCodes.PAYMENT_REQUIRED) expect((await ctx.delete(`/v1/agents/${agent.id}`)).statusCode).toBe(StatusCodes.PAYMENT_REQUIRED) }) diff --git a/packages/server/utils/src/agent-ai-utils.ts b/packages/server/utils/src/agent-ai-utils.ts index faf6787df8c3..f9f38bd4c1ca 100644 --- a/packages/server/utils/src/agent-ai-utils.ts +++ b/packages/server/utils/src/agent-ai-utils.ts @@ -238,7 +238,7 @@ function estimateTokenCount({ messages, systemPromptLength }: { messages: ModelM function collapseStaleToolOutputs({ messages }: { messages: ModelMessage[] }): ModelMessage[] { const totalToolResults = messages.reduce((count, message) => { if (message.role !== 'tool' || !Array.isArray(message.content)) return count - return count + message.content.filter((part) => part.type === 'tool-result').length + return count + message.content.filter((part) => part.type === 'tool-result' && !SCHEMA_TOOL_NAMES.has(part.toolName)).length }, 0) const staleCount = totalToolResults - KEEP_RECENT_TOOL_RESULTS diff --git a/packages/server/utils/test/agent-ai-utils.test.ts b/packages/server/utils/test/agent-ai-utils.test.ts index 79113d1cc10f..17693dc1dba3 100644 --- a/packages/server/utils/test/agent-ai-utils.test.ts +++ b/packages/server/utils/test/agent-ai-utils.test.ts @@ -310,6 +310,21 @@ describe('collapseStaleToolOutputs', () => { expect(outputAt(0)).not.toContain('omitted to save context') expect(outputAt(1)).toContain('omitted to save context') // ordinary stale result still collapses }) + + it('pinned schema results do not consume a keep-recent slot', () => { + const big = 'z'.repeat(2000) + const schemaMessage: ModelMessage = { + role: 'tool', + content: [{ type: 'tool-result', toolCallId: 'schema', toolName: 'ap_get_piece_props', output: { type: 'text', value: big } }], + } + const messages: ModelMessage[] = [schemaMessage, ...Array.from({ length: 6 }, (_, i) => toolResultMessage({ id: `c${i}`, outputText: big }))] + const out = agentAiUtils.collapseStaleToolOutputs({ messages }) + const outputAt = (idx: number): string => JSON.stringify(Array.isArray(out[idx].content) ? out[idx].content[0] : undefined) + + for (let i = 0; i < messages.length; i++) { + expect(outputAt(i)).not.toContain('omitted to save context') + } + }) }) describe('estimateTokenCount', () => { diff --git a/packages/web/public/locales/en/translation.json b/packages/web/public/locales/en/translation.json index ac8132d67a45..16e6de2d426f 100644 --- a/packages/web/public/locales/en/translation.json +++ b/packages/web/public/locales/en/translation.json @@ -1,7 +1,25 @@ { + "Agents need an AI provider": "Agents need an AI provider", + "Add a provider once, then I can build agents from a sentence.": "Add a provider once, then I can build agents from a sentence.", + "An agent is an assistant with instructions and tools. Describe the job and I'll write both.": "An agent is an assistant with instructions and tools. Describe the job and I'll write both.", + "Ask your platform admin to connect an AI provider.": "Ask your platform admin to connect an AI provider.", + "Ask your platform admin to turn on a provider for chat.": "Ask your platform admin to turn on a provider for chat.", + "Create your first agent": "Create your first agent", "Connect an account": "Connect an account", + "Describe a task for your agent… e.g. research our competitors and send me a weekly brief": "Describe a task for your agent… e.g. research our competitors and send me a weekly brief", "Different account per action": "Different account per action", "Account was deleted": "Account was deleted", + "Enrich a new lead with company details and write the first email": "Enrich a new lead with company details and write the first email", + "Lead enrichment": "Lead enrichment", + "New agent": "New agent", + "No provider is turned on for chat": "No provider is turned on for chat", + "Popular starting points": "Popular starting points", + "Read a support ticket, tag its severity, and route it to a team": "Read a support ticket, tag its severity, and route it to a team", + "Research a company and send me a cited brief on it": "Research a company and send me a cited brief on it", + "Research keywords for a topic and draft a post that targets them": "Research keywords for a topic and draft a post that targets them", + "SEO writer": "SEO writer", + "Support triage": "Support triage", + "Turn on a provider for chat": "Turn on a provider for chat", "Write instructions before testing": "Write instructions before testing", "Try it before it goes live": "Try it before it goes live", "Needs a model to run": "Needs a model to run", @@ -11,6 +29,7 @@ "Pick a model before testing": "Pick a model before testing", "Try {name}...": "Try {name}...", "Give the agent a real task. It answers on the settings beside you, so you can watch a change work before every flow gets it.": "Give the agent a real task. It answers on the settings beside you, so you can watch a change work before every flow gets it.", + "Write one by hand instead": "Write one by hand instead", "Your changes couldn't be staged for testing. Try again.": "Your changes couldn't be staged for testing. Try again.", "Support": "Support", "Runs": "Runs", @@ -47,6 +66,8 @@ "The service rejected the request. Review the step input and verify each field matches what the service expects.": "The service rejected the request. Review the step input and verify each field matches what the service expects.", "The service rejected the request. Review the step input and the message below for details.": "The service rejected the request. Review the step input and the message below for details.", "The step did not complete successfully. Check the step configuration and the message below.": "The step did not complete successfully. Check the step configuration and the message below.", + "Your most reliable teammate for getting work done, powered by your tools and guided by your words.": "Your most reliable teammate for getting work done, powered by your tools and guided by your words.", + "Your project has a provider, but writing an agent for you needs one turned on for chat.": "Your project has a provider, but writing an agent for you needs one turned on for chat.", "{count, plural, =1 {1 item} other {# items}}": "{count, plural, =1 {1 item} other {# items}}", "Insert": "Insert", "Empty List": "Empty List", @@ -2440,18 +2461,14 @@ "Enrich a lead": "Enrich a lead", "Your agents": "Your agents", "Search agents": "Search agents", - "New agent": "New agent", "No tools": "No tools", "Private": "Private", "No description yet": "No description yet", - "No agents yet": "No agents yet", "No agents match that search": "No agents match that search", "Agent deleted": "Agent deleted", "Agents": "Agents", "Grid view": "Grid view", "List view": "List view", - "Start from a template": "Start from a template", - "Start blank": "Start blank", "Create agent": "Create agent", "Instructions": "Instructions", "Draft weekly launch posts and file them in Notion…": "Draft weekly launch posts and file them in Notion…", @@ -2466,7 +2483,6 @@ "That didn't work. Try describing the agent another way.": "That didn't work. Try describing the agent another way.", "The agent wasn't saved. Try again.": "The agent wasn't saved. Try again.", "Your changes weren't saved. Try again.": "Your changes weren't saved. Try again.", - "Describe one above, or pick a template.": "Describe one above, or pick a template.", "Try another name, or clear the search.": "Try another name, or clear the search.", "Showing the first {count}": "Showing the first {count}", "Build an agent once, then use it in any flow.": "Build an agent once, then use it in any flow.", @@ -2484,7 +2500,6 @@ "Expand conversations": "Expand conversations", "Agent saved": "Agent saved", "Collapse conversations": "Collapse conversations", - "Start from a template, or build one from scratch.": "Start from a template, or build one from scratch.", "Pick a model so this agent can answer.": "Pick a model so this agent can answer.", "agentConfigTooLarge": "Agent configuration is too large", "Building your agent": "Building your agent", diff --git a/packages/web/src/app/routes/agents/index.tsx b/packages/web/src/app/routes/agents/index.tsx index af363ff494ff..330a7b8a4255 100644 --- a/packages/web/src/app/routes/agents/index.tsx +++ b/packages/web/src/app/routes/agents/index.tsx @@ -1,22 +1,32 @@ import { + AgentIcon, AgentSummary, + ColorName, MAX_DRAFT_PROMPT_LENGTH, PROJECT_COLOR_PALETTE, } from '@activepieces/shared'; import { t } from 'i18next'; import { ArrowUp, - Settings2, ChevronsUpDown, LayoutGrid, List, - Plus, + Pencil, Search, + SearchX, + Settings2, } from 'lucide-react'; import { useMemo, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { LockedFeatureGuard } from '@/app/components/locked-feature-guard'; +import { + Empty, + EmptyDescription, + EmptyHeader, + EmptyMedia, + EmptyTitle, +} from '@/components/custom/empty'; import { Button } from '@/components/ui/button'; import { DropdownMenu, @@ -28,7 +38,7 @@ import { import { Skeleton } from '@/components/ui/skeleton'; import { Textarea } from '@/components/ui/textarea'; import { AgentCard } from '@/features/agents/agent-card'; -import { CreateAgentDialog } from '@/features/agents/create-agent-dialog'; +import { AgentTrioMark } from '@/features/agents/agent-mark'; import { agentsMutations, agentsQueries, @@ -37,15 +47,45 @@ import { import { createAgentUtils } from '@/features/agents/lib/create-agent-utils'; import { aiProviderQueries } from '@/features/platform-admin/hooks/ai-provider-hooks'; import { projectCollectionUtils } from '@/features/projects'; +import { useIsPlatformAdmin } from '@/hooks/authorization-hooks'; import { api } from '@/lib/api'; import { cn } from '@/lib/utils'; +import { + showsAgentList, + showsFirstRun, + showsNoMatchNotice, +} from './lib/agents-list-state'; + const SUGGESTIONS = [ 'Triage support tickets', 'Research a company', 'Enrich a lead', ]; +const TEMPLATE_STARTERS: TemplateStarter[] = [ + { + label: 'Research analyst', + dot: '#0D9488', + prompt: 'Research a company and send me a cited brief on it', + }, + { + label: 'Support triage', + dot: '#D97706', + prompt: 'Read a support ticket, tag its severity, and route it to a team', + }, + { + label: 'Lead enrichment', + dot: '#2563EB', + prompt: 'Enrich a new lead with company details and write the first email', + }, + { + label: 'SEO writer', + dot: '#E11D48', + prompt: 'Research keywords for a topic and draft a post that targets them', + }, +]; + const SORT_LABELS = { updated: 'Recently updated', created: 'Recently created', @@ -80,12 +120,12 @@ const AgentsPageContent = () => { const [layout, setLayout] = useState<'grid' | 'list'>('grid'); const [sort, setSort] = useState('updated'); const [prompt, setPrompt] = useState(''); - const [creating, setCreating] = useState(false); const navigate = useNavigate(); const { project } = projectCollectionUtils.useCurrentProject(); const { data: allProjects } = projectCollectionUtils.useAll(); const agentsAvailable = useAgentsAvailable(); - const { data, isLoading } = agentsQueries.useAgents({ + const isPlatformAdmin = useIsPlatformAdmin(); + const { data, isLoading, isSuccess } = agentsQueries.useAgents({ enabled: agentsAvailable, }); @@ -104,14 +144,18 @@ const AgentsPageContent = () => { const createAgent = agentsMutations.useCreateAgent({ onSuccess: (agent) => navigate(`/projects/${agent.projectId}/agents/${agent.id}`), + onError: () => undefined, }); const { data: chatProvider, isLoading: isLoadingProvider, isError: providerLookupFailed, } = aiProviderQueries.useChatProvider(); + const { data: projectProviders } = aiProviderQueries.useProjectAiProviders(); const needsProvider = !isLoadingProvider && !providerLookupFailed && chatProvider === undefined; + const chatIsOffOnEveryProvider = + needsProvider && (projectProviders?.length ?? 0) > 0; const isBuilding = draftAgent.isPending || createAgent.isPending; const buildError = draftAgent.error ?? createAgent.error ?? null; @@ -135,35 +179,123 @@ const AgentsPageContent = () => { ); }; + const createBlankAgent = () => { + if (createAgent.isPending) { + return; + } + createAgent.mutate( + createAgentUtils.buildCreateRequest({ + draft: { + displayName: t('New agent'), + description: '', + icon: AgentIcon.BOT, + color: ColorName.PURPLE, + instructions: '', + }, + projectId: project.id, + }), + ); + }; + const projectById = useMemo( () => new Map((allProjects ?? []).map((entry) => [entry.id, entry])), [allProjects], ); + const firstRun = showsFirstRun({ + listLoaded: isSuccess, + hasAnyAgents: (data?.data.length ?? 0) > 0, + search, + }); + return ( -
-
-

+
+
+ {firstRun && ( + <> +
+ + + )} +

{isBuilding ? t('Building your agent') + : chatIsOffOnEveryProvider + ? t('No provider is turned on for chat') + : needsProvider + ? t('Agents need an AI provider') + : firstRun + ? t('Create your first agent') : t('What should your agent do?')}

-

- {needsProvider - ? t('Connect an AI provider and I can start building agents.') +

+ {chatIsOffOnEveryProvider + ? t( + 'Your project has a provider, but writing an agent for you needs one turned on for chat.', + ) + : needsProvider + ? t('Add a provider once, then I can build agents from a sentence.') : isBuilding ? t('Picking the tools and writing its instructions') + : firstRun + ? t( + 'Your most reliable teammate for getting work done, powered by your tools and guided by your words.', + ) : t( - "Describe what you need. I'll pick the tools and set up the steps.", + "An agent is an assistant with instructions and tools. Describe the job and I'll write both.", )}

- {needsProvider && ( + {needsProvider && + (isPlatformAdmin ? ( + + ) : ( +

+ {chatIsOffOnEveryProvider + ? t('Ask your platform admin to turn on a provider for chat.') + : t('Ask your platform admin to connect an AI provider.')} +

+ ))} + {chatIsOffOnEveryProvider && ( )}
{ 'mt-4 flex min-h-14 w-full max-w-[680px] items-end gap-3.5 rounded-[28px] border bg-muted ps-5 pe-2 py-2 transition-colors', isBuilding ? 'border-primary/40' : 'border-border', needsProvider && 'hidden', + firstRun && + 'relative mt-6 max-w-[632px] flex-col items-stretch gap-4 rounded-xl bg-background px-[18px] pb-[14px] pt-[18px] shadow-[0_2px_12px_rgba(0,0,0,0.06)]', )} >