MCPcopy Index your code
hub / github.com/simstudioai/sim / resolveAccessToken

Function resolveAccessToken

apps/sim/lib/webhooks/providers/monday.ts:28–53  ·  view source on GitHub ↗

* Resolves an OAuth access token from the webhook's credential configuration. * Follows the Airtable pattern: credentialId → getCredentialOwner → refreshAccessTokenIfNeeded.

(
  config: Record<string, unknown>,
  userId: string,
  requestId: string
)

Source from the content-addressed store, hash-verified

26 * Follows the Airtable pattern: credentialId → getCredentialOwner → refreshAccessTokenIfNeeded.
27 */
28async function resolveAccessToken(
29 config: Record<string, unknown>,
30 userId: string,
31 requestId: string
32): Promise<string> {
33 const credentialId = config.credentialId as string | undefined
34
35 if (credentialId) {
36 const credentialOwner = await getCredentialOwner(credentialId, requestId)
37 if (credentialOwner) {
38 const token = await refreshAccessTokenIfNeeded(
39 credentialOwner.accountId,
40 credentialOwner.userId,
41 requestId
42 )
43 if (token) return token
44 }
45 }
46
47 const fallbackToken = await getOAuthToken(userId, 'monday')
48 if (fallbackToken) return fallbackToken
49
50 throw new Error(
51 'Monday.com account connection required. Please connect your Monday.com account in the trigger configuration and try again.'
52 )
53}
54
55export const mondayHandler: WebhookProviderHandler = {
56 /**

Callers 1

createSubscriptionFunction · 0.70

Calls 3

getCredentialOwnerFunction · 0.90
getOAuthTokenFunction · 0.90

Tested by

no test coverage detected