@sentry/junior-google 0.320.0 → 0.322.0

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.
Files changed (2) hide show
  1. package/dist/index.js +20 -11
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1314,20 +1314,23 @@ function viewerIsOnEvent(event, viewer) {
1314
1314
  ...(event.attendees ?? []).map((attendee) => attendee.email)
1315
1315
  ].some((email) => email?.toLowerCase() === viewer);
1316
1316
  }
1317
- const EVENT_READ_TTL_MS = 1e4;
1317
+ const EVENT_READ_TTL_MS = 3e5;
1318
1318
  /**
1319
1319
  * Read the linked event from Junior's calendar. Nothing for an event on
1320
1320
  * another calendar, or one that Google no longer returns.
1321
1321
  */
1322
- async function readLinkedEvent(ctx, url) {
1322
+ async function readLinkedEvent(ctx, url, options) {
1323
1323
  const config = readGoogleConfig();
1324
1324
  const link = calendarLink(url);
1325
1325
  const eventId = config && link && parseEventLink(link, config.accountEmail);
1326
1326
  if (!eventId) return null;
1327
- return await ctx.cache.getOrLoad(`calendar-event:${eventId}`, async () => ({
1327
+ const key = `calendar-event:${eventId}`;
1328
+ if (ctx.cacheOnly) return await ctx.cache.get(key, { stale: true }) ?? null;
1329
+ return await ctx.cache.getOrLoad(key, async () => ({
1330
+ staleIfError: true,
1328
1331
  value: await fetchLinkedEvent(ctx, eventId),
1329
1332
  ttlMs: EVENT_READ_TTL_MS
1330
- }));
1333
+ }), options);
1331
1334
  }
1332
1335
  async function fetchLinkedEvent(ctx, eventId) {
1333
1336
  const response = await googleApiRequest(ctx, {
@@ -1344,7 +1347,8 @@ async function fetchLinkedEvent(ctx, eventId) {
1344
1347
  return parsed.success ? parsed.data : null;
1345
1348
  }
1346
1349
  async function canViewGoogleCalendarLink(ctx, url) {
1347
- const event = await readLinkedEvent(ctx, url);
1350
+ if (ctx.cacheOnly) return true;
1351
+ const event = await readLinkedEvent(ctx, url, { refresh: true });
1348
1352
  return !!event && viewerIsOnEvent(event, ctx.viewer.email.toLowerCase());
1349
1353
  }
1350
1354
  async function resolveGoogleCalendarLink(ctx, url) {
@@ -1399,6 +1403,7 @@ const googleCalendarLinks = {
1399
1403
  filters: CALENDAR_EVENT_FILTERS
1400
1404
  }
1401
1405
  }],
1406
+ cacheOnlyReads: true,
1402
1407
  canView: canViewGoogleCalendarLink,
1403
1408
  label: (url) => calendarLink(url) ? "Calendar event" : void 0,
1404
1409
  objectTypes: ["calendar_event"],
@@ -1557,7 +1562,7 @@ function parseFileLink(url) {
1557
1562
  if (root === "drive" && segment === "folders") return fileLink(url, id, (mimeType) => mimeType === FOLDER_MIME_TYPE);
1558
1563
  return url.pathname === "/open" ? fileLink(url, url.searchParams.get("id"), () => true) : void 0;
1559
1564
  }
1560
- const FILE_READ_TTL_MS = 1e4;
1565
+ const FILE_READ_TTL_MS = 3e5;
1561
1566
  async function fetchFile(ctx, file) {
1562
1567
  const response = await googleApiRequest(ctx, {
1563
1568
  headers: resourceKeyHeaders(file),
@@ -1580,12 +1585,14 @@ function fitsLink(file, link) {
1580
1585
  * Nothing when the account cannot open it, it is trashed, or it does not fit
1581
1586
  * the link.
1582
1587
  */
1583
- async function readLinkedFile(ctx, link) {
1588
+ async function readLinkedFile(ctx, link, options) {
1584
1589
  const { fileId, resourceKey } = link.file;
1585
- const file = await ctx.cache.getOrLoad(`drive-file:${fileId}:${resourceKey ?? ""}`, async () => ({
1590
+ const key = `drive-file:${fileId}:${resourceKey ?? ""}`;
1591
+ const file = ctx.cacheOnly ? await ctx.cache.get(key, { stale: true }) ?? null : await ctx.cache.getOrLoad(key, async () => ({
1592
+ staleIfError: true,
1586
1593
  value: await fetchFile(ctx, link.file),
1587
1594
  ttlMs: FILE_READ_TTL_MS
1588
- }));
1595
+ }), options);
1589
1596
  return fitsLink(file, link) ? file : void 0;
1590
1597
  }
1591
1598
  /**
@@ -1621,7 +1628,8 @@ function thumbnailFileLink(ref) {
1621
1628
  async function canViewGoogleFileLink(ctx, url) {
1622
1629
  const config = readGoogleConfig();
1623
1630
  const link = parseFileLink(url);
1624
- const file = config && link && await readLinkedFile(ctx, link);
1631
+ if (ctx.cacheOnly) return !!config && !!link;
1632
+ const file = config && link && await readLinkedFile(ctx, link, { refresh: true });
1625
1633
  return !!file && await personCanOpenFile(ctx, ctx.viewer.email, {
1626
1634
  ...file,
1627
1635
  resourceKey: link.file.resourceKey
@@ -1632,7 +1640,7 @@ async function resolveGoogleFileLink(ctx, url) {
1632
1640
  const file = link && await readLinkedFile(ctx, link);
1633
1641
  if (!link || !file) return void 0;
1634
1642
  const type = googleFileType(file.mimeType);
1635
- const summary = type === "document" ? await docSummary(ctx, link.file) : void 0;
1643
+ const summary = type === "document" && !ctx.cacheOnly ? await docSummary(ctx, link.file) : void 0;
1636
1644
  const modifiedAtMs = file.modifiedTime ? Date.parse(file.modifiedTime) : NaN;
1637
1645
  const thumbnailUrl = !type && file.thumbnailLink ? ctx.imagePath(thumbnailRef(file, link), Number.isFinite(modifiedAtMs) ? String(modifiedAtMs) : void 0) : void 0;
1638
1646
  const owner = file.owners?.[0];
@@ -1681,6 +1689,7 @@ const googleFileLinks = {
1681
1689
  path: "/open"
1682
1690
  }
1683
1691
  ],
1692
+ cacheOnlyReads: true,
1684
1693
  canView: canViewGoogleFileLink,
1685
1694
  objectTypes: ["document"],
1686
1695
  readTool: (object) => object.displayType && GOOGLE_FILE_DISPLAY_TYPES.has(object.displayType) ? "readGoogleFile" : void 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/junior-google",
3
- "version": "0.320.0",
3
+ "version": "0.322.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -22,7 +22,7 @@
22
22
  "migrations"
23
23
  ],
24
24
  "dependencies": {
25
- "@sentry/junior-plugin-api": "0.320.0",
25
+ "@sentry/junior-plugin-api": "0.322.0",
26
26
  "commander": "^14.0.3",
27
27
  "drizzle-orm": "1.0.0-rc.6",
28
28
  "p-limit": "^7.3.3",