@mcpher/gas-fakes 1.2.28 → 1.2.30
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/package.json +2 -2
- package/src/services/calendarapp/fakecalendar.js +81 -11
- package/src/services/calendarapp/fakecalendarapp.js +133 -1
- package/src/services/calendarapp/fakecalendarevent.js +507 -1
- package/src/services/calendarapp/fakecalendareventseries.js +412 -0
- package/src/services/calendarapp/fakeeventguest.js +44 -0
- package/src/services/calendarapp/fakeeventrecurrence.js +38 -1
- package/src/services/calendarapp/fakerecurrencerule.js +48 -0
- package/src/services/enums/calendarenums.js +42 -37
- package/src/services/gmailapp/fakegmailapp.js +6 -10
- package/src/services/scriptapp/behavior.js +19 -25
- package/src/support/backoff.js +7 -1
- package/src/support/helpers.js +1 -1
- package/src/support/sxcalendar.js +15 -3
|
@@ -342,38 +342,32 @@ class FakeBehavior {
|
|
|
342
342
|
return this.__sandboxMode;
|
|
343
343
|
}
|
|
344
344
|
addFile(id) {
|
|
345
|
-
if (
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
this.__createdIds.add(id);
|
|
352
|
-
}
|
|
345
|
+
if (!is.nonEmptyString(id)) {
|
|
346
|
+
throw new Error(`Invalid sandbox id parameter (${id}) - must be a non-empty string`);
|
|
347
|
+
}
|
|
348
|
+
if (!this.isKnown(id)) {
|
|
349
|
+
slogger.log(`...adding file ${id} to sandbox allowed list`);
|
|
350
|
+
this.__createdIds.add(id);
|
|
353
351
|
}
|
|
354
352
|
return id
|
|
355
353
|
}
|
|
356
354
|
addGmailId(id) {
|
|
357
|
-
if (
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
this.__createdGmailIds.add(id);
|
|
364
|
-
}
|
|
355
|
+
if (!is.nonEmptyString(id)) {
|
|
356
|
+
throw new Error(`Invalid sandbox id parameter (${id}) - must be a non-empty string`);
|
|
357
|
+
}
|
|
358
|
+
if (!this.isKnownGmail(id)) {
|
|
359
|
+
slogger.log(`...adding gmail id ${id} to sandbox allowed list`);
|
|
360
|
+
this.__createdGmailIds.add(id);
|
|
365
361
|
}
|
|
366
362
|
return id
|
|
367
363
|
}
|
|
368
364
|
addCalendarId(id) {
|
|
369
|
-
if (
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
this.__createdCalendarIds.add(id);
|
|
376
|
-
}
|
|
365
|
+
if (!is.nonEmptyString(id)) {
|
|
366
|
+
throw new Error(`Invalid sandbox id parameter (${id}) - must be a non-empty string`);
|
|
367
|
+
}
|
|
368
|
+
if (!this.isKnownCalendar(id)) {
|
|
369
|
+
slogger.log(`...adding calendar id ${id} to sandbox allowed list`);
|
|
370
|
+
this.__createdCalendarIds.add(id);
|
|
377
371
|
}
|
|
378
372
|
return id
|
|
379
373
|
}
|
|
@@ -549,7 +543,7 @@ class FakeBehavior {
|
|
|
549
543
|
trashedCalendars = Array.from(this.__createdCalendarIds).reduce((acc, id) => {
|
|
550
544
|
try {
|
|
551
545
|
// Delete calendar
|
|
552
|
-
Calendar.Calendars.delete(id);
|
|
546
|
+
Calendar.Calendars.delete(id, { noLog404: true });
|
|
553
547
|
slogger.log(`...deleted calendar ${id}`);
|
|
554
548
|
acc.push(id);
|
|
555
549
|
} catch (e) {
|
package/src/support/backoff.js
CHANGED
|
@@ -7,7 +7,13 @@ const defaultOptions = {
|
|
|
7
7
|
initialDelay: 100,
|
|
8
8
|
factor: 2,
|
|
9
9
|
jitter: true,
|
|
10
|
-
shouldRetry: (err) => [429, 500, 503].includes(err.response?.status) ||
|
|
10
|
+
shouldRetry: (err) => [429, 500, 503].includes(err.response?.status) ||
|
|
11
|
+
err.code == 429 ||
|
|
12
|
+
(err.response?.status === 403 && (
|
|
13
|
+
err.message?.toLowerCase().includes('usage limit') ||
|
|
14
|
+
err.message?.toLowerCase().includes('rate limit') ||
|
|
15
|
+
err.errors?.some(e => ['rateLimitExceeded', 'userRateLimitExceeded', 'calendarUsageLimitsExceeded'].includes(e.reason))
|
|
16
|
+
)),
|
|
11
17
|
onRetry: () => {},
|
|
12
18
|
};
|
|
13
19
|
|
package/src/support/helpers.js
CHANGED
|
@@ -33,7 +33,7 @@ export const wontBeImplemented = (item="That") => {
|
|
|
33
33
|
throw new Error(mess)
|
|
34
34
|
}
|
|
35
35
|
// added parents to the minfield length as its often needed
|
|
36
|
-
const minFieldsList = ["name","id","mimeType","kind","parents"]
|
|
36
|
+
const minFieldsList = ["name","id","mimeType","kind","parents","md5Checksum","size"]
|
|
37
37
|
/**
|
|
38
38
|
* minimum fields these are the filds I'll take back from the API to enable basic DriveApp - these are the defaults returned by the api
|
|
39
39
|
* any other will be picked up on demand
|
|
@@ -29,19 +29,27 @@ export const sxCalendar = async (Auth, { prop, method, params, options = {} }) =
|
|
|
29
29
|
const maxRetries = 7;
|
|
30
30
|
let delay = 1777;
|
|
31
31
|
|
|
32
|
+
const { noLog404, ...validParams } = params || {};
|
|
33
|
+
|
|
32
34
|
for (let i = 0; i < maxRetries; i++) {
|
|
33
35
|
let response;
|
|
34
36
|
let error;
|
|
35
37
|
|
|
36
38
|
try {
|
|
37
39
|
const callish = apiClient[prop];
|
|
38
|
-
response = await callish[method](
|
|
40
|
+
response = await callish[method](validParams, options);
|
|
39
41
|
} catch (err) {
|
|
40
42
|
error = err;
|
|
41
43
|
response = err.response;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
const isRetryable = [429, 500, 503].includes(response?.status) ||
|
|
46
|
+
const isRetryable = [429, 500, 503].includes(response?.status) ||
|
|
47
|
+
error?.code == 429 ||
|
|
48
|
+
(response?.status === 403 && (
|
|
49
|
+
error?.message?.toLowerCase().includes('usage limit') ||
|
|
50
|
+
error?.message?.toLowerCase().includes('rate limit') ||
|
|
51
|
+
error?.errors?.some(e => ['rateLimitExceeded', 'userRateLimitExceeded', 'calendarUsageLimitsExceeded'].includes(e.reason))
|
|
52
|
+
));
|
|
45
53
|
|
|
46
54
|
if (isRetryable && i < maxRetries - 1) {
|
|
47
55
|
// add a random jitter to avoid thundering herd
|
|
@@ -53,7 +61,11 @@ export const sxCalendar = async (Auth, { prop, method, params, options = {} }) =
|
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
if (error || isRetryable) {
|
|
56
|
-
|
|
64
|
+
if (noLog404 && (response?.status === 404 || error?.code === 404 || response?.status === 400 || error?.code === 400)) {
|
|
65
|
+
// Suppress logging for expected 404s (or 400s which can happen if already deleted)
|
|
66
|
+
} else {
|
|
67
|
+
syncError(`Failed in sxCalendar for ${prop}.${method}`, error);
|
|
68
|
+
}
|
|
57
69
|
return { data: null, response: responseSyncify(response) };
|
|
58
70
|
}
|
|
59
71
|
return { data: response.data, response: responseSyncify(response) };
|