@pipedream/harvest 0.0.6 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -12
- package/actions/create-invoice/create-invoice.mjs +116 -0
- package/actions/create-project/create-project.mjs +138 -0
- package/actions/create-task-assignment/create-task-assignment.mjs +77 -0
- package/actions/create-timesheet-entry/create-timesheet-entry.mjs +39 -38
- package/actions/create-user/create-user.mjs +109 -0
- package/actions/create-user-assignment/create-user-assignment.mjs +85 -0
- package/actions/delete-invoice/delete-invoice.mjs +38 -0
- package/actions/delete-project/delete-project.mjs +38 -0
- package/actions/delete-task-assignment/delete-task-assignment.mjs +45 -0
- package/actions/delete-time-entry/delete-time-entry.mjs +38 -0
- package/actions/delete-user/delete-user.mjs +39 -0
- package/actions/delete-user-assignment/delete-user-assignment.mjs +45 -0
- package/actions/get-invoice/get-invoice.mjs +39 -0
- package/actions/get-me/get-me.mjs +32 -0
- package/actions/get-project/get-project.mjs +39 -0
- package/actions/get-projects/get-projects.mjs +20 -12
- package/actions/get-task-assignment/get-task-assignment.mjs +46 -0
- package/actions/get-time-entry/get-time-entry.mjs +39 -0
- package/actions/get-time-report/get-time-report.mjs +80 -0
- package/actions/get-user/get-user.mjs +40 -0
- package/actions/get-user-assignment/get-user-assignment.mjs +46 -0
- package/actions/list-account-id-options/list-account-id-options.mjs +33 -0
- package/actions/list-clients/list-clients.mjs +57 -0
- package/actions/list-invoices/list-invoices.mjs +86 -0
- package/actions/list-task-assignments/list-task-assignments.mjs +66 -0
- package/actions/list-tasks/list-tasks.mjs +57 -0
- package/actions/list-time-entries/list-time-entries.mjs +150 -0
- package/actions/list-user-assignments/list-user-assignments.mjs +74 -0
- package/actions/list-users/list-users.mjs +57 -0
- package/actions/start-timer/start-timer.mjs +9 -6
- package/actions/stop-timer/stop-timer.mjs +9 -6
- package/actions/update-invoice/update-invoice.mjs +114 -0
- package/actions/update-project/update-project.mjs +140 -0
- package/actions/update-task-assignment/update-task-assignment.mjs +77 -0
- package/actions/update-time-entry/update-time-entry.mjs +92 -0
- package/actions/update-user/update-user.mjs +106 -0
- package/actions/update-user-assignment/update-user-assignment.mjs +84 -0
- package/common/constants.mjs +51 -1
- package/common/utils.mjs +50 -1
- package/harvest.app.mjs +683 -110
- package/package.json +3 -3
- package/sources/new-invoice-entry/new-invoice-entry.mjs +1 -1
- package/sources/new-timesheet-entry/new-timesheet-entry.mjs +1 -1
package/common/utils.mjs
CHANGED
|
@@ -1,3 +1,52 @@
|
|
|
1
|
+
import constants from "./constants.mjs";
|
|
2
|
+
|
|
3
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
4
|
+
|
|
5
|
+
// Caps how long a single Retry-After wait can be, so a large or misbehaving header value
|
|
6
|
+
// (e.g. an intermediate proxy or a monthly-limit response) can't block execution for
|
|
7
|
+
// unpredictably long stretches across maxRetries attempts.
|
|
8
|
+
const MAX_RETRY_AFTER_MS = 30000;
|
|
9
|
+
|
|
10
|
+
/* Retries a single request on 429, honoring the response's Retry-After header (seconds)
|
|
11
|
+
instead of guessing a backoff. Falls through unchanged for any other status/error. */
|
|
12
|
+
const withRetryAfter = async (fn, maxRetries = 3) => {
|
|
13
|
+
for (let attempt = 0; ; attempt++) {
|
|
14
|
+
try {
|
|
15
|
+
return await fn();
|
|
16
|
+
} catch (err) {
|
|
17
|
+
const status = err?.response?.status ?? err?.status;
|
|
18
|
+
if (status !== 429 || attempt >= maxRetries) {
|
|
19
|
+
throw err;
|
|
20
|
+
}
|
|
21
|
+
const retryAfterSeconds = Number(err?.response?.headers?.["retry-after"]);
|
|
22
|
+
const delayMs = Number.isFinite(retryAfterSeconds) && retryAfterSeconds > 0
|
|
23
|
+
? Math.min(retryAfterSeconds * 1000, MAX_RETRY_AFTER_MS)
|
|
24
|
+
: constants.RATE_LIMIT_BATCH_DELAY_MS;
|
|
25
|
+
await sleep(delayMs);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/* Runs fn over items in small concurrent batches, pausing between batches, so callers
|
|
31
|
+
don't blow through Harvest's rate limit with an unbounded Promise.all. Fails fast: the
|
|
32
|
+
first rejection (after any retries inside fn) propagates immediately and no partial
|
|
33
|
+
results are returned. */
|
|
34
|
+
const mapWithRateLimit = async (items, fn, {
|
|
35
|
+
batchSize = constants.RATE_LIMIT_BATCH_SIZE,
|
|
36
|
+
delayMs = constants.RATE_LIMIT_BATCH_DELAY_MS,
|
|
37
|
+
} = {}) => {
|
|
38
|
+
const results = [];
|
|
39
|
+
for (let i = 0; i < items.length; i += batchSize) {
|
|
40
|
+
const batch = items.slice(i, i + batchSize);
|
|
41
|
+
const batchResults = await Promise.all(batch.map(fn));
|
|
42
|
+
results.push(...batchResults);
|
|
43
|
+
if (i + batchSize < items.length) {
|
|
44
|
+
await sleep(delayMs);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return results;
|
|
48
|
+
};
|
|
49
|
+
|
|
1
50
|
const removeNullEntries = (obj) =>
|
|
2
51
|
obj && Object.entries(obj).reduce((acc, [
|
|
3
52
|
key,
|
|
@@ -62,5 +111,5 @@ const isValidTime = (timeString) => {
|
|
|
62
111
|
};
|
|
63
112
|
|
|
64
113
|
export {
|
|
65
|
-
removeNullEntries, isValidDate, isValidTime,
|
|
114
|
+
removeNullEntries, isValidDate, isValidTime, mapWithRateLimit, withRetryAfter,
|
|
66
115
|
};
|