Skip to content

Commit 6c399b8

Browse files
authored
Google contacts batch sync (#2567)
* add quota limiter with conf set from env vars * add: respect quota limits and use batch sync * update, refactor unit tests * remove non-null assertions
1 parent a959420 commit 6c399b8

File tree

9 files changed

+1407
-408
lines changed

9 files changed

+1407
-408
lines changed

.env.docker

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,20 @@ AZURE_CLIENT_ID = your_azure_client_id # ( REQUIRED ) Azure client ID
122122
AZURE_SECRET = your_azure_client_secret # ( REQUIRED ) Azure secret
123123

124124

125+
# ==============| GOOGLE CONTACTS Sync |============= #
126+
127+
# Critical Read Operations (API Limit: 90/min)
128+
GOOGLE_CONTACTS_CRITICAL_READ_REQUESTS = 80 # ( OPTIONAL ) Number of requests allowed per interval
129+
GOOGLE_CONTACTS_CRITICAL_READ_INTERVAL = 60 # ( OPTIONAL ) Rate limit interval in seconds
130+
131+
# Critical Write Operations (API Limit: 90/min)
132+
GOOGLE_CONTACTS_CRITICAL_WRITE_REQUESTS = 80 # ( OPTIONAL ) Number of requests allowed per interval
133+
GOOGLE_CONTACTS_CRITICAL_WRITE_INTERVAL = 60 # ( OPTIONAL ) Rate limit interval in seconds
134+
135+
# Read Operations - Groups (API Limit: 120/min)
136+
GOOGLE_CONTACTS_READ_REQUESTS = 110 # ( OPTIONAL ) Number of requests allowed per interval
137+
GOOGLE_CONTACTS_READ_INTERVAL = 60 # ( OPTIONAL ) Rate limit interval in seconds
138+
139+
# Write Operations - Groups/Delete (API Limit: 90/min)
140+
GOOGLE_CONTACTS_WRITE_REQUESTS = 80 # ( OPTIONAL ) Number of requests allowed per interval
141+
GOOGLE_CONTACTS_WRITE_INTERVAL = 60 # ( OPTIONAL ) Rate limit interval in seconds

backend/.env.dev

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,21 @@ ENRICH_LAYER_API_KEY = test-api-key
124124
# ==============| THIRD-PARTY - IMAP EMAIL FETCHING SERVICE |============= #
125125
EMAIL_FETCHING_SERVICE_URL = http://localhost:8084
126126
EMAIL_FETCHING_SERVICE_API_TOKEN = "test-key"
127+
128+
# ==============| GOOGLE CONTACTS Sync |============= #
129+
130+
# Critical Read Operations (API Limit: 90/min)
131+
GOOGLE_CONTACTS_CRITICAL_READ_REQUESTS = 80 # ( OPTIONAL ) Number of requests allowed per interval
132+
GOOGLE_CONTACTS_CRITICAL_READ_INTERVAL = 60 # ( OPTIONAL ) Rate limit interval in seconds
133+
134+
# Critical Write Operations (API Limit: 90/min)
135+
GOOGLE_CONTACTS_CRITICAL_WRITE_REQUESTS = 80 # ( OPTIONAL ) Number of requests allowed per interval
136+
GOOGLE_CONTACTS_CRITICAL_WRITE_INTERVAL = 60 # ( OPTIONAL ) Rate limit interval in seconds
137+
138+
# Read Operations - Groups (API Limit: 120/min)
139+
GOOGLE_CONTACTS_READ_REQUESTS = 110 # ( OPTIONAL ) Number of requests allowed per interval
140+
GOOGLE_CONTACTS_READ_INTERVAL = 60 # ( OPTIONAL ) Rate limit interval in seconds
141+
142+
# Write Operations - Groups/Delete (API Limit: 90/min)
143+
GOOGLE_CONTACTS_WRITE_REQUESTS = 80 # ( OPTIONAL ) Number of requests allowed per interval
144+
GOOGLE_CONTACTS_WRITE_INTERVAL = 60 # ( OPTIONAL ) Rate limit interval in seconds

backend/src/config/schema.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,31 @@ const schema = z.object({
117117
ENRICH_LAYER_URL: z.string().min(1).optional(),
118118
ENRICH_LAYER_API_KEY: z.string().min(1).optional(),
119119

120+
/** GOOGLE CONTACTS SYNC */
121+
GOOGLE_CONTACTS_CRITICAL_READ_REQUESTS: z.coerce
122+
.number()
123+
.positive()
124+
.default(80),
125+
GOOGLE_CONTACTS_CRITICAL_READ_INTERVAL: z.coerce
126+
.number()
127+
.positive()
128+
.default(60),
129+
130+
GOOGLE_CONTACTS_CRITICAL_WRITE_REQUESTS: z.coerce
131+
.number()
132+
.positive()
133+
.default(80),
134+
GOOGLE_CONTACTS_CRITICAL_WRITE_INTERVAL: z.coerce
135+
.number()
136+
.positive()
137+
.default(60),
138+
139+
GOOGLE_CONTACTS_READ_REQUESTS: z.coerce.number().positive().default(110),
140+
GOOGLE_CONTACTS_READ_INTERVAL: z.coerce.number().positive().default(60),
141+
142+
GOOGLE_CONTACTS_WRITE_REQUESTS: z.coerce.number().positive().default(80),
143+
GOOGLE_CONTACTS_WRITE_INTERVAL: z.coerce.number().positive().default(60),
144+
120145
NODE_ENV: z.enum(['development', 'production', 'test']).default('production')
121146
});
122147

backend/src/controllers/contacts.controller.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ async function validateRequest(
3232
}
3333

3434
let googleContactsOptions: ExportOptions['googleContactsOptions'] = {
35+
userId: user.id,
3536
accessToken: undefined,
3637
refreshToken: undefined,
3738
updateEmptyFieldsOnly
@@ -44,9 +45,9 @@ async function validateRequest(
4445
)) as OAuthMiningSourceCredentials;
4546

4647
googleContactsOptions = {
48+
...googleContactsOptions,
4749
accessToken: oauthCredentials?.accessToken,
48-
refreshToken: oauthCredentials?.refreshToken,
49-
updateEmptyFieldsOnly
50+
refreshToken: oauthCredentials?.refreshToken
5051
};
5152
}
5253

0 commit comments

Comments
 (0)