From 5e856d32fde22f7a94b088d8be588a00dfbd1cc5 Mon Sep 17 00:00:00 2001 From: d-klotz Date: Tue, 29 Sep 2026 19:10:36 -0300 Subject: [PATCH 01/12] feat(hubspot): declare the rate-limit policy HubSpot limits each account that installs a marketplace OAuth app to 110 requests per 10 seconds, and answers a throttled call with a 429 whose body names the limit in `policyName`. The Requester met every such 429 with its fixed 1, 3, 10, 30, 60 and 180 second ladder, whatever the response said. Declare `static rateLimit` so the Requester can use what the response says: - A burst 429 (`TEN_SECONDLY_ROLLING`) returns a reason-only hint. A real `Retry-After` then wins, and the 10 second burst window is the fallback. - A `DAILY` 429 returns a one hour probe (`source: 'static'`). HubSpot resets the daily limit at midnight in the account's time zone, which the module does not know, so no UTC reset time is computed. One hour is over the in-process budget, so the Requester throws a `RateLimitError` with `reason: 'daily'` and `retryAt` and does not sleep. - Any other status is not a limit. - `userHints.daily.links` points at the API usage guidelines. `maxConcurrency` (10) is a pacing figure that HubSpot does not document. It is declared for the pacing phase and nothing reads it yet. The tests use recorded-style 429 responses and a stubbed fetch. They need a `@friggframework/core` that exports `RateLimitError` (friggframework/frigg#656). The dependency range is unchanged until the release that ships it is known. Refs ADR-049. Co-Authored-By: Claude Sonnet 5.5 Co-Authored-By: Claude Opus 5.5 --- packages/v1-ready/hubspot/README.md | 20 ++ packages/v1-ready/hubspot/api.js | 31 +++ .../v1-ready/hubspot/tests/rateLimit.test.js | 231 ++++++++++++++++++ 3 files changed, 282 insertions(+) create mode 100644 packages/v1-ready/hubspot/tests/rateLimit.test.js diff --git a/packages/v1-ready/hubspot/README.md b/packages/v1-ready/hubspot/README.md index c2ad5b2e..3bec4dcc 100644 --- a/packages/v1-ready/hubspot/README.md +++ b/packages/v1-ready/hubspot/README.md @@ -113,3 +113,23 @@ colliding. - **`HUBSPOT_WEBHOOK`** — queue event (worker, hydrated integration): default no-op; override via `binding.handlers.HUBSPOT_WEBHOOK` to run your per-event logic with the correct per-account context. + +## Rate limits + +`Api.rateLimit` tells the Frigg Requester how HubSpot limits calls. The numbers come +from the [API usage guidelines and limits](https://developers.hubspot.com/docs/developer-tooling/platform/usage-guidelines). +A `@friggframework/core` release without rate-limit awareness ignores the declaration. + +- **Burst:** each account that installs a marketplace OAuth app is limited to 110 + requests every 10 seconds. A throttled call returns `429` with `policyName` + `TEN_SECONDLY_ROLLING`. The Requester waits for `Retry-After` when the response has + one, and for the 10 second window when it has none. +- **Daily:** a `429` with `policyName` `DAILY`. HubSpot resets the daily limit at + midnight in the account's time zone, which the module does not know, so it does not + compute a reset time. It reports a one hour probe interval: the Requester throws a + `RateLimitError` with `reason: 'daily'` and a `retryAt` one hour ahead. It does not + sleep for an hour in process. +- **Any other status** is not a limit and keeps its normal handling. + +HubSpot documents no `Retry-After` or reset header for these responses, and the search +endpoints send no `X-HubSpot-RateLimit-*` headers at all. diff --git a/packages/v1-ready/hubspot/api.js b/packages/v1-ready/hubspot/api.js index 92768119..9eafa7f1 100644 --- a/packages/v1-ready/hubspot/api.js +++ b/packages/v1-ready/hubspot/api.js @@ -1,6 +1,37 @@ const {OAuth2Requester, get} = require('@friggframework/core'); +const DAILY_PROBE_INTERVAL_MS = 3_600_000; + class Api extends OAuth2Requester { + static rateLimit = { + scope: 'entity', + windows: [{ name: 'burst', limit: 110, perMs: 10_000 }], + maxConcurrency: 10, + parsers: ['retryAfter', 'resetHeaders'], + classify({ status, body }) { + if (status !== 429) return null; + if (body?.policyName === 'DAILY') { + return { + reason: 'daily', + policy: 'DAILY', + waitMs: DAILY_PROBE_INTERVAL_MS, + source: 'static', + }; + } + return { reason: 'burst', policy: body?.policyName }; + }, + userHints: { + daily: { + links: [ + { + label: 'API usage guidelines and limits', + url: 'https://developers.hubspot.com/docs/developer-tooling/platform/usage-guidelines', + }, + ], + }, + }, + }; + constructor(params) { super(params); // The majority of the properties for OAuth are default loaded by OAuth2Requester. diff --git a/packages/v1-ready/hubspot/tests/rateLimit.test.js b/packages/v1-ready/hubspot/tests/rateLimit.test.js new file mode 100644 index 00000000..4c24d361 --- /dev/null +++ b/packages/v1-ready/hubspot/tests/rateLimit.test.js @@ -0,0 +1,231 @@ +const { FetchError, RateLimitError } = require('@friggframework/core'); +const { Api } = require('../api'); + +const ONE_HOUR_MS = 3_600_000; + +const burstLimitBody = { + status: 'error', + message: 'You have reached your ten_secondly_rolling limit.', + errorType: 'RATE_LIMIT', + correlationId: '00000000-0000-4000-8000-000000000000', + policyName: 'TEN_SECONDLY_ROLLING', +}; + +const dailyLimitBody = { + status: 'error', + message: 'You have reached your daily limit.', + errorType: 'RATE_LIMIT', + correlationId: '00000000-0000-4000-8000-000000000000', + policyName: 'DAILY', +}; + +const burstHeaders = { + 'X-HubSpot-RateLimit-Max': '110', + 'X-HubSpot-RateLimit-Remaining': '0', + 'X-HubSpot-RateLimit-Interval-Milliseconds': '10000', +}; + +function throttledFetch(responses) { + const queue = [...responses]; + return jest.fn(async () => { + const next = queue.shift(); + if (!next) throw new Error('unexpected fetch call'); + const body = next.body ?? {}; + return { + status: next.status, + bodyUsed: false, + headers: new Map( + Object.entries({ + 'Content-Type': next.contentType ?? 'application/json', + ...next.headers, + }) + ), + json: async () => body, + text: jest.fn(async () => next.text ?? JSON.stringify(body)), + }; + }); +} + +const limited = (body, headers) => ({ status: 429, body, headers }); +const ok = { status: 200, body: { results: [] } }; + +describe('HubSpot rate limits', () => { + let delays; + + beforeEach(() => { + delays = []; + const realSetTimeout = global.setTimeout; + jest.spyOn(global, 'setTimeout').mockImplementation( + (fn, delay, ...args) => { + delays.push(delay); + return realSetTimeout(fn, 0, ...args); + } + ); + jest.spyOn(Math, 'random').mockReturnValue(0); + }); + + afterEach(() => jest.restoreAllMocks()); + + const makeApi = (fetch, ApiClass = Api) => + new ApiClass({ + fetch, + requestTimeoutMs: 0, + delegate: { name: 'hubspot', entity: { id: 7 } }, + }); + + describe('a burst 429', () => { + it('waits as long as Retry-After says, then retries', async () => { + const fetch = throttledFetch([ + limited(burstLimitBody, { + ...burstHeaders, + 'Retry-After': '2', + }), + ok, + ]); + + const result = await makeApi(fetch).listCompanies(); + + expect(result).toEqual({ results: [] }); + expect(delays).toEqual([2_000]); + expect(fetch).toHaveBeenCalledTimes(2); + }); + + it('waits the 10 second burst window when the response has no Retry-After', async () => { + const fetch = throttledFetch([ + limited(burstLimitBody, burstHeaders), + ok, + ]); + + const result = await makeApi(fetch).listCompanies(); + + expect(result).toEqual({ results: [] }); + expect(delays).toEqual([10_000]); + expect(fetch).toHaveBeenCalledTimes(2); + }); + + it('keeps the burst reason and the policy name when a long Retry-After makes it throw', async () => { + const fetch = throttledFetch([ + limited(burstLimitBody, { 'Retry-After': '400' }), + ok, + ]); + + const error = await makeApi(fetch) + .listCompanies() + .catch((e) => e); + + expect(error).toBeInstanceOf(RateLimitError); + expect(error).toMatchObject({ + reason: 'burst', + policy: 'TEN_SECONDLY_ROLLING', + source: 'header', + waitMs: 400_000, + }); + expect(fetch).toHaveBeenCalledTimes(1); + }); + + it('waits the burst window when the body is not JSON', async () => { + const fetch = throttledFetch([ + { + status: 429, + contentType: 'text/html', + text: 'Too Many Requests', + }, + ok, + ]); + + await makeApi(fetch).listCompanies(); + + expect(delays).toEqual([10_000]); + }); + }); + + describe('a DAILY 429', () => { + it('throws a RateLimitError that probes again in one hour', async () => { + const fetch = throttledFetch([limited(dailyLimitBody), ok]); + const before = Date.now(); + + const error = await makeApi(fetch) + .listCompanies() + .catch((e) => e); + + expect(error).toBeInstanceOf(RateLimitError); + expect(error).toBeInstanceOf(FetchError); + expect(error).toMatchObject({ + isRateLimited: true, + statusCode: 429, + reason: 'daily', + policy: 'DAILY', + source: 'static', + waitMs: ONE_HOUR_MS, + module: 'hubspot', + scopeKey: 'hubspot:entity:7', + }); + expect(error.retryAt.getTime()).toBeGreaterThanOrEqual( + before + ONE_HOUR_MS + ); + expect(error.retryAt.getTime()).toBeLessThanOrEqual( + Date.now() + ONE_HOUR_MS + ); + expect(fetch).toHaveBeenCalledTimes(1); + expect(delays).toEqual([]); + }); + + it('sleeps the probe interval and retries when the in-process budget allows it', async () => { + class PatientApi extends Api { + static rateLimit = { + ...Api.rateLimit, + maxInProcessWaitMs: ONE_HOUR_MS + 60_000, + }; + } + const fetch = throttledFetch([limited(dailyLimitBody), ok]); + + const result = await makeApi(fetch, PatientApi).listCompanies(); + + expect(result).toEqual({ results: [] }); + expect(delays).toEqual([ONE_HOUR_MS]); + expect(fetch).toHaveBeenCalledTimes(2); + }); + + it('links the daily reason to the HubSpot usage guidelines', () => { + const { links } = Api.rateLimit.userHints.daily; + + expect(links).toEqual([ + { + label: expect.any(String), + url: 'https://developers.hubspot.com/docs/developer-tooling/platform/usage-guidelines', + }, + ]); + }); + }); + + describe('other failures', () => { + it('does not treat a 403 as a limit', async () => { + const fetch = throttledFetch([ + { + status: 403, + body: { status: 'error', category: 'MISSING_SCOPES' }, + }, + ok, + ]); + + const error = await makeApi(fetch) + .listCompanies() + .catch((e) => e); + + expect(error).toBeInstanceOf(FetchError); + expect(error).not.toBeInstanceOf(RateLimitError); + expect(error.statusCode).toBe(403); + expect(fetch).toHaveBeenCalledTimes(1); + expect(delays).toEqual([]); + }); + }); + + it('declares its limits', () => { + expect(Api.rateLimit).toMatchObject({ + scope: 'entity', + windows: [{ name: 'burst', limit: 110, perMs: 10_000 }], + maxConcurrency: 10, + parsers: ['retryAfter', 'resetHeaders'], + }); + }); +}); From 953b606cc679df418d4f2d6c437c219fc075a8e2 Mon Sep 17 00:00:00 2001 From: d-klotz Date: Tue, 29 Sep 2026 19:10:36 -0300 Subject: [PATCH 02/12] feat(salesforce): classify the API request and concurrency limits Salesforce counts the API calls of an org over a rolling 24 hours. An org over its limit gets a 403 whose error code is `REQUEST_LIMIT_EXCEEDED`, and no reset time. The module drives jsforce, not the Requester, and a jsforce error has no `statusCode` (`HttpApiError`: `name` equals `errorCode`), so the Requester never sees it and the queue worker gets an opaque error. `REQUEST_LIMIT_EXCEEDED` is also the error for too many concurrent requests that run 20 seconds or longer, which clears in seconds. Reporting it as a daily limit would put a sync on hold for an hour. - Declare `static rateLimit`: a per-org daily rolling window and a `classify` that recognises `REQUEST_LIMIT_EXCEEDED`. Salesforce documents no field that tells the two limits apart, so `classify` reads the message: one that contains "concurrent" is a concurrency limit with a 30 second wait, and any other message is a daily limit. The message text is not documented, so the default stays daily. With no reset time to read, a daily limit gets a static one hour probe. Both reasons link to the API request limits page. - Add the public `withLimits(call)`. On a failed call it runs `classifyRateLimit` and throws a `RateLimitError`, with the jsforce error kept as `cause`. It rethrows any other error unchanged. The data methods use it. A consumer that calls `api.conn` directly wraps its own calls with `api.withLimits(() => api.conn.query(soql))`, as the README says. - Before it throws, `withLimits` tells the delegate with `_notifyRateLimited`, as the Requester does when it throws a `RateLimitError`, so the integration can record a warning for the user. Core writes that warning only for a limit longer than its in-process cap, so the daily limit gets one and the 30 second concurrency limit does not. A core without that method skips the call. - `module` on the error is `_telemetryModuleLabel()`, the label the Requester puts on its own `RateLimitError`. An API instance has no `name`. `RateLimitError` and `classifyRateLimit` come from `@friggframework/core` (friggframework/frigg#656) and are read at runtime. The dependency range is unchanged. On a core that does not export both yet, `withLimits` rethrows the original jsforce error, so the module can be released before an app upgrades its core. The token and refresh code is untouched, and `conn.limitInfo` is not read yet. Refs ADR-049. Co-Authored-By: Claude Sonnet 5.5 Co-Authored-By: Claude Opus 5.5 --- packages/v1-ready/salesforce/README.md | 18 +- packages/v1-ready/salesforce/api.js | 98 +++++- packages/v1-ready/salesforce/test/api.test.js | 294 ++++++++++++++++++ 3 files changed, 398 insertions(+), 12 deletions(-) diff --git a/packages/v1-ready/salesforce/README.md b/packages/v1-ready/salesforce/README.md index 0cc28d42..efe1e239 100644 --- a/packages/v1-ready/salesforce/README.md +++ b/packages/v1-ready/salesforce/README.md @@ -43,4 +43,20 @@ The integration user needs additional permissions depending on which Salesforce | **Campaigns, CampaignMembers** | Enable the **Marketing User** checkbox on the user record (**Setup → Users → [user] → Edit → Advanced User Details → Marketing User ✓**). This is a feature gate separate from object-level CRUD — even a user with full Edit on Campaigns cannot insert a Campaign without it. | | **Contacts, Accounts, Leads, Opportunities** | Standard API access is sufficient. No additional flags needed beyond the base integration user profile. | -> **Open question — license compatibility:** The Marketing User flag historically consumes a Marketing User feature license. It is currently unconfirmed whether this flag can be assigned to a Salesforce Integration User license (which is stripped-down and cheaper). If your integration creates Campaigns and you plan to use an Integration license, verify this in a Developer org before advising customers — it may require a full Salesforce seat instead. \ No newline at end of file +> **Open question — license compatibility:** The Marketing User flag historically consumes a Marketing User feature license. It is currently unconfirmed whether this flag can be assigned to a Salesforce Integration User license (which is stripped-down and cheaper). If your integration creates Campaigns and you plan to use an Integration license, verify this in a Developer org before advising customers — it may require a full Salesforce seat instead. + +## Rate limits + +Salesforce counts the API calls of an org over a rolling 24 hours ([API request limits and allocations](https://developer.salesforce.com/docs/platform/salesforce-app-limits-cheatsheet/guide/salesforce-app-limits-platform-api.html)). An org over its limit gets a `403` with the error code `REQUEST_LIMIT_EXCEEDED`. Salesforce documents no reset time for it. + +`Api.rateLimit` declares that limit for the Frigg Requester. The module drives jsforce, not the Requester, so `api.withLimits(call)` applies the declaration to jsforce calls. It awaits `call()`. When the call fails with `REQUEST_LIMIT_EXCEEDED`, it throws a `RateLimitError` with `reason: 'daily'` and a `retryAt` one hour ahead, because there is no reset time to wait for and the module probes every hour. `cause` keeps the jsforce error. Any other error is rethrown unchanged. + +The data methods (`create`, `update`, `upsert`, `list`, `find`, `get`, `delete`, `getGlobalMetadata`) use `withLimits` already. `api.conn` is a plain jsforce connection, so a consumer that calls it directly wraps its own calls: + +```javascript +const result = await api.withLimits(() => api.conn.query(soql)); +``` + +Salesforce also returns `REQUEST_LIMIT_EXCEEDED` when too many requests that run for 20 seconds or longer are in flight at once (25 in a production org, 5 in a Developer Edition org). That limit clears in seconds, not in a day. Salesforce documents no field that tells the two apart, so `withLimits` reads the error message: a message that contains "concurrent" (Salesforce sends `ConcurrentPerOrgLongTxn` for it) is reported as `reason: 'concurrency'` with a `retryAt` 30 seconds ahead. Any other message stays a daily limit. + +When it throws a `RateLimitError` for a limit that lasts longer than the in-process cap (5 minutes by default: the daily limit, not the 30 second concurrency limit), `withLimits` also has the integration record one rate-limit warning for its users, as the Frigg Requester does. On a core that cannot record the warning, it only throws. A core that does not export `RateLimitError` and `classifyRateLimit` (older than the release that added them) makes `withLimits` rethrow the original jsforce error. diff --git a/packages/v1-ready/salesforce/api.js b/packages/v1-ready/salesforce/api.js index fdfb64e8..ec4f33f9 100644 --- a/packages/v1-ready/salesforce/api.js +++ b/packages/v1-ready/salesforce/api.js @@ -1,7 +1,18 @@ -const { get, OAuth2Requester } = require('@friggframework/core'); +const { + get, + OAuth2Requester, + RateLimitError, + classifyRateLimit, +} = require('@friggframework/core'); const jsforce = require('jsforce'); const crypto = require('crypto'); +const STATIC_WAIT_MS = { daily: 3_600_000, concurrency: 30_000 }; +const LIMITS_LINK = { + label: 'API request limits and allocations', + url: 'https://developer.salesforce.com/docs/platform/salesforce-app-limits-cheatsheet/guide/salesforce-app-limits-platform-api.html', +}; + class Api extends OAuth2Requester { // URL-unreserved and outside the base64url alphabet. static STATE_VERIFIER_DELIMITER = '~'; @@ -15,6 +26,22 @@ class Api extends OAuth2Requester { 'inactive_org', ]); + static rateLimit = { + scope: 'entity', + windows: [{ name: 'daily', rollingMs: 86_400_000 }], + classify({ body }) { + if (body?.errorCode !== 'REQUEST_LIMIT_EXCEEDED') return null; + const reason = /concurrent/i.test(body.message ?? '') + ? 'concurrency' + : 'daily'; + return { reason, waitMs: STATIC_WAIT_MS[reason], source: 'static' }; + }, + userHints: { + daily: { links: [LIMITS_LINK] }, + concurrency: { links: [LIMITS_LINK] }, + }, + }; + constructor(params) { super(params); this.jsforce = jsforce; @@ -156,23 +183,66 @@ class Api extends OAuth2Requester { return this.get('User', this.conn.userInfo.id); } + async withLimits(call) { + try { + return await call(); + } catch (err) { + const rateLimitError = this._rateLimitErrorFor(err); + if (!rateLimitError) throw err; + await this._notifyRateLimited?.(rateLimitError); + throw rateLimitError; + } + } + + _rateLimitErrorFor(err) { + if ( + typeof classifyRateLimit !== 'function' || + typeof RateLimitError !== 'function' + ) { + return null; + } + const hint = classifyRateLimit(this.constructor.rateLimit, { + status: err?.statusCode, + headers: {}, + body: { + errorCode: err?.errorCode ?? err?.name, + message: err?.message, + }, + }); + if (!hint) return null; + return new RateLimitError({ + hint, + module: this._telemetryModuleLabel(), + resource: this.conn.instanceUrl, + cause: err, + }); + } + async create(object, data) { - const response = await this.conn.sobject(object).create(data); + const response = await this.withLimits(() => + this.conn.sobject(object).create(data) + ); return response; } async update(object, data) { - const response = await this.conn.sobject(object).update(data); + const response = await this.withLimits(() => + this.conn.sobject(object).update(data) + ); return response; } async upsert(object, data) { - const response = await this.conn.sobject(object).upsert(data); + const response = await this.withLimits(() => + this.conn.sobject(object).upsert(data) + ); return response; } async list(object, ids = {}) { - const response = await this.conn.sobject(object).retrieve(ids); + const response = await this.withLimits(() => + this.conn.sobject(object).retrieve(ids) + ); return response; } @@ -182,24 +252,30 @@ class Api extends OAuth2Requester { returnFields = { '*': 1 }, options = {} ) { - const response = await this.conn - .sobject(object) - .find(findFilter, returnFields, options); + const response = await this.withLimits(() => + this.conn.sobject(object).find(findFilter, returnFields, options) + ); return response; } async getGlobalMetadata() { - const response = await this.conn.describeGlobal(); + const response = await this.withLimits(() => + this.conn.describeGlobal() + ); return response; } async get(object, id) { - const response = await this.conn.sobject(object).retrieve(id); + const response = await this.withLimits(() => + this.conn.sobject(object).retrieve(id) + ); return response; } async delete(object, data) { - const response = await this.conn.sobject(object).del(data); + const response = await this.withLimits(() => + this.conn.sobject(object).del(data) + ); return response; } diff --git a/packages/v1-ready/salesforce/test/api.test.js b/packages/v1-ready/salesforce/test/api.test.js index eedccd30..59954ccd 100644 --- a/packages/v1-ready/salesforce/test/api.test.js +++ b/packages/v1-ready/salesforce/test/api.test.js @@ -26,6 +26,7 @@ jest.mock('jsforce', () => { }; }); +const { RateLimitError } = require('@friggframework/core'); const { Api } = require('../api'); const baseParams = { @@ -561,3 +562,296 @@ describe('Salesforce Api token refresh', () => { expect(callback).toHaveBeenCalledWith(expect.any(Error)); }); }); + +describe('Salesforce Api rate limits', () => { + const ONE_HOUR_MS = 3_600_000; + + const jsforceError = (errorCode, message) => + Object.assign(new Error(message), { name: errorCode, errorCode }); + const limitError = () => + jsforceError('REQUEST_LIMIT_EXCEEDED', 'TotalRequests Limit exceeded.'); + const invalidField = () => + jsforceError('INVALID_FIELD', "No such column 'Nope__c' on Contact"); + const rejectionOf = (promise) => promise.catch((error) => error); + + const dataMethods = [ + ['create', (api) => api.create('Contact', { LastName: 'Doe' })], + [ + 'update', + (api) => api.update('Contact', { Id: '003', LastName: 'D' }), + ], + ['upsert', (api) => api.upsert('Contact', { LastName: 'Doe' })], + ['list', (api) => api.list('Contact', ['003'])], + ['find', (api) => api.find('Contact', { LastName: 'Doe' })], + ['getGlobalMetadata', (api) => api.getGlobalMetadata()], + ['get', (api) => api.get('Contact', '003')], + ['delete', (api) => api.delete('Contact', '003')], + ]; + + let api; + let sobject; + + beforeEach(() => { + jest.clearAllMocks(); + api = new Api({ + ...baseParams, + delegate: { ...baseParams.delegate, name: 'salesforce' }, + }); + sobject = { + create: jest.fn(), + update: jest.fn(), + upsert: jest.fn(), + retrieve: jest.fn(), + find: jest.fn(), + del: jest.fn(), + }; + api.conn.sobject = jest.fn(() => sobject); + api.conn.describeGlobal = jest.fn(); + }); + + afterEach(() => { + jest.restoreAllMocks(); + jest.dontMock('@friggframework/core'); + delete api.conn.sobject; + delete api.conn.describeGlobal; + }); + + describe('withLimits', () => { + const now = Date.parse('2026-09-28T12:00:00Z'); + + beforeEach(() => { + jest.spyOn(Date, 'now').mockReturnValue(now); + }); + + it('returns what the call returns', async () => { + const result = await api.withLimits(async () => ({ totalSize: 1 })); + + expect(result).toEqual({ totalSize: 1 }); + }); + + it('turns REQUEST_LIMIT_EXCEEDED into a RateLimitError for a daily limit', async () => { + const cause = limitError(); + + const error = await rejectionOf( + api.withLimits(() => Promise.reject(cause)) + ); + + expect(error).toBeInstanceOf(RateLimitError); + expect(error).toMatchObject({ + isRateLimited: true, + reason: 'daily', + source: 'static', + waitMs: ONE_HOUR_MS, + module: 'salesforce', + }); + expect(error.cause).toBe(cause); + expect(error.retryAt).toEqual(new Date(now + ONE_HOUR_MS)); + }); + + it('names the org instance in the error', async () => { + const error = await rejectionOf( + api.withLimits(() => Promise.reject(limitError())) + ); + + expect(error.url).toBe(api.conn.instanceUrl); + }); + + it.each([ + ['INVALID_FIELD', invalidField], + [ + 'INSUFFICIENT_ACCESS', + () => jsforceError('INSUFFICIENT_ACCESS', 'No access'), + ], + ['no error code', () => new Error('socket hang up')], + ])('rethrows %s unchanged', async (_label, build) => { + const original = build(); + + const error = await rejectionOf( + api.withLimits(() => Promise.reject(original)) + ); + + expect(error).toBe(original); + }); + + it('tells the delegate about the limit before it throws', async () => { + const notify = jest.fn().mockResolvedValue(undefined); + api._notifyRateLimited = notify; + + const error = await rejectionOf( + api.withLimits(() => Promise.reject(limitError())) + ); + + expect(error).toBeInstanceOf(RateLimitError); + expect(notify).toHaveBeenCalledTimes(1); + expect(notify).toHaveBeenCalledWith(error); + }); + + it('does not tell the delegate about an error that is not a limit', async () => { + const notify = jest.fn().mockResolvedValue(undefined); + api._notifyRateLimited = notify; + + await rejectionOf( + api.withLimits(() => Promise.reject(invalidField())) + ); + + expect(notify).not.toHaveBeenCalled(); + }); + + it('still throws the RateLimitError on a core that cannot notify', async () => { + api._notifyRateLimited = undefined; + + const error = await rejectionOf( + api.withLimits(() => Promise.reject(limitError())) + ); + + expect(error).toBeInstanceOf(RateLimitError); + }); + + it.each([ + 'ConcurrentPerOrgLongTxn Concurrent API Request Limit exceeded', + 'Concurrent requests limit exceeded.', + ])( + 'reports %j as a concurrency limit, which clears in seconds', + async (message) => { + const error = await rejectionOf( + api.withLimits(() => + Promise.reject( + jsforceError('REQUEST_LIMIT_EXCEEDED', message) + ) + ) + ); + + expect(error).toMatchObject({ + reason: 'concurrency', + source: 'static', + waitMs: 30_000, + }); + expect(error.retryAt).toEqual(new Date(now + 30_000)); + } + ); + + it('reports any other REQUEST_LIMIT_EXCEEDED message as a daily limit', async () => { + const error = await rejectionOf( + api.withLimits(() => + Promise.reject( + jsforceError('REQUEST_LIMIT_EXCEEDED', 'Something new') + ) + ) + ); + + expect(error).toMatchObject({ + reason: 'daily', + waitMs: ONE_HOUR_MS, + }); + }); + + it('links the concurrency reason to the Salesforce API request limits too', () => { + expect(Api.rateLimit.userHints.concurrency.links).toEqual( + Api.rateLimit.userHints.daily.links + ); + }); + + it('rethrows the original error on a core without the rate-limit exports', async () => { + let OldCoreApi; + jest.isolateModules(() => { + jest.doMock('@friggframework/core', () => { + const { + RateLimitError: _error, + classifyRateLimit: _classify, + ...rest + } = jest.requireActual('@friggframework/core'); + return rest; + }); + OldCoreApi = require('../api').Api; + }); + const oldApi = new OldCoreApi({ + ...baseParams, + delegate: { ...baseParams.delegate, name: 'salesforce' }, + }); + const cause = limitError(); + + const error = await rejectionOf( + oldApi.withLimits(() => Promise.reject(cause)) + ); + + expect(error).toBe(cause); + }); + + it('links the daily reason to the Salesforce API request limits', () => { + expect(Api.rateLimit.userHints.daily.links).toEqual([ + { + label: expect.any(String), + url: 'https://developer.salesforce.com/docs/platform/salesforce-app-limits-cheatsheet/guide/salesforce-app-limits-platform-api.html', + }, + ]); + }); + }); + + describe('the data methods', () => { + it.each(dataMethods)( + '%s raises a RateLimitError when Salesforce reports REQUEST_LIMIT_EXCEEDED', + async (_name, invoke) => { + const cause = limitError(); + Object.values(sobject).forEach((fn) => + fn.mockRejectedValue(cause) + ); + api.conn.describeGlobal.mockRejectedValue(cause); + + const error = await rejectionOf(invoke(api)); + + expect(error).toBeInstanceOf(RateLimitError); + expect(error.cause).toBe(cause); + } + ); + + it.each(dataMethods)( + '%s rethrows any other Salesforce error unchanged', + async (_name, invoke) => { + const original = invalidField(); + Object.values(sobject).forEach((fn) => + fn.mockRejectedValue(original) + ); + api.conn.describeGlobal.mockRejectedValue(original); + + const error = await rejectionOf(invoke(api)); + + expect(error).toBe(original); + } + ); + + it('create passes its arguments to jsforce and returns the result', async () => { + sobject.create.mockResolvedValue({ id: '003', success: true }); + + const result = await api.create('Contact', { LastName: 'Doe' }); + + expect(api.conn.sobject).toHaveBeenCalledWith('Contact'); + expect(sobject.create).toHaveBeenCalledWith({ LastName: 'Doe' }); + expect(result).toEqual({ id: '003', success: true }); + }); + + it('find passes its arguments to jsforce and returns the result', async () => { + sobject.find.mockResolvedValue([{ Id: '003' }]); + + const result = await api.find( + 'Contact', + { LastName: 'Doe' }, + { Id: 1 }, + { limit: 5 } + ); + + expect(sobject.find).toHaveBeenCalledWith( + { LastName: 'Doe' }, + { Id: 1 }, + { limit: 5 } + ); + expect(result).toEqual([{ Id: '003' }]); + }); + }); + + it('declares a rolling 24 hour limit per org', () => { + expect(Api.rateLimit).toMatchObject({ + scope: 'entity', + windows: [{ name: 'daily', rollingMs: 86_400_000 }], + }); + }); +}); From 1b8f32580af5ed7b34452ceb1cb60dfdbb18e429 Mon Sep 17 00:00:00 2001 From: d-klotz Date: Tue, 29 Sep 2026 19:10:36 -0300 Subject: [PATCH 03/12] feat(pipedrive): declare the rate-limit policy Pipedrive limits an OAuth app per token over a rolling 2 second window and sends `x-ratelimit-reset` with the throttled response. A recorded 429 also carries `Retry-After`. The Requester met every such 429 with its fixed 1, 3, 10, 30, 60 and 180 second ladder. Declare `static rateLimit`: - `scope: 'entity'` and a burst window of 80 requests per 2 seconds. That is the lowest OAuth allowance in the docs (Lite 80, Growth 160, Premium 400, Ultimate 480). Pipedrive reports the real figure in `x-ratelimit-limit`. - `parsers: ['retryAfter', 'resetHeaders']`, the two header families Pipedrive sends. `x-ratelimit-reset` is a wait in seconds. - No `classify`. A spent daily token budget answers with a 429 and no documented wait time. Unless the response carries one of those headers, it keeps the fixed ladder and then the redelivery it has today. Add `RateLimitPolicy` and the types it uses to the module's `frigg-core.d.ts` shim, copied from the core types (friggframework/frigg#656). The subclass declares its own static, so the shim's `OAuth2Requester` needs no change. Core reads `x-ratelimit-reset` by default, so the wait tests characterise the behaviour with recorded headers, and the declaration test pins the numbers. The tests need a `@friggframework/core` with rate-limit awareness. The dependency range is unchanged until the release that ships it is known. Refs ADR-049. Co-Authored-By: Claude Sonnet 5.5 Co-Authored-By: Claude Opus 5.5 --- packages/v1-ready/pipedrive/README.md | 8 ++ packages/v1-ready/pipedrive/frigg-core.d.ts | 48 ++++++++ packages/v1-ready/pipedrive/src/api.ts | 13 +- .../v1-ready/pipedrive/test/rateLimit.test.ts | 111 ++++++++++++++++++ 4 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 packages/v1-ready/pipedrive/test/rateLimit.test.ts diff --git a/packages/v1-ready/pipedrive/README.md b/packages/v1-ready/pipedrive/README.md index 6ce9a082..881d2b0a 100644 --- a/packages/v1-ready/pipedrive/README.md +++ b/packages/v1-ready/pipedrive/README.md @@ -3,3 +3,11 @@ This is the API Module for pipedrive that allows the [Frigg](https://friggframework.org) code to talk to the pipedrive API. Read more on the [Frigg documentation site](https://docs.friggframework.org/api-modules/list/pipedrive + +## Rate limits + +`Api.rateLimit` tells the Frigg Requester how Pipedrive limits calls. The numbers come from [Pipedrive's rate limiting guide](https://pipedrive.readme.io/docs/core-api-concepts-rate-limiting). + +- **Burst:** a rolling 2 second window, counted per token. An OAuth app gets 80 requests in the window on the Lite plan, 160 on Growth, 400 on Premium and 480 on Ultimate. The module declares 80, the lowest. Pipedrive reports the real figure in `x-ratelimit-limit`. +- **A throttled call** returns `429`. The Requester waits for `Retry-After` when the response has one, and otherwise for `x-ratelimit-reset` (in seconds), then retries. +- **Daily token budget:** each company has a budget of 30,000 tokens times a plan multiplier times the number of seats. It resets at midnight in Pipedrive's server time zone. When it is spent, every call gets a `429`. Pipedrive documents no wait time for it, so the module declares none. Unless the response carries `Retry-After` or `x-ratelimit-reset`, such a `429` keeps the fixed backoff ladder, and then the queue redelivers the message. diff --git a/packages/v1-ready/pipedrive/frigg-core.d.ts b/packages/v1-ready/pipedrive/frigg-core.d.ts index 013c9f93..f08aaefe 100644 --- a/packages/v1-ready/pipedrive/frigg-core.d.ts +++ b/packages/v1-ready/pipedrive/frigg-core.d.ts @@ -39,6 +39,54 @@ declare module '@friggframework/core' { headers?: Record; } + export type RateLimitScope = + | "credential" + | "entity" + | "app" + | ((requester: OAuth2Requester) => string | number | null | undefined); + + export type RateLimitSignal = { + status?: number; + headers?: { get(name: string): string | null } | object; + body?: unknown; + }; + + export type RateLimitWindow = { + name: string; + limit?: number; + perMs?: number; + rollingMs?: number; + resets?: { at: string; tz: string }; + }; + + export type RateLimitHint = { + retryAt: Date; + waitMs: number; + reason: "burst" | "daily" | "monthly" | "concurrency" | "unknown"; + policy?: string; + remaining?: number; + source: "header" | "body" | "static" | "backoff"; + }; + + export type RateLimitPolicy = { + scope?: RateLimitScope; + windows?: RateLimitWindow[]; + maxConcurrency?: number; + minRetryAfterMs?: number; + maxInProcessWaitMs?: number; + parsers?: Array<"retryAfter" | "resetHeaders" | "ietf">; + classify?(signal: RateLimitSignal): + | (Partial> & { + source?: "header" | "body" | "static"; + }) + | null + | undefined; + userHints?: Record< + string, + { links?: Array<{ label: string; url: string }> } + >; + }; + export class OAuth2Requester { access_token: string | null; refresh_token: string | null; diff --git a/packages/v1-ready/pipedrive/src/api.ts b/packages/v1-ready/pipedrive/src/api.ts index 163b7549..b1c22c81 100644 --- a/packages/v1-ready/pipedrive/src/api.ts +++ b/packages/v1-ready/pipedrive/src/api.ts @@ -1,4 +1,9 @@ -import { get, OAuth2Requester, RequestOptions } from "@friggframework/core"; +import { + get, + OAuth2Requester, + RateLimitPolicy, + RequestOptions, +} from "@friggframework/core"; import { OAuth2RequesterOptions, ActivityParams, @@ -23,6 +28,12 @@ import { } from "./types"; export class Api extends OAuth2Requester { + static rateLimit: RateLimitPolicy = { + scope: "entity", + windows: [{ name: "burst", limit: 80, perMs: 2_000 }], + parsers: ["retryAfter", "resetHeaders"], + }; + companyDomain: string | null; URLs: { activities: string; diff --git a/packages/v1-ready/pipedrive/test/rateLimit.test.ts b/packages/v1-ready/pipedrive/test/rateLimit.test.ts new file mode 100644 index 00000000..e2ff276c --- /dev/null +++ b/packages/v1-ready/pipedrive/test/rateLimit.test.ts @@ -0,0 +1,111 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { Api } from "../src/api"; + +type FakeResponse = { + status: number; + headers?: Record; + body?: unknown; +}; + +function throttledFetch(responses: FakeResponse[]) { + const queue = [...responses]; + return vi.fn(async () => { + const next = queue.shift(); + if (!next) throw new Error("unexpected fetch call"); + const body = next.body ?? {}; + return { + status: next.status, + bodyUsed: false, + headers: new Map( + Object.entries({ "Content-Type": "application/json", ...next.headers }) + ), + json: async () => body, + text: vi.fn(async () => JSON.stringify(body)), + }; + }); +} + +const ok: FakeResponse = { status: 200, body: { success: true, data: [] } }; +const limited = (headers?: Record): FakeResponse => ({ + status: 429, + headers, +}); + +const recordedBurstHeaders = { + "x-ratelimit-limit": "10", + "x-ratelimit-remaining": "0", + "x-ratelimit-reset": "10", + "Retry-After": "10", +}; + +describe("Pipedrive rate limits", () => { + let delays: Array; + + beforeEach(() => { + delays = []; + const realSetTimeout = globalThis.setTimeout; + vi.spyOn(globalThis, "setTimeout").mockImplementation((( + fn: () => void, + delay?: number, + ...args: unknown[] + ) => { + delays.push(delay); + return realSetTimeout(fn, 0, ...args); + }) as typeof setTimeout); + vi.spyOn(Math, "random").mockReturnValue(0); + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); + + const makeApi = (fetch: ReturnType) => + new Api({ + companyDomain: "https://acme.pipedrive.com", + fetch, + requestTimeoutMs: 0, + } as any); + + it("waits as long as x-ratelimit-reset says, then retries", async () => { + const fetch = throttledFetch([ + limited({ + "x-ratelimit-limit": "80", + "x-ratelimit-remaining": "0", + "x-ratelimit-reset": "2", + }), + ok, + ]); + + const result = await makeApi(fetch).listDeals(); + + expect(result).toEqual({ success: true, data: [] }); + expect(delays).toEqual([2_000]); + expect(fetch).toHaveBeenCalledTimes(2); + }); + + it("waits the 10 seconds of a recorded 429 that carries Retry-After and x-ratelimit-reset", async () => { + const fetch = throttledFetch([limited(recordedBurstHeaders), ok]); + + await makeApi(fetch).listDeals(); + + expect(delays).toEqual([10_000]); + expect(fetch).toHaveBeenCalledTimes(2); + }); + + it("keeps the fixed backoff ladder for a 429 with no headers, as for an exhausted daily budget", async () => { + const fetch = throttledFetch([limited(), ok]); + + await makeApi(fetch).listDeals(); + + expect(delays).toEqual([1_000]); + expect(fetch).toHaveBeenCalledTimes(2); + }); + + it("declares the lowest documented OAuth burst allowance", () => { + expect(Api.rateLimit).toMatchObject({ + scope: "entity", + windows: [{ name: "burst", limit: 80, perMs: 2_000 }], + parsers: ["retryAfter", "resetHeaders"], + }); + }); +}); From 204c5bb97c0c10061e36ce9c9e5087e98a6dc7db Mon Sep 17 00:00:00 2001 From: d-klotz Date: Mon, 9 Nov 2026 18:49:26 -0300 Subject: [PATCH 04/12] feat(hubspot): wait out the per-second search limit The CRM search endpoints have their own limit of 5 requests per second per account. A throttled search returns 429 with policyName SECONDLY and no rate-limit headers, so the Requester waited the 10 second burst window. classify now gives a 1 second wait for SECONDLY, and the policy declares the search window. The probe interval test now sets the in-process budget through runWithInvocationDeadline: core no longer reads maxInProcessWaitMs from the module policy. Co-Authored-By: Claude Opus 5.5 --- packages/v1-ready/hubspot/README.md | 3 ++ packages/v1-ready/hubspot/api.js | 14 ++++++- .../v1-ready/hubspot/tests/rateLimit.test.js | 42 +++++++++++++++---- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/packages/v1-ready/hubspot/README.md b/packages/v1-ready/hubspot/README.md index 3bec4dcc..0a4cbb90 100644 --- a/packages/v1-ready/hubspot/README.md +++ b/packages/v1-ready/hubspot/README.md @@ -124,6 +124,9 @@ A `@friggframework/core` release without rate-limit awareness ignores the declar requests every 10 seconds. A throttled call returns `429` with `policyName` `TEN_SECONDLY_ROLLING`. The Requester waits for `Retry-After` when the response has one, and for the 10 second window when it has none. +- **Search:** the CRM search endpoints have their own limit of 5 requests per second + per account, outside the burst limit. A throttled search returns `429` with + `policyName` `SECONDLY`. The Requester waits 1 second, then retries. - **Daily:** a `429` with `policyName` `DAILY`. HubSpot resets the daily limit at midnight in the account's time zone, which the module does not know, so it does not compute a reset time. It reports a one hour probe interval: the Requester throws a diff --git a/packages/v1-ready/hubspot/api.js b/packages/v1-ready/hubspot/api.js index 9eafa7f1..76781bdd 100644 --- a/packages/v1-ready/hubspot/api.js +++ b/packages/v1-ready/hubspot/api.js @@ -1,15 +1,27 @@ const {OAuth2Requester, get} = require('@friggframework/core'); const DAILY_PROBE_INTERVAL_MS = 3_600_000; +const SEARCH_WINDOW_MS = 1_000; class Api extends OAuth2Requester { static rateLimit = { scope: 'entity', - windows: [{ name: 'burst', limit: 110, perMs: 10_000 }], + windows: [ + { name: 'burst', limit: 110, perMs: 10_000 }, + { name: 'search', limit: 5, perMs: SEARCH_WINDOW_MS }, + ], maxConcurrency: 10, parsers: ['retryAfter', 'resetHeaders'], classify({ status, body }) { if (status !== 429) return null; + if (body?.policyName === 'SECONDLY') { + return { + reason: 'burst', + policy: 'SECONDLY', + waitMs: SEARCH_WINDOW_MS, + source: 'static', + }; + } if (body?.policyName === 'DAILY') { return { reason: 'daily', diff --git a/packages/v1-ready/hubspot/tests/rateLimit.test.js b/packages/v1-ready/hubspot/tests/rateLimit.test.js index 4c24d361..777ae85f 100644 --- a/packages/v1-ready/hubspot/tests/rateLimit.test.js +++ b/packages/v1-ready/hubspot/tests/rateLimit.test.js @@ -1,4 +1,8 @@ -const { FetchError, RateLimitError } = require('@friggframework/core'); +const { + FetchError, + RateLimitError, + runWithInvocationDeadline, +} = require('@friggframework/core'); const { Api } = require('../api'); const ONE_HOUR_MS = 3_600_000; @@ -19,6 +23,14 @@ const dailyLimitBody = { policyName: 'DAILY', }; +const searchLimitBody = { + status: 'error', + message: 'You have reached your secondly limit.', + errorType: 'RATE_LIMIT', + correlationId: '00000000-0000-4000-8000-000000000000', + policyName: 'SECONDLY', +}; + const burstHeaders = { 'X-HubSpot-RateLimit-Max': '110', 'X-HubSpot-RateLimit-Remaining': '0', @@ -139,6 +151,18 @@ describe('HubSpot rate limits', () => { }); }); + describe('a SECONDLY 429 from a search endpoint', () => { + it('waits the 1 second search window, then retries', async () => { + const fetch = throttledFetch([limited(searchLimitBody), ok]); + + const result = await makeApi(fetch).searchCompanies({}); + + expect(result).toEqual({ results: [] }); + expect(delays).toEqual([1_000]); + expect(fetch).toHaveBeenCalledTimes(2); + }); + }); + describe('a DAILY 429', () => { it('throws a RateLimitError that probes again in one hour', async () => { const fetch = throttledFetch([limited(dailyLimitBody), ok]); @@ -171,15 +195,12 @@ describe('HubSpot rate limits', () => { }); it('sleeps the probe interval and retries when the in-process budget allows it', async () => { - class PatientApi extends Api { - static rateLimit = { - ...Api.rateLimit, - maxInProcessWaitMs: ONE_HOUR_MS + 60_000, - }; - } const fetch = throttledFetch([limited(dailyLimitBody), ok]); - const result = await makeApi(fetch, PatientApi).listCompanies(); + const result = await runWithInvocationDeadline( + { maxInProcessWaitMs: ONE_HOUR_MS + 60_000 }, + () => makeApi(fetch).listCompanies() + ); expect(result).toEqual({ results: [] }); expect(delays).toEqual([ONE_HOUR_MS]); @@ -223,7 +244,10 @@ describe('HubSpot rate limits', () => { it('declares its limits', () => { expect(Api.rateLimit).toMatchObject({ scope: 'entity', - windows: [{ name: 'burst', limit: 110, perMs: 10_000 }], + windows: [ + { name: 'burst', limit: 110, perMs: 10_000 }, + { name: 'search', limit: 5, perMs: 1_000 }, + ], maxConcurrency: 10, parsers: ['retryAfter', 'resetHeaders'], }); From 12917f3c4d601a0f6337be1a2d31ad1f00bc4490 Mon Sep 17 00:00:00 2001 From: d-klotz Date: Mon, 9 Nov 2026 18:53:29 -0300 Subject: [PATCH 05/12] fix(pipedrive): drop maxInProcessWaitMs from the core type shim Core no longer reads maxInProcessWaitMs from the module policy. The caller sets the in-process budget through runWithInvocationDeadline. Co-Authored-By: Claude Opus 5.5 --- packages/v1-ready/pipedrive/frigg-core.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/v1-ready/pipedrive/frigg-core.d.ts b/packages/v1-ready/pipedrive/frigg-core.d.ts index f08aaefe..b0f65725 100644 --- a/packages/v1-ready/pipedrive/frigg-core.d.ts +++ b/packages/v1-ready/pipedrive/frigg-core.d.ts @@ -73,7 +73,6 @@ declare module '@friggframework/core' { windows?: RateLimitWindow[]; maxConcurrency?: number; minRetryAfterMs?: number; - maxInProcessWaitMs?: number; parsers?: Array<"retryAfter" | "resetHeaders" | "ietf">; classify?(signal: RateLimitSignal): | (Partial> & { From ba4b63d67bb9a89c690bf6e0d2c3a813f13ec127 Mon Sep 17 00:00:00 2001 From: d-klotz Date: Wed, 25 Nov 2026 16:29:59 -0300 Subject: [PATCH 06/12] chore(deps): require @friggframework/core 2.0.0-next.129 HubSpot, Salesforce and Pipedrive declare rate-limit policies that only core 2.0.0-next.129 reads (ADR-049: RateLimitError, classifyRateLimit and the RATE_LIMITED queue event). Raise the range of the three modules to ^2.0.0-next.129 and drop the HubSpot README note about cores without rate-limit awareness. Lockfile updated with npm 10.8.2, the npm of the Node 18 release job. Co-Authored-By: Claude Opus 5.5 --- package-lock.json | 258 +++++++++++++++------- packages/v1-ready/hubspot/README.md | 1 - packages/v1-ready/hubspot/package.json | 2 +- packages/v1-ready/pipedrive/package.json | 2 +- packages/v1-ready/salesforce/package.json | 2 +- 5 files changed, 185 insertions(+), 80 deletions(-) diff --git a/package-lock.json b/package-lock.json index c73a4a2e..a3a06f6b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7478,7 +7478,6 @@ "version": "3.1113.0", "resolved": "https://registry.npmjs.org/@aws-sdk/client-scheduler/-/client-scheduler-3.1113.0.tgz", "integrity": "sha512-1vdzaO+mSivNNQYTROPML7mSfto3g9cSv+2bIfsww5fzh3K8F15AEQ4fu0hrCDW9O5FrfKcbxQy0rdePmSXTHA==", - "dev": true, "license": "Apache-2.0", "dependencies": { "@aws-sdk/core": "^3.977.8", @@ -7498,7 +7497,6 @@ "version": "3.977.8", "resolved": "https://registry.npmjs.org/@aws-sdk/core/-/core-3.977.8.tgz", "integrity": "sha512-7+Kcrkvrk9lM/m7jRhHpT4jCdvzGHsuaSRbF8TdzzkY1mRzp/Ogwf9c7H29k4gGhey0BBWhCWr16+t0J61gwmg==", - "dev": true, "license": "Apache-2.0", "dependencies": { "@aws-sdk/types": "^3.974.4", @@ -7518,7 +7516,6 @@ "version": "3.972.69", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-env/-/credential-provider-env-3.972.69.tgz", "integrity": "sha512-AreCFzcB4kH2HF9031Ot0jSJr3KXvRg6e8uDeub20JEVdZU3Bv0sTq1plc7VsT3KiqutlzH7l0j50UcCWHUioA==", - "dev": true, "license": "Apache-2.0", "dependencies": { "@aws-sdk/core": "^3.977.8", @@ -7535,7 +7532,6 @@ "version": "3.972.71", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-http/-/credential-provider-http-3.972.71.tgz", "integrity": "sha512-A8ObcqVmDMnk4F9NozZ7JwmUu9Q4xyBJkmyq1C5U+wNM9ht9J7+EuuyabsLWXZnOoTqFaJuYBYTKf5CTipkEjA==", - "dev": true, "license": "Apache-2.0", "dependencies": { "@aws-sdk/core": "^3.977.8", @@ -7554,7 +7550,6 @@ "version": "3.973.14", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-ini/-/credential-provider-ini-3.973.14.tgz", "integrity": "sha512-7c+Wti2LsERNWMfm7ySz3/6RPopFW3Nmn7s63Xpcq6R/tRuY5hpvkHA2xVgi5ukJbvok9l0IDtVEvqTtg+X7dw==", - "dev": true, "license": "Apache-2.0", "dependencies": { "@aws-sdk/core": "^3.977.8", @@ -7579,7 +7574,6 @@ "version": "3.972.80", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-node/-/credential-provider-node-3.972.80.tgz", "integrity": "sha512-bE2qh8ww4iClO1jHsBXdOE8FUgzDbdxbyorNjSCoPSkQd51k3jODItuPZfuwcLHZqDXsH+bI4AMHhqtuyR7mSg==", - "dev": true, "license": "Apache-2.0", "dependencies": { "@aws-sdk/credential-provider-env": "^3.972.69", @@ -7602,7 +7596,6 @@ "version": "3.972.69", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-process/-/credential-provider-process-3.972.69.tgz", "integrity": "sha512-9kpTNdZTrcqXTfhxM7fgl9Z68ek3Fu5oe3Yf+A/pJGibEqpgZxz2tSY7SinmyCIU2PJ+ygY4FPoBBnLpocMtrQ==", - "dev": true, "license": "Apache-2.0", "dependencies": { "@aws-sdk/core": "^3.977.8", @@ -7619,7 +7612,6 @@ "version": "3.973.13", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-sso/-/credential-provider-sso-3.973.13.tgz", "integrity": "sha512-Oc81qauMPzUoTnAS2YKpNwY6sY/LUyQTEeaf6yP197WMxkEBQfcKLR1MFpD7+pNTubXnfkH6gwpji+Gc7iyD2Q==", - "dev": true, "license": "Apache-2.0", "dependencies": { "@aws-sdk/core": "^3.977.8", @@ -7638,7 +7630,6 @@ "version": "3.972.75", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-web-identity/-/credential-provider-web-identity-3.972.75.tgz", "integrity": "sha512-YPN6uoGDgjjjeVFZrcOeCJqmB6zpXoeeNgIjqe+DexJaWqdjVfCCe+VAZwli9Z2h8KhFW8oxkO39emQ1tyz/Mw==", - "dev": true, "license": "Apache-2.0", "dependencies": { "@aws-sdk/core": "^3.977.8", @@ -7656,7 +7647,6 @@ "version": "3.1111.0", "resolved": "https://registry.npmjs.org/@aws-sdk/token-providers/-/token-providers-3.1111.0.tgz", "integrity": "sha512-JfljgoVtl+s3Qy21n9a7Z48uCQaOXcN74KJ3TEQfPoB293GrXFSt6HSQJF1sTZ8c/5QedEvd3NjJQMO4u9qa5A==", - "dev": true, "license": "Apache-2.0", "dependencies": { "@aws-sdk/core": "^3.977.8", @@ -7674,7 +7664,6 @@ "version": "3.974.4", "resolved": "https://registry.npmjs.org/@aws-sdk/types/-/types-3.974.4.tgz", "integrity": "sha512-dSFDNG00MEz0/xl5gxL62giLd1iYyJsTxZ1I1DOj6lC+bbgLB4TRsYClJg3b62dhXT1uATzsTNXPnC+33EJV3A==", - "dev": true, "license": "Apache-2.0", "dependencies": { "@smithy/types": "^4.16.1", @@ -7688,7 +7677,6 @@ "version": "0.3.0", "resolved": "https://registry.npmjs.org/@aws/lambda-invoke-store/-/lambda-invoke-store-0.3.0.tgz", "integrity": "sha512-sl4Bm6yiMNYrZKkqqDFWN0UfnWhlS8ivKxrYl+6t0gCLrqr8y3B2IqZZbFRkfaVVp7C/baApyh71P+LeE1A2sQ==", - "dev": true, "license": "Apache-2.0", "engines": { "node": ">=18.0.0" @@ -7698,7 +7686,6 @@ "version": "3.33.2", "resolved": "https://registry.npmjs.org/@smithy/core/-/core-3.33.2.tgz", "integrity": "sha512-CUGXpnPkVdjUCbix+83sWLW9VFgQOm44MDOx/ihITJMAnOZKvL8YYIc7DR9pP/tZ8CIRvMiON/TucvygqbHO3w==", - "dev": true, "license": "Apache-2.0", "dependencies": { "@smithy/types": "^4.17.2", @@ -7712,7 +7699,6 @@ "version": "4.5.2", "resolved": "https://registry.npmjs.org/@smithy/credential-provider-imds/-/credential-provider-imds-4.5.2.tgz", "integrity": "sha512-A9uSdn72ozbRUSit0eib0TW7nXuNPlaeM0zcGkJ+nE6tFcSDbnmtwoxbTCFBukVQcszDAyvsd7+rTduPTXpygg==", - "dev": true, "license": "Apache-2.0", "dependencies": { "@smithy/core": "^3.33.2", @@ -7727,7 +7713,6 @@ "version": "5.7.2", "resolved": "https://registry.npmjs.org/@smithy/fetch-http-handler/-/fetch-http-handler-5.7.2.tgz", "integrity": "sha512-nZyWTmSpJEXl6VtWVMBJve/7x12DZu6sIX1z1a+ZMaHlQQRs9Zpu6NbTe/gmxYXVRpkjxyDYpZ5gx2IM6f/Wkw==", - "dev": true, "license": "Apache-2.0", "dependencies": { "@smithy/core": "^3.33.2", @@ -7742,7 +7727,6 @@ "version": "4.11.2", "resolved": "https://registry.npmjs.org/@smithy/node-http-handler/-/node-http-handler-4.11.2.tgz", "integrity": "sha512-avwAh9HM3h2lcfjvP3zYIZGf+XVgLQ91wOJ2qoFbNpW1UZeZb33aGlhTZvtkANHfcGhJroRY64525OjfgOg30g==", - "dev": true, "license": "Apache-2.0", "dependencies": { "@smithy/core": "^3.33.2", @@ -7757,7 +7741,6 @@ "version": "5.7.2", "resolved": "https://registry.npmjs.org/@smithy/signature-v4/-/signature-v4-5.7.2.tgz", "integrity": "sha512-P7Ki6px6OOrxVtx8K7nLmyx4SlXUW/uTKDdMG44UHefmPGSRMBKe2v+TM59WdLcpUIrBrnuCsIqiM2MbsZjmhw==", - "dev": true, "license": "Apache-2.0", "dependencies": { "@smithy/core": "^3.33.2", @@ -7772,7 +7755,6 @@ "version": "4.17.2", "resolved": "https://registry.npmjs.org/@smithy/types/-/types-4.17.2.tgz", "integrity": "sha512-FOKpVZob9MPTn2znRzGrnsMHv7BOsKVw3XiP/cOyYLDVZ9qKp4nifIiSCuUU/fIj5Vu0UOAxCFr+qRAtG0NUkA==", - "dev": true, "license": "Apache-2.0", "dependencies": { "tslib": "^2.6.2" @@ -7785,7 +7767,6 @@ "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", - "dev": true, "license": "0BSD" }, "node_modules/@aws-sdk/client-secrets-manager": { @@ -22426,7 +22407,6 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz", "integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==", - "dev": true, "license": "MIT", "dependencies": { "ajv": "^8.0.0" @@ -22444,7 +22424,6 @@ "version": "8.18.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.18.0.tgz", "integrity": "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A==", - "dev": true, "license": "MIT", "dependencies": { "fast-deep-equal": "^3.1.3", @@ -22461,7 +22440,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", - "dev": true, "license": "MIT" }, "node_modules/all-contributors-cli": { @@ -23176,9 +23154,9 @@ } }, "node_modules/body-parser": { - "version": "1.20.6", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.6.tgz", - "integrity": "sha512-p5tAzS57i5MV9fZFDj9LeIiTZEufbSe2eDozP+ElheSUq1m74CRq1jI4mYNDdVs9vQztXFLuk/Gd6BWTdwRJ5g==", + "version": "1.20.9", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.9.tgz", + "integrity": "sha512-FISIQxV5u91Y9gvuFq3q/tA/qTqLJn3AhRcEvyozyhJTh5OBFFtv827AdHU7Rbyct4r+Ba1/99oFa1Y3yuFsdw==", "license": "MIT", "dependencies": { "bytes": "~3.1.2", @@ -23189,7 +23167,7 @@ "http-errors": "~2.0.1", "iconv-lite": "~0.4.24", "on-finished": "~2.4.1", - "qs": "~6.15.1", + "qs": "~6.16.0", "raw-body": "~2.5.3", "type-is": "~1.6.18", "unpipe": "~1.0.0" @@ -27151,9 +27129,9 @@ "license": "Apache-2.0" }, "node_modules/express": { - "version": "4.22.2", - "resolved": "https://registry.npmjs.org/express/-/express-4.22.2.tgz", - "integrity": "sha512-IuL+Elrou2ZvCFHs18/CIzy2Nzvo25nZ1/D2eIZlz7c+QUayAcYoiM2BthCjs+EBHVpjYjcuLDAiCWgeIX3X1Q==", + "version": "4.22.3", + "resolved": "https://registry.npmjs.org/express/-/express-4.22.3.tgz", + "integrity": "sha512-Bdcs4+3qlpVlx2NRn6fgX2Ue2/gGRaPeawebgclM0ERSCqDpA+owF1fdPwjJUTAJWMTuAaxjDf+hzb0/4eKvvw==", "license": "MIT", "dependencies": { "accepts": "~1.3.8", @@ -27175,9 +27153,9 @@ "methods": "~1.1.2", "on-finished": "~2.4.1", "parseurl": "~1.3.3", - "path-to-regexp": "~0.1.12", + "path-to-regexp": "~0.1.13", "proxy-addr": "~2.0.7", - "qs": "~6.15.1", + "qs": "~6.16.0", "range-parser": "~1.2.1", "safe-buffer": "5.2.1", "send": "~0.19.0", @@ -27236,7 +27214,6 @@ "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", - "dev": true, "license": "MIT" }, "node_modules/fast-glob": { @@ -27294,7 +27271,6 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.0.tgz", "integrity": "sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA==", - "dev": true, "funding": [ { "type": "github", @@ -35909,9 +35885,9 @@ } }, "node_modules/qs": { - "version": "6.15.3", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.3.tgz", - "integrity": "sha512-O9gl3zCl5h5blw1KGUzQKhA5oUXSl8rwUIM5o0S3nCXMliSvy5Dzx7/DJcI+SwgICv+IneSZwhBh1oSyEHA71A==", + "version": "6.16.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.16.2.tgz", + "integrity": "sha512-VYdnB5S7/0IeXzBacUtwNAaM6d7Y/PgYnNC7bJCI6meqA/OgnsQbZMtVW8Dt2D1PHgbHGtYmhSoEIgvt7xZ2ZA==", "license": "BSD-3-Clause", "dependencies": { "es-define-property": "^1.0.1", @@ -36319,7 +36295,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", - "dev": true, "license": "MIT", "engines": { "node": ">=0.10.0" @@ -53487,7 +53462,7 @@ "version": "1.1.7", "license": "MIT", "dependencies": { - "@friggframework/core": "^2.0.0-next.89" + "@friggframework/core": "^2.0.0-next.129" }, "devDependencies": { "@friggframework/devtools": "^1.1.2", @@ -53500,36 +53475,47 @@ } }, "packages/v1-ready/hubspot/node_modules/@friggframework/core": { - "version": "2.0.0-next.89", - "resolved": "https://registry.npmjs.org/@friggframework/core/-/core-2.0.0-next.89.tgz", - "integrity": "sha512-AhxMCO+6aw9RGti6vzo8VOMTD8bufsFPNn+5ZVkMc61XjcGyLMsOUiCeC01ZH33ny4+davhTOYj8zGRKFaXIkQ==", + "version": "2.0.0-next.129", + "resolved": "https://registry.npmjs.org/@friggframework/core/-/core-2.0.0-next.129.tgz", + "integrity": "sha512-JJ3iAJeFnNzAkAG+hIZ0bIAmwH955tQW4FZ5DtThh1NbVKeUHvHVMF0MUYYyKd0EJfOmBAr5rEINGaZZ9X0LVQ==", "license": "MIT", "dependencies": { "@aws-sdk/client-apigatewaymanagementapi": "^3.588.0", "@aws-sdk/client-kms": "^3.588.0", "@aws-sdk/client-lambda": "^3.714.0", + "@aws-sdk/client-s3": "^3.588.0", + "@aws-sdk/client-scheduler": "^3.588.0", "@aws-sdk/client-sqs": "^3.588.0", + "@aws-sdk/client-ssm": "^3.588.0", + "@aws-sdk/s3-request-presigner": "^3.588.0", + "@friggframework/schemas": "2.0.0-next.129", "@hapi/boom": "^10.0.1", + "@opentelemetry/api": "^1.9.1", + "@opentelemetry/context-async-hooks": "^2.9.0", + "@opentelemetry/exporter-metrics-otlp-http": "^0.220.0", + "@opentelemetry/exporter-trace-otlp-http": "^0.220.0", + "@opentelemetry/resources": "^2.9.0", + "@opentelemetry/sdk-metrics": "^2.9.0", + "@opentelemetry/sdk-trace-base": "^2.9.0", "bcryptjs": "^2.4.3", - "body-parser": "^1.20.2", + "body-parser": "^1.20.9", "bson": "^4.7.2", "chalk": "^4.1.2", - "common-tags": "^1.8.2", "cors": "^2.8.5", "dotenv": "^16.4.7", - "express": "^4.19.2", + "express": "^4.22.3", "express-async-handler": "^1.2.0", - "form-data": "^4.0.0", + "form-data": "^4.0.6", "fs-extra": "^11.2.0", - "lodash": "4.17.21", + "lodash": "4.18.1", "lodash.get": "^4.4.2", "node-fetch": "^2.6.7", "serverless-http": "^2.7.0", - "uuid": "^9.0.1" + "uuid": "^11.1.1" }, "peerDependencies": { - "@prisma/client": "^6.16.3", - "prisma": "^6.16.3" + "@prisma/client": "^6.19.3", + "prisma": "^6.19.3" }, "peerDependenciesMeta": { "@prisma/client": { @@ -53540,6 +53526,32 @@ } } }, + "packages/v1-ready/hubspot/node_modules/@friggframework/schemas": { + "version": "2.0.0-next.129", + "resolved": "https://registry.npmjs.org/@friggframework/schemas/-/schemas-2.0.0-next.129.tgz", + "integrity": "sha512-i5RDVq/+Q3lZB1bQAmfSFhgZOYUCrM8wfWNI2Q++Y1+CAv3LYFhhEAKPiQZKy5xE5Mv1nWVyXr8L7mMyWfJxdQ==", + "license": "MIT", + "dependencies": { + "ajv": "^8.20.0", + "ajv-formats": "^2.1.1" + } + }, + "packages/v1-ready/hubspot/node_modules/ajv": { + "version": "8.20.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz", + "integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, "packages/v1-ready/hubspot/node_modules/dotenv": { "version": "16.6.1", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.6.1.tgz", @@ -53552,17 +53564,29 @@ "url": "https://dotenvx.com" } }, + "packages/v1-ready/hubspot/node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "license": "MIT" + }, + "packages/v1-ready/hubspot/node_modules/lodash": { + "version": "4.18.1", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.18.1.tgz", + "integrity": "sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q==", + "license": "MIT" + }, "packages/v1-ready/hubspot/node_modules/uuid": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", - "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "version": "11.1.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.1.tgz", + "integrity": "sha512-vIYxrBCC/N/K+Js3qSN88go7kIfNPssr/hHCesKCQNAjmgvYS2oqr69kIufEG+O4+PfezOH4EbIeHCfFov8ZgQ==", "funding": [ "https://github.com/sponsors/broofa", "https://github.com/sponsors/ctavan" ], "license": "MIT", "bin": { - "uuid": "dist/bin/uuid" + "uuid": "dist/esm/bin/uuid" } }, "packages/v1-ready/ironclad": { @@ -56249,7 +56273,7 @@ "version": "2.0.0", "license": "MIT", "dependencies": { - "@friggframework/core": "^2.0.0-next.16", + "@friggframework/core": "^2.0.0-next.129", "dotenv": "^16.0.0" }, "devDependencies": { @@ -56260,36 +56284,47 @@ } }, "packages/v1-ready/pipedrive/node_modules/@friggframework/core": { - "version": "2.0.0-next.75", - "resolved": "https://registry.npmjs.org/@friggframework/core/-/core-2.0.0-next.75.tgz", - "integrity": "sha512-y053DvLZvCJAEzw5t3FchiMtMAVZepSZp8vMaGrlUlFeRsRp8MAP6PqTwzzSWWpPpSauT1uV9qMMAahRnhfYhA==", + "version": "2.0.0-next.129", + "resolved": "https://registry.npmjs.org/@friggframework/core/-/core-2.0.0-next.129.tgz", + "integrity": "sha512-JJ3iAJeFnNzAkAG+hIZ0bIAmwH955tQW4FZ5DtThh1NbVKeUHvHVMF0MUYYyKd0EJfOmBAr5rEINGaZZ9X0LVQ==", "license": "MIT", "dependencies": { "@aws-sdk/client-apigatewaymanagementapi": "^3.588.0", "@aws-sdk/client-kms": "^3.588.0", "@aws-sdk/client-lambda": "^3.714.0", + "@aws-sdk/client-s3": "^3.588.0", + "@aws-sdk/client-scheduler": "^3.588.0", "@aws-sdk/client-sqs": "^3.588.0", + "@aws-sdk/client-ssm": "^3.588.0", + "@aws-sdk/s3-request-presigner": "^3.588.0", + "@friggframework/schemas": "2.0.0-next.129", "@hapi/boom": "^10.0.1", + "@opentelemetry/api": "^1.9.1", + "@opentelemetry/context-async-hooks": "^2.9.0", + "@opentelemetry/exporter-metrics-otlp-http": "^0.220.0", + "@opentelemetry/exporter-trace-otlp-http": "^0.220.0", + "@opentelemetry/resources": "^2.9.0", + "@opentelemetry/sdk-metrics": "^2.9.0", + "@opentelemetry/sdk-trace-base": "^2.9.0", "bcryptjs": "^2.4.3", - "body-parser": "^1.20.2", + "body-parser": "^1.20.9", "bson": "^4.7.2", "chalk": "^4.1.2", - "common-tags": "^1.8.2", "cors": "^2.8.5", "dotenv": "^16.4.7", - "express": "^4.19.2", + "express": "^4.22.3", "express-async-handler": "^1.2.0", - "form-data": "^4.0.0", + "form-data": "^4.0.6", "fs-extra": "^11.2.0", - "lodash": "4.17.21", + "lodash": "4.18.1", "lodash.get": "^4.4.2", "node-fetch": "^2.6.7", "serverless-http": "^2.7.0", - "uuid": "^9.0.1" + "uuid": "^11.1.1" }, "peerDependencies": { - "@prisma/client": "^6.16.3", - "prisma": "^6.16.3" + "@prisma/client": "^6.19.3", + "prisma": "^6.19.3" }, "peerDependenciesMeta": { "@prisma/client": { @@ -56300,6 +56335,16 @@ } } }, + "packages/v1-ready/pipedrive/node_modules/@friggframework/schemas": { + "version": "2.0.0-next.129", + "resolved": "https://registry.npmjs.org/@friggframework/schemas/-/schemas-2.0.0-next.129.tgz", + "integrity": "sha512-i5RDVq/+Q3lZB1bQAmfSFhgZOYUCrM8wfWNI2Q++Y1+CAv3LYFhhEAKPiQZKy5xE5Mv1nWVyXr8L7mMyWfJxdQ==", + "license": "MIT", + "dependencies": { + "ajv": "^8.20.0", + "ajv-formats": "^2.1.1" + } + }, "packages/v1-ready/pipedrive/node_modules/@types/node": { "version": "20.19.37", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.37.tgz", @@ -56310,6 +56355,22 @@ "undici-types": "~6.21.0" } }, + "packages/v1-ready/pipedrive/node_modules/ajv": { + "version": "8.20.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz", + "integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, "packages/v1-ready/pipedrive/node_modules/dotenv": { "version": "16.6.1", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.6.1.tgz", @@ -56322,6 +56383,18 @@ "url": "https://dotenvx.com" } }, + "packages/v1-ready/pipedrive/node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "license": "MIT" + }, + "packages/v1-ready/pipedrive/node_modules/lodash": { + "version": "4.18.1", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.18.1.tgz", + "integrity": "sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q==", + "license": "MIT" + }, "packages/v1-ready/pipedrive/node_modules/undici-types": { "version": "6.21.0", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", @@ -56330,16 +56403,16 @@ "license": "MIT" }, "packages/v1-ready/pipedrive/node_modules/uuid": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", - "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "version": "11.1.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.1.tgz", + "integrity": "sha512-vIYxrBCC/N/K+Js3qSN88go7kIfNPssr/hHCesKCQNAjmgvYS2oqr69kIufEG+O4+PfezOH4EbIeHCfFov8ZgQ==", "funding": [ "https://github.com/sponsors/broofa", "https://github.com/sponsors/ctavan" ], "license": "MIT", "bin": { - "uuid": "dist/bin/uuid" + "uuid": "dist/esm/bin/uuid" } }, "packages/v1-ready/quo": { @@ -56652,7 +56725,7 @@ "version": "1.0.2", "license": "MIT", "dependencies": { - "@friggframework/core": "^2.0.0-next.110", + "@friggframework/core": "^2.0.0-next.129", "jsforce": "^3.8.1" }, "devDependencies": { @@ -56666,18 +56739,20 @@ } }, "packages/v1-ready/salesforce/node_modules/@friggframework/core": { - "version": "2.0.0-next.110", - "resolved": "https://registry.npmjs.org/@friggframework/core/-/core-2.0.0-next.110.tgz", - "integrity": "sha512-T8MGYKxseuwzb1MNMAs8+Tlm0j+4yZGTUDQ1tUTiOcEfx9pmYKtg/7cW6dq9+s0h8zutpbDKxG+c2hFWBwuGfg==", + "version": "2.0.0-next.129", + "resolved": "https://registry.npmjs.org/@friggframework/core/-/core-2.0.0-next.129.tgz", + "integrity": "sha512-JJ3iAJeFnNzAkAG+hIZ0bIAmwH955tQW4FZ5DtThh1NbVKeUHvHVMF0MUYYyKd0EJfOmBAr5rEINGaZZ9X0LVQ==", "license": "MIT", "dependencies": { "@aws-sdk/client-apigatewaymanagementapi": "^3.588.0", "@aws-sdk/client-kms": "^3.588.0", "@aws-sdk/client-lambda": "^3.714.0", "@aws-sdk/client-s3": "^3.588.0", + "@aws-sdk/client-scheduler": "^3.588.0", "@aws-sdk/client-sqs": "^3.588.0", "@aws-sdk/client-ssm": "^3.588.0", "@aws-sdk/s3-request-presigner": "^3.588.0", + "@friggframework/schemas": "2.0.0-next.129", "@hapi/boom": "^10.0.1", "@opentelemetry/api": "^1.9.1", "@opentelemetry/context-async-hooks": "^2.9.0", @@ -56687,13 +56762,12 @@ "@opentelemetry/sdk-metrics": "^2.9.0", "@opentelemetry/sdk-trace-base": "^2.9.0", "bcryptjs": "^2.4.3", - "body-parser": "^1.20.5", + "body-parser": "^1.20.9", "bson": "^4.7.2", "chalk": "^4.1.2", - "common-tags": "^1.8.2", "cors": "^2.8.5", "dotenv": "^16.4.7", - "express": "^4.22.2", + "express": "^4.22.3", "express-async-handler": "^1.2.0", "form-data": "^4.0.6", "fs-extra": "^11.2.0", @@ -56716,6 +56790,32 @@ } } }, + "packages/v1-ready/salesforce/node_modules/@friggframework/schemas": { + "version": "2.0.0-next.129", + "resolved": "https://registry.npmjs.org/@friggframework/schemas/-/schemas-2.0.0-next.129.tgz", + "integrity": "sha512-i5RDVq/+Q3lZB1bQAmfSFhgZOYUCrM8wfWNI2Q++Y1+CAv3LYFhhEAKPiQZKy5xE5Mv1nWVyXr8L7mMyWfJxdQ==", + "license": "MIT", + "dependencies": { + "ajv": "^8.20.0", + "ajv-formats": "^2.1.1" + } + }, + "packages/v1-ready/salesforce/node_modules/ajv": { + "version": "8.20.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz", + "integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, "packages/v1-ready/salesforce/node_modules/dotenv": { "version": "16.6.1", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.6.1.tgz", @@ -56728,6 +56828,12 @@ "url": "https://dotenvx.com" } }, + "packages/v1-ready/salesforce/node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "license": "MIT" + }, "packages/v1-ready/salesforce/node_modules/lodash": { "version": "4.18.1", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.18.1.tgz", diff --git a/packages/v1-ready/hubspot/README.md b/packages/v1-ready/hubspot/README.md index 0a4cbb90..4b039dd7 100644 --- a/packages/v1-ready/hubspot/README.md +++ b/packages/v1-ready/hubspot/README.md @@ -118,7 +118,6 @@ colliding. `Api.rateLimit` tells the Frigg Requester how HubSpot limits calls. The numbers come from the [API usage guidelines and limits](https://developers.hubspot.com/docs/developer-tooling/platform/usage-guidelines). -A `@friggframework/core` release without rate-limit awareness ignores the declaration. - **Burst:** each account that installs a marketplace OAuth app is limited to 110 requests every 10 seconds. A throttled call returns `429` with `policyName` diff --git a/packages/v1-ready/hubspot/package.json b/packages/v1-ready/hubspot/package.json index 19db157b..8a06c625 100644 --- a/packages/v1-ready/hubspot/package.json +++ b/packages/v1-ready/hubspot/package.json @@ -20,6 +20,6 @@ "prettier": "^2.7.1" }, "dependencies": { - "@friggframework/core": "^2.0.0-next.89" + "@friggframework/core": "^2.0.0-next.129" } } diff --git a/packages/v1-ready/pipedrive/package.json b/packages/v1-ready/pipedrive/package.json index 6575c456..f2a02aae 100644 --- a/packages/v1-ready/pipedrive/package.json +++ b/packages/v1-ready/pipedrive/package.json @@ -18,7 +18,7 @@ "LICENSE.md" ], "dependencies": { - "@friggframework/core": "^2.0.0-next.16", + "@friggframework/core": "^2.0.0-next.129", "dotenv": "^16.0.0" }, "devDependencies": { diff --git a/packages/v1-ready/salesforce/package.json b/packages/v1-ready/salesforce/package.json index d36e593a..2b4da200 100644 --- a/packages/v1-ready/salesforce/package.json +++ b/packages/v1-ready/salesforce/package.json @@ -21,7 +21,7 @@ "prettier": "^2.7.1" }, "dependencies": { - "@friggframework/core": "^2.0.0-next.110", + "@friggframework/core": "^2.0.0-next.129", "jsforce": "^3.8.1" } } \ No newline at end of file From 4819f9f16da73a35857dbbb6040e9901e7d47db1 Mon Sep 17 00:00:00 2001 From: d-klotz Date: Wed, 25 Nov 2026 16:29:59 -0300 Subject: [PATCH 07/12] refactor(salesforce): drop the pre-release core fallbacks from withLimits Core 2.0.0-next.129 exports RateLimitError and classifyRateLimit and records the user warning from the RATE_LIMITED event of the queue worker, so withLimits no longer: - calls _notifyRateLimited, which this core does not have; - returns the jsforce error when the rate-limit exports are missing. The tests for both fallbacks go with them. Co-Authored-By: Claude Opus 5.5 --- packages/v1-ready/salesforce/README.md | 2 - packages/v1-ready/salesforce/api.js | 11 +--- packages/v1-ready/salesforce/test/api.test.js | 61 ------------------- 3 files changed, 1 insertion(+), 73 deletions(-) diff --git a/packages/v1-ready/salesforce/README.md b/packages/v1-ready/salesforce/README.md index efe1e239..52cc92a3 100644 --- a/packages/v1-ready/salesforce/README.md +++ b/packages/v1-ready/salesforce/README.md @@ -58,5 +58,3 @@ const result = await api.withLimits(() => api.conn.query(soql)); ``` Salesforce also returns `REQUEST_LIMIT_EXCEEDED` when too many requests that run for 20 seconds or longer are in flight at once (25 in a production org, 5 in a Developer Edition org). That limit clears in seconds, not in a day. Salesforce documents no field that tells the two apart, so `withLimits` reads the error message: a message that contains "concurrent" (Salesforce sends `ConcurrentPerOrgLongTxn` for it) is reported as `reason: 'concurrency'` with a `retryAt` 30 seconds ahead. Any other message stays a daily limit. - -When it throws a `RateLimitError` for a limit that lasts longer than the in-process cap (5 minutes by default: the daily limit, not the 30 second concurrency limit), `withLimits` also has the integration record one rate-limit warning for its users, as the Frigg Requester does. On a core that cannot record the warning, it only throws. A core that does not export `RateLimitError` and `classifyRateLimit` (older than the release that added them) makes `withLimits` rethrow the original jsforce error. diff --git a/packages/v1-ready/salesforce/api.js b/packages/v1-ready/salesforce/api.js index ec4f33f9..4aa8da86 100644 --- a/packages/v1-ready/salesforce/api.js +++ b/packages/v1-ready/salesforce/api.js @@ -187,20 +187,11 @@ class Api extends OAuth2Requester { try { return await call(); } catch (err) { - const rateLimitError = this._rateLimitErrorFor(err); - if (!rateLimitError) throw err; - await this._notifyRateLimited?.(rateLimitError); - throw rateLimitError; + throw this._rateLimitErrorFor(err) ?? err; } } _rateLimitErrorFor(err) { - if ( - typeof classifyRateLimit !== 'function' || - typeof RateLimitError !== 'function' - ) { - return null; - } const hint = classifyRateLimit(this.constructor.rateLimit, { status: err?.statusCode, headers: {}, diff --git a/packages/v1-ready/salesforce/test/api.test.js b/packages/v1-ready/salesforce/test/api.test.js index 59954ccd..1652adec 100644 --- a/packages/v1-ready/salesforce/test/api.test.js +++ b/packages/v1-ready/salesforce/test/api.test.js @@ -611,7 +611,6 @@ describe('Salesforce Api rate limits', () => { afterEach(() => { jest.restoreAllMocks(); - jest.dontMock('@friggframework/core'); delete api.conn.sobject; delete api.conn.describeGlobal; }); @@ -673,40 +672,6 @@ describe('Salesforce Api rate limits', () => { expect(error).toBe(original); }); - it('tells the delegate about the limit before it throws', async () => { - const notify = jest.fn().mockResolvedValue(undefined); - api._notifyRateLimited = notify; - - const error = await rejectionOf( - api.withLimits(() => Promise.reject(limitError())) - ); - - expect(error).toBeInstanceOf(RateLimitError); - expect(notify).toHaveBeenCalledTimes(1); - expect(notify).toHaveBeenCalledWith(error); - }); - - it('does not tell the delegate about an error that is not a limit', async () => { - const notify = jest.fn().mockResolvedValue(undefined); - api._notifyRateLimited = notify; - - await rejectionOf( - api.withLimits(() => Promise.reject(invalidField())) - ); - - expect(notify).not.toHaveBeenCalled(); - }); - - it('still throws the RateLimitError on a core that cannot notify', async () => { - api._notifyRateLimited = undefined; - - const error = await rejectionOf( - api.withLimits(() => Promise.reject(limitError())) - ); - - expect(error).toBeInstanceOf(RateLimitError); - }); - it.each([ 'ConcurrentPerOrgLongTxn Concurrent API Request Limit exceeded', 'Concurrent requests limit exceeded.', @@ -751,32 +716,6 @@ describe('Salesforce Api rate limits', () => { ); }); - it('rethrows the original error on a core without the rate-limit exports', async () => { - let OldCoreApi; - jest.isolateModules(() => { - jest.doMock('@friggframework/core', () => { - const { - RateLimitError: _error, - classifyRateLimit: _classify, - ...rest - } = jest.requireActual('@friggframework/core'); - return rest; - }); - OldCoreApi = require('../api').Api; - }); - const oldApi = new OldCoreApi({ - ...baseParams, - delegate: { ...baseParams.delegate, name: 'salesforce' }, - }); - const cause = limitError(); - - const error = await rejectionOf( - oldApi.withLimits(() => Promise.reject(cause)) - ); - - expect(error).toBe(cause); - }); - it('links the daily reason to the Salesforce API request limits', () => { expect(Api.rateLimit.userHints.daily.links).toEqual([ { From f20ec17967cd2d41411669b315023308e9cd16b7 Mon Sep 17 00:00:00 2001 From: d-klotz Date: Wed, 25 Nov 2026 16:29:59 -0300 Subject: [PATCH 08/12] refactor(pipedrive): drop the copied rate-limit types from the core shim The RateLimitPolicy types were copied from core into frigg-core.d.ts before core was released. Core ships them only as ambient declarations that this module's build does not load, so the static is now an untyped literal. The rateLimit test still pins the declared values. Co-Authored-By: Claude Opus 5.5 --- packages/v1-ready/pipedrive/frigg-core.d.ts | 47 --------------------- packages/v1-ready/pipedrive/src/api.ts | 9 +--- 2 files changed, 2 insertions(+), 54 deletions(-) diff --git a/packages/v1-ready/pipedrive/frigg-core.d.ts b/packages/v1-ready/pipedrive/frigg-core.d.ts index b0f65725..013c9f93 100644 --- a/packages/v1-ready/pipedrive/frigg-core.d.ts +++ b/packages/v1-ready/pipedrive/frigg-core.d.ts @@ -39,53 +39,6 @@ declare module '@friggframework/core' { headers?: Record; } - export type RateLimitScope = - | "credential" - | "entity" - | "app" - | ((requester: OAuth2Requester) => string | number | null | undefined); - - export type RateLimitSignal = { - status?: number; - headers?: { get(name: string): string | null } | object; - body?: unknown; - }; - - export type RateLimitWindow = { - name: string; - limit?: number; - perMs?: number; - rollingMs?: number; - resets?: { at: string; tz: string }; - }; - - export type RateLimitHint = { - retryAt: Date; - waitMs: number; - reason: "burst" | "daily" | "monthly" | "concurrency" | "unknown"; - policy?: string; - remaining?: number; - source: "header" | "body" | "static" | "backoff"; - }; - - export type RateLimitPolicy = { - scope?: RateLimitScope; - windows?: RateLimitWindow[]; - maxConcurrency?: number; - minRetryAfterMs?: number; - parsers?: Array<"retryAfter" | "resetHeaders" | "ietf">; - classify?(signal: RateLimitSignal): - | (Partial> & { - source?: "header" | "body" | "static"; - }) - | null - | undefined; - userHints?: Record< - string, - { links?: Array<{ label: string; url: string }> } - >; - }; - export class OAuth2Requester { access_token: string | null; refresh_token: string | null; diff --git a/packages/v1-ready/pipedrive/src/api.ts b/packages/v1-ready/pipedrive/src/api.ts index b1c22c81..81d3262f 100644 --- a/packages/v1-ready/pipedrive/src/api.ts +++ b/packages/v1-ready/pipedrive/src/api.ts @@ -1,9 +1,4 @@ -import { - get, - OAuth2Requester, - RateLimitPolicy, - RequestOptions, -} from "@friggframework/core"; +import { get, OAuth2Requester, RequestOptions } from "@friggframework/core"; import { OAuth2RequesterOptions, ActivityParams, @@ -28,7 +23,7 @@ import { } from "./types"; export class Api extends OAuth2Requester { - static rateLimit: RateLimitPolicy = { + static rateLimit = { scope: "entity", windows: [{ name: "burst", limit: 80, perMs: 2_000 }], parsers: ["retryAfter", "resetHeaders"], From 3d7189f4def688782beb59125f39a9e57005f41c Mon Sep 17 00:00:00 2001 From: d-klotz Date: Wed, 25 Nov 2026 17:05:22 -0300 Subject: [PATCH 09/12] feat(pipedrive): treat a 429 with burst requests left as the daily budget Pipedrive rejects every call with a 429 once a company's daily token budget is spent, until midnight server time. The module had no classify, so the Requester read x-ratelimit-reset and retried every 2 seconds. Pipedrive documents no header or body that marks the daily budget. x-ratelimit-remaining is documented as the requests left in the 2 second burst window, so a 429 that still has requests left there is not the burst limit. classify reports it as reason 'daily' with a static one hour probe, and links the rate limiting guide. A 429 with no requests left, or without the header, keeps its current handling. Also declare the search limit of 10 requests per 2 seconds. classify receives only the status, headers and body, not the URL, so a throttled search cannot be told apart and is handled like any other 429. Co-Authored-By: Claude Opus 5.5 --- packages/v1-ready/pipedrive/README.md | 5 +- packages/v1-ready/pipedrive/src/api.ts | 35 +++++++++- .../v1-ready/pipedrive/test/rateLimit.test.ts | 66 ++++++++++++++++++- 3 files changed, 101 insertions(+), 5 deletions(-) diff --git a/packages/v1-ready/pipedrive/README.md b/packages/v1-ready/pipedrive/README.md index 881d2b0a..49e02787 100644 --- a/packages/v1-ready/pipedrive/README.md +++ b/packages/v1-ready/pipedrive/README.md @@ -9,5 +9,6 @@ Read more on the [Frigg documentation site](https://docs.friggframework.org/api- `Api.rateLimit` tells the Frigg Requester how Pipedrive limits calls. The numbers come from [Pipedrive's rate limiting guide](https://pipedrive.readme.io/docs/core-api-concepts-rate-limiting). - **Burst:** a rolling 2 second window, counted per token. An OAuth app gets 80 requests in the window on the Lite plan, 160 on Growth, 400 on Premium and 480 on Ultimate. The module declares 80, the lowest. Pipedrive reports the real figure in `x-ratelimit-limit`. -- **A throttled call** returns `429`. The Requester waits for `Retry-After` when the response has one, and otherwise for `x-ratelimit-reset` (in seconds), then retries. -- **Daily token budget:** each company has a budget of 30,000 tokens times a plan multiplier times the number of seats. It resets at midnight in Pipedrive's server time zone. When it is spent, every call gets a `429`. Pipedrive documents no wait time for it, so the module declares none. Unless the response carries `Retry-After` or `x-ratelimit-reset`, such a `429` keeps the fixed backoff ladder, and then the queue redelivers the message. +- **A throttled call** returns `429`. When the 2 second window has no requests left (`x-ratelimit-remaining: 0`), the Requester waits for `Retry-After` when the response has one, and otherwise for `x-ratelimit-reset` (in seconds), then retries. A `429` with no `x-ratelimit-remaining` keeps the fixed backoff ladder. +- **Search:** the search endpoints (`searchPersons`, `search`) have their own limit of 10 requests per 2 seconds on every plan. The module declares it, but the Requester does not pass the request URL to the policy, so a throttled search is handled like any other `429`. +- **Daily token budget:** each company has a budget of 30,000 tokens times a plan multiplier times the number of seats. It resets at midnight in Pipedrive's server time zone. When it is spent, every call gets a `429`, and Pipedrive documents no header or body that marks it. The module treats a `429` that leaves requests in the 2 second window (`x-ratelimit-remaining` above 0) as the spent budget: the Requester throws a `RateLimitError` with `reason: 'daily'` and a `retryAt` one hour ahead, and does not sleep in process. diff --git a/packages/v1-ready/pipedrive/src/api.ts b/packages/v1-ready/pipedrive/src/api.ts index 81d3262f..1c83f4ed 100644 --- a/packages/v1-ready/pipedrive/src/api.ts +++ b/packages/v1-ready/pipedrive/src/api.ts @@ -22,11 +22,44 @@ import { ListLeadsParams, } from "./types"; +const DAILY_PROBE_INTERVAL_MS = 3_600_000; + export class Api extends OAuth2Requester { static rateLimit = { scope: "entity", - windows: [{ name: "burst", limit: 80, perMs: 2_000 }], + windows: [ + { name: "burst", limit: 80, perMs: 2_000 }, + { name: "search", limit: 10, perMs: 2_000 }, + ], parsers: ["retryAfter", "resetHeaders"], + // Pipedrive documents no marker for a spent daily budget. A 429 that + // leaves requests in the 2 s window is not the burst limit. + classify({ + status, + headers, + }: { + status?: number; + headers?: { get?(name: string): string | null }; + }) { + if (status !== 429) return null; + const remaining = Number(headers?.get?.("x-ratelimit-remaining")); + if (!(remaining > 0)) return null; + return { + reason: "daily", + waitMs: DAILY_PROBE_INTERVAL_MS, + source: "static", + }; + }, + userHints: { + daily: { + links: [ + { + label: "Pipedrive API rate limiting", + url: "https://pipedrive.readme.io/docs/core-api-concepts-rate-limiting", + }, + ], + }, + }, }; companyDomain: string | null; diff --git a/packages/v1-ready/pipedrive/test/rateLimit.test.ts b/packages/v1-ready/pipedrive/test/rateLimit.test.ts index e2ff276c..ca554deb 100644 --- a/packages/v1-ready/pipedrive/test/rateLimit.test.ts +++ b/packages/v1-ready/pipedrive/test/rateLimit.test.ts @@ -25,6 +25,8 @@ function throttledFetch(responses: FakeResponse[]) { }); } +const ONE_HOUR_MS = 3_600_000; + const ok: FakeResponse = { status: 200, body: { success: true, data: [] } }; const limited = (headers?: Record): FakeResponse => ({ status: 429, @@ -101,11 +103,71 @@ describe("Pipedrive rate limits", () => { expect(fetch).toHaveBeenCalledTimes(2); }); - it("declares the lowest documented OAuth burst allowance", () => { + describe("a 429 that leaves requests in the 2 second window", () => { + it("throws a RateLimitError that probes the daily budget again in one hour", async () => { + const fetch = throttledFetch([ + limited({ + "x-ratelimit-limit": "80", + "x-ratelimit-remaining": "79", + "x-ratelimit-reset": "2", + }), + ok, + ]); + const before = Date.now(); + + const error = await makeApi(fetch) + .listDeals() + .catch((e) => e); + + expect(error).toMatchObject({ + isRateLimited: true, + statusCode: 429, + reason: "daily", + source: "static", + waitMs: ONE_HOUR_MS, + }); + expect(error.retryAt.getTime()).toBeGreaterThanOrEqual( + before + ONE_HOUR_MS + ); + expect(fetch).toHaveBeenCalledTimes(1); + expect(delays).toEqual([]); + }); + + it("is not a limit when the status is not 429", async () => { + const fetch = throttledFetch([ + { + status: 400, + headers: { "x-ratelimit-remaining": "79" }, + body: { success: false, error: "Bad request" }, + }, + ]); + + const error = await makeApi(fetch) + .listDeals() + .catch((e) => e); + + expect(error.isRateLimited).toBeUndefined(); + expect(fetch).toHaveBeenCalledTimes(1); + }); + }); + + it("declares the lowest documented OAuth burst allowance and the search limit", () => { expect(Api.rateLimit).toMatchObject({ scope: "entity", - windows: [{ name: "burst", limit: 80, perMs: 2_000 }], + windows: [ + { name: "burst", limit: 80, perMs: 2_000 }, + { name: "search", limit: 10, perMs: 2_000 }, + ], parsers: ["retryAfter", "resetHeaders"], }); }); + + it("links the daily reason to Pipedrive's rate limiting guide", () => { + expect(Api.rateLimit.userHints.daily.links).toEqual([ + { + label: expect.any(String), + url: "https://pipedrive.readme.io/docs/core-api-concepts-rate-limiting", + }, + ]); + }); }); From aeaae18170e182d7b72851f6661f9305f3fae278 Mon Sep 17 00:00:00 2001 From: d-klotz Date: Wed, 25 Nov 2026 17:16:30 -0300 Subject: [PATCH 10/12] fix(pipedrive): drop the daily-budget guess and label a spent window as burst 3d7189f read any 429 with requests left in the 2 second window as the spent daily budget and held it for an hour. Pipedrive documents no marker for that 429, and a throttled search (10 per 2 seconds) can arrive with burst requests left, so a search would wait an hour instead of about 2 seconds. Remove the rule, its probe constant, the daily user hint and the search window, which core never reads. classify now returns reason 'burst' for a 429 with x-ratelimit-remaining of 0, so its RateLimitError is no longer 'unknown'. Retry-After and x-ratelimit-reset still supply the wait. The README lists the daily budget and the search limit as known gaps. Co-Authored-By: Claude Opus 5.5 --- packages/v1-ready/pipedrive/README.md | 11 +- packages/v1-ready/pipedrive/src/api.ts | 28 +--- .../v1-ready/pipedrive/test/rateLimit.test.ts | 121 +++++++++--------- 3 files changed, 71 insertions(+), 89 deletions(-) diff --git a/packages/v1-ready/pipedrive/README.md b/packages/v1-ready/pipedrive/README.md index 49e02787..6b7188a6 100644 --- a/packages/v1-ready/pipedrive/README.md +++ b/packages/v1-ready/pipedrive/README.md @@ -9,6 +9,11 @@ Read more on the [Frigg documentation site](https://docs.friggframework.org/api- `Api.rateLimit` tells the Frigg Requester how Pipedrive limits calls. The numbers come from [Pipedrive's rate limiting guide](https://pipedrive.readme.io/docs/core-api-concepts-rate-limiting). - **Burst:** a rolling 2 second window, counted per token. An OAuth app gets 80 requests in the window on the Lite plan, 160 on Growth, 400 on Premium and 480 on Ultimate. The module declares 80, the lowest. Pipedrive reports the real figure in `x-ratelimit-limit`. -- **A throttled call** returns `429`. When the 2 second window has no requests left (`x-ratelimit-remaining: 0`), the Requester waits for `Retry-After` when the response has one, and otherwise for `x-ratelimit-reset` (in seconds), then retries. A `429` with no `x-ratelimit-remaining` keeps the fixed backoff ladder. -- **Search:** the search endpoints (`searchPersons`, `search`) have their own limit of 10 requests per 2 seconds on every plan. The module declares it, but the Requester does not pass the request URL to the policy, so a throttled search is handled like any other `429`. -- **Daily token budget:** each company has a budget of 30,000 tokens times a plan multiplier times the number of seats. It resets at midnight in Pipedrive's server time zone. When it is spent, every call gets a `429`, and Pipedrive documents no header or body that marks it. The module treats a `429` that leaves requests in the 2 second window (`x-ratelimit-remaining` above 0) as the spent budget: the Requester throws a `RateLimitError` with `reason: 'daily'` and a `retryAt` one hour ahead, and does not sleep in process. +- **A throttled call** returns `429`. One with no requests left in the 2 second window (`x-ratelimit-remaining: 0`) is a burst limit. The Requester waits for `Retry-After` when the response has one, and otherwise for `x-ratelimit-reset` (in seconds), then retries. A `429` with neither header keeps the fixed backoff ladder. + +### Known gaps + +- **The daily token budget is not classified.** Each company has a budget of 30,000 tokens times a plan multiplier times the number of seats, reset at midnight in Pipedrive's server time zone. When it is spent, every call gets a `429`. Pipedrive documents no header or body that marks that `429`, so the module handles it as a burst limit and retries on its wait until midnight. +- **A throttled search is not told apart.** The search endpoints (`searchPersons`, `search`) have their own limit of 10 requests per 2 seconds on every plan. The Requester does not pass the request URL to `classify`, so a throttled search gets the wait of any other `429`. + +Fixing either needs a real `429` sample that marks it, or a core that passes the URL to `classify`. diff --git a/packages/v1-ready/pipedrive/src/api.ts b/packages/v1-ready/pipedrive/src/api.ts index 1c83f4ed..5d1c7672 100644 --- a/packages/v1-ready/pipedrive/src/api.ts +++ b/packages/v1-ready/pipedrive/src/api.ts @@ -22,18 +22,11 @@ import { ListLeadsParams, } from "./types"; -const DAILY_PROBE_INTERVAL_MS = 3_600_000; - export class Api extends OAuth2Requester { static rateLimit = { scope: "entity", - windows: [ - { name: "burst", limit: 80, perMs: 2_000 }, - { name: "search", limit: 10, perMs: 2_000 }, - ], + windows: [{ name: "burst", limit: 80, perMs: 2_000 }], parsers: ["retryAfter", "resetHeaders"], - // Pipedrive documents no marker for a spent daily budget. A 429 that - // leaves requests in the 2 s window is not the burst limit. classify({ status, headers, @@ -42,23 +35,8 @@ export class Api extends OAuth2Requester { headers?: { get?(name: string): string | null }; }) { if (status !== 429) return null; - const remaining = Number(headers?.get?.("x-ratelimit-remaining")); - if (!(remaining > 0)) return null; - return { - reason: "daily", - waitMs: DAILY_PROBE_INTERVAL_MS, - source: "static", - }; - }, - userHints: { - daily: { - links: [ - { - label: "Pipedrive API rate limiting", - url: "https://pipedrive.readme.io/docs/core-api-concepts-rate-limiting", - }, - ], - }, + const remaining = headers?.get?.("x-ratelimit-remaining")?.trim(); + return remaining === "0" ? { reason: "burst" } : null; }, }; diff --git a/packages/v1-ready/pipedrive/test/rateLimit.test.ts b/packages/v1-ready/pipedrive/test/rateLimit.test.ts index ca554deb..efe75995 100644 --- a/packages/v1-ready/pipedrive/test/rateLimit.test.ts +++ b/packages/v1-ready/pipedrive/test/rateLimit.test.ts @@ -25,8 +25,6 @@ function throttledFetch(responses: FakeResponse[]) { }); } -const ONE_HOUR_MS = 3_600_000; - const ok: FakeResponse = { status: 200, body: { success: true, data: [] } }; const limited = (headers?: Record): FakeResponse => ({ status: 429, @@ -94,7 +92,7 @@ describe("Pipedrive rate limits", () => { expect(fetch).toHaveBeenCalledTimes(2); }); - it("keeps the fixed backoff ladder for a 429 with no headers, as for an exhausted daily budget", async () => { + it("keeps the fixed backoff ladder for a 429 with no rate-limit headers", async () => { const fetch = throttledFetch([limited(), ok]); await makeApi(fetch).listDeals(); @@ -103,71 +101,72 @@ describe("Pipedrive rate limits", () => { expect(fetch).toHaveBeenCalledTimes(2); }); - describe("a 429 that leaves requests in the 2 second window", () => { - it("throws a RateLimitError that probes the daily budget again in one hour", async () => { - const fetch = throttledFetch([ - limited({ - "x-ratelimit-limit": "80", - "x-ratelimit-remaining": "79", - "x-ratelimit-reset": "2", - }), - ok, - ]); - const before = Date.now(); - - const error = await makeApi(fetch) - .listDeals() - .catch((e) => e); - - expect(error).toMatchObject({ - isRateLimited: true, - statusCode: 429, - reason: "daily", - source: "static", - waitMs: ONE_HOUR_MS, - }); - expect(error.retryAt.getTime()).toBeGreaterThanOrEqual( - before + ONE_HOUR_MS - ); - expect(fetch).toHaveBeenCalledTimes(1); - expect(delays).toEqual([]); - }); - - it("is not a limit when the status is not 429", async () => { - const fetch = throttledFetch([ - { - status: 400, - headers: { "x-ratelimit-remaining": "79" }, - body: { success: false, error: "Bad request" }, - }, - ]); - - const error = await makeApi(fetch) - .listDeals() - .catch((e) => e); - - expect(error.isRateLimited).toBeUndefined(); - expect(fetch).toHaveBeenCalledTimes(1); + it("reports a 429 with no requests left in the 2 second window as a burst limit", async () => { + const fetch = throttledFetch([ + limited({ + "x-ratelimit-limit": "80", + "x-ratelimit-remaining": "0", + "x-ratelimit-reset": "400", + }), + ok, + ]); + const before = Date.now(); + + const error = await makeApi(fetch) + .listDeals() + .catch((e) => e); + + expect(error).toMatchObject({ + name: "RateLimitError", + statusCode: 429, + reason: "burst", + source: "header", + waitMs: 400_000, }); + expect(error.retryAt.getTime()).toBeGreaterThanOrEqual(before + 400_000); + expect(fetch).toHaveBeenCalledTimes(1); }); - it("declares the lowest documented OAuth burst allowance and the search limit", () => { - expect(Api.rateLimit).toMatchObject({ - scope: "entity", - windows: [ - { name: "burst", limit: 80, perMs: 2_000 }, - { name: "search", limit: 10, perMs: 2_000 }, - ], - parsers: ["retryAfter", "resetHeaders"], - }); + it("waits x-ratelimit-reset for a 429 that leaves requests in the window, such as a throttled search", async () => { + const fetch = throttledFetch([ + limited({ + "x-ratelimit-limit": "80", + "x-ratelimit-remaining": "79", + "x-ratelimit-reset": "2", + }), + ok, + ]); + + const result = await makeApi(fetch).searchPersons({ term: "Ada" }); + + expect(result).toEqual({ success: true, data: [] }); + expect(delays).toEqual([2_000]); + expect(fetch).toHaveBeenCalledTimes(2); }); - it("links the daily reason to Pipedrive's rate limiting guide", () => { - expect(Api.rateLimit.userHints.daily.links).toEqual([ + it("does not treat a 400 as a limit", async () => { + const fetch = throttledFetch([ { - label: expect.any(String), - url: "https://pipedrive.readme.io/docs/core-api-concepts-rate-limiting", + status: 400, + headers: { "x-ratelimit-remaining": "0" }, + body: { success: false, error: "Bad request" }, }, ]); + + const error = await makeApi(fetch) + .listDeals() + .catch((e) => e); + + expect(error.name).toBe("FetchError"); + expect(error.statusCode).toBe(400); + expect(fetch).toHaveBeenCalledTimes(1); + }); + + it("declares the lowest documented OAuth burst allowance", () => { + expect(Api.rateLimit).toMatchObject({ + scope: "entity", + windows: [{ name: "burst", limit: 80, perMs: 2_000 }], + parsers: ["retryAfter", "resetHeaders"], + }); }); }); From 4b0e29fd01cfa36c69f9208f54177b608b969d10 Mon Sep 17 00:00:00 2001 From: d-klotz Date: Wed, 25 Nov 2026 17:16:30 -0300 Subject: [PATCH 11/12] refactor(hubspot): drop rate-limit settings core does not read - The search window: classify returns reason 'burst' for SECONDLY and core picks a window only by reason, so a window named search is never read. The 1 second SECONDLY wait stays. - maxConcurrency: core does not pace on it, and HubSpot documents no concurrency figure. - The resetHeaders parser: HubSpot sends X-HubSpot-RateLimit-* headers, not x-ratelimit-reset. Co-Authored-By: Claude Opus 5.5 --- packages/v1-ready/hubspot/api.js | 8 ++------ packages/v1-ready/hubspot/tests/rateLimit.test.js | 13 +++++-------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/packages/v1-ready/hubspot/api.js b/packages/v1-ready/hubspot/api.js index 76781bdd..d45fd182 100644 --- a/packages/v1-ready/hubspot/api.js +++ b/packages/v1-ready/hubspot/api.js @@ -6,12 +6,8 @@ const SEARCH_WINDOW_MS = 1_000; class Api extends OAuth2Requester { static rateLimit = { scope: 'entity', - windows: [ - { name: 'burst', limit: 110, perMs: 10_000 }, - { name: 'search', limit: 5, perMs: SEARCH_WINDOW_MS }, - ], - maxConcurrency: 10, - parsers: ['retryAfter', 'resetHeaders'], + windows: [{ name: 'burst', limit: 110, perMs: 10_000 }], + parsers: ['retryAfter'], classify({ status, body }) { if (status !== 429) return null; if (body?.policyName === 'SECONDLY') { diff --git a/packages/v1-ready/hubspot/tests/rateLimit.test.js b/packages/v1-ready/hubspot/tests/rateLimit.test.js index 777ae85f..bb462111 100644 --- a/packages/v1-ready/hubspot/tests/rateLimit.test.js +++ b/packages/v1-ready/hubspot/tests/rateLimit.test.js @@ -151,8 +151,8 @@ describe('HubSpot rate limits', () => { }); }); - describe('a SECONDLY 429 from a search endpoint', () => { - it('waits the 1 second search window, then retries', async () => { + describe('a SECONDLY 429, read as the search limit', () => { + it('waits 1 second, then retries', async () => { const fetch = throttledFetch([limited(searchLimitBody), ok]); const result = await makeApi(fetch).searchCompanies({}); @@ -244,12 +244,9 @@ describe('HubSpot rate limits', () => { it('declares its limits', () => { expect(Api.rateLimit).toMatchObject({ scope: 'entity', - windows: [ - { name: 'burst', limit: 110, perMs: 10_000 }, - { name: 'search', limit: 5, perMs: 1_000 }, - ], - maxConcurrency: 10, - parsers: ['retryAfter', 'resetHeaders'], + windows: [{ name: 'burst', limit: 110, perMs: 10_000 }], + parsers: ['retryAfter'], }); + expect(Api.rateLimit.maxConcurrency).toBeUndefined(); }); }); From 8b6ec50aefc46a5d0afe41b91ee0e639c8e47f11 Mon Sep 17 00:00:00 2001 From: d-klotz Date: Wed, 25 Nov 2026 17:16:30 -0300 Subject: [PATCH 12/12] docs(hubspot): state only the documented rate-limit facts HubSpot's docs name DAILY and TEN_SECONDLY_ROLLING, not SECONDLY, so the README says the module treats SECONDLY as the search limit if it appears. It also gives the burst limits of privately distributed apps next to the 110 per 10 seconds of marketplace apps. Co-Authored-By: Claude Opus 5.5 --- packages/v1-ready/hubspot/README.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/v1-ready/hubspot/README.md b/packages/v1-ready/hubspot/README.md index 4b039dd7..211b0cf6 100644 --- a/packages/v1-ready/hubspot/README.md +++ b/packages/v1-ready/hubspot/README.md @@ -119,13 +119,19 @@ colliding. `Api.rateLimit` tells the Frigg Requester how HubSpot limits calls. The numbers come from the [API usage guidelines and limits](https://developers.hubspot.com/docs/developer-tooling/platform/usage-guidelines). +HubSpot's docs name two `policyName` values for a `429`: `DAILY` and +`TEN_SECONDLY_ROLLING`. + - **Burst:** each account that installs a marketplace OAuth app is limited to 110 - requests every 10 seconds. A throttled call returns `429` with `policyName` - `TEN_SECONDLY_ROLLING`. The Requester waits for `Retry-After` when the response has - one, and for the 10 second window when it has none. + requests every 10 seconds, the figure the module declares. A privately distributed + app gets 100 (Free, Starter), 190 (Professional, Enterprise) or 250 (with the API + limit increase) requests every 10 seconds. The Requester waits for `Retry-After` + when the response has one, and for the 10 second window when it has none. - **Search:** the CRM search endpoints have their own limit of 5 requests per second - per account, outside the burst limit. A throttled search returns `429` with - `policyName` `SECONDLY`. The Requester waits 1 second, then retries. + per account, outside the burst limit. HubSpot does not document what a throttled + search returns. If a `429` has `policyName` `SECONDLY`, the module treats it as this + limit: the Requester waits 1 second, then retries. Any other search `429` gets the + burst handling. - **Daily:** a `429` with `policyName` `DAILY`. HubSpot resets the daily limit at midnight in the account's time zone, which the module does not know, so it does not compute a reset time. It reports a one hour probe interval: the Requester throws a