@@ -16,7 +16,7 @@ import {
16
16
TimeEntry
17
17
} from './toggl-types' ;
18
18
import { EnrichedCustomer , EnrichedProject } from './types' ;
19
- import { initFetch , Logger } from './utils' ;
19
+ import { initFetch , Logger , sleep } from './utils' ;
20
20
21
21
const BASE_URL = 'https://api.track.toggl.com/api/v8' ;
22
22
const TIME_ENTRIES_PATH = 'time_entries' ;
@@ -175,11 +175,14 @@ export const enrichTimeEntries = async (
175
175
billableTimeEntries : TimeEntry [ ]
176
176
) : Promise < ClientTimeEntries [ ] > => {
177
177
const customers : Grouped = { } ;
178
+ let cached = false ;
178
179
for ( const timeEntry of billableTimeEntries ) {
179
180
const { duration, pid } = timeEntry ;
180
181
181
182
const togglProject = await fetchProject ( pid ) ;
183
+ if ( ! cached ) await sleep ( 1000 ) ;
182
184
const togglCustomer = await fetchClient ( togglProject . cid ) ;
185
+ cached = true ;
183
186
184
187
const contentfulCustomers = await fetchCustomers ( ) ;
185
188
const contentfulCustomer = contentfulCustomers . find (
@@ -291,6 +294,7 @@ export async function updateTogglClients() {
291
294
( { name, notes } ) =>
292
295
notes === customer . sys . id || customer . fields . name === name
293
296
) ;
297
+ await sleep ( 1000 ) ;
294
298
await fetch ( `${ BASE_URL } /${ CLIENT_PATH } ${ found ? `/${ found . id } ` : '' } ` , {
295
299
method : found ? 'PUT' : 'POST' ,
296
300
body : JSON . stringify ( {
@@ -306,6 +310,7 @@ export async function updateTogglClients() {
306
310
307
311
export async function updateTogglProjects ( ) {
308
312
const togglClients = await fetch < Customer [ ] > ( `${ BASE_URL } /${ CLIENT_PATH } ` ) ;
313
+ await sleep ( 1000 ) ;
309
314
const togglProjects = await fetch < Project [ ] > (
310
315
`${ BASE_URL } /${ WORKSPACE_PATH } /${ WORKSPACE_ID } /${ PROJECT_PATH } `
311
316
) ;
@@ -317,6 +322,7 @@ export async function updateTogglProjects() {
317
322
const togglProject = togglProjects . find (
318
323
( { name, cid } ) => cid === togglClient . id && project . fields . name === name
319
324
) ;
325
+ await sleep ( 1000 ) ;
320
326
await fetch (
321
327
`${ BASE_URL } /${ PROJECT_PATH } ${ togglProject ? `/${ togglProject . id } ` : '' } ` ,
322
328
{
0 commit comments