@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 CHANGED
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "name": "@mcpher/gas-fakes",
36
36
  "author": "bruce mcpherson",
37
- "version": "1.2.30",
37
+ "version": "1.2.32",
38
38
  "license": "MIT",
39
39
  "main": "main.js",
40
40
  "description": "A proof of concept implementation of Apps Script Environment on Node",
@@ -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 { whitelistServices, blacklistServices, whitelistItems, gmailSandbox } =
77
- sandboxConfig;
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
@@ -4,7 +4,7 @@ const require = createRequire(import.meta.url);
4
4
  const pjson = require("../../package.json");
5
5
 
6
6
  export const VERSION = pjson.version;
7
- export const CLI_VERSION = "0.0.19";
7
+ export const CLI_VERSION = "0.0.20";
8
8
  export const MCP_VERSION = "0.0.7";
9
9
 
10
10
  /**
@@ -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
@@ -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({ params: {
177
- fileId,
178
- mimeType
179
- }, method: 'export' })
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({params: {
191
- fileId,
192
- alt: 'media'
193
- }, method: 'get' })
204
+ return sxStreamer({
205
+ params: {
206
+ fileId,
207
+ alt: 'media'
208
+ }, method: 'get'
209
+ })
194
210
 
195
211
  }
196
212
 
@@ -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