@mshindi-labs/google 1.2.1 → 1.3.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 (76) hide show
  1. package/README.md +4 -2
  2. package/dist/calendar.cjs +114 -162
  3. package/dist/calendar.cjs.map +1 -1
  4. package/dist/calendar.d.cts +1 -1
  5. package/dist/calendar.d.ts +1 -1
  6. package/dist/calendar.js +45 -93
  7. package/dist/calendar.js.map +1 -1
  8. package/dist/chunk-2MJE3WQ5.js +63 -0
  9. package/dist/chunk-2MJE3WQ5.js.map +1 -0
  10. package/dist/chunk-4UEM6VO4.cjs +119 -0
  11. package/dist/chunk-4UEM6VO4.cjs.map +1 -0
  12. package/dist/{chunk-FCHXM22B.js → chunk-6VGR73PY.js} +45 -2
  13. package/dist/{chunk-FCHXM22B.js.map → chunk-6VGR73PY.js.map} +1 -1
  14. package/dist/{chunk-6RDWEYXZ.js → chunk-7YVRJ3GY.js} +5 -4
  15. package/dist/chunk-7YVRJ3GY.js.map +1 -0
  16. package/dist/chunk-7ZLAL7UY.cjs +63 -0
  17. package/dist/chunk-7ZLAL7UY.cjs.map +1 -0
  18. package/dist/chunk-BYHOVCN3.cjs +20 -0
  19. package/dist/chunk-BYHOVCN3.cjs.map +1 -0
  20. package/dist/chunk-FPEP5FL5.js +87 -0
  21. package/dist/chunk-FPEP5FL5.js.map +1 -0
  22. package/dist/chunk-JA2JLBNN.js +119 -0
  23. package/dist/chunk-JA2JLBNN.js.map +1 -0
  24. package/dist/{chunk-DPAPYMB3.cjs → chunk-KFQ4O6MT.cjs} +57 -56
  25. package/dist/chunk-KFQ4O6MT.cjs.map +1 -0
  26. package/dist/chunk-LWCB3V7V.js +20 -0
  27. package/dist/chunk-LWCB3V7V.js.map +1 -0
  28. package/dist/{chunk-6PMJ6VB6.cjs → chunk-RWRVNSQG.cjs} +6 -6
  29. package/dist/{chunk-6PMJ6VB6.cjs.map → chunk-RWRVNSQG.cjs.map} +1 -1
  30. package/dist/{chunk-SXD5K23S.js → chunk-UR3KSPDZ.js} +2 -2
  31. package/dist/{chunk-JZVDD4DL.cjs → chunk-UUXXCUIB.cjs} +45 -2
  32. package/dist/chunk-UUXXCUIB.cjs.map +1 -0
  33. package/dist/{chunk-JDA3ZRUY.cjs → chunk-V5Q6XSYZ.cjs} +3 -3
  34. package/dist/{chunk-JDA3ZRUY.cjs.map → chunk-V5Q6XSYZ.cjs.map} +1 -1
  35. package/dist/{chunk-S357VL5V.cjs → chunk-X7QL7AQ6.cjs} +48 -17
  36. package/dist/chunk-X7QL7AQ6.cjs.map +1 -0
  37. package/dist/{chunk-4V5ZJNPI.js → chunk-ZPDFK5VR.js} +2 -2
  38. package/dist/core.cjs +28 -18
  39. package/dist/core.cjs.map +1 -1
  40. package/dist/core.d.cts +19 -2
  41. package/dist/core.d.ts +19 -2
  42. package/dist/core.js +14 -4
  43. package/dist/core.js.map +1 -1
  44. package/dist/{create-google-Bo8_Nc1C.d.cts → create-google-B0fX1ixG.d.cts} +1 -0
  45. package/dist/{create-google-snvkHaEk.d.ts → create-google-CjsKhktN.d.ts} +1 -0
  46. package/dist/gmail.cjs +43 -41
  47. package/dist/gmail.cjs.map +1 -1
  48. package/dist/gmail.d.cts +1 -1
  49. package/dist/gmail.d.ts +1 -1
  50. package/dist/gmail.js +9 -7
  51. package/dist/gmail.js.map +1 -1
  52. package/dist/postgres.cjs +8 -8
  53. package/dist/postgres.js +1 -1
  54. package/dist/sheets.cjs +1317 -0
  55. package/dist/sheets.cjs.map +1 -0
  56. package/dist/sheets.d.cts +292 -0
  57. package/dist/sheets.d.ts +292 -0
  58. package/dist/sheets.js +1317 -0
  59. package/dist/sheets.js.map +1 -0
  60. package/dist/testing.cjs +905 -38
  61. package/dist/testing.cjs.map +1 -1
  62. package/dist/testing.d.cts +133 -1
  63. package/dist/testing.d.ts +133 -1
  64. package/dist/testing.js +897 -30
  65. package/dist/testing.js.map +1 -1
  66. package/dist/transport-uuotQ13Y.d.cts +137 -0
  67. package/dist/transport-uuotQ13Y.d.ts +137 -0
  68. package/package.json +17 -1
  69. package/dist/chunk-6RDWEYXZ.js.map +0 -1
  70. package/dist/chunk-AMBBE4TW.js +0 -56
  71. package/dist/chunk-AMBBE4TW.js.map +0 -1
  72. package/dist/chunk-DPAPYMB3.cjs.map +0 -1
  73. package/dist/chunk-JZVDD4DL.cjs.map +0 -1
  74. package/dist/chunk-S357VL5V.cjs.map +0 -1
  75. /package/dist/{chunk-SXD5K23S.js.map → chunk-UR3KSPDZ.js.map} +0 -0
  76. /package/dist/{chunk-4V5ZJNPI.js.map → chunk-ZPDFK5VR.js.map} +0 -0
package/dist/calendar.cjs CHANGED
@@ -1,31 +1,36 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
+ var _chunkBYHOVCN3cjs = require('./chunk-BYHOVCN3.cjs');
3
4
 
4
5
 
6
+ var _chunk7ZLAL7UYcjs = require('./chunk-7ZLAL7UY.cjs');
5
7
 
6
8
 
7
9
 
8
10
 
9
- var _chunkS357VL5Vcjs = require('./chunk-S357VL5V.cjs');
10
11
 
11
12
 
12
13
 
13
- var _chunkDPAPYMB3cjs = require('./chunk-DPAPYMB3.cjs');
14
14
 
15
15
 
16
- var _chunkJDA3ZRUYcjs = require('./chunk-JDA3ZRUY.cjs');
17
16
 
17
+ var _chunkX7QL7AQ6cjs = require('./chunk-X7QL7AQ6.cjs');
18
18
 
19
19
 
20
+ var _chunkKFQ4O6MTcjs = require('./chunk-KFQ4O6MT.cjs');
20
21
 
21
22
 
23
+ var _chunkV5Q6XSYZcjs = require('./chunk-V5Q6XSYZ.cjs');
22
24
 
23
25
 
24
26
 
25
27
 
26
28
 
27
29
 
28
- var _chunkJZVDD4DLcjs = require('./chunk-JZVDD4DL.cjs');
30
+
31
+
32
+
33
+ var _chunkUUXXCUIBcjs = require('./chunk-UUXXCUIB.cjs');
29
34
 
30
35
  // src/calendar/service.ts
31
36
  var _crypto = require('crypto');
@@ -105,75 +110,59 @@ var NETWORK_CODES = /* @__PURE__ */ new Set([
105
110
  "ETIMEDOUT",
106
111
  "ESOCKETTIMEDOUT"
107
112
  ]);
108
- var RATE_REASONS = /* @__PURE__ */ new Set(["rateLimitExceeded", "userRateLimitExceeded"]);
109
113
  function classifyCalendarError(err) {
110
- if (err instanceof _chunkJZVDD4DLcjs.GoogleLibError) return { kind: "fail", error: err };
111
- const e = _chunkS357VL5Vcjs.asErr.call(void 0, err);
112
- const status = _chunkS357VL5Vcjs.readStatus.call(void 0, e);
113
- const reason = _chunkS357VL5Vcjs.readReason.call(void 0, e);
114
- const code = _chunkS357VL5Vcjs.readNetCode.call(void 0, e);
114
+ if (err instanceof _chunkUUXXCUIBcjs.GoogleLibError) return { kind: "fail", error: err };
115
+ const e = _chunkX7QL7AQ6cjs.asErr.call(void 0, err);
116
+ const status = _chunkX7QL7AQ6cjs.readStatus.call(void 0, e);
117
+ const reason = _chunkX7QL7AQ6cjs.readReason.call(void 0, e);
118
+ const code = _chunkX7QL7AQ6cjs.readNetCode.call(void 0, e);
115
119
  const opts = { cause: err };
116
- if (status === 429 || status === 403 && reason !== null && RATE_REASONS.has(reason)) {
117
- return { kind: "retry", delayMs: _chunkS357VL5Vcjs.readRetryAfterMs.call(void 0, e) };
120
+ if (status === 429 || status === 403 && reason !== null && _chunkX7QL7AQ6cjs.RATE_REASONS.has(reason)) {
121
+ return { kind: "retry", delayMs: _chunkX7QL7AQ6cjs.readRetryAfterMs.call(void 0, e) };
118
122
  }
119
123
  if (status === 401) return { kind: "unauthorized" };
120
124
  if (status === 409) return { kind: "duplicate" };
121
125
  if (status === 404 || status === 410) return { kind: "gone" };
122
126
  if (status === 412) return { kind: "precondition" };
123
127
  if (status === 400) {
124
- if (/conference/i.test(_chunkS357VL5Vcjs.readMessages.call(void 0, e))) {
128
+ if (/conference/i.test(_chunkX7QL7AQ6cjs.readMessages.call(void 0, e))) {
125
129
  return {
126
130
  kind: "fail",
127
- error: new (0, _chunkJZVDD4DLcjs.ConferencingUnavailableError)(void 0, opts)
131
+ error: new (0, _chunkUUXXCUIBcjs.ConferencingUnavailableError)(void 0, opts)
128
132
  };
129
133
  }
130
- return { kind: "fail", error: new (0, _chunkJZVDD4DLcjs.GoogleApiError)(400, reason, opts) };
134
+ return { kind: "fail", error: new (0, _chunkUUXXCUIBcjs.GoogleApiError)(400, reason, opts) };
131
135
  }
132
136
  if (status !== null && status >= 500) return { kind: "retry", delayMs: null };
133
- if (code !== null && (NETWORK_CODES.has(code) || code.startsWith("ERR_TLS_") || code.startsWith("CERT_") || code === "ABORT_ERR") || e.name === "AbortError" || /socket hang up/i.test(_chunkS357VL5Vcjs.readMessages.call(void 0, e))) {
137
+ if (code !== null && (NETWORK_CODES.has(code) || code.startsWith("ERR_TLS_") || code.startsWith("CERT_") || code === "ABORT_ERR") || e.name === "AbortError" || /socket hang up/i.test(_chunkX7QL7AQ6cjs.readMessages.call(void 0, e))) {
134
138
  return { kind: "retry", delayMs: null };
135
139
  }
136
140
  if (status !== null) {
137
- return { kind: "fail", error: new (0, _chunkJZVDD4DLcjs.GoogleApiError)(status, reason, opts) };
141
+ return { kind: "fail", error: new (0, _chunkUUXXCUIBcjs.GoogleApiError)(status, reason, opts) };
138
142
  }
139
- return { kind: "fail", error: new (0, _chunkJZVDD4DLcjs.GoogleApiError)(0, code, opts) };
143
+ return { kind: "fail", error: new (0, _chunkUUXXCUIBcjs.GoogleApiError)(0, code, opts) };
140
144
  }
141
- var defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
142
- async function withCalendarRetry(fn, opts = {}) {
143
- const maxAttempts = _nullishCoalesce(opts.maxAttempts, () => ( 3));
144
- const baseMs = _nullishCoalesce(opts.baseMs, () => ( 250));
145
- const capMs = _nullishCoalesce(opts.capMs, () => ( 8e3));
146
- const sleep = _nullishCoalesce(opts.sleep, () => ( defaultSleep));
147
- const random = _nullishCoalesce(opts.random, () => ( Math.random));
148
- for (let attempt = 0; ; attempt++) {
149
- try {
150
- return await fn();
151
- } catch (err) {
145
+ function withCalendarRetry(fn, opts = {}) {
146
+ return _chunkX7QL7AQ6cjs.runWithRetry.call(void 0, fn, {
147
+ ...opts,
148
+ classify: (err) => {
152
149
  const c = classifyCalendarError(err);
153
- if (c.kind === "fail") throw c.error;
154
- if (c.kind === "unauthorized") throw new CalendarUnauthorizedSignal();
155
- if (c.kind === "duplicate") throw new DuplicateEventSignal();
156
- if (c.kind === "gone") throw new EventGoneSignal();
157
- if (c.kind === "precondition") throw new PreconditionFailedSignal();
158
- if (c.delayMs !== null && c.delayMs > capMs) {
159
- throw new (0, _chunkJZVDD4DLcjs.RateLimitedError)(c.delayMs, { cause: err });
150
+ switch (c.kind) {
151
+ case "retry":
152
+ return c;
153
+ case "fail":
154
+ return { kind: "throw", error: c.error };
155
+ case "unauthorized":
156
+ return { kind: "throw", error: new CalendarUnauthorizedSignal() };
157
+ case "duplicate":
158
+ return { kind: "throw", error: new DuplicateEventSignal() };
159
+ case "gone":
160
+ return { kind: "throw", error: new EventGoneSignal() };
161
+ case "precondition":
162
+ return { kind: "throw", error: new PreconditionFailedSignal() };
160
163
  }
161
- if (attempt + 1 >= maxAttempts) {
162
- const e = _chunkS357VL5Vcjs.asErr.call(void 0, err);
163
- const status = _chunkS357VL5Vcjs.readStatus.call(void 0, e);
164
- if (status === 429 || status === 403) {
165
- throw new (0, _chunkJZVDD4DLcjs.RateLimitedError)(c.delayMs, { cause: err });
166
- }
167
- if (status !== null) {
168
- throw new (0, _chunkJZVDD4DLcjs.GoogleApiError)(status, _chunkS357VL5Vcjs.readReason.call(void 0, e), { cause: err });
169
- }
170
- throw new (0, _chunkJZVDD4DLcjs.GoogleApiError)(0, _chunkS357VL5Vcjs.readNetCode.call(void 0, e), { cause: err });
171
- }
172
- await sleep(
173
- _nullishCoalesce(c.delayMs, () => ( random() * Math.min(capMs, baseMs * 2 ** attempt)))
174
- );
175
164
  }
176
- }
165
+ });
177
166
  }
178
167
 
179
168
  // src/calendar/time.ts
@@ -208,12 +197,12 @@ function formatter(tz) {
208
197
  }
209
198
  function assertTimeZone(tz, field) {
210
199
  if (typeof tz !== "string" || tz.length === 0 || tz.length > 64) {
211
- throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)(field);
200
+ throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)(field);
212
201
  }
213
202
  try {
214
203
  new Intl.DateTimeFormat("en-US", { timeZone: tz });
215
204
  } catch (e2) {
216
- throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)(field);
205
+ throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)(field);
217
206
  }
218
207
  return tz;
219
208
  }
@@ -269,47 +258,47 @@ var WEEKDAYS2 = [
269
258
  var HHMM = /^(\d{2}):(\d{2})$/;
270
259
  function intIn(value, min, max, field) {
271
260
  if (typeof value !== "number" || !Number.isInteger(value) || value < min || value > max) {
272
- throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)(field);
261
+ throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)(field);
273
262
  }
274
263
  return value;
275
264
  }
276
265
  var isDate = (d) => d instanceof Date && !Number.isNaN(d.getTime());
277
266
  function parseHHMM(s, allow24, field) {
278
267
  const m = typeof s === "string" ? HHMM.exec(s) : null;
279
- if (m === null) throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)(field);
268
+ if (m === null) throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)(field);
280
269
  const h = Number(m[1]);
281
270
  const min = Number(m[2]);
282
271
  if (allow24 && h === 24 && min === 0) return DAY_MINUTES;
283
- if (h > 23 || min > 59) throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)(field);
272
+ if (h > 23 || min > 59) throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)(field);
284
273
  return h * 60 + min;
285
274
  }
286
275
  function parseHours(wh, path) {
287
- if (typeof wh !== "object" || wh === null) throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)(path);
276
+ if (typeof wh !== "object" || wh === null) throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)(path);
288
277
  const { timeZone, days } = wh;
289
278
  const tz = assertTimeZone(timeZone, `${path}.timeZone`);
290
279
  const daysField = `${path}.days`;
291
280
  if (typeof days !== "object" || days === null)
292
- throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)(daysField);
281
+ throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)(daysField);
293
282
  const out = { timeZone: tz, days: {} };
294
283
  for (const [key, list] of Object.entries(days)) {
295
284
  if (!WEEKDAYS2.includes(key) || !Array.isArray(list)) {
296
- throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)(daysField);
285
+ throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)(daysField);
297
286
  }
298
287
  out.days[key] = list.map((iv) => {
299
288
  const { start, end } = _nullishCoalesce(iv, () => ( {}));
300
289
  const s = parseHHMM(start, false, daysField);
301
290
  const e = parseHHMM(end, true, daysField);
302
- if (s >= e) throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)(daysField);
291
+ if (s >= e) throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)(daysField);
303
292
  return { start: s, end: e };
304
293
  });
305
294
  }
306
295
  return out;
307
296
  }
308
297
  function prepareBusy(ranges, buffer, field) {
309
- if (!Array.isArray(ranges)) throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)(field);
298
+ if (!Array.isArray(ranges)) throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)(field);
310
299
  const list = ranges.map((r) => {
311
300
  const { start, end } = _nullishCoalesce(r, () => ( {}));
312
- if (!isDate(start) || !isDate(end)) throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)(field);
301
+ if (!isDate(start) || !isDate(end)) throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)(field);
313
302
  return { start: start.getTime() - buffer, end: end.getTime() + buffer };
314
303
  });
315
304
  list.sort((a, b) => a.start - b.start);
@@ -436,7 +425,7 @@ function parseSlotParams(input) {
436
425
  const overrides = /* @__PURE__ */ new Map();
437
426
  const byAttendee = _nullishCoalesce(input.workingHoursByAttendee, () => ( {}));
438
427
  if (typeof byAttendee !== "object" || byAttendee === null)
439
- throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)("workingHoursByAttendee");
428
+ throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)("workingHoursByAttendee");
440
429
  for (const [email, wh] of Object.entries(byAttendee)) {
441
430
  overrides.set(
442
431
  email.toLowerCase(),
@@ -463,18 +452,18 @@ function findCommonSlots(input) {
463
452
  tenant,
464
453
  overrides
465
454
  } = parseSlotParams(input);
466
- if (!isDate(input.now)) throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)("now");
455
+ if (!isDate(input.now)) throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)("now");
467
456
  const { window } = input;
468
457
  if (typeof window !== "object" || window === null || !isDate(window.start) || !isDate(window.end)) {
469
- throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)("window");
458
+ throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)("window");
470
459
  }
471
460
  const winStart = window.start.getTime();
472
461
  const winEnd = window.end.getTime();
473
462
  if (winEnd <= winStart || winEnd - winStart > MAX_WINDOW_MS) {
474
- throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)("window");
463
+ throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)("window");
475
464
  }
476
465
  if (typeof input.busy !== "object" || input.busy === null)
477
- throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)("busy");
466
+ throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)("busy");
478
467
  const people = Object.entries(input.busy).map(
479
468
  ([email, ranges]) => ({
480
469
  hours: _nullishCoalesce(overrides.get(email.toLowerCase()), () => ( tenant)),
@@ -526,7 +515,7 @@ var CALENDAR_ID = "primary";
526
515
  var ifMatchArgs = (ifMatch) => ifMatch === void 0 ? [] : [{ headers: { "If-Match": ifMatch } }];
527
516
  function createCalendarApiTransport() {
528
517
  const client = async (accessToken) => {
529
- const mod = await _chunkJDA3ZRUYcjs.loadPeer.call(void 0, "@googleapis/calendar");
518
+ const mod = await _chunkV5Q6XSYZcjs.loadPeer.call(void 0, "@googleapis/calendar");
530
519
  const { calendar } = mod.calendar ? mod : mod.default;
531
520
  const auth = new (0, _googleauthlibrary.OAuth2Client)();
532
521
  auth.setCredentials({ access_token: accessToken });
@@ -620,7 +609,7 @@ var CHANGE_KEYS = /* @__PURE__ */ new Set([
620
609
  var MAX_EVENT_MS = 24 * 36e5;
621
610
  var MAX_WINDOW_MS2 = 31 * 24 * 36e5;
622
611
  var fail = (field) => {
623
- throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)(field);
612
+ throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)(field);
624
613
  };
625
614
  var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
626
615
  function requireString(v, field, min, max) {
@@ -676,7 +665,7 @@ function validAttendees(v, organizerEmail) {
676
665
  v.forEach((raw, i) => {
677
666
  if (!isObject(raw)) fail(`attendees[${i}]`);
678
667
  const a = raw;
679
- const email = _chunkS357VL5Vcjs.normalizeEmail.call(void 0, a.email);
668
+ const email = _chunkBYHOVCN3cjs.normalizeEmail.call(void 0, a.email);
680
669
  if (email === null) fail(`attendees[${i}]`);
681
670
  let displayName = null;
682
671
  if (a.displayName !== void 0) {
@@ -765,7 +754,7 @@ function validateAvailabilityInput(input) {
765
754
  if (!Array.isArray(i.attendees)) return fail("attendees");
766
755
  const seen = /* @__PURE__ */ new Set();
767
756
  for (const raw of i.attendees) {
768
- const email = _chunkS357VL5Vcjs.normalizeEmail.call(void 0, raw);
757
+ const email = _chunkBYHOVCN3cjs.normalizeEmail.call(void 0, raw);
769
758
  if (email === null) fail("attendees");
770
759
  seen.add(email.toLowerCase());
771
760
  }
@@ -792,7 +781,7 @@ var STATUSES = ["confirmed", "tentative", "cancelled"];
792
781
  function assertManaged(e, tenantId) {
793
782
  const priv = _optionalChain([e, 'access', _2 => _2.extendedProperties, 'optionalAccess', _3 => _3.private]);
794
783
  if (_optionalChain([priv, 'optionalAccess', _4 => _4.mshindiGoogle]) !== "v1" || priv.mshindiTenant !== tenantId) {
795
- throw new (0, _chunkJZVDD4DLcjs.EventNotManagedError)();
784
+ throw new (0, _chunkUUXXCUIBcjs.EventNotManagedError)();
796
785
  }
797
786
  }
798
787
  function meetingOf(e) {
@@ -859,7 +848,6 @@ var PATCH_ATTEMPTS = 3;
859
848
  var MAX_EVENT_MS2 = 24 * 36e5;
860
849
  var BACKOFF_BASE_MS = 250;
861
850
  var BACKOFF_CAP_MS = 8e3;
862
- var defaultSleep2 = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
863
851
  var conferenceStatus = (e) => _optionalChain([e, 'access', _29 => _29.conferenceData, 'optionalAccess', _30 => _30.createRequest, 'optionalAccess', _31 => _31.status, 'optionalAccess', _32 => _32.statusCode]);
864
852
  var meetReady = (e) => conferenceStatus(e) === "success" && (_nullishCoalesce(_optionalChain([e, 'access', _33 => _33.conferenceData, 'optionalAccess', _34 => _34.entryPoints]), () => ( []))).some(
865
853
  (p) => p.entryPointType === "video" && typeof p.uri === "string"
@@ -868,13 +856,13 @@ var inviteState = (e) => _optionalChain([e, 'access', _35 => _35.extendedPropert
868
856
  function requireIds(input, fields) {
869
857
  for (const field of fields) {
870
858
  const v = _optionalChain([input, 'optionalAccess', _38 => _38[field]]);
871
- if (typeof v !== "string" || v === "") throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)(field);
859
+ if (typeof v !== "string" || v === "") throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)(field);
872
860
  }
873
861
  }
874
862
  function parseSendUpdates(v) {
875
863
  if (v === void 0) return "all";
876
864
  if (typeof v !== "string" || !Object.prototype.hasOwnProperty.call(GOOGLE_SEND_UPDATES, v)) {
877
- throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)("sendUpdates");
865
+ throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)("sendUpdates");
878
866
  }
879
867
  return GOOGLE_SEND_UPDATES[v];
880
868
  }
@@ -1006,12 +994,12 @@ function eventBody(id, ev, stamp) {
1006
994
  };
1007
995
  }
1008
996
  function sanitize(err) {
1009
- if (err instanceof _chunkJZVDD4DLcjs.GoogleLibError) return err;
1010
- if (err instanceof EventGoneSignal) return new (0, _chunkJZVDD4DLcjs.EventNotFoundError)();
997
+ if (err instanceof _chunkUUXXCUIBcjs.GoogleLibError) return err;
998
+ if (err instanceof EventGoneSignal) return new (0, _chunkUUXXCUIBcjs.EventNotFoundError)();
1011
999
  if (err instanceof DuplicateEventSignal || err instanceof PreconditionFailedSignal) {
1012
- return new (0, _chunkJZVDD4DLcjs.EventConflictError)();
1000
+ return new (0, _chunkUUXXCUIBcjs.EventConflictError)();
1013
1001
  }
1014
- return new (0, _chunkJZVDD4DLcjs.GoogleApiError)(0, null, { cause: err });
1002
+ return new (0, _chunkUUXXCUIBcjs.GoogleApiError)(0, null, { cause: err });
1015
1003
  }
1016
1004
  var REASONS = {
1017
1005
  notFound: "not_found",
@@ -1043,64 +1031,28 @@ function createCalendar(google, opts = {}) {
1043
1031
  ...opts.random ? { random: opts.random } : {}
1044
1032
  };
1045
1033
  const retry = (fn) => withCalendarRetry(fn, retryOpts);
1046
- const sleep = _nullishCoalesce(opts.sleep, () => ( defaultSleep2));
1034
+ const sleep = _nullishCoalesce(opts.sleep, () => ( _chunkX7QL7AQ6cjs.defaultSleep));
1047
1035
  const random = _nullishCoalesce(opts.random, () => ( Math.random));
1048
1036
  const rethrow = (err) => withCalendarRetry(() => Promise.reject(err), {
1049
1037
  ...retryOpts,
1050
1038
  maxAttempts: 1
1051
1039
  });
1052
- async function withToken(tenantId, connectionId, fn) {
1053
- const { store, tokens, emit, now, logger } = google[_chunkDPAPYMB3cjs.internals];
1054
- const first = await tokens.getAccessToken(tenantId, connectionId);
1055
- const { refreshToken: _omit, ...view } = first.connection;
1056
- void _omit;
1057
- _chunkDPAPYMB3cjs.assertServiceScopes.call(void 0, view.scopes, ["calendar"], { tenantId, connectionId });
1058
- let result;
1059
- try {
1060
- result = await fn(first.accessToken, view);
1061
- } catch (err) {
1062
- if (!(err instanceof CalendarUnauthorizedSignal)) throw err;
1063
- const fresh = await tokens.getAccessToken(tenantId, connectionId, {
1064
- forceRefresh: true
1065
- });
1066
- try {
1067
- result = await fn(fresh.accessToken, view);
1068
- } catch (err2) {
1069
- if (!(err2 instanceof CalendarUnauthorizedSignal)) throw err2;
1070
- await store.updateConnectionStatus(
1071
- tenantId,
1072
- connectionId,
1073
- "revoked",
1074
- "unauthorized"
1075
- );
1076
- tokens.evict(connectionId);
1077
- await emit({
1078
- type: "connection.revoked",
1079
- tenantId,
1080
- connectionId,
1081
- reason: "unauthorized",
1082
- at: now()
1083
- });
1084
- throw new (0, _chunkJZVDD4DLcjs.ConnectionRevokedError)("unauthorized", {
1085
- tenantId,
1086
- connectionId
1087
- });
1088
- }
1089
- }
1090
- try {
1091
- await store.touchConnection(tenantId, connectionId, now());
1092
- } catch (e3) {
1093
- try {
1094
- _optionalChain([logger, 'optionalAccess', _41 => _41.warn, 'call', _42 => _42("google touchConnection failed")]);
1095
- } catch (e4) {
1096
- }
1097
- }
1098
- return result;
1040
+ function withToken(tenantId, connectionId, fn) {
1041
+ return _chunk7ZLAL7UYcjs.withConnectionToken.call(void 0,
1042
+ google,
1043
+ {
1044
+ tenantId,
1045
+ connectionId,
1046
+ service: "calendar",
1047
+ isUnauthorized: (e) => e instanceof CalendarUnauthorizedSignal
1048
+ },
1049
+ fn
1050
+ );
1099
1051
  }
1100
1052
  const warn = (message) => {
1101
1053
  try {
1102
- _optionalChain([google, 'access', _43 => _43[_chunkDPAPYMB3cjs.internals], 'access', _44 => _44.logger, 'optionalAccess', _45 => _45.warn, 'call', _46 => _46(message)]);
1103
- } catch (e5) {
1054
+ _optionalChain([google, 'access', _41 => _41[_chunkKFQ4O6MTcjs.internals], 'access', _42 => _42.logger, 'optionalAccess', _43 => _43.warn, 'call', _44 => _44(message)]);
1055
+ } catch (e3) {
1104
1056
  }
1105
1057
  };
1106
1058
  const getManaged = async (accessToken, eventId, tenantId) => {
@@ -1108,7 +1060,7 @@ function createCalendar(google, opts = {}) {
1108
1060
  try {
1109
1061
  e = await retry(() => transport.get({ accessToken, eventId }));
1110
1062
  } catch (err) {
1111
- if (err instanceof EventGoneSignal) throw new (0, _chunkJZVDD4DLcjs.EventNotFoundError)();
1063
+ if (err instanceof EventGoneSignal) throw new (0, _chunkUUXXCUIBcjs.EventNotFoundError)();
1112
1064
  throw err;
1113
1065
  }
1114
1066
  assertManaged(e, tenantId);
@@ -1157,7 +1109,7 @@ function createCalendar(google, opts = {}) {
1157
1109
  } else if (cal.errors.length > 0) {
1158
1110
  out[email] = {
1159
1111
  status: "unknown",
1160
- reason: _nullishCoalesce(REASONS[_nullishCoalesce(_optionalChain([cal, 'access', _47 => _47.errors, 'access', _48 => _48[0], 'optionalAccess', _49 => _49.reason]), () => ( ""))], () => ( "error"))
1112
+ reason: _nullishCoalesce(REASONS[_nullishCoalesce(_optionalChain([cal, 'access', _45 => _45.errors, 'access', _46 => _46[0], 'optionalAccess', _47 => _47.reason]), () => ( ""))], () => ( "error"))
1161
1113
  };
1162
1114
  } else {
1163
1115
  out[email] = { status: "ok", busy: mergeBusy(cal.busy, window) };
@@ -1167,13 +1119,13 @@ function createCalendar(google, opts = {}) {
1167
1119
  }
1168
1120
  async function createEvent(input) {
1169
1121
  for (const field of ["tenantId", "connectionId", "actorId"]) {
1170
- if (typeof _optionalChain([input, 'optionalAccess', _50 => _50[field]]) !== "string" || input[field] === "") {
1171
- throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)(field);
1122
+ if (typeof _optionalChain([input, 'optionalAccess', _48 => _48[field]]) !== "string" || input[field] === "") {
1123
+ throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)(field);
1172
1124
  }
1173
1125
  }
1174
1126
  validateCreateInput(input, "");
1175
1127
  const { tenantId, connectionId, actorId } = input;
1176
- const { emit, now, logger } = google[_chunkDPAPYMB3cjs.internals];
1128
+ const { emit, now, logger } = google[_chunkKFQ4O6MTcjs.internals];
1177
1129
  let ownInsertMayHaveLanded = false;
1178
1130
  let released = false;
1179
1131
  let releaseAttempted = false;
@@ -1211,7 +1163,7 @@ function createCalendar(google, opts = {}) {
1211
1163
  ownInsertMayHaveLanded = true;
1212
1164
  return out;
1213
1165
  } catch (err) {
1214
- const status = _chunkS357VL5Vcjs.readStatus.call(void 0, _chunkS357VL5Vcjs.asErr.call(void 0, err));
1166
+ const status = _chunkX7QL7AQ6cjs.readStatus.call(void 0, _chunkX7QL7AQ6cjs.asErr.call(void 0, err));
1215
1167
  if (classifyCalendarError(err).kind === "retry" && status !== 429 && status !== 403) {
1216
1168
  ownInsertMayHaveLanded = true;
1217
1169
  }
@@ -1226,7 +1178,7 @@ function createCalendar(google, opts = {}) {
1226
1178
  event2 = await getEv();
1227
1179
  } catch (err2) {
1228
1180
  if (err2 instanceof EventGoneSignal) {
1229
- throw new (0, _chunkJZVDD4DLcjs.EventConflictError)(
1181
+ throw new (0, _chunkUUXXCUIBcjs.EventConflictError)(
1230
1182
  "An event with this idempotency key exists but cannot be read"
1231
1183
  );
1232
1184
  }
@@ -1286,19 +1238,19 @@ function createCalendar(google, opts = {}) {
1286
1238
  throw safe;
1287
1239
  }
1288
1240
  function assertReplayable(e, tenant, key, fp) {
1289
- const priv = _optionalChain([e, 'access', _51 => _51.extendedProperties, 'optionalAccess', _52 => _52.private]);
1290
- if (_optionalChain([priv, 'optionalAccess', _53 => _53.mshindiGoogle]) !== "v1" || priv.mshindiTenant !== tenant || priv.mshindiKey !== key) {
1291
- throw new (0, _chunkJZVDD4DLcjs.EventConflictError)(
1241
+ const priv = _optionalChain([e, 'access', _49 => _49.extendedProperties, 'optionalAccess', _50 => _50.private]);
1242
+ if (_optionalChain([priv, 'optionalAccess', _51 => _51.mshindiGoogle]) !== "v1" || priv.mshindiTenant !== tenant || priv.mshindiKey !== key) {
1243
+ throw new (0, _chunkUUXXCUIBcjs.EventConflictError)(
1292
1244
  "An event with this id exists and is not owned by this idempotency key"
1293
1245
  );
1294
1246
  }
1295
1247
  if (e.status === "cancelled") {
1296
- throw new (0, _chunkJZVDD4DLcjs.EventConflictError)(
1248
+ throw new (0, _chunkUUXXCUIBcjs.EventConflictError)(
1297
1249
  "The event for this idempotency key was cancelled; use a new idempotency key"
1298
1250
  );
1299
1251
  }
1300
1252
  if (priv.mshindiFingerprint !== fp) {
1301
- throw new (0, _chunkJZVDD4DLcjs.EventConflictError)(
1253
+ throw new (0, _chunkUUXXCUIBcjs.EventConflictError)(
1302
1254
  "An event with this idempotency key exists with different details; use updateEvent to change it"
1303
1255
  );
1304
1256
  }
@@ -1333,15 +1285,15 @@ function createCalendar(google, opts = {}) {
1333
1285
  if (attempt + 1 >= RELEASE_ATTEMPTS) throw err;
1334
1286
  }
1335
1287
  }
1336
- } catch (e6) {
1288
+ } catch (e4) {
1337
1289
  try {
1338
- _optionalChain([logger, 'optionalAccess', _54 => _54.warn, 'call', _55 => _55(
1290
+ _optionalChain([logger, 'optionalAccess', _52 => _52.warn, 'call', _53 => _53(
1339
1291
  "google calendar: could not withdraw event after Meet creation failed"
1340
1292
  )]);
1341
- } catch (e7) {
1293
+ } catch (e5) {
1342
1294
  }
1343
1295
  }
1344
- throw new (0, _chunkJZVDD4DLcjs.ConferencingUnavailableError)(
1296
+ throw new (0, _chunkUUXXCUIBcjs.ConferencingUnavailableError)(
1345
1297
  "Google Meet link could not be created; the event was withdrawn without notifying guests. Retry with a new idempotency key.",
1346
1298
  { tenantId, connectionId }
1347
1299
  );
@@ -1377,7 +1329,7 @@ function createCalendar(google, opts = {}) {
1377
1329
  return { event: current, byUs: c.kind === "retry" };
1378
1330
  }
1379
1331
  if (current.status === "cancelled") {
1380
- throw new (0, _chunkJZVDD4DLcjs.EventConflictError)(
1332
+ throw new (0, _chunkUUXXCUIBcjs.EventConflictError)(
1381
1333
  "The event for this idempotency key was cancelled; use a new idempotency key"
1382
1334
  );
1383
1335
  }
@@ -1403,7 +1355,7 @@ function createCalendar(google, opts = {}) {
1403
1355
  validateChanges(input.changes, "");
1404
1356
  const sendUpdates = parseSendUpdates(input.sendUpdates);
1405
1357
  const { tenantId, connectionId, actorId, eventId } = input;
1406
- const { emit, now } = google[_chunkDPAPYMB3cjs.internals];
1358
+ const { emit, now } = google[_chunkKFQ4O6MTcjs.internals];
1407
1359
  let attempted = null;
1408
1360
  try {
1409
1361
  const out = await withToken(
@@ -1412,26 +1364,26 @@ function createCalendar(google, opts = {}) {
1412
1364
  async (accessToken, connection) => {
1413
1365
  const changes = validateChanges(input.changes, connection.email);
1414
1366
  const current = await getManaged(accessToken, eventId, tenantId);
1415
- if (current.status === "cancelled") throw new (0, _chunkJZVDD4DLcjs.EventCancelledError)();
1416
- if (!_optionalChain([current, 'access', _56 => _56.start, 'optionalAccess', _57 => _57.dateTime]) || !_optionalChain([current, 'access', _58 => _58.end, 'optionalAccess', _59 => _59.dateTime])) {
1417
- throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)("start");
1367
+ if (current.status === "cancelled") throw new (0, _chunkUUXXCUIBcjs.EventCancelledError)();
1368
+ if (!_optionalChain([current, 'access', _54 => _54.start, 'optionalAccess', _55 => _55.dateTime]) || !_optionalChain([current, 'access', _56 => _56.end, 'optionalAccess', _57 => _57.dateTime])) {
1369
+ throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)("start");
1418
1370
  }
1419
1371
  const before = toNormalized(current);
1420
1372
  if (Number.isNaN(before.start.getTime()) || Number.isNaN(before.end.getTime())) {
1421
- throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)("start");
1373
+ throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)("start");
1422
1374
  }
1423
1375
  const wanted = withKnownNames(before, changes);
1424
1376
  const next = { ...before, ...wanted };
1425
1377
  const span = next.end.getTime() - next.start.getTime();
1426
1378
  if (!(span > 0 && span <= MAX_EVENT_MS2)) {
1427
- throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)("end");
1379
+ throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)("end");
1428
1380
  }
1429
1381
  const changed = changedKeys(current, before, wanted);
1430
1382
  if (changed.length === 0) {
1431
1383
  return {
1432
1384
  event: current,
1433
1385
  next,
1434
- changed: _nullishCoalesce(_optionalChain([attempted, 'optionalAccess', _60 => _60.changed]), () => ( null))
1386
+ changed: _nullishCoalesce(_optionalChain([attempted, 'optionalAccess', _58 => _58.changed]), () => ( null))
1435
1387
  };
1436
1388
  }
1437
1389
  const body = updatePatch(current, next, changed, fingerprint(next));
@@ -1440,7 +1392,7 @@ function createCalendar(google, opts = {}) {
1440
1392
  if (body.requestId !== null) {
1441
1393
  try {
1442
1394
  event = await pollConference(accessToken, eventId, event);
1443
- } catch (e8) {
1395
+ } catch (e6) {
1444
1396
  }
1445
1397
  if (!meetReady(event)) {
1446
1398
  warn(
@@ -1473,7 +1425,7 @@ function createCalendar(google, opts = {}) {
1473
1425
  async function patchVerified(accessToken, body, next, changed) {
1474
1426
  const landed = (e) => {
1475
1427
  const got = toNormalized(e);
1476
- return changed.every((k) => same(k, got, next)) && (body.requestId === null || _optionalChain([e, 'access', _61 => _61.conferenceData, 'optionalAccess', _62 => _62.createRequest, 'optionalAccess', _63 => _63.requestId]) === body.requestId);
1428
+ return changed.every((k) => same(k, got, next)) && (body.requestId === null || _optionalChain([e, 'access', _59 => _59.conferenceData, 'optionalAccess', _60 => _60.createRequest, 'optionalAccess', _61 => _61.requestId]) === body.requestId);
1477
1429
  };
1478
1430
  for (let attempt = 0; ; attempt++) {
1479
1431
  try {
@@ -1488,7 +1440,7 @@ function createCalendar(google, opts = {}) {
1488
1440
  const c = classifyCalendarError(err);
1489
1441
  if (c.kind !== "retry") return rethrow(err);
1490
1442
  const current = await getManaged(accessToken, eventId, tenantId);
1491
- if (current.status === "cancelled") throw new (0, _chunkJZVDD4DLcjs.EventCancelledError)();
1443
+ if (current.status === "cancelled") throw new (0, _chunkUUXXCUIBcjs.EventCancelledError)();
1492
1444
  if (landed(current)) return current;
1493
1445
  const tooLong = c.delayMs !== null && c.delayMs > BACKOFF_CAP_MS;
1494
1446
  if (attempt + 1 >= PATCH_ATTEMPTS || tooLong) return rethrow(err);
@@ -1508,7 +1460,7 @@ function createCalendar(google, opts = {}) {
1508
1460
  ]);
1509
1461
  const sendUpdates = parseSendUpdates(input.sendUpdates);
1510
1462
  const { tenantId, connectionId, actorId, eventId } = input;
1511
- const { emit, now } = google[_chunkDPAPYMB3cjs.internals];
1463
+ const { emit, now } = google[_chunkKFQ4O6MTcjs.internals];
1512
1464
  let ownDeleteMayHaveLanded = false;
1513
1465
  try {
1514
1466
  const cancelled = await withToken(
@@ -1529,7 +1481,7 @@ function createCalendar(google, opts = {}) {
1529
1481
  sendUpdates: inviteState(current) === "pending" ? "none" : sendUpdates
1530
1482
  });
1531
1483
  } catch (err) {
1532
- const status = _chunkS357VL5Vcjs.readStatus.call(void 0, _chunkS357VL5Vcjs.asErr.call(void 0, err));
1484
+ const status = _chunkX7QL7AQ6cjs.readStatus.call(void 0, _chunkX7QL7AQ6cjs.asErr.call(void 0, err));
1533
1485
  if (classifyCalendarError(err).kind === "retry" && status !== 429 && status !== 403) {
1534
1486
  ownDeleteMayHaveLanded = true;
1535
1487
  }
@@ -1564,7 +1516,7 @@ function createCalendar(google, opts = {}) {
1564
1516
  }
1565
1517
  async function failed(err, operation, ids) {
1566
1518
  const safe = sanitize(err);
1567
- const { emit, now } = google[_chunkDPAPYMB3cjs.internals];
1519
+ const { emit, now } = google[_chunkKFQ4O6MTcjs.internals];
1568
1520
  await emit({
1569
1521
  type: "calendar_event.failed",
1570
1522
  ...ids,
@@ -1590,7 +1542,7 @@ function createCalendar(google, opts = {}) {
1590
1542
  if (v.status === "ok") busy[email] = v.busy;
1591
1543
  }
1592
1544
  const slots = findCommonSlots({
1593
- now: google[_chunkDPAPYMB3cjs.internals].now(),
1545
+ now: google[_chunkKFQ4O6MTcjs.internals].now(),
1594
1546
  window,
1595
1547
  durationMinutes: input.durationMinutes,
1596
1548
  workingHours: input.workingHours,
@@ -1613,8 +1565,8 @@ function createCalendar(google, opts = {}) {
1613
1565
  },
1614
1566
  async getEvent(input) {
1615
1567
  for (const field of ["tenantId", "connectionId", "eventId"]) {
1616
- if (typeof _optionalChain([input, 'optionalAccess', _64 => _64[field]]) !== "string" || input[field] === "") {
1617
- throw new (0, _chunkJZVDD4DLcjs.InvalidEventError)(field);
1568
+ if (typeof _optionalChain([input, 'optionalAccess', _62 => _62[field]]) !== "string" || input[field] === "") {
1569
+ throw new (0, _chunkUUXXCUIBcjs.InvalidEventError)(field);
1618
1570
  }
1619
1571
  }
1620
1572
  const { tenantId, connectionId, eventId } = input;