-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add triggers ids support ENG-2903 #1038
Closed
Closed
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
df7aba9
feat: add fetch by trigger ids
himanshu-dixit 1786e62
feat: add invariant
himanshu-dixit 7027ecc
feat: prettier
himanshu-dixit 1dc542a
feat: remove invariant
himanshu-dixit c382661
feat: trigger
himanshu-dixit 103dea6
feat: trigger spec
himanshu-dixit 06fd71d
feat: ENG-2910
himanshu-dixit 98f92c2
Merge branch 'master' into ft-add-triggers-ids-support
himanshu-dixit 6866640
Merge branch 'master' of github.com:ComposioHQ/composio into ft-add-t…
himanshu-dixit 360b0bb
feat: update trigger
himanshu-dixit 6e5f8ec
Merge branch 'master' into ft-add-triggers-ids-support
himanshu-dixit 073a137
Merge branch 'master' into ft-add-triggers-ids-support
himanshu-dixit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,25 @@ import logger from "../../utils/logger"; | |
import { BackendClient } from "./backendClient"; | ||
|
||
import apiClient from "../client/client"; | ||
|
||
import z from "zod"; | ||
import { CEG } from "../utils/error"; | ||
import { ListTriggersData } from "../client"; | ||
import { TELEMETRY_LOGGER } from "../utils/telemetry"; | ||
import { TELEMETRY_EVENTS } from "../utils/telemetry/events"; | ||
import { SDK_ERROR_CODES } from "../utils/errors/src/constants"; | ||
|
||
type RequiredQuery = ListTriggersData["query"]; | ||
|
||
const ZTriggerQuery = z.object({ | ||
triggerIds: z.array(z.string()).optional(), | ||
appNames: z.array(z.string()).optional(), | ||
connectedAccountsIds: z.array(z.string()).optional(), | ||
integrationIds: z.array(z.string()).optional(), | ||
showEnabledOnly: z.boolean().optional(), | ||
}); | ||
|
||
type TTriggerQuery = z.infer<typeof ZTriggerQuery>; | ||
|
||
export class Triggers { | ||
trigger_to_client_event = "trigger_to_client"; | ||
|
||
|
@@ -29,18 +40,32 @@ export class Triggers { | |
* @returns {CancelablePromise<ListTriggersResponse>} A promise that resolves to the list of all triggers. | ||
* @throws {ApiError} If the request fails. | ||
*/ | ||
async list(data: RequiredQuery = {}) { | ||
async list(data: TTriggerQuery = {}) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The JSDoc comment for the /**
* Retrieves a list of triggers based on provided filters.
* @param {TTriggerQuery} data Query parameters for filtering triggers
* @param {string[]} [data.triggerIds] - Filter by specific trigger IDs
* @param {string[]} [data.appNames] - Filter by app names
* @param {string[]} [data.connectedAccountsIds] - Filter by connected account IDs
* @param {string[]} [data.integrationIds] - Filter by integration IDs
* @param {boolean} [data.showEnabledOnly] - Show only enabled triggers
* @throws {CustomError} When no valid filter parameters are provided
* @returns {Promise<Array>} List of matching triggers
*/ |
||
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, { | ||
method: "list", | ||
file: this.fileName, | ||
params: { data }, | ||
}); | ||
|
||
try { | ||
const { | ||
appNames, | ||
triggerIds, | ||
connectedAccountsIds, | ||
integrationIds, | ||
showEnabledOnly, | ||
} = ZTriggerQuery.parse(data); | ||
|
||
const { data: response } = await apiClient.triggers.listTriggers({ | ||
query: { | ||
appNames: data?.appNames, | ||
appNames: appNames?.join(","), | ||
triggerIds: triggerIds?.join(","), | ||
connectedAccountIds: connectedAccountsIds?.join(","), | ||
integrationIds: integrationIds?.join(","), | ||
showEnabledOnly: showEnabledOnly, | ||
}, | ||
}); | ||
|
||
return response || []; | ||
} catch (error) { | ||
throw CEG.handleAllError(error); | ||
|
@@ -162,9 +187,28 @@ export class Triggers { | |
params: { filters }, | ||
}); | ||
if (!fn) throw new Error("Function is required for trigger subscription"); | ||
//@ts-ignore | ||
const clientId = await this.backendClient.getClientId(); | ||
//@ts-ignore | ||
|
||
const availableTriggers = await this.list({ | ||
appNames: filters.appName ? [filters.appName] : undefined, | ||
triggerIds: filters.triggerId ? [filters.triggerId] : undefined, | ||
connectedAccountsIds: filters.connectionId | ||
? [filters.connectionId] | ||
: undefined, | ||
integrationIds: filters.integrationId | ||
? [filters.integrationId] | ||
: undefined, | ||
}); | ||
|
||
if (availableTriggers.length === 0) { | ||
throw CEG.getCustomError(SDK_ERROR_CODES.COMMON.INVALID_PARAMS_PASSED, { | ||
message: "No triggers match the specified filters", | ||
description: "The provided filters did not return any triggers.", | ||
possibleFix: | ||
"Verify the filters and ensure a trigger is set up with the specified criteria.", | ||
}); | ||
} | ||
|
||
await PusherUtils.getPusherClient( | ||
this.backendClient.baseUrl, | ||
this.backendClient.apiKey | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in
connectedAccountsIds
. It should beconnectedAccountIds
to match the expected query parameter in the API call.