@mcpher/gas-fakes 1.2.30 → 1.2.32
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 +1 -1
- package/src/cli/executor.js +32 -2
- package/src/cli/utils.js +1 -1
- package/src/support/helpers.js +1 -1
- package/src/support/sxdrive.js +24 -8
- package/src/support/utils.js +13 -1
package/package.json
CHANGED
package/src/cli/executor.js
CHANGED
|
@@ -66,6 +66,30 @@ function generateGmailSandbox(gmailSandbox) {
|
|
|
66
66
|
return temp;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
function generateCalendarSandbox(calendarSandbox) {
|
|
70
|
+
if (!calendarSandbox) return [];
|
|
71
|
+
const { calendarWhitelist, usageLimit, cleanup } = calendarSandbox;
|
|
72
|
+
const temp = [
|
|
73
|
+
"const calendarSettings = behavior.sandboxService.CalendarApp;",
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
if (calendarWhitelist && calendarWhitelist.length > 0) {
|
|
77
|
+
temp.push(
|
|
78
|
+
`calendarSettings.calendarWhitelist = ${JSON.stringify(
|
|
79
|
+
calendarWhitelist
|
|
80
|
+
)};`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
if (calendarSandbox.hasOwnProperty("cleanup")) {
|
|
84
|
+
temp.push(`calendarSettings.cleanup = ${cleanup};`);
|
|
85
|
+
}
|
|
86
|
+
if (usageLimit) {
|
|
87
|
+
// usageLimit can be a number or an object, so stringify ensures correct format.
|
|
88
|
+
temp.push(`calendarSettings.usageLimit = ${JSON.stringify(usageLimit)};`);
|
|
89
|
+
}
|
|
90
|
+
return temp;
|
|
91
|
+
}
|
|
92
|
+
|
|
69
93
|
function generateSandboxSetupScript(sandboxConfig) {
|
|
70
94
|
const script = [
|
|
71
95
|
"const behavior = ScriptApp.__behavior;",
|
|
@@ -73,12 +97,18 @@ function generateSandboxSetupScript(sandboxConfig) {
|
|
|
73
97
|
"behavior.strictSandbox = true;",
|
|
74
98
|
];
|
|
75
99
|
|
|
76
|
-
const {
|
|
77
|
-
|
|
100
|
+
const {
|
|
101
|
+
whitelistServices,
|
|
102
|
+
blacklistServices,
|
|
103
|
+
whitelistItems,
|
|
104
|
+
gmailSandbox,
|
|
105
|
+
calendarSandbox,
|
|
106
|
+
} = sandboxConfig;
|
|
78
107
|
|
|
79
108
|
script.push(...generateServiceWhitelistScript(whitelistServices));
|
|
80
109
|
script.push(...generateServiceBlacklistScript(blacklistServices));
|
|
81
110
|
script.push(...generateGmailSandbox(gmailSandbox));
|
|
111
|
+
script.push(...generateCalendarSandbox(calendarSandbox));
|
|
82
112
|
|
|
83
113
|
const itemWhitelist = generateItemWhitelistScript(whitelistItems);
|
|
84
114
|
if (itemWhitelist) {
|
package/src/cli/utils.js
CHANGED
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","md5Checksum","size"]
|
|
36
|
+
const minFieldsList = ["name","id","mimeType","kind","parents","md5Checksum","size","trashed","createdTime","modifiedTime"]
|
|
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
|
package/src/support/sxdrive.js
CHANGED
|
@@ -11,6 +11,7 @@ import intoStream from 'into-stream';
|
|
|
11
11
|
import { getStreamAsBuffer } from 'get-stream';
|
|
12
12
|
import { syncWarn, syncError, syncLog } from './workersync/synclogger.js';
|
|
13
13
|
import { getDriveApiClient } from '../services/advdrive/drapis.js';
|
|
14
|
+
import { translateFieldsToV2 } from './utils.js';
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -60,6 +61,17 @@ export const sxDrive = async (Auth, { prop, method, params, options }) => {
|
|
|
60
61
|
|
|
61
62
|
const isRetryable = [429, 500, 503].includes(response?.status) || error?.code == 429;
|
|
62
63
|
|
|
64
|
+
// handle invalid field selection - sometimes old files dont support createdTime or modifiedTime
|
|
65
|
+
// we'll try to fallback to createdDate and modifiedDate
|
|
66
|
+
const isInvalidField = error?.message?.includes("Invalid field selection") && (params?.fields?.includes("createdTime") || params?.fields?.includes("modifiedTime"));
|
|
67
|
+
|
|
68
|
+
if (isInvalidField && i < maxRetries - 1) {
|
|
69
|
+
const fileId = params?.fileId ? ` for file ${params.fileId}` : "";
|
|
70
|
+
syncWarn(`Invalid field selection error on Drive API call ${prop}.${method}${fileId}. Retrying with v2 field names...`);
|
|
71
|
+
params.fields = translateFieldsToV2(params.fields);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
|
|
63
75
|
if (isRetryable && i < maxRetries - 1) {
|
|
64
76
|
// add a random jitter to avoid thundering herd
|
|
65
77
|
const jitter = Math.floor(Math.random() * 1000);
|
|
@@ -173,10 +185,12 @@ const sxStreamer = async ({
|
|
|
173
185
|
*/
|
|
174
186
|
export const sxDriveExport = async (_, { id: fileId, mimeType }) => {
|
|
175
187
|
|
|
176
|
-
return sxStreamer({
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
188
|
+
return sxStreamer({
|
|
189
|
+
params: {
|
|
190
|
+
fileId,
|
|
191
|
+
mimeType
|
|
192
|
+
}, method: 'export'
|
|
193
|
+
})
|
|
180
194
|
|
|
181
195
|
}
|
|
182
196
|
/**
|
|
@@ -187,10 +201,12 @@ export const sxDriveExport = async (_, { id: fileId, mimeType }) => {
|
|
|
187
201
|
*/
|
|
188
202
|
export const sxDriveMedia = async (_, { id: fileId }) => {
|
|
189
203
|
|
|
190
|
-
return sxStreamer({
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
204
|
+
return sxStreamer({
|
|
205
|
+
params: {
|
|
206
|
+
fileId,
|
|
207
|
+
alt: 'media'
|
|
208
|
+
}, method: 'get'
|
|
209
|
+
})
|
|
194
210
|
|
|
195
211
|
}
|
|
196
212
|
|
package/src/support/utils.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import is from '@sindresorhus/is';
|
|
4
4
|
import { assert } from '@sindresorhus/is'
|
|
5
|
-
import {slogger} from './slogger.js'
|
|
5
|
+
import { slogger } from './slogger.js'
|
|
6
6
|
|
|
7
7
|
const isNU = (item) => is.null(item) || is.undefined(item)
|
|
8
8
|
|
|
@@ -171,6 +171,18 @@ export const mergeParamStrings = (...args) => {
|
|
|
171
171
|
}).sort().join(",")
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
/**
|
|
175
|
+
* translated field names from v3 to v2
|
|
176
|
+
* @param {string} fields a comma separated fields string
|
|
177
|
+
* @returns {string} the modified string
|
|
178
|
+
*/
|
|
179
|
+
export const translateFieldsToV2 = (fields) => {
|
|
180
|
+
if (!is.string(fields)) return fields
|
|
181
|
+
return fields
|
|
182
|
+
.replace(/\bcreatedTime\b/g, 'createdDate')
|
|
183
|
+
.replace(/\bmodifiedTime\b/g, 'modifiedDate')
|
|
184
|
+
}
|
|
185
|
+
|
|
174
186
|
const capital = (str) => str.substring(0, 1).toUpperCase() + str.substring(1)
|
|
175
187
|
const unCapital = (str) => str.substring(0, 1).toLowerCase() + str.substring(1)
|
|
176
188
|
|