@@ -16,7 +16,7 @@ import {
1616 TimeEntry
1717} from './toggl-types' ;
1818import { EnrichedCustomer , EnrichedProject } from './types' ;
19- import { initFetch , Logger } from './utils' ;
19+ import { initFetch , Logger , sleep } from './utils' ;
2020
2121const BASE_URL = 'https://api.track.toggl.com/api/v8' ;
2222const TIME_ENTRIES_PATH = 'time_entries' ;
@@ -175,11 +175,14 @@ export const enrichTimeEntries = async (
175175 billableTimeEntries : TimeEntry [ ]
176176) : Promise < ClientTimeEntries [ ] > => {
177177 const customers : Grouped = { } ;
178+ let cached = false ;
178179 for ( const timeEntry of billableTimeEntries ) {
179180 const { duration, pid } = timeEntry ;
180181
181182 const togglProject = await fetchProject ( pid ) ;
183+ if ( ! cached ) await sleep ( 1000 ) ;
182184 const togglCustomer = await fetchClient ( togglProject . cid ) ;
185+ cached = true ;
183186
184187 const contentfulCustomers = await fetchCustomers ( ) ;
185188 const contentfulCustomer = contentfulCustomers . find (
@@ -291,6 +294,7 @@ export async function updateTogglClients() {
291294 ( { name, notes } ) =>
292295 notes === customer . sys . id || customer . fields . name === name
293296 ) ;
297+ await sleep ( 1000 ) ;
294298 await fetch ( `${ BASE_URL } /${ CLIENT_PATH } ${ found ? `/${ found . id } ` : '' } ` , {
295299 method : found ? 'PUT' : 'POST' ,
296300 body : JSON . stringify ( {
@@ -306,6 +310,7 @@ export async function updateTogglClients() {
306310
307311export async function updateTogglProjects ( ) {
308312 const togglClients = await fetch < Customer [ ] > ( `${ BASE_URL } /${ CLIENT_PATH } ` ) ;
313+ await sleep ( 1000 ) ;
309314 const togglProjects = await fetch < Project [ ] > (
310315 `${ BASE_URL } /${ WORKSPACE_PATH } /${ WORKSPACE_ID } /${ PROJECT_PATH } `
311316 ) ;
@@ -317,6 +322,7 @@ export async function updateTogglProjects() {
317322 const togglProject = togglProjects . find (
318323 ( { name, cid } ) => cid === togglClient . id && project . fields . name === name
319324 ) ;
325+ await sleep ( 1000 ) ;
320326 await fetch (
321327 `${ BASE_URL } /${ PROJECT_PATH } ${ togglProject ? `/${ togglProject . id } ` : '' } ` ,
322328 {
0 commit comments