@oomol-lab/open-flow 0.1.0-alpha.0 → 0.1.0-alpha.10

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 (72) hide show
  1. package/dist/browser/addNodeOptions-BwrMvPQC.js +5230 -0
  2. package/dist/browser/assets/typeScriptWorker-CaA4llbX.js +59850 -0
  3. package/dist/browser/carbon-DMCVsjHo.js +53 -0
  4. package/dist/browser/{project-change.js → change-Cu6pQIit.js} +15 -45
  5. package/dist/browser/createLucideIcon-COMgwa_u.js +5317 -0
  6. package/dist/browser/createResourceDialog-YgMLylQz.js +467 -0
  7. package/dist/browser/{dist-o4dBuwiG.js → dist-3Mj8q8Pr.js} +28 -28
  8. package/dist/browser/{dist-CIq6ue3I.js → dist-BKuSVKCC.js} +1115 -1103
  9. package/dist/browser/{dist-DL0SDskM.js → dist-BMqL-qR5.js} +473 -906
  10. package/dist/browser/{dist-CLZJNoWB.js → dist-BN4ZCyOB.js} +10 -10
  11. package/dist/browser/{dist-zyY--HOV.js → dist-BpopSHwP.js} +3 -3
  12. package/dist/browser/dist-C46JByB-.js +252 -0
  13. package/dist/browser/{dist-BbyiRq3c.js → dist-CJpzJrLM.js} +294 -284
  14. package/dist/browser/{dist-Djd02JSy.js → dist-CPuF50D9.js} +198 -198
  15. package/dist/browser/{dist-CvcmLAMW.js → dist-CUSrALSX.js} +115 -115
  16. package/dist/browser/dist-CeSZ2xSM.js +444 -0
  17. package/dist/browser/{dist-7oZK9QXZ.js → dist-DMi8_lU3.js} +5 -5
  18. package/dist/browser/{dist-B9OV3YTx.js → dist-DUzA0Ukh.js} +22 -22
  19. package/dist/browser/{dist-aWSZx4q1.js → dist-DWADUsVB.js} +75 -75
  20. package/dist/browser/{dist-BLk5M0uK.js → dist-Mecbzdl2.js} +3 -3
  21. package/dist/browser/{esm-DXw7EADW.js → esm-CvAs_mAS.js} +14 -24
  22. package/dist/browser/field-BrEG-7ap.js +312 -0
  23. package/dist/browser/flow-authoring-edge.d.ts +3 -0
  24. package/dist/browser/flow-authoring-module.d.ts +4 -0
  25. package/dist/browser/flow-authoring-node.d.ts +84 -0
  26. package/dist/browser/flow-authoring.d.ts +4 -0
  27. package/dist/browser/flow-authoring.js +522 -0
  28. package/dist/browser/{project-change.d.ts → flow-change.d.ts} +27 -36
  29. package/dist/browser/flow-change.js +231 -0
  30. package/dist/browser/{project-notifications.d.ts → flow-notifications.d.ts} +6 -3
  31. package/dist/browser/flowRunInputEditorStore-DXOyyY7o.js +8219 -0
  32. package/dist/browser/flowWorkspace-X_T_DcQf.js +46003 -0
  33. package/dist/browser/{lib-S4ccuMeT.js → lib-GrGxYjsJ.js} +3 -5
  34. package/dist/browser/licenses.md +620 -12
  35. package/dist/browser/{markdownContent-ZZFfSRqO.js → markdownContent-BI-2PmDX.js} +4071 -4035
  36. package/dist/browser/typeScriptSession-Dagu_tRs.js +2549 -0
  37. package/dist/browser/workbench-contract.d.ts +4 -5
  38. package/dist/browser/workbench.css +1 -1
  39. package/dist/browser/workbench.d.ts +2 -1
  40. package/dist/browser/workbench.js +3920 -2138
  41. package/dist/common/connector-action.d.ts +6 -0
  42. package/dist/common/connector-action.js +38 -30
  43. package/dist/common/control-api-conformance.js +223 -359
  44. package/dist/common/control-api-errors.d.ts +20 -24
  45. package/dist/common/control-api.d.ts +44 -73
  46. package/dist/common/control-api.js +150 -203
  47. package/dist/common/cron-trigger.d.ts +1 -1
  48. package/dist/common/cron-trigger.js +1 -1
  49. package/dist/common/flow-encoding.d.ts +11 -0
  50. package/dist/common/{project-encoding.js → flow-encoding.js} +14 -13
  51. package/dist/common/{project-notifications.d.ts → flow-notifications.d.ts} +6 -3
  52. package/dist/common/{project-semantics.d.ts → flow-semantics.d.ts} +9 -12
  53. package/dist/common/{project-semantics.js → flow-semantics.js} +594 -597
  54. package/dist/common/integration-trigger.d.ts +2 -1
  55. package/dist/common/integration-trigger.js +1 -1
  56. package/dist/common/poll-trigger.d.ts +1 -1
  57. package/dist/common/provider-triggers.js +1057 -948
  58. package/dist/common/run-lifecycle.js +1 -1
  59. package/dist/common/runtime-contract.d.ts +1 -1
  60. package/dist/common/runtime-contract.js +1 -1
  61. package/dist/common/scheduler.d.ts +7 -7
  62. package/dist/common/scheduler.js +237 -232
  63. package/dist/common/webhook-trigger.d.ts +1 -1
  64. package/dist/common/webhook-trigger.js +35 -1
  65. package/package.json +20 -10
  66. package/dist/browser/addNodeOptions-DqoIueCR.js +0 -33746
  67. package/dist/browser/carbon-nMY84Amv.js +0 -53
  68. package/dist/browser/composite-7VwgfnXx.js +0 -6088
  69. package/dist/browser/createResourceDialog-ByuJWdSL.js +0 -439
  70. package/dist/browser/dist-n-z5HtaO.js +0 -4
  71. package/dist/browser/flowWorkspace-DwVMpcar.js +0 -22092
  72. package/dist/common/project-encoding.d.ts +0 -11
@@ -1,17 +1,7 @@
1
- new TextEncoder();
2
- var e = class extends Error {
3
- constructor(...e) {
4
- super(...e), this.name = "PollConnectionError";
5
- }
6
- }, t = class extends Error {
7
- constructor(...e) {
8
- super(...e), this.name = "PermanentPollError";
9
- }
10
- }, n = class extends Error {
11
- constructor(...e) {
12
- super(...e), this.name = "TransientPollError";
13
- }
14
- }, r = "LIST_RECORDS_ITERATOR_NOT_AVAILABLE", i = {
1
+ import { PermanentPollError as e, PollConnectionError as t, TransientPollError as n } from "./poll-trigger.js";
2
+ import { IntegrationConnectionError as r, PermanentIntegrationError as i, TransientIntegrationError as a } from "./integration-trigger.js";
3
+ //#region src/trigger/providers/airtable/on-record-changed.ts
4
+ var o = "LIST_RECORDS_ITERATOR_NOT_AVAILABLE", s = {
15
5
  snapshot: {
16
6
  configSchema: {
17
7
  additionalProperties: !1,
@@ -102,29 +92,29 @@ var e = class extends Error {
102
92
  type: "poll"
103
93
  },
104
94
  async poll(e) {
105
- let t = a(e.config);
95
+ let t = c(e.config);
106
96
  if (e.checkpoint === null) return {
107
- checkpoint: await c(e, t),
97
+ checkpoint: await d(e, t),
108
98
  events: []
109
99
  };
110
- let n = o(e.checkpoint), r = await l(e, t, n), i = [], s = 0;
100
+ let n = l(e.checkpoint), r = await f(e, t, n), i = [], a = 0;
111
101
  for (let e of r.records) {
112
102
  let n = g(e.fields?.[t.triggerField]);
113
- n == null ? s += 1 : i.push({
103
+ n == null ? a += 1 : i.push({
114
104
  record: e,
115
105
  value: n
116
106
  });
117
107
  }
118
- let d = i.flatMap(({ record: e, value: r }) => r == n.cursor && n.boundaryIds.includes(e.id) ? [] : [h(t, e, r)]), f = u(n, r, i);
108
+ let o = i.flatMap(({ record: e, value: r }) => r == n.cursor && n.boundaryIds.includes(e.id) ? [] : [ne(t, e, r)]), s = p(n, r, i);
119
109
  return {
120
- checkpoint: f.checkpoint,
121
- events: d,
122
- filtered: s,
123
- ...f.hasMore ? { hasMore: !0 } : {}
110
+ checkpoint: s.checkpoint,
111
+ events: o,
112
+ filtered: a,
113
+ ...s.hasMore ? { hasMore: !0 } : {}
124
114
  };
125
115
  }
126
116
  };
127
- function a(e) {
117
+ function c(e) {
128
118
  return {
129
119
  baseId: e.baseId,
130
120
  fields: e.fields ?? [],
@@ -135,10 +125,10 @@ function a(e) {
135
125
  view: (e.view ?? "").trim()
136
126
  };
137
127
  }
138
- function o(e) {
139
- let n = _(e), r = g(n?.cursor), i = n?.boundaryIds;
140
- if (r == null || !Array.isArray(i) || i.some((e) => typeof e != "string")) throw new t("Airtable checkpoint is invalid; recreate the Trigger.");
141
- let a = s(n?.pending);
128
+ function l(t) {
129
+ let n = _(t), r = g(n?.cursor), i = n?.boundaryIds;
130
+ if (r == null || !Array.isArray(i) || i.some((e) => typeof e != "string")) throw new e("Airtable checkpoint is invalid; recreate the Trigger.");
131
+ let a = u(n?.pending);
142
132
  return {
143
133
  boundaryIds: i,
144
134
  cursor: r,
@@ -147,7 +137,7 @@ function o(e) {
147
137
  ...a == null ? {} : { pending: a }
148
138
  };
149
139
  }
150
- function s(e) {
140
+ function u(e) {
151
141
  let t = _(e), n = g(t?.cursor), r = t?.boundaryIds;
152
142
  return n == null || !Array.isArray(r) || r.some((e) => typeof e != "string") ? null : {
153
143
  boundaryIds: r,
@@ -155,16 +145,16 @@ function s(e) {
155
145
  ...t?.cursorExclusive === !0 ? { cursorExclusive: !0 } : {}
156
146
  };
157
147
  }
158
- async function c(e, n) {
159
- let r = await ie(e, n, ee(n));
160
- ae(r, "seed list");
161
- let i = oe(r.data);
148
+ async function d(t, n) {
149
+ let r = await se(t, n, re(n));
150
+ ce(r, "seed list");
151
+ let i = le(r.data);
162
152
  if (i.records.length == 0) return {
163
153
  boundaryIds: [],
164
- cursor: e.now.toISOString()
154
+ cursor: t.now.toISOString()
165
155
  };
166
156
  let a = g(i.records[0]?.fields?.[n.triggerField]);
167
- if (a == null) throw new t("The Airtable trigger field is not a time field.");
157
+ if (a == null) throw new e("The Airtable trigger field is not a time field.");
168
158
  let o = i.records.filter((e) => g(e.fields?.[n.triggerField]) === a).map(({ id: e }) => e);
169
159
  return o.length == i.records.length && i.offset ? {
170
160
  boundaryIds: [],
@@ -175,29 +165,29 @@ async function c(e, n) {
175
165
  cursor: a
176
166
  };
177
167
  }
178
- async function l(e, t, n) {
179
- let i = [], a = n.offset, o = Math.min(Math.ceil(t.maxRecordsPerPoll / 100), 10);
180
- for (let s = 0; s < o; s += 1) {
181
- let o = await ie(e, t, te(t, n, a));
182
- if (a != null && o.status == 422 && se(o.data) == r) return {
168
+ async function f(e, t, n) {
169
+ let r = [], i = n.offset, a = Math.min(Math.ceil(t.maxRecordsPerPoll / 100), 10);
170
+ for (let s = 0; s < a; s += 1) {
171
+ let a = await se(e, t, ie(t, n, i));
172
+ if (i != null && a.status == 422 && ue(a.data) == o) return {
183
173
  offsetWentStale: !0,
184
- records: i
174
+ records: r
185
175
  };
186
- ae(o, "record list");
187
- let s = oe(o.data);
188
- if (i.push(...s.records), !s.offset) return {
176
+ ce(a, "record list");
177
+ let s = le(a.data);
178
+ if (r.push(...s.records), !s.offset) return {
189
179
  offsetWentStale: !1,
190
- records: i
180
+ records: r
191
181
  };
192
- a = s.offset;
182
+ i = s.offset;
193
183
  }
194
184
  return {
195
- offset: a,
185
+ offset: i,
196
186
  offsetWentStale: !1,
197
- records: i
187
+ records: r
198
188
  };
199
189
  }
200
- function u(e, t, n) {
190
+ function p(e, t, n) {
201
191
  let r = {
202
192
  boundaryIds: e.boundaryIds,
203
193
  cursor: e.cursor,
@@ -207,9 +197,9 @@ function u(e, t, n) {
207
197
  checkpoint: r,
208
198
  hasMore: !1
209
199
  };
210
- let i = f(e.pending, d(n));
200
+ let i = ee(e.pending, m(n));
211
201
  return t.offset == null ? {
212
- checkpoint: i == null ? r : p(r, i),
202
+ checkpoint: i == null ? r : h(r, i),
213
203
  hasMore: !1
214
204
  } : {
215
205
  checkpoint: {
@@ -220,22 +210,22 @@ function u(e, t, n) {
220
210
  hasMore: !0
221
211
  };
222
212
  }
223
- function d(e) {
213
+ function m(e) {
224
214
  if (e.length == 0) return;
225
215
  let t = e.reduce((e, t) => t.value > e ? t.value : e, e[0].value);
226
- return m(t, e.filter(({ value: e }) => e == t).map(({ record: e }) => e.id));
216
+ return te(t, e.filter(({ value: e }) => e == t).map(({ record: e }) => e.id));
227
217
  }
228
- function f(e, t) {
229
- return e == null ? t : t == null ? e : p(e, t);
218
+ function ee(e, t) {
219
+ return e == null ? t : t == null ? e : h(e, t);
230
220
  }
231
- function p(e, t) {
221
+ function h(e, t) {
232
222
  return t.cursor > e.cursor ? t : e.cursor > t.cursor ? e : e.cursorExclusive === !0 || t.cursorExclusive === !0 ? {
233
223
  boundaryIds: [],
234
224
  cursor: e.cursor,
235
225
  cursorExclusive: !0
236
- } : m(e.cursor, [.../* @__PURE__ */ new Set([...e.boundaryIds, ...t.boundaryIds])]);
226
+ } : te(e.cursor, [.../* @__PURE__ */ new Set([...e.boundaryIds, ...t.boundaryIds])]);
237
227
  }
238
- function m(e, t) {
228
+ function te(e, t) {
239
229
  return t.length > 200 ? {
240
230
  boundaryIds: [],
241
231
  cursor: e,
@@ -245,7 +235,7 @@ function m(e, t) {
245
235
  cursor: e
246
236
  };
247
237
  }
248
- function h(e, t, n) {
238
+ function ne(e, t, n) {
249
239
  return {
250
240
  dedupeKey: `${t.id}:${n}`,
251
241
  payload: {
@@ -259,10 +249,10 @@ function h(e, t, n) {
259
249
  }
260
250
  };
261
251
  }
262
- function ee(e) {
252
+ function re(e) {
263
253
  return {
264
254
  fields: [e.triggerField],
265
- filterByFormula: re([ne(e.triggerField), ...e.formula.length == 0 ? [] : [e.formula]]),
255
+ filterByFormula: oe([ae(e.triggerField), ...e.formula.length == 0 ? [] : [e.formula]]),
266
256
  pageSize: 100,
267
257
  sort: [{
268
258
  direction: "desc",
@@ -271,11 +261,11 @@ function ee(e) {
271
261
  ...e.view.length == 0 ? {} : { view: e.view }
272
262
  };
273
263
  }
274
- function te(e, t, n) {
264
+ function ie(e, t, n) {
275
265
  let r = `DATETIME_PARSE("${t.cursor}", "YYYY-MM-DDTHH:mm:ss.SSSZ")`, i = t.cursorExclusive === !0 ? `IS_AFTER({${e.triggerField}}, ${r})` : `NOT(IS_BEFORE({${e.triggerField}}, ${r}))`, a = e.fields.includes(e.triggerField) ? e.fields : [...e.fields, e.triggerField];
276
266
  return {
277
- filterByFormula: re([
278
- ne(e.triggerField),
267
+ filterByFormula: oe([
268
+ ae(e.triggerField),
279
269
  i,
280
270
  ...e.formula.length == 0 ? [] : [e.formula]
281
271
  ]),
@@ -289,13 +279,13 @@ function te(e, t, n) {
289
279
  ...n == null ? {} : { offset: n }
290
280
  };
291
281
  }
292
- function ne(e) {
282
+ function ae(e) {
293
283
  return `NOT({${e}} = BLANK())`;
294
284
  }
295
- function re(e) {
285
+ function oe(e) {
296
286
  return `AND(${e.join(", ")})`;
297
287
  }
298
- async function ie(e, t, r) {
288
+ async function se(e, t, r) {
299
289
  let i = `/${t.baseId}/${encodeURIComponent(t.tableIdOrName)}/listRecords`;
300
290
  try {
301
291
  return await e.connector.execute({
@@ -307,17 +297,17 @@ async function ie(e, t, r) {
307
297
  throw new n(`Airtable proxy request to ${i} failed.`, { cause: e });
308
298
  }
309
299
  }
310
- function ae(i, a) {
311
- if (!(i.status >= 200 && i.status < 300)) throw i.status == 401 || i.status == 403 ? new e(`Airtable ${a} rejected the Connection.`) : i.status == 404 ? new t("The Airtable base or table was not found.") : i.status == 422 && se(i.data) !== r ? new t("Airtable rejected the trigger field, formula, or view.") : new n(`Airtable ${a} failed with status ${i.status}.`);
300
+ function ce(r, i) {
301
+ if (!(r.status >= 200 && r.status < 300)) throw r.status == 401 || r.status == 403 ? new t(`Airtable ${i} rejected the Connection.`) : r.status == 404 ? new e("The Airtable base or table was not found.") : r.status == 422 && ue(r.data) !== o ? new e("Airtable rejected the trigger field, formula, or view.") : new n(`Airtable ${i} failed with status ${r.status}.`);
312
302
  }
313
- function oe(e) {
303
+ function le(e) {
314
304
  let t = _(e);
315
305
  return {
316
306
  records: Array.isArray(t?.records) ? t.records : [],
317
307
  ...typeof t?.offset == "string" ? { offset: t.offset } : {}
318
308
  };
319
309
  }
320
- function se(e) {
310
+ function ue(e) {
321
311
  let t = _(e)?.error;
322
312
  if (typeof t == "string") return t;
323
313
  let n = _(t)?.type;
@@ -331,20 +321,47 @@ function g(e) {
331
321
  function _(e) {
332
322
  return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
333
323
  }
334
- new TextEncoder();
335
- var v = class extends Error {
336
- constructor(...e) {
337
- super(...e), this.name = "IntegrationConnectionError";
338
- }
339
- }, y = class extends Error {
340
- constructor(...e) {
341
- super(...e), this.name = "PermanentIntegrationError";
342
- }
343
- }, b = class extends Error {
344
- constructor(...e) {
345
- super(...e), this.name = "TransientIntegrationError";
324
+ //#endregion
325
+ //#region src/trigger/providers/signature.ts
326
+ var v = new TextEncoder();
327
+ function de(e) {
328
+ return v.encode(e);
329
+ }
330
+ function fe(e, t) {
331
+ return e != null && ve(v.encode(e), v.encode(t));
332
+ }
333
+ async function pe(e, t, n) {
334
+ let r = n == null ? void 0 : ge(n);
335
+ return r != null && ve(r, await he(e, t));
336
+ }
337
+ async function me(e, t, n) {
338
+ let r = n == null ? void 0 : _e(n);
339
+ return r != null && ve(r, await he(e, t));
340
+ }
341
+ async function he(e, t) {
342
+ let n = await crypto.subtle.importKey("raw", v.encode(e), {
343
+ hash: "SHA-256",
344
+ name: "HMAC"
345
+ }, !1, ["sign"]), r = t.reduce((e, t) => e + t.byteLength, 0), i = new Uint8Array(r), a = 0;
346
+ for (let e of t) i.set(e, a), a += e.byteLength;
347
+ return new Uint8Array(await crypto.subtle.sign("HMAC", n, i));
348
+ }
349
+ function ge(e) {
350
+ try {
351
+ return Uint8Array.from(atob(e), (e) => e.charCodeAt(0));
352
+ } catch {
353
+ return;
346
354
  }
347
- }, ce = {
355
+ }
356
+ function _e(e) {
357
+ if (!(e.length == 0 || e.length % 2 != 0 || !/^[0-9a-f]+$/i.test(e))) return Uint8Array.from({ length: e.length / 2 }, (t, n) => Number.parseInt(e.slice(n * 2, n * 2 + 2), 16));
358
+ }
359
+ function ve(e, t) {
360
+ let n = e.byteLength ^ t.byteLength, r = Math.max(e.byteLength, t.byteLength);
361
+ for (let i = 0; i < r; i += 1) n |= (e[i] ?? 0) ^ (t[i] ?? 0);
362
+ return n == 0;
363
+ }
364
+ var ye = {
348
365
  initialState: {
349
366
  checkpoint: null,
350
367
  subscription: {}
@@ -383,7 +400,7 @@ var v = class extends Error {
383
400
  title: "GitHub Repo Event Config",
384
401
  type: "object"
385
402
  },
386
- definitionVersion: 1,
403
+ definitionVersion: 2,
387
404
  description: "Triggers when selected GitHub webhook events occur in a repository.",
388
405
  displayName: "GitHub: Repository Event",
389
406
  endpoint: {
@@ -415,65 +432,72 @@ var v = class extends Error {
415
432
  provider: "github",
416
433
  type: "integration"
417
434
  },
418
- receive(e) {
419
- let t = e.header("x-github-event")?.trim();
420
- if (!t) return {
435
+ async receive(e) {
436
+ let t = e.header("x-hub-signature-256");
437
+ if (!t?.startsWith("sha256=") || !await me(e.callbackSecret, [e.rawBody], t.slice(7))) return {
438
+ body: "",
439
+ contentType: "text/plain",
440
+ outcome: "respond",
441
+ status: 404
442
+ };
443
+ let n = e.header("x-github-event")?.trim();
444
+ if (!n) return {
421
445
  outcome: "ignored",
422
446
  reason: "GitHub event header is missing."
423
447
  };
424
- if (t == "ping") return {
448
+ if (n == "ping") return {
425
449
  outcome: "ignored",
426
450
  reason: "GitHub ping handshake."
427
451
  };
428
- let n = le(e.config);
429
- if (!n.events.includes("*") && !n.events.includes(t)) return {
452
+ let r = be(e.config);
453
+ if (!r.events.includes("*") && !r.events.includes(n)) return {
430
454
  outcome: "ignored",
431
455
  reason: "GitHub event is not subscribed."
432
456
  };
433
- let r = e.header("x-github-delivery") ?? "";
457
+ let i = e.header("x-github-delivery") ?? "";
434
458
  return {
435
- dedupeKey: r.length == 0 ? void 0 : r,
459
+ dedupeKey: i.length == 0 ? void 0 : i,
436
460
  outcome: "event",
437
461
  payload: {
438
462
  body: e.payload,
439
- deliveryId: r,
440
- event: t
463
+ deliveryId: i,
464
+ event: n
441
465
  }
442
466
  };
443
467
  },
444
468
  async reconcile(e) {
445
- let t = pe(e.state), n = le(e.config), r = me(t);
469
+ let t = Te(e.state), n = be(e.config), r = Ee(t);
446
470
  if (!e.active) {
447
- if (r ??= await de(e, n), r != null) {
448
- let t = await S(e, "hook delete", {
449
- endpoint: `${x(n)}/${r}`,
471
+ if (r ??= await Ce(e, n), r != null) {
472
+ let t = await y(e, "hook delete", {
473
+ endpoint: `${xe(n)}/${r}`,
450
474
  method: "DELETE"
451
475
  });
452
- t.status != 404 && C(t, "hook delete");
476
+ t.status != 404 && b(t, "hook delete");
453
477
  }
454
- return await t.saveSubscription({}, he(e.now)), { outcome: "ready" };
478
+ return await t.saveSubscription({}, De(e.now)), { outcome: "ready" };
455
479
  }
456
- let i = ue(e.endpointUrl, n);
480
+ let o = Se(e.endpointUrl, e.callbackSecret, n);
457
481
  if (r == null) {
458
- let t = await S(e, "hook create", {
459
- body: i,
460
- endpoint: x(n),
482
+ let t = await y(e, "hook create", {
483
+ body: o,
484
+ endpoint: xe(n),
461
485
  method: "POST"
462
486
  });
463
- if (t.status == 201) r = fe(t.data);
487
+ if (t.status == 201) r = we(t.data);
464
488
  else if (t.status == 422) {
465
- if (r = await de(e, n), r == null) throw new y("GitHub rejected the webhook configuration.");
466
- } else throw C(t, "hook create"), new b(`GitHub hook create returned unexpected status ${t.status}.`);
489
+ if (r = await Ce(e, n), r == null) throw new i("GitHub rejected the webhook configuration.");
490
+ } else throw b(t, "hook create"), new a(`GitHub hook create returned unexpected status ${t.status}.`);
467
491
  }
468
- let a = await S(e, "hook update", {
469
- body: i,
470
- endpoint: `${x(n)}/${r}`,
492
+ let s = await y(e, "hook update", {
493
+ body: o,
494
+ endpoint: `${xe(n)}/${r}`,
471
495
  method: "PATCH"
472
496
  });
473
- return a.status == 404 ? (await t.saveSubscription({}, e.now), { outcome: "pending" }) : (C(a, "hook update"), await t.saveSubscription({ hookId: r }, he(e.now)), { outcome: "ready" });
497
+ return s.status == 404 ? (await t.saveSubscription({}, e.now), { outcome: "pending" }) : (b(s, "hook update"), await t.saveSubscription({ hookId: r }, De(e.now)), { outcome: "ready" });
474
498
  }
475
499
  };
476
- function le(e) {
500
+ function be(e) {
477
501
  return {
478
502
  events: [...new Set(e.events)],
479
503
  insecureSsl: e.insecureSsl ?? !1,
@@ -481,25 +505,26 @@ function le(e) {
481
505
  repo: e.repo
482
506
  };
483
507
  }
484
- function x(e) {
508
+ function xe(e) {
485
509
  return `/repos/${encodeURIComponent(e.owner)}/${encodeURIComponent(e.repo)}/hooks`;
486
510
  }
487
- function ue(e, t) {
511
+ function Se(e, t, n) {
488
512
  return {
489
513
  active: !0,
490
514
  config: {
491
515
  content_type: "json",
492
- insecure_ssl: t.insecureSsl ? "1" : "0",
516
+ insecure_ssl: n.insecureSsl ? "1" : "0",
517
+ secret: t,
493
518
  url: e
494
519
  },
495
- events: t.events,
520
+ events: n.events,
496
521
  name: "web"
497
522
  };
498
523
  }
499
- async function de(e, t) {
524
+ async function Ce(e, t) {
500
525
  for (let n = 1; n <= 10; n += 1) {
501
- let r = await S(e, "hook list", {
502
- endpoint: x(t),
526
+ let r = await y(e, "hook list", {
527
+ endpoint: xe(t),
503
528
  method: "GET",
504
529
  query: {
505
530
  page: n,
@@ -507,50 +532,50 @@ async function de(e, t) {
507
532
  }
508
533
  });
509
534
  if (r.status == 404) return null;
510
- C(r, "hook list");
535
+ b(r, "hook list");
511
536
  let i = Array.isArray(r.data) ? r.data : [];
512
537
  for (let t of i) {
513
- let n = w(t);
514
- if (w(n?.config)?.url === e.endpointUrl && (typeof n?.id == "number" || typeof n?.id == "string")) return String(n.id);
538
+ let n = Oe(t);
539
+ if (Oe(n?.config)?.url === e.endpointUrl && (typeof n?.id == "number" || typeof n?.id == "string")) return String(n.id);
515
540
  }
516
541
  if (i.length < 100) return null;
517
542
  }
518
543
  return null;
519
544
  }
520
- async function S(e, t, n) {
545
+ async function y(e, t, n) {
521
546
  try {
522
547
  return await e.connector.execute(n, e.signal);
523
548
  } catch (e) {
524
- throw e instanceof v ? e : new b(`GitHub ${t} request failed.`, { cause: e });
549
+ throw e instanceof r ? e : new a(`GitHub ${t} request failed.`, { cause: e });
525
550
  }
526
551
  }
527
- function C(e, t) {
552
+ function b(e, t) {
528
553
  if (e.status >= 200 && e.status < 300) return;
529
- let n = w(e.data)?.message;
530
- throw e.status == 403 && typeof n == "string" && /rate limit/i.test(n) ? new b(`GitHub ${t} was rate limited.`) : [401, 403].includes(e.status) ? new v(`GitHub ${t} rejected the Connection.`) : [404, 422].includes(e.status) ? new y(`GitHub ${t} rejected the subscription.`) : new b(`GitHub ${t} failed with status ${e.status}.`);
554
+ let n = Oe(e.data)?.message;
555
+ throw e.status == 403 && typeof n == "string" && /rate limit/i.test(n) ? new a(`GitHub ${t} was rate limited.`) : [401, 403].includes(e.status) ? new r(`GitHub ${t} rejected the Connection.`) : [404, 422].includes(e.status) ? new i(`GitHub ${t} rejected the subscription.`) : new a(`GitHub ${t} failed with status ${e.status}.`);
531
556
  }
532
- function fe(e) {
533
- let t = w(e)?.id;
534
- if (typeof t != "number" && typeof t != "string") throw new b("GitHub hook response is missing its ID.");
557
+ function we(e) {
558
+ let t = Oe(e)?.id;
559
+ if (typeof t != "number" && typeof t != "string") throw new a("GitHub hook response is missing its ID.");
535
560
  return String(t);
536
561
  }
537
- function pe(e) {
538
- if (e == null) throw new y("GitHub Integration state is missing.");
562
+ function Te(e) {
563
+ if (e == null) throw new i("GitHub Integration state is missing.");
539
564
  return e;
540
565
  }
541
- function me(e) {
566
+ function Ee(e) {
542
567
  let t = e.subscription.hookId;
543
568
  return typeof t == "string" && t.length > 0 ? t : null;
544
569
  }
545
- function he(e) {
570
+ function De(e) {
546
571
  return new Date(e.getTime() + 2592e6);
547
572
  }
548
- function w(e) {
573
+ function Oe(e) {
549
574
  return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
550
575
  }
551
576
  //#endregion
552
577
  //#region src/trigger/providers/gitlab/on-project-event.ts
553
- var ge = [
578
+ var ke = [
554
579
  "push",
555
580
  "tag_push",
556
581
  "issues",
@@ -568,7 +593,7 @@ var ge = [
568
593
  "emoji",
569
594
  "resource_access_token",
570
595
  "resource_deploy_token"
571
- ], _e = /* @__PURE__ */ new Map([
596
+ ], Ae = /* @__PURE__ */ new Map([
572
597
  ["Push Hook", "push"],
573
598
  ["Tag Push Hook", "tag_push"],
574
599
  ["Issue Hook", "issues"],
@@ -586,7 +611,7 @@ var ge = [
586
611
  ["Emoji Hook", "emoji"],
587
612
  ["Resource Access Token Hook", "resource_access_token"],
588
613
  ["Resource Deploy Token Hook", "resource_deploy_token"]
589
- ]), ve = {
614
+ ]), je = {
590
615
  initialState: {
591
616
  checkpoint: null,
592
617
  subscription: {}
@@ -597,7 +622,7 @@ var ge = [
597
622
  properties: {
598
623
  events: {
599
624
  items: {
600
- enum: ge,
625
+ enum: ke,
601
626
  type: "string"
602
627
  },
603
628
  minItems: 1,
@@ -624,7 +649,7 @@ var ge = [
624
649
  title: "GitLab Project Event Config",
625
650
  type: "object"
626
651
  },
627
- definitionVersion: 1,
652
+ definitionVersion: 2,
628
653
  description: "Triggers when selected GitLab webhook events occur in a project.",
629
654
  displayName: "GitLab: Project Event",
630
655
  endpoint: {
@@ -659,17 +684,23 @@ var ge = [
659
684
  type: "integration"
660
685
  },
661
686
  receive(e) {
687
+ if (!fe(e.header("x-gitlab-token"), e.callbackSecret)) return {
688
+ body: "",
689
+ contentType: "text/plain",
690
+ outcome: "respond",
691
+ status: 404
692
+ };
662
693
  let t = e.header("x-gitlab-event")?.trim();
663
694
  if (!t) return {
664
695
  outcome: "ignored",
665
696
  reason: "GitLab event header is missing."
666
697
  };
667
- let n = _e.get(t);
698
+ let n = Ae.get(t);
668
699
  if (n == null) return {
669
700
  outcome: "ignored",
670
701
  reason: "GitLab event header is unknown."
671
702
  };
672
- if (!ye(e.config).events.includes(n)) return {
703
+ if (!Me(e.config).events.includes(n)) return {
673
704
  outcome: "ignored",
674
705
  reason: "GitLab event is not subscribed."
675
706
  };
@@ -686,36 +717,36 @@ var ge = [
686
717
  };
687
718
  },
688
719
  async reconcile(e) {
689
- let t = we(e.state), n = ye(e.config), r = Te(t);
720
+ let t = Le(e.state), n = Me(e.config), r = Re(t);
690
721
  if (!e.active) {
691
- let i = r == null ? await xe(e, n) : [r];
692
- for (let t of i ?? []) await Se(e, n, t);
693
- return await t.saveSubscription({}, Ee(e.now)), { outcome: "ready" };
722
+ let i = r == null ? await Pe(e, n) : [r];
723
+ for (let t of i ?? []) await Fe(e, n, t);
724
+ return await t.saveSubscription({}, ze(e.now)), { outcome: "ready" };
694
725
  }
695
- let i = await xe(e, n);
696
- if (i == null) throw new y("The GitLab project does not exist or is not visible.");
697
- let a = r ?? i[0];
698
- if (a == null) {
699
- let t = await E(e, "hook create", {
700
- body: be(e.endpointUrl, n),
701
- endpoint: T(n),
726
+ let a = await Pe(e, n);
727
+ if (a == null) throw new i("The GitLab project does not exist or is not visible.");
728
+ let o = r ?? a[0];
729
+ if (o == null) {
730
+ let t = await S(e, "hook create", {
731
+ body: Ne(e.endpointUrl, e.callbackSecret, n),
732
+ endpoint: x(n),
702
733
  method: "POST"
703
734
  });
704
- D(t, "hook create"), a = Ce(t.data);
735
+ C(t, "hook create"), o = Ie(t.data);
705
736
  } else {
706
- let r = await E(e, "hook update", {
707
- body: be(e.endpointUrl, n),
708
- endpoint: `${T(n)}/${a}`,
737
+ let r = await S(e, "hook update", {
738
+ body: Ne(e.endpointUrl, e.callbackSecret, n),
739
+ endpoint: `${x(n)}/${o}`,
709
740
  method: "PUT"
710
741
  });
711
742
  if (r.status == 404) return await t.saveSubscription({}, e.now), { outcome: "pending" };
712
- D(r, "hook update");
743
+ C(r, "hook update");
713
744
  }
714
- for (let t of i.filter((e) => e != a)) await Se(e, n, t);
715
- return await t.saveSubscription({ hookId: a }, Ee(e.now)), { outcome: "ready" };
745
+ for (let t of a.filter((e) => e != o)) await Fe(e, n, t);
746
+ return await t.saveSubscription({ hookId: o }, ze(e.now)), { outcome: "ready" };
716
747
  }
717
748
  };
718
- function ye(e) {
749
+ function Me(e) {
719
750
  return {
720
751
  events: e.events,
721
752
  insecureSsl: e.insecureSsl ?? !1,
@@ -723,25 +754,26 @@ function ye(e) {
723
754
  pushBranchFilter: e.pushBranchFilter ?? ""
724
755
  };
725
756
  }
726
- function T(e) {
757
+ function x(e) {
727
758
  return `/projects/${encodeURIComponent(e.project)}/hooks`;
728
759
  }
729
- function be(e, t) {
760
+ function Ne(e, t, n) {
730
761
  return {
731
762
  branch_filter_strategy: "wildcard",
732
763
  description: "Managed by Open Flow.",
733
- enable_ssl_verification: !t.insecureSsl,
764
+ enable_ssl_verification: !n.insecureSsl,
734
765
  name: `Open Flow ${e.slice(e.lastIndexOf("/") + 1)}`,
735
- push_events_branch_filter: t.pushBranchFilter,
766
+ push_events_branch_filter: n.pushBranchFilter,
736
767
  url: e,
737
- ...Object.fromEntries(ge.map((e) => [`${e}_events`, t.events.includes(e)]))
768
+ token: t,
769
+ ...Object.fromEntries(ke.map((e) => [`${e}_events`, n.events.includes(e)]))
738
770
  };
739
771
  }
740
- async function xe(e, t) {
772
+ async function Pe(e, t) {
741
773
  let n = [];
742
774
  for (let r = 1; r <= 10; r += 1) {
743
- let i = await E(e, "hook list", {
744
- endpoint: T(t),
775
+ let i = await S(e, "hook list", {
776
+ endpoint: x(t),
745
777
  method: "GET",
746
778
  query: {
747
779
  page: r,
@@ -749,59 +781,59 @@ async function xe(e, t) {
749
781
  }
750
782
  });
751
783
  if (i.status == 404) return null;
752
- D(i, "hook list");
784
+ C(i, "hook list");
753
785
  let a = Array.isArray(i.data) ? i.data : [];
754
786
  for (let t of a) {
755
- let r = De(t);
787
+ let r = Be(t);
756
788
  r?.url === e.endpointUrl && (typeof r.id == "number" || typeof r.id == "string") && n.push(String(r.id));
757
789
  }
758
790
  if (a.length < 100) break;
759
791
  }
760
792
  return n;
761
793
  }
762
- async function Se(e, t, n) {
763
- let r = await E(e, "hook delete", {
764
- endpoint: `${T(t)}/${n}`,
794
+ async function Fe(e, t, n) {
795
+ let r = await S(e, "hook delete", {
796
+ endpoint: `${x(t)}/${n}`,
765
797
  method: "DELETE"
766
798
  });
767
- r.status != 404 && D(r, "hook delete");
799
+ r.status != 404 && C(r, "hook delete");
768
800
  }
769
- async function E(e, t, n) {
801
+ async function S(e, t, n) {
770
802
  try {
771
803
  return await e.connector.execute(n, e.signal);
772
804
  } catch (e) {
773
- throw e instanceof v ? e : new b(`GitLab ${t} request failed.`, { cause: e });
805
+ throw e instanceof r ? e : new a(`GitLab ${t} request failed.`, { cause: e });
774
806
  }
775
807
  }
776
- function D(e, t) {
777
- if (!(e.status >= 200 && e.status < 300)) throw e.status == 401 || e.status == 403 ? new v(`GitLab ${t} rejected the Connection.`) : [
808
+ function C(e, t) {
809
+ if (!(e.status >= 200 && e.status < 300)) throw e.status == 401 || e.status == 403 ? new r(`GitLab ${t} rejected the Connection.`) : [
778
810
  400,
779
811
  404,
780
812
  422
781
- ].includes(e.status) ? new y(`GitLab ${t} rejected the subscription.`) : new b(`GitLab ${t} failed with status ${e.status}.`);
813
+ ].includes(e.status) ? new i(`GitLab ${t} rejected the subscription.`) : new a(`GitLab ${t} failed with status ${e.status}.`);
782
814
  }
783
- function Ce(e) {
784
- let t = De(e)?.id;
785
- if (typeof t != "number" && typeof t != "string") throw new b("GitLab hook response is missing its ID.");
815
+ function Ie(e) {
816
+ let t = Be(e)?.id;
817
+ if (typeof t != "number" && typeof t != "string") throw new a("GitLab hook response is missing its ID.");
786
818
  return String(t);
787
819
  }
788
- function we(e) {
789
- if (e == null) throw new y("GitLab Integration state is missing.");
820
+ function Le(e) {
821
+ if (e == null) throw new i("GitLab Integration state is missing.");
790
822
  return e;
791
823
  }
792
- function Te(e) {
824
+ function Re(e) {
793
825
  let t = e.subscription.hookId;
794
826
  return typeof t == "string" && t.length > 0 ? t : null;
795
827
  }
796
- function Ee(e) {
828
+ function ze(e) {
797
829
  return new Date(e.getTime() + 2592e6);
798
830
  }
799
- function De(e) {
831
+ function Be(e) {
800
832
  return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
801
833
  }
802
834
  //#endregion
803
835
  //#region src/trigger/providers/gmail/on-message-received.ts
804
- var Oe = 25, ke = 5, Ae = {
836
+ var Ve = 25, He = 5, Ue = {
805
837
  snapshot: {
806
838
  configSchema: {
807
839
  additionalProperties: !1,
@@ -826,7 +858,7 @@ var Oe = 25, ke = 5, Ae = {
826
858
  type: "array"
827
859
  },
828
860
  maxMessagesPerPoll: {
829
- default: Oe,
861
+ default: Ve,
830
862
  maximum: 100,
831
863
  minimum: 1,
832
864
  type: "integer"
@@ -897,20 +929,20 @@ var Oe = 25, ke = 5, Ae = {
897
929
  type: "poll"
898
930
  },
899
931
  async poll(e) {
900
- let t = je(e.config);
932
+ let t = We(e.config);
901
933
  if (e.checkpoint === null) return {
902
- checkpoint: { historyId: await Me(e) },
934
+ checkpoint: { historyId: await Ge(e) },
903
935
  events: []
904
936
  };
905
- let n = Ne(e.checkpoint), r = await Pe(e, t.labelNamesOrIds), { candidates: i, lastPage: a } = await Fe(e, n, r, t.maxMessagesPerPoll), o = Ie(n.historyId, a), s = [], c = 0;
937
+ let n = Ke(e.checkpoint), r = await qe(e, t.labelNamesOrIds), { candidates: i, lastPage: a } = await Je(e, n, r, t.maxMessagesPerPoll), o = Ye(n.historyId, a), s = [], c = 0;
906
938
  for (let n of i) {
907
- let i = await Le(e, n.id);
939
+ let i = await Xe(e, n.id);
908
940
  if (i != null) {
909
- if (!await Re(e, i, t, r)) {
941
+ if (!await Ze(e, i, t, r)) {
910
942
  c += 1;
911
943
  continue;
912
944
  }
913
- s.push(Ve(i));
945
+ s.push(et(i));
914
946
  }
915
947
  }
916
948
  return {
@@ -921,59 +953,59 @@ var Oe = 25, ke = 5, Ae = {
921
953
  };
922
954
  }
923
955
  };
924
- function je(e) {
956
+ function We(e) {
925
957
  return {
926
958
  includeDrafts: e.includeDrafts ?? !1,
927
959
  includeSpamAndTrash: e.includeSpamAndTrash ?? !1,
928
960
  labelNamesOrIds: e.labelNamesOrIds ?? [],
929
- maxMessagesPerPoll: e.maxMessagesPerPoll ?? Oe,
961
+ maxMessagesPerPoll: e.maxMessagesPerPoll ?? Ve,
930
962
  readStatus: e.readStatus ?? "All",
931
963
  search: (e.search ?? "").trim(),
932
964
  sender: (e.sender ?? "").trim()
933
965
  };
934
966
  }
935
- async function Me(e) {
936
- let t = await O(e, "/users/me/profile");
937
- k(t, "profile fetch");
938
- let r = j(t.data)?.historyId;
967
+ async function Ge(e) {
968
+ let t = await w(e, "/users/me/profile");
969
+ T(t, "profile fetch");
970
+ let r = D(t.data)?.historyId;
939
971
  if (typeof r != "string" || r.length == 0) throw new n("Gmail profile historyId is missing.");
940
972
  return r;
941
973
  }
942
- function Ne(e) {
943
- let n = j(e);
944
- if (typeof n?.historyId != "string" || n.historyId.length == 0) throw new t("Gmail checkpoint historyId is missing; recreate the Trigger.");
974
+ function Ke(t) {
975
+ let n = D(t);
976
+ if (typeof n?.historyId != "string" || n.historyId.length == 0) throw new e("Gmail checkpoint historyId is missing; recreate the Trigger.");
945
977
  return {
946
978
  historyId: n.historyId,
947
979
  ...typeof n.pageToken == "string" ? { pageToken: n.pageToken } : {}
948
980
  };
949
981
  }
950
- async function Pe(e, n) {
982
+ async function qe(t, n) {
951
983
  if (n.length == 0) return [];
952
- let r = await O(e, "/users/me/labels");
953
- k(r, "labels list");
954
- let i = j(r.data)?.labels, a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map();
984
+ let r = await w(t, "/users/me/labels");
985
+ T(r, "labels list");
986
+ let i = D(r.data)?.labels, a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map();
955
987
  if (Array.isArray(i)) for (let e of i) {
956
- let t = j(e);
988
+ let t = D(e);
957
989
  typeof t?.id == "string" && t.id.length != 0 && (a.add(t.id), typeof t.name == "string" && t.name.length > 0 && o.set(t.name.toLowerCase(), t.id));
958
990
  }
959
- return [...new Set(n.map((e) => {
960
- let n = a.has(e) ? e : o.get(e.toLowerCase());
961
- if (n == null) throw new t(`Gmail label "${e}" does not exist.`);
991
+ return [...new Set(n.map((t) => {
992
+ let n = a.has(t) ? t : o.get(t.toLowerCase());
993
+ if (n == null) throw new e(`Gmail label "${t}" does not exist.`);
962
994
  return n;
963
995
  }))];
964
996
  }
965
- async function Fe(e, n, r, i) {
997
+ async function Je(t, n, r, i) {
966
998
  let a = /* @__PURE__ */ new Map(), o = n.pageToken, s = {};
967
- for (let c = 0; c < ke; c += 1) {
968
- let c = await O(e, "/users/me/history", {
999
+ for (let c = 0; c < He; c += 1) {
1000
+ let c = await w(t, "/users/me/history", {
969
1001
  historyTypes: "messageAdded",
970
1002
  labelId: r[0],
971
1003
  maxResults: i,
972
1004
  pageToken: o,
973
1005
  startHistoryId: n.historyId
974
1006
  });
975
- if (c.status == 404) throw new t("Gmail history checkpoint expired; recreate the Trigger.");
976
- k(c, "history list"), s = j(c.data) ?? {};
1007
+ if (c.status == 404) throw new e("Gmail history checkpoint expired; recreate the Trigger.");
1008
+ T(c, "history list"), s = D(c.data) ?? {};
977
1009
  for (let e of s.history ?? []) for (let t of e.messagesAdded ?? []) {
978
1010
  let e = t.message?.id;
979
1011
  e != null && e.length > 0 && !a.has(e) && a.set(e, { id: e });
@@ -985,7 +1017,7 @@ async function Fe(e, n, r, i) {
985
1017
  lastPage: s
986
1018
  };
987
1019
  }
988
- function Ie(e, t) {
1020
+ function Ye(e, t) {
989
1021
  if (t.nextPageToken) return {
990
1022
  checkpoint: {
991
1023
  historyId: e,
@@ -999,32 +1031,32 @@ function Ie(e, t) {
999
1031
  hasMore: !1
1000
1032
  };
1001
1033
  }
1002
- async function Le(e, t) {
1003
- let n = await O(e, `/users/me/messages/${encodeURIComponent(t)}`, { format: "metadata" });
1004
- return n.status == 404 ? null : (k(n, "message metadata fetch"), j(n.data) ?? null);
1034
+ async function Xe(e, t) {
1035
+ let n = await w(e, `/users/me/messages/${encodeURIComponent(t)}`, { format: "metadata" });
1036
+ return n.status == 404 ? null : (T(n, "message metadata fetch"), D(n.data) ?? null);
1005
1037
  }
1006
- async function Re(e, t, n, r) {
1038
+ async function Ze(e, t, n, r) {
1007
1039
  let i = t.labelIds ?? [];
1008
1040
  if (!n.includeSpamAndTrash && (i.includes("SPAM") || i.includes("TRASH")) || !n.includeDrafts && i.includes("DRAFT") || n.readStatus == "Unread" && !i.includes("UNREAD") || n.readStatus == "Read" && i.includes("UNREAD") || !r.every((e) => i.includes(e))) return !1;
1009
- let a = ze(n);
1010
- return a.length == 0 || await Be(e, t, a, n.includeSpamAndTrash);
1041
+ let a = Qe(n);
1042
+ return a.length == 0 || await $e(e, t, a, n.includeSpamAndTrash);
1011
1043
  }
1012
- function ze(e) {
1044
+ function Qe(e) {
1013
1045
  let t = e.search.length == 0 ? [] : [e.search], n = e.sender.replaceAll("\"", "").trim();
1014
1046
  return n.length > 0 && t.push(`from:${/\s/.test(n) ? `"${n}"` : n}`), t.join(" ");
1015
1047
  }
1016
- async function Be(e, t, n, r) {
1017
- let i = A(t.payload?.headers ?? [], "Message-ID").replace(/^</, "").replace(/>$/, "");
1048
+ async function $e(e, t, n, r) {
1049
+ let i = E(t.payload?.headers ?? [], "Message-ID").replace(/^</, "").replace(/>$/, "");
1018
1050
  if (i.length == 0) return !1;
1019
- let a = await O(e, "/users/me/messages", {
1051
+ let a = await w(e, "/users/me/messages", {
1020
1052
  includeSpamTrash: r ? "true" : void 0,
1021
1053
  q: `${n} rfc822msgid:${i}`
1022
1054
  });
1023
- k(a, "query match");
1024
- let o = j(a.data)?.messages;
1025
- return Array.isArray(o) && o.some((e) => j(e)?.id === t.id);
1055
+ T(a, "query match");
1056
+ let o = D(a.data)?.messages;
1057
+ return Array.isArray(o) && o.some((e) => D(e)?.id === t.id);
1026
1058
  }
1027
- function Ve(e) {
1059
+ function et(e) {
1028
1060
  let t = e.payload?.headers ?? [];
1029
1061
  return {
1030
1062
  dedupeKey: e.id,
@@ -1032,15 +1064,15 @@ function Ve(e) {
1032
1064
  historyId: e.historyId ?? null,
1033
1065
  labelIds: e.labelIds ?? [],
1034
1066
  messageId: e.id,
1035
- messageTimestamp: He(e.internalDate, A(t, "Date")),
1036
- sender: A(t, "From"),
1037
- subject: A(t, "Subject"),
1067
+ messageTimestamp: tt(e.internalDate, E(t, "Date")),
1068
+ sender: E(t, "From"),
1069
+ subject: E(t, "Subject"),
1038
1070
  threadId: e.threadId ?? "",
1039
- to: A(t, "To")
1071
+ to: E(t, "To")
1040
1072
  }
1041
1073
  };
1042
1074
  }
1043
- async function O(e, t, r = {}) {
1075
+ async function w(e, t, r = {}) {
1044
1076
  try {
1045
1077
  return await e.connector.execute({
1046
1078
  endpoint: t,
@@ -1051,13 +1083,13 @@ async function O(e, t, r = {}) {
1051
1083
  throw new n(`Gmail proxy request to ${t} failed.`, { cause: e });
1052
1084
  }
1053
1085
  }
1054
- function k(t, r) {
1055
- if (!(t.status >= 200 && t.status < 300)) throw t.status == 401 || t.status == 403 ? new e(`Gmail ${r} rejected the Connection.`) : new n(`Gmail ${r} failed with status ${t.status}.`);
1086
+ function T(e, r) {
1087
+ if (!(e.status >= 200 && e.status < 300)) throw e.status == 401 || e.status == 403 ? new t(`Gmail ${r} rejected the Connection.`) : new n(`Gmail ${r} failed with status ${e.status}.`);
1056
1088
  }
1057
- function A(e, t) {
1089
+ function E(e, t) {
1058
1090
  return e.find((e) => e.name.toLowerCase() == t.toLowerCase())?.value ?? "";
1059
1091
  }
1060
- function He(e, t) {
1092
+ function tt(e, t) {
1061
1093
  let n = e == null ? NaN : Number(e);
1062
1094
  if (Number.isFinite(n)) {
1063
1095
  let e = new Date(n);
@@ -1066,21 +1098,21 @@ function He(e, t) {
1066
1098
  let r = Date.parse(t);
1067
1099
  return Number.isNaN(r) ? "" : new Date(r).toISOString();
1068
1100
  }
1069
- function j(e) {
1101
+ function D(e) {
1070
1102
  return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
1071
1103
  }
1072
1104
  //#endregion
1073
1105
  //#region src/trigger/providers/google-calendar/on-event-changed.ts
1074
- var M = [
1106
+ var O = [
1075
1107
  "created",
1076
1108
  "updated",
1077
1109
  "cancelled"
1078
- ], Ue = /* @__PURE__ */ new Set([
1110
+ ], nt = /* @__PURE__ */ new Set([
1079
1111
  "rateLimitExceeded",
1080
1112
  "userRateLimitExceeded",
1081
1113
  "quotaExceeded",
1082
1114
  "usageLimits"
1083
- ]), We = {
1115
+ ]), rt = {
1084
1116
  snapshot: {
1085
1117
  configSchema: {
1086
1118
  additionalProperties: !1,
@@ -1091,9 +1123,9 @@ var M = [
1091
1123
  type: "string"
1092
1124
  },
1093
1125
  changes: {
1094
- default: M,
1126
+ default: O,
1095
1127
  items: {
1096
- enum: M,
1128
+ enum: O,
1097
1129
  type: "string"
1098
1130
  },
1099
1131
  minItems: 1,
@@ -1132,7 +1164,7 @@ var M = [
1132
1164
  },
1133
1165
  calendarId: { type: "string" },
1134
1166
  changeType: {
1135
- enum: M,
1167
+ enum: O,
1136
1168
  type: "string"
1137
1169
  },
1138
1170
  created: { type: ["string", "null"] },
@@ -1183,22 +1215,22 @@ var M = [
1183
1215
  type: "poll"
1184
1216
  },
1185
1217
  async poll(e) {
1186
- let t = Ge(e.config);
1187
- if (e.checkpoint === null) return qe(e, t, e.now.toISOString());
1188
- let n = Ke(e.checkpoint);
1189
- return n.calendarId === t.calendarId ? "seedTimeMin" in n ? qe(e, t, n.seedTimeMin, n.pageToken) : Je(e, t, n) : qe(e, t, e.now.toISOString());
1218
+ let t = it(e.config);
1219
+ if (e.checkpoint === null) return ot(e, t, e.now.toISOString());
1220
+ let n = at(e.checkpoint);
1221
+ return n.calendarId === t.calendarId ? "seedTimeMin" in n ? ot(e, t, n.seedTimeMin, n.pageToken) : st(e, t, n) : ot(e, t, e.now.toISOString());
1190
1222
  }
1191
1223
  };
1192
- function Ge(e) {
1224
+ function it(e) {
1193
1225
  return {
1194
1226
  calendarId: e.calendarId,
1195
- changes: new Set(e.changes ?? M),
1227
+ changes: new Set(e.changes ?? O),
1196
1228
  matchTerm: (e.matchTerm ?? "").trim(),
1197
1229
  maxEventsPerPoll: e.maxEventsPerPoll ?? 100
1198
1230
  };
1199
1231
  }
1200
- function Ke(e) {
1201
- let n = N(e), r = typeof n?.pageToken == "string" ? n.pageToken : void 0, i = typeof n?.calendarId == "string" ? n.calendarId : void 0;
1232
+ function at(t) {
1233
+ let n = k(t), r = typeof n?.pageToken == "string" ? n.pageToken : void 0, i = typeof n?.calendarId == "string" ? n.calendarId : void 0;
1202
1234
  if (typeof n?.syncToken == "string" && n.syncToken.length > 0) return {
1203
1235
  calendarId: i,
1204
1236
  ...r == null ? {} : { pageToken: r },
@@ -1209,27 +1241,27 @@ function Ke(e) {
1209
1241
  ...r == null ? {} : { pageToken: r },
1210
1242
  seedTimeMin: n.seedTimeMin
1211
1243
  };
1212
- throw new t("Google Calendar checkpoint is invalid; recreate the Trigger.");
1244
+ throw new e("Google Calendar checkpoint is invalid; recreate the Trigger.");
1213
1245
  }
1214
- async function qe(e, t, r, i) {
1246
+ async function ot(e, t, r, i) {
1215
1247
  let a = i;
1216
1248
  for (let i = 0; i < 2; i += 1) {
1217
- let i = await Qe(e, t.calendarId, {
1249
+ let i = await dt(e, t.calendarId, {
1218
1250
  maxResults: 2500,
1219
1251
  pageToken: a,
1220
1252
  showDeleted: "true",
1221
1253
  singleEvents: "false",
1222
1254
  timeMin: r
1223
1255
  });
1224
- if (a != null && et(i)) return {
1256
+ if (a != null && pt(i)) return {
1225
1257
  checkpoint: {
1226
1258
  calendarId: t.calendarId,
1227
1259
  seedTimeMin: r
1228
1260
  },
1229
1261
  events: []
1230
1262
  };
1231
- $e(e, i, "seed full sync");
1232
- let o = N(i.data) ?? {};
1263
+ ft(e, i, "seed full sync");
1264
+ let o = k(i.data) ?? {};
1233
1265
  if (o.nextSyncToken) return {
1234
1266
  checkpoint: {
1235
1267
  calendarId: t.calendarId,
@@ -1250,17 +1282,17 @@ async function qe(e, t, r, i) {
1250
1282
  hasMore: !0
1251
1283
  };
1252
1284
  }
1253
- async function Je(e, t, r) {
1285
+ async function st(e, t, r) {
1254
1286
  let i = [], a = 0, o = r.pageToken;
1255
1287
  for (let s = 0; s < 5; s += 1) {
1256
- let s = await Qe(e, t.calendarId, {
1288
+ let s = await dt(e, t.calendarId, {
1257
1289
  maxResults: t.maxEventsPerPoll,
1258
1290
  pageToken: o,
1259
1291
  showDeleted: "true",
1260
1292
  singleEvents: "false",
1261
1293
  syncToken: r.syncToken
1262
1294
  });
1263
- if (o != null && et(s)) return {
1295
+ if (o != null && pt(s)) return {
1264
1296
  checkpoint: {
1265
1297
  calendarId: t.calendarId,
1266
1298
  syncToken: r.syncToken
@@ -1268,16 +1300,16 @@ async function Je(e, t, r) {
1268
1300
  events: i,
1269
1301
  filtered: a
1270
1302
  };
1271
- $e(e, s, "incremental sync");
1272
- let c = N(s.data) ?? {};
1303
+ ft(e, s, "incremental sync");
1304
+ let c = k(s.data) ?? {};
1273
1305
  for (let e of c.items ?? []) {
1274
1306
  if (e.id == null || e.id.length == 0) continue;
1275
- let n = Ye(e);
1276
- if (!t.changes.has(n) || !Xe(e, t.matchTerm)) {
1307
+ let n = ct(e);
1308
+ if (!t.changes.has(n) || !lt(e, t.matchTerm)) {
1277
1309
  a += 1;
1278
1310
  continue;
1279
1311
  }
1280
- i.push(Ze(e, e.id, n, t.calendarId));
1312
+ i.push(ut(e, e.id, n, t.calendarId));
1281
1313
  }
1282
1314
  if (c.nextSyncToken) return {
1283
1315
  checkpoint: {
@@ -1301,12 +1333,12 @@ async function Je(e, t, r) {
1301
1333
  hasMore: !0
1302
1334
  };
1303
1335
  }
1304
- function Ye(e) {
1336
+ function ct(e) {
1305
1337
  if (e.status == "cancelled") return "cancelled";
1306
- let t = it(e.created), n = it(e.updated);
1338
+ let t = _t(e.created), n = _t(e.updated);
1307
1339
  return t != null && t == n ? "created" : "updated";
1308
1340
  }
1309
- function Xe(e, t) {
1341
+ function lt(e, t) {
1310
1342
  if (t.length == 0) return !0;
1311
1343
  let n = t.toLowerCase();
1312
1344
  return [
@@ -1316,14 +1348,14 @@ function Xe(e, t) {
1316
1348
  ...(e.attendees ?? []).map(({ email: e }) => e)
1317
1349
  ].some((e) => typeof e == "string" && e.toLowerCase().includes(n));
1318
1350
  }
1319
- function Ze(e, t, n, r) {
1351
+ function ut(e, t, n, r) {
1320
1352
  return {
1321
1353
  dedupeKey: `${t}:${e.updated ?? e.etag ?? ""}`,
1322
1354
  payload: {
1323
1355
  attendeeEmails: (e.attendees ?? []).flatMap(({ email: e }) => e == null || e.length == 0 ? [] : [e]),
1324
1356
  calendarId: r,
1325
1357
  changeType: n,
1326
- created: rt(e.created),
1358
+ created: gt(e.created),
1327
1359
  creatorEmail: e.creator?.email ?? null,
1328
1360
  description: e.description ?? null,
1329
1361
  end: e.end ?? null,
@@ -1337,11 +1369,11 @@ function Ze(e, t, n, r) {
1337
1369
  start: e.start ?? null,
1338
1370
  status: e.status ?? "",
1339
1371
  summary: e.summary ?? null,
1340
- updated: rt(e.updated)
1372
+ updated: gt(e.updated)
1341
1373
  }
1342
1374
  };
1343
1375
  }
1344
- async function Qe(e, t, r) {
1376
+ async function dt(e, t, r) {
1345
1377
  let i = `/calendars/${encodeURIComponent(t)}/events`;
1346
1378
  try {
1347
1379
  return await e.connector.execute({
@@ -1353,40 +1385,40 @@ async function Qe(e, t, r) {
1353
1385
  throw new n(`Google Calendar proxy request to ${i} failed.`, { cause: e });
1354
1386
  }
1355
1387
  }
1356
- function $e(r, i, a) {
1357
- if (!(i.status >= 200 && i.status < 300)) throw i.status == 410 || i.status == 400 && nt(i.data) ? new t("Google Calendar sync token expired; recreate the Trigger.") : i.status == 400 || i.status == 404 && r.checkpoint === null ? new t(`Google Calendar ${a} rejected the configuration.`) : i.status == 401 ? new e(`Google Calendar ${a} rejected the Connection.`) : i.status == 403 ? tt(i.data).some((e) => Ue.has(e)) ? new n(`Google Calendar ${a} was rate limited.`) : new e(`Google Calendar ${a} rejected the Connection.`) : new n(`Google Calendar ${a} failed with status ${i.status}.`);
1388
+ function ft(r, i, a) {
1389
+ if (!(i.status >= 200 && i.status < 300)) throw i.status == 410 || i.status == 400 && ht(i.data) ? new e("Google Calendar sync token expired; recreate the Trigger.") : i.status == 400 || i.status == 404 && r.checkpoint === null ? new e(`Google Calendar ${a} rejected the configuration.`) : i.status == 401 ? new t(`Google Calendar ${a} rejected the Connection.`) : i.status == 403 ? mt(i.data).some((e) => nt.has(e)) ? new n(`Google Calendar ${a} was rate limited.`) : new t(`Google Calendar ${a} rejected the Connection.`) : new n(`Google Calendar ${a} failed with status ${i.status}.`);
1358
1390
  }
1359
- function et(e) {
1360
- return e.status == 400 && !nt(e.data);
1391
+ function pt(e) {
1392
+ return e.status == 400 && !ht(e.data);
1361
1393
  }
1362
- function tt(e) {
1363
- let t = N(N(e)?.error)?.errors;
1394
+ function mt(e) {
1395
+ let t = k(k(e)?.error)?.errors;
1364
1396
  return Array.isArray(t) ? t.flatMap((e) => {
1365
- let t = N(e)?.reason;
1397
+ let t = k(e)?.reason;
1366
1398
  return typeof t == "string" ? [t] : [];
1367
1399
  }) : [];
1368
1400
  }
1369
- function nt(e) {
1370
- if (tt(e).includes("fullSyncRequired")) return !0;
1371
- let t = N(N(e)?.error)?.message;
1401
+ function ht(e) {
1402
+ if (mt(e).includes("fullSyncRequired")) return !0;
1403
+ let t = k(k(e)?.error)?.message;
1372
1404
  return typeof t == "string" && t.includes("fullSyncRequired");
1373
1405
  }
1374
- function rt(e) {
1406
+ function gt(e) {
1375
1407
  if (e == null || e.length == 0) return null;
1376
1408
  let t = Date.parse(e);
1377
1409
  return Number.isNaN(t) ? null : new Date(t).toISOString();
1378
1410
  }
1379
- function it(e) {
1411
+ function _t(e) {
1380
1412
  if (e == null || e.length == 0) return null;
1381
1413
  let t = Date.parse(e);
1382
1414
  return Number.isNaN(t) ? null : Math.floor(t / 1e3);
1383
1415
  }
1384
- function N(e) {
1416
+ function k(e) {
1385
1417
  return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
1386
1418
  }
1387
1419
  //#endregion
1388
1420
  //#region src/trigger/providers/google-drive/changes.ts
1389
- var at = 6012e5, ot = 36e5, st = 6e4, ct = 6e4, lt = 2, ut = 100, dt = new TextEncoder(), ft = "nextPageToken,newStartPageToken,changes(fileId,kind,changeType,removed,time,driveId,file(id,name,mimeType,webViewLink,createdTime,modifiedTime,size,driveId,parents,shared,starred,trashed))", pt = {
1421
+ var vt = 6012e5, yt = 36e5, bt = 6e4, xt = 6e4, St = 2, Ct = 100, wt = new TextEncoder(), Tt = "nextPageToken,newStartPageToken,changes(fileId,kind,changeType,removed,time,driveId,file(id,name,mimeType,webViewLink,createdTime,modifiedTime,size,driveId,parents,shared,starred,trashed))", Et = {
1390
1422
  initialState: {
1391
1423
  checkpoint: null,
1392
1424
  subscription: { channels: [] }
@@ -1418,7 +1450,7 @@ var at = 6012e5, ot = 36e5, st = 6e4, ct = 6e4, lt = 2, ut = 100, dt = new TextE
1418
1450
  type: "boolean"
1419
1451
  },
1420
1452
  pageSize: {
1421
- default: ut,
1453
+ default: Ct,
1422
1454
  description: "Maximum changes included in one Flow Run.",
1423
1455
  maximum: 100,
1424
1456
  minimum: 1,
@@ -1502,24 +1534,24 @@ var at = 6012e5, ot = 36e5, st = 6e4, ct = 6e4, lt = 2, ut = 100, dt = new TextE
1502
1534
  type: "integration"
1503
1535
  },
1504
1536
  async receive(e) {
1505
- let t = P(e.state), n = e.header("x-goog-channel-id"), r = e.header("x-goog-resource-id"), i = e.header("x-goog-resource-state"), a = e.header("x-goog-channel-token");
1506
- if (n == null || r == null || i == null || a == null) return {
1537
+ let t = A(e.state), n = e.header("x-goog-channel-id"), r = e.header("x-goog-resource-id"), i = e.header("x-goog-resource-state"), o = e.header("x-goog-channel-token");
1538
+ if (n == null || r == null || i == null || o == null) return {
1507
1539
  body: "",
1508
1540
  contentType: "text/plain",
1509
1541
  outcome: "respond",
1510
1542
  status: 404
1511
1543
  };
1512
- let o = gt(t), s = o.find((t) => t.id == n && Date.parse(t.expiration) > e.now.getTime());
1513
- if (s == null || !kt(a, await Ot(e.callbackSecret, n)) || s.resourceId != null && s.resourceId != r) return {
1544
+ let s = kt(t), c = s.find((t) => t.id == n && Date.parse(t.expiration) > e.now.getTime());
1545
+ if (c == null || !Ht(o, await Vt(e.callbackSecret, n)) || c.resourceId != null && c.resourceId != r) return {
1514
1546
  body: "",
1515
1547
  contentType: "text/plain",
1516
1548
  outcome: "respond",
1517
1549
  status: 404
1518
1550
  };
1519
- if (s.resourceId ?? (o = o.map((e) => e.id == n ? {
1551
+ if (c.resourceId ?? (s = s.map((e) => e.id == n ? {
1520
1552
  ...e,
1521
1553
  resourceId: r
1522
- } : e), await F(t, o, e.now)), i != "sync" && i != "change") return {
1554
+ } : e), await j(t, s, e.now)), i != "sync" && i != "change") return {
1523
1555
  outcome: "ignored",
1524
1556
  reason: "Google Drive notification state is not actionable."
1525
1557
  };
@@ -1536,86 +1568,86 @@ var at = 6012e5, ot = 36e5, st = 6e4, ct = 6e4, lt = 2, ut = 100, dt = new TextE
1536
1568
  outcome: "ignored",
1537
1569
  reason: "The Team cannot admit Trigger events."
1538
1570
  };
1539
- let c = mt(e.config), l = ht(t.checkpoint), u = await xt(e, c, l), d = L(u.nextPageToken), f = d ?? L(u.newStartPageToken);
1540
- if (f == null) throw new b("Google Drive changes response is missing its next checkpoint.");
1541
- let p = {
1571
+ let l = Dt(e.config), u = Ot(t.checkpoint), d = await Pt(e, l, u), f = N(d.nextPageToken), p = f ?? N(d.newStartPageToken);
1572
+ if (p == null) throw new a("Google Drive changes response is missing its next checkpoint.");
1573
+ let m = {
1542
1574
  changedTypes: (e.header("x-goog-changed") ?? "").split(",").map((e) => e.trim()).filter((e) => e.length > 0),
1543
1575
  messageNumber: e.header("x-goog-message-number") ?? null,
1544
1576
  resourceState: i,
1545
1577
  resourceUri: e.header("x-goog-resource-uri") ?? null
1546
- }, m = (u.changes ?? []).map((e) => Dt(e, p)), h = {
1547
- checkpoint: { pageToken: f },
1548
- continue: d != null,
1549
- dedupeKey: `${c.driveId ?? "my-drive"}:${l}`
1578
+ }, ee = (d.changes ?? []).map((e) => Bt(e, m)), h = {
1579
+ checkpoint: { pageToken: p },
1580
+ continue: f != null,
1581
+ dedupeKey: `${l.driveId ?? "my-drive"}:${u}`
1550
1582
  };
1551
- return m.length == 0 ? {
1583
+ return ee.length == 0 ? {
1552
1584
  ...h,
1553
1585
  outcome: "ignored",
1554
1586
  reason: "Google Drive change page is empty."
1555
1587
  } : {
1556
1588
  ...h,
1557
1589
  outcome: "event",
1558
- payload: { events: m }
1590
+ payload: { events: ee }
1559
1591
  };
1560
1592
  },
1561
1593
  async reconcile(e) {
1562
- let t = P(e.state), n = gt(t), r = e.now.getTime(), i = n.filter((e) => Date.parse(e.expiration) > r);
1563
- if (i.length != n.length && (n = i, await F(t, n, e.now)), !e.active) return await vt(e, n);
1594
+ let t = A(e.state), n = kt(t), r = e.now.getTime(), i = n.filter((e) => Date.parse(e.expiration) > r);
1595
+ if (i.length != n.length && (n = i, await j(t, n, e.now)), !e.active) return await jt(e, n);
1564
1596
  let a = n.filter((e) => e.state == "creating" && e.resourceId != null).toSorted((e, t) => Date.parse(t.createdAt) - Date.parse(e.createdAt))[0];
1565
1597
  a != null && (n = n.map((e) => ({
1566
1598
  ...e,
1567
1599
  state: e.id == a.id ? "active" : "retiring"
1568
- })), await F(t, n, e.now));
1569
- let o = n.find((e) => e.state == "active"), s = n.filter((e) => e.state == "creating").filter((e) => Date.parse(e.createdAt) + st <= r);
1600
+ })), await j(t, n, e.now));
1601
+ let o = n.find((e) => e.state == "active"), s = n.filter((e) => e.state == "creating").filter((e) => Date.parse(e.createdAt) + bt <= r);
1570
1602
  if (s.length > 0) {
1571
1603
  let r = new Set(s.map((e) => e.id));
1572
1604
  n = n.map((e) => r.has(e.id) ? {
1573
1605
  ...e,
1574
1606
  state: "retiring"
1575
- } : e), await F(t, n, e.now);
1607
+ } : e), await j(t, n, e.now);
1576
1608
  }
1577
1609
  if (o = n.find((e) => e.state == "active"), o != null) {
1578
1610
  try {
1579
- n = await yt(e, n);
1611
+ n = await Mt(e, n);
1580
1612
  } catch {
1581
1613
  return { outcome: "ready" };
1582
1614
  }
1583
- if (o = n.find((e) => e.state == "active"), o != null && Date.parse(o.expiration) - ot > r) return await F(t, n, I(n, e.now)), { outcome: "ready" };
1615
+ if (o = n.find((e) => e.state == "active"), o != null && Date.parse(o.expiration) - yt > r) return await j(t, n, M(n, e.now)), { outcome: "ready" };
1584
1616
  }
1585
- return n.some((e) => e.state == "creating") || n.filter((e) => e.resourceId == null).length >= lt ? (await F(t, n, I(n, e.now)), { outcome: o == null ? "pending" : "ready" }) : await _t(e, n);
1617
+ return n.some((e) => e.state == "creating") || n.filter((e) => e.resourceId == null).length >= St ? (await j(t, n, M(n, e.now)), { outcome: o == null ? "pending" : "ready" }) : await At(e, n);
1586
1618
  }
1587
1619
  };
1588
- function P(e) {
1589
- if (e == null) throw new y("Google Drive Integration state is missing.");
1620
+ function A(e) {
1621
+ if (e == null) throw new i("Google Drive Integration state is missing.");
1590
1622
  return e;
1591
1623
  }
1592
- function mt(e) {
1624
+ function Dt(e) {
1593
1625
  return {
1594
1626
  ...typeof e.driveId == "string" ? { driveId: e.driveId } : {},
1595
1627
  includeCorpusRemovals: e.includeCorpusRemovals ?? !1,
1596
1628
  includeItemsFromAllDrives: e.includeItemsFromAllDrives ?? !0,
1597
1629
  includeRemoved: e.includeRemoved ?? !0,
1598
- pageSize: e.pageSize ?? ut,
1630
+ pageSize: e.pageSize ?? Ct,
1599
1631
  restrictToMyDrive: e.restrictToMyDrive ?? !1
1600
1632
  };
1601
1633
  }
1602
- function ht(e) {
1603
- let t = R(e) ? L(e.pageToken) : void 0;
1604
- if (t == null) throw new y("Google Drive checkpoint pageToken is missing.");
1634
+ function Ot(e) {
1635
+ let t = P(e) ? N(e.pageToken) : void 0;
1636
+ if (t == null) throw new i("Google Drive checkpoint pageToken is missing.");
1605
1637
  return t;
1606
1638
  }
1607
- function gt(e) {
1639
+ function kt(e) {
1608
1640
  let t = e.subscription.channels;
1609
- if (!Array.isArray(t)) throw new y("Google Drive channel state is invalid.");
1641
+ if (!Array.isArray(t)) throw new i("Google Drive channel state is invalid.");
1610
1642
  let n = t.map((e) => {
1611
- if (typeof e != "object" || !e || Array.isArray(e)) throw new y("Google Drive channel is invalid.");
1643
+ if (typeof e != "object" || !e || Array.isArray(e)) throw new i("Google Drive channel is invalid.");
1612
1644
  let t = e;
1613
1645
  if (typeof t.createdAt != "string" || !Number.isFinite(Date.parse(t.createdAt)) || typeof t.expiration != "string" || !Number.isFinite(Date.parse(t.expiration)) || typeof t.id != "string" || ![
1614
1646
  "active",
1615
1647
  "creating",
1616
1648
  "retiring",
1617
1649
  "stopping"
1618
- ].includes(String(t.state)) || t.resourceId != null && typeof t.resourceId != "string") throw new y("Google Drive channel fields are invalid.");
1650
+ ].includes(String(t.state)) || t.resourceId != null && typeof t.resourceId != "string") throw new i("Google Drive channel fields are invalid.");
1619
1651
  let n = {
1620
1652
  createdAt: t.createdAt,
1621
1653
  expiration: t.expiration,
@@ -1624,99 +1656,99 @@ function gt(e) {
1624
1656
  };
1625
1657
  return typeof t.resourceId == "string" ? Object.assign(n, { resourceId: t.resourceId }) : n;
1626
1658
  });
1627
- if (new Set(n.map((e) => e.id)).size != n.length) throw new y("Google Drive channel IDs are duplicated.");
1659
+ if (new Set(n.map((e) => e.id)).size != n.length) throw new i("Google Drive channel IDs are duplicated.");
1628
1660
  return n;
1629
1661
  }
1630
- async function _t(e, t) {
1631
- let n = P(e.state), r = mt(e.config), i;
1632
- n.checkpoint === null ? (i = await bt(e, r), await n.saveCheckpoint({ pageToken: i })) : i = ht(n.checkpoint);
1633
- let a = {
1662
+ async function At(e, t) {
1663
+ let n = A(e.state), o = Dt(e.config), s;
1664
+ n.checkpoint === null ? (s = await Nt(e, o), await n.saveCheckpoint({ pageToken: s })) : s = Ot(n.checkpoint);
1665
+ let c = {
1634
1666
  createdAt: e.now.toISOString(),
1635
- expiration: new Date(e.now.getTime() + at).toISOString(),
1667
+ expiration: new Date(e.now.getTime() + vt).toISOString(),
1636
1668
  id: crypto.randomUUID(),
1637
1669
  state: "creating"
1638
1670
  };
1639
- t = [...t, a], await F(n, t, new Date(e.now.getTime() + st));
1640
- let o;
1671
+ t = [...t, c], await j(n, t, new Date(e.now.getTime() + bt));
1672
+ let l;
1641
1673
  try {
1642
- o = await Ct(e, {
1674
+ l = await It(e, {
1643
1675
  body: {
1644
1676
  address: e.endpointUrl,
1645
- expiration: String(Date.parse(a.expiration)),
1646
- id: a.id,
1647
- token: await Ot(e.callbackSecret, a.id),
1677
+ expiration: String(Date.parse(c.expiration)),
1678
+ id: c.id,
1679
+ token: await Vt(e.callbackSecret, c.id),
1648
1680
  type: "web_hook"
1649
1681
  },
1650
1682
  endpoint: "/changes/watch",
1651
1683
  method: "POST",
1652
1684
  query: {
1653
- ...r.driveId == null ? {} : { driveId: r.driveId },
1654
- includeItemsFromAllDrives: r.driveId != null || r.includeItemsFromAllDrives,
1655
- pageToken: i,
1656
- restrictToMyDrive: r.restrictToMyDrive,
1685
+ ...o.driveId == null ? {} : { driveId: o.driveId },
1686
+ includeItemsFromAllDrives: o.driveId != null || o.includeItemsFromAllDrives,
1687
+ pageToken: s,
1688
+ restrictToMyDrive: o.restrictToMyDrive,
1657
1689
  supportsAllDrives: !0
1658
1690
  }
1659
1691
  }, "changes.watch");
1660
- } catch (r) {
1661
- throw (r instanceof v || r instanceof y) && await F(n, t.filter((e) => e.id != a.id), e.now), r;
1692
+ } catch (a) {
1693
+ throw (a instanceof r || a instanceof i) && await j(n, t.filter((e) => e.id != c.id), e.now), a;
1662
1694
  }
1663
- let s = L(o.resourceId);
1664
- if (s == null) throw new b("Google Drive changes.watch response is missing resourceId.");
1665
- let c = At(o.expiration) ?? a.expiration;
1666
- t = t.map((e) => e.id == a.id ? {
1695
+ let u = N(l.resourceId);
1696
+ if (u == null) throw new a("Google Drive changes.watch response is missing resourceId.");
1697
+ let d = Ut(l.expiration) ?? c.expiration;
1698
+ t = t.map((e) => e.id == c.id ? {
1667
1699
  ...e,
1668
- expiration: c,
1669
- resourceId: s,
1700
+ expiration: d,
1701
+ resourceId: u,
1670
1702
  state: "active"
1671
1703
  } : e.state == "active" ? {
1672
1704
  ...e,
1673
1705
  state: "retiring"
1674
- } : e), await F(n, t, I(t, e.now));
1706
+ } : e), await j(n, t, M(t, e.now));
1675
1707
  try {
1676
- t = await yt(e, t);
1708
+ t = await Mt(e, t);
1677
1709
  } catch {
1678
1710
  return { outcome: "ready" };
1679
1711
  }
1680
- return await F(n, t, I(t, e.now)), { outcome: "ready" };
1712
+ return await j(n, t, M(t, e.now)), { outcome: "ready" };
1681
1713
  }
1682
- async function vt(e, t) {
1683
- let n = P(e.state);
1714
+ async function jt(e, t) {
1715
+ let n = A(e.state);
1684
1716
  return t.some((e) => e.state == "active" || e.state == "creating") && (t = t.map((e) => ({
1685
1717
  ...e,
1686
1718
  state: "retiring"
1687
- })), await F(n, t, e.now)), t = await yt(e, t), t.length == 0 ? { outcome: "ready" } : (await F(n, t, I(t, e.now)), { outcome: "pending" });
1719
+ })), await j(n, t, e.now)), t = await Mt(e, t), t.length == 0 ? { outcome: "ready" } : (await j(n, t, M(t, e.now)), { outcome: "pending" });
1688
1720
  }
1689
- async function yt(e, t) {
1690
- let n = P(e.state);
1721
+ async function Mt(e, t) {
1722
+ let n = A(e.state);
1691
1723
  for (let r of t) {
1692
1724
  if (r.state != "retiring" && r.state != "stopping" || r.resourceId == null) continue;
1693
1725
  let i = t.map((e) => e.id == r.id ? {
1694
1726
  ...e,
1695
1727
  state: "stopping"
1696
1728
  } : e);
1697
- await F(n, i, new Date(e.now.getTime() + ct)), await St(e, r), t = i.filter((e) => e.id != r.id), await F(n, t, e.now);
1729
+ await j(n, i, new Date(e.now.getTime() + xt)), await Ft(e, r), t = i.filter((e) => e.id != r.id), await j(n, t, e.now);
1698
1730
  }
1699
1731
  return t;
1700
1732
  }
1701
- async function bt(e, t) {
1702
- let n = await Ct(e, {
1733
+ async function Nt(e, t) {
1734
+ let n = await It(e, {
1703
1735
  endpoint: "/changes/startPageToken",
1704
1736
  method: "GET",
1705
1737
  query: {
1706
1738
  ...t.driveId == null ? {} : { driveId: t.driveId },
1707
1739
  supportsAllDrives: !0
1708
1740
  }
1709
- }, "changes.getStartPageToken"), r = R(n) ? L(n.startPageToken) : void 0;
1710
- if (r == null) throw new b("Google Drive startPageToken response is invalid.");
1741
+ }, "changes.getStartPageToken"), r = P(n) ? N(n.startPageToken) : void 0;
1742
+ if (r == null) throw new a("Google Drive startPageToken response is invalid.");
1711
1743
  return r;
1712
1744
  }
1713
- async function xt(e, t, n) {
1714
- return await Ct(e, {
1745
+ async function Pt(e, t, n) {
1746
+ return await It(e, {
1715
1747
  endpoint: "/changes",
1716
1748
  method: "GET",
1717
1749
  query: {
1718
1750
  ...t.driveId == null ? {} : { driveId: t.driveId },
1719
- fields: ft,
1751
+ fields: Tt,
1720
1752
  includeCorpusRemovals: t.includeCorpusRemovals,
1721
1753
  includeItemsFromAllDrives: t.driveId != null || t.includeItemsFromAllDrives,
1722
1754
  includeRemoved: t.includeCorpusRemovals || t.includeRemoved,
@@ -1727,8 +1759,8 @@ async function xt(e, t, n) {
1727
1759
  }
1728
1760
  }, "changes.list");
1729
1761
  }
1730
- async function St(e, t) {
1731
- let n = await wt(e, {
1762
+ async function Ft(e, t) {
1763
+ let n = await Lt(e, {
1732
1764
  body: {
1733
1765
  id: t.id,
1734
1766
  resourceId: t.resourceId
@@ -1736,31 +1768,31 @@ async function St(e, t) {
1736
1768
  endpoint: "/channels/stop",
1737
1769
  method: "POST"
1738
1770
  });
1739
- n.status >= 200 && n.status < 300 || n.status == 404 || Tt(n, "channels.stop");
1771
+ n.status >= 200 && n.status < 300 || n.status == 404 || Rt(n, "channels.stop");
1740
1772
  }
1741
- async function Ct(e, t, n) {
1742
- let r = await wt(e, t);
1743
- if (r.status >= 200 && r.status < 300 && R(r.data)) return r.data;
1744
- Tt(r, n);
1773
+ async function It(e, t, n) {
1774
+ let r = await Lt(e, t);
1775
+ if (r.status >= 200 && r.status < 300 && P(r.data)) return r.data;
1776
+ Rt(r, n);
1745
1777
  }
1746
- async function wt(e, t) {
1778
+ async function Lt(e, t) {
1747
1779
  try {
1748
1780
  return await e.connector.execute(t, e.signal);
1749
1781
  } catch (e) {
1750
- throw e instanceof v ? e : new b("Google Drive proxy request failed.", { cause: e });
1782
+ throw e instanceof r ? e : new a("Google Drive proxy request failed.", { cause: e });
1751
1783
  }
1752
1784
  }
1753
- function Tt(e, t) {
1754
- let n = Et(e.data);
1755
- throw e.status == 401 || e.status == 403 && !n.toLowerCase().includes("ratelimit") ? new v(`Google Drive ${t} requires Connection reauthorization.`) : e.status == 408 || e.status == 429 || e.status >= 500 ? new b(`Google Drive ${t} is temporarily unavailable.`) : new y(`Google Drive ${t} rejected the subscription${n == "" ? "." : ` with ${n}.`}`);
1785
+ function Rt(e, t) {
1786
+ let n = zt(e.data);
1787
+ throw e.status == 401 || e.status == 403 && !n.toLowerCase().includes("ratelimit") ? new r(`Google Drive ${t} requires Connection reauthorization.`) : e.status == 408 || e.status == 429 || e.status >= 500 ? new a(`Google Drive ${t} is temporarily unavailable.`) : new i(`Google Drive ${t} rejected the subscription${n == "" ? "." : ` with ${n}.`}`);
1756
1788
  }
1757
- function Et(e) {
1758
- if (!R(e) || !R(e.error)) return "";
1789
+ function zt(e) {
1790
+ if (!P(e) || !P(e.error)) return "";
1759
1791
  let t = e.error.errors;
1760
- return Array.isArray(t) && R(t[0]) && typeof t[0].reason == "string" ? t[0].reason : typeof e.error.status == "string" ? e.error.status : "";
1792
+ return Array.isArray(t) && P(t[0]) && typeof t[0].reason == "string" ? t[0].reason : typeof e.error.status == "string" ? e.error.status : "";
1761
1793
  }
1762
- function Dt(e, t) {
1763
- let n = L(e.driveId), r = L(e.fileId), i = L(e.time), a = L(e.changeType), o = e.removed === !0;
1794
+ function Bt(e, t) {
1795
+ let n = N(e.driveId), r = N(e.fileId), i = N(e.time), a = N(e.changeType), o = e.removed === !0;
1764
1796
  return {
1765
1797
  changeId: [
1766
1798
  n ?? "my-drive",
@@ -1771,51 +1803,51 @@ function Dt(e, t) {
1771
1803
  ].join(":"),
1772
1804
  changeType: a ?? null,
1773
1805
  driveId: n ?? null,
1774
- file: R(e.file) ? e.file : null,
1806
+ file: P(e.file) ? e.file : null,
1775
1807
  fileId: r ?? null,
1776
1808
  notification: t,
1777
1809
  removed: o,
1778
1810
  time: i ?? null
1779
1811
  };
1780
1812
  }
1781
- async function F(e, t, n) {
1813
+ async function j(e, t, n) {
1782
1814
  await e.saveSubscription({ channels: t }, n);
1783
1815
  }
1784
- function I(e, t) {
1785
- let n = e.map((e) => e.state == "active" ? Date.parse(e.expiration) - ot : e.state == "creating" ? Date.parse(e.createdAt) + st : e.resourceId == null ? Date.parse(e.expiration) : t.getTime() + ct), r = n.length == 0 ? t.getTime() + ct : Math.min(...n);
1816
+ function M(e, t) {
1817
+ let n = e.map((e) => e.state == "active" ? Date.parse(e.expiration) - yt : e.state == "creating" ? Date.parse(e.createdAt) + bt : e.resourceId == null ? Date.parse(e.expiration) : t.getTime() + xt), r = n.length == 0 ? t.getTime() + xt : Math.min(...n);
1786
1818
  return new Date(Math.max(t.getTime(), r));
1787
1819
  }
1788
- async function Ot(e, t) {
1789
- let n = await crypto.subtle.importKey("raw", dt.encode(e), {
1820
+ async function Vt(e, t) {
1821
+ let n = await crypto.subtle.importKey("raw", wt.encode(e), {
1790
1822
  hash: "SHA-256",
1791
1823
  name: "HMAC"
1792
- }, !1, ["sign"]), r = new Uint8Array(await crypto.subtle.sign("HMAC", n, dt.encode(`google-drive-channel/v1/${t}`)));
1824
+ }, !1, ["sign"]), r = new Uint8Array(await crypto.subtle.sign("HMAC", n, wt.encode(`google-drive-channel/v1/${t}`)));
1793
1825
  return btoa(String.fromCharCode(...r)).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
1794
1826
  }
1795
- function kt(e, t) {
1827
+ function Ht(e, t) {
1796
1828
  if (e.length != t.length) return !1;
1797
1829
  let n = 0;
1798
1830
  for (let r = 0; r < t.length; r += 1) n |= e.charCodeAt(r) ^ t.charCodeAt(r);
1799
1831
  return n == 0;
1800
1832
  }
1801
- function At(e) {
1833
+ function Ut(e) {
1802
1834
  let t = typeof e == "string" || typeof e == "number" ? Number(e) : NaN;
1803
1835
  return Number.isFinite(t) && t > 0 ? new Date(t).toISOString() : void 0;
1804
1836
  }
1805
- function L(e) {
1837
+ function N(e) {
1806
1838
  return typeof e == "string" && e.length > 0 ? e : void 0;
1807
1839
  }
1808
- function R(e) {
1840
+ function P(e) {
1809
1841
  return typeof e == "object" && !!e && !Array.isArray(e);
1810
1842
  }
1811
1843
  //#endregion
1812
1844
  //#region src/trigger/providers/google-drive/on-file-change.ts
1813
- var z = "application/vnd.google-apps.folder", jt = "nextPageToken,incompleteSearch,files(id,name,mimeType,createdTime,modifiedTime,parents,trashed,webViewLink,driveId,size,version,lastModifyingUser(displayName,emailAddress))", Mt = /* @__PURE__ */ new Set([
1845
+ var Wt = "application/vnd.google-apps.folder", Gt = "nextPageToken,incompleteSearch,files(id,name,mimeType,createdTime,modifiedTime,parents,trashed,webViewLink,driveId,size,version,lastModifyingUser(displayName,emailAddress))", Kt = /* @__PURE__ */ new Set([
1814
1846
  "rateLimitExceeded",
1815
1847
  "userRateLimitExceeded",
1816
1848
  "dailyLimitExceeded",
1817
1849
  "sharingRateLimitExceeded"
1818
- ]), Nt = /* @__PURE__ */ new Set(["insufficientFilePermissions", "appNotAuthorizedToFile"]), Pt = {
1850
+ ]), qt = /* @__PURE__ */ new Set(["insufficientFilePermissions", "appNotAuthorizedToFile"]), Jt = {
1819
1851
  snapshot: {
1820
1852
  configSchema: {
1821
1853
  additionalProperties: !1,
@@ -1929,16 +1961,16 @@ var z = "application/vnd.google-apps.folder", jt = "nextPageToken,incompleteSear
1929
1961
  type: "poll"
1930
1962
  },
1931
1963
  async poll(e) {
1932
- let t = Ft(e.config);
1933
- if (e.checkpoint === null) return Lt(e, t);
1934
- let n = It(e.checkpoint);
1935
- return n.changeType === t.changeType ? zt(e, t, n) : {
1936
- checkpoint: Rt(e.now, t.changeType),
1964
+ let t = Yt(e.config);
1965
+ if (e.checkpoint === null) return Zt(e, t);
1966
+ let n = Xt(e.checkpoint);
1967
+ return n.changeType === t.changeType ? $t(e, t, n) : {
1968
+ checkpoint: Qt(e.now, t.changeType),
1937
1969
  events: []
1938
1970
  };
1939
1971
  }
1940
1972
  };
1941
- function Ft(e) {
1973
+ function Yt(e) {
1942
1974
  return {
1943
1975
  changeType: e.changeType,
1944
1976
  driveId: e.driveId ?? "",
@@ -1949,9 +1981,9 @@ function Ft(e) {
1949
1981
  namePrefix: e.namePrefix ?? ""
1950
1982
  };
1951
1983
  }
1952
- function It(e) {
1953
- let n = B(e);
1954
- if (typeof n?.since != "string" || Number.isNaN(Date.parse(n.since))) throw new t("Google Drive checkpoint is invalid; recreate the Trigger.");
1984
+ function Xt(t) {
1985
+ let n = F(t);
1986
+ if (typeof n?.since != "string" || Number.isNaN(Date.parse(n.since))) throw new e("Google Drive checkpoint is invalid; recreate the Trigger.");
1955
1987
  let r = n.boundaryKeys;
1956
1988
  return {
1957
1989
  since: n.since,
@@ -1963,23 +1995,23 @@ function It(e) {
1963
1995
  ...Array.isArray(r) ? { boundaryKeys: r.filter((e) => typeof e == "string") } : {}
1964
1996
  };
1965
1997
  }
1966
- async function Lt(e, r) {
1967
- let i = await qt(e, `/drive/v3/files/${encodeURIComponent(r.folderId)}`, {
1998
+ async function Zt(t, r) {
1999
+ let i = await cn(t, `/drive/v3/files/${encodeURIComponent(r.folderId)}`, {
1968
2000
  fields: "id,name,mimeType,driveId,trashed",
1969
2001
  supportsAllDrives: "true"
1970
2002
  });
1971
- Jt(i, "folder probe");
1972
- let a = B(i.data);
2003
+ ln(i, "folder probe");
2004
+ let a = F(i.data);
1973
2005
  if (a == null) throw new n("Google Drive folder probe returned no payload.");
1974
- if (a.mimeType !== z) throw new t("Google Drive folderId does not point to a folder.");
1975
- if (a.trashed === !0) throw new t("The Google Drive folder is in the trash.");
1976
- if (r.driveId.length > 0 && (a.driveId ?? "") !== r.driveId) throw new t("The configured Google Drive shared drive does not contain this folder.");
2006
+ if (a.mimeType !== Wt) throw new e("Google Drive folderId does not point to a folder.");
2007
+ if (a.trashed === !0) throw new e("The Google Drive folder is in the trash.");
2008
+ if (r.driveId.length > 0 && (a.driveId ?? "") !== r.driveId) throw new e("The configured Google Drive shared drive does not contain this folder.");
1977
2009
  return {
1978
- checkpoint: Rt(e.now, r.changeType),
2010
+ checkpoint: Qt(t.now, r.changeType),
1979
2011
  events: []
1980
2012
  };
1981
2013
  }
1982
- function Rt(e, t) {
2014
+ function Qt(e, t) {
1983
2015
  let n = e.toISOString();
1984
2016
  return {
1985
2017
  changeType: t,
@@ -1987,11 +2019,11 @@ function Rt(e, t) {
1987
2019
  since: n
1988
2020
  };
1989
2021
  }
1990
- async function zt(e, t, n) {
1991
- let r = Ht(t, n.since, n.floor), i = `${t.driveId}|${r}`, a = n.pageQuery == i ? n.pageToken : void 0, o = await qt(e, "/drive/v3/files", {
2022
+ async function $t(e, t, n) {
2023
+ let r = nn(t, n.since, n.floor), i = `${t.driveId}|${r}`, a = n.pageQuery == i ? n.pageToken : void 0, o = await cn(e, "/drive/v3/files", {
1992
2024
  corpora: t.driveId.length == 0 ? "allDrives" : "drive",
1993
2025
  driveId: t.driveId.length == 0 ? void 0 : t.driveId,
1994
- fields: jt,
2026
+ fields: Gt,
1995
2027
  includeItemsFromAllDrives: "true",
1996
2028
  pageSize: t.maxFilesPerPoll,
1997
2029
  pageToken: a,
@@ -1999,74 +2031,74 @@ async function zt(e, t, n) {
1999
2031
  spaces: "drive",
2000
2032
  supportsAllDrives: "true"
2001
2033
  });
2002
- Jt(o, "files list");
2003
- let s = B(o.data) ?? {}, c = new Set(n.boundaryKeys ?? []), l = [], u = [], d = a == null ? void 0 : n.maxSeen;
2034
+ ln(o, "files list");
2035
+ let s = F(o.data) ?? {}, c = new Set(n.boundaryKeys ?? []), l = [], u = [], d = a == null ? void 0 : n.maxSeen;
2004
2036
  for (let e of s.files ?? []) {
2005
2037
  if (e.id == null || e.id.length == 0) continue;
2006
- let n = Gt(e, t.changeType);
2038
+ let n = on(e, t.changeType);
2007
2039
  if (n == null) continue;
2008
- let r = Kt(e, e.id, n, t.changeType);
2009
- u.push(r.dedupeKey), Qt(n, d) && (d = n), c.has(r.dedupeKey) || l.push(r);
2040
+ let r = sn(e, e.id, n, t.changeType);
2041
+ u.push(r.dedupeKey), pn(n, d) && (d = n), c.has(r.dedupeKey) || l.push(r);
2010
2042
  }
2011
2043
  if (s.incompleteSearch === !0) {
2012
- let e = a == null ? {} : Bt(a, i, d);
2044
+ let e = a == null ? {} : en(a, i, d);
2013
2045
  return {
2014
- checkpoint: Vt(n, t.changeType, n.since, u, e),
2046
+ checkpoint: tn(n, t.changeType, n.since, u, e),
2015
2047
  events: l
2016
2048
  };
2017
2049
  }
2018
2050
  if (s.nextPageToken) return {
2019
- checkpoint: Vt(n, t.changeType, n.since, u, Bt(s.nextPageToken, i, d)),
2051
+ checkpoint: tn(n, t.changeType, n.since, u, en(s.nextPageToken, i, d)),
2020
2052
  events: l,
2021
2053
  hasMore: !0
2022
2054
  };
2023
2055
  let f = d ?? n.since;
2024
2056
  return {
2025
- checkpoint: Vt(n, t.changeType, f, u),
2057
+ checkpoint: tn(n, t.changeType, f, u),
2026
2058
  events: l
2027
2059
  };
2028
2060
  }
2029
- function Bt(e, t, n) {
2061
+ function en(e, t, n) {
2030
2062
  return {
2031
2063
  pageQuery: t,
2032
2064
  pageToken: e,
2033
2065
  ...n == null ? {} : { maxSeen: n }
2034
2066
  };
2035
2067
  }
2036
- function Vt(e, t, n, r, i = {}) {
2068
+ function tn(e, t, n, r, i = {}) {
2037
2069
  let a = [.../* @__PURE__ */ new Set([...e.boundaryKeys ?? [], ...r])].map((e) => ({
2038
2070
  at: Date.parse(e.slice(e.indexOf(":") + 1)),
2039
2071
  key: e
2040
- })).filter(({ at: t }) => t >= Ut(n, e.floor)).toSorted((e, t) => t.at - e.at).slice(0, 200).map(({ key: e }) => e);
2072
+ })).filter(({ at: t }) => t >= rn(n, e.floor)).toSorted((e, t) => t.at - e.at).slice(0, 200).map(({ key: e }) => e);
2041
2073
  return {
2042
2074
  changeType: t,
2043
2075
  since: n,
2044
- ...Wt(e.floor, n),
2076
+ ...an(e.floor, n),
2045
2077
  ...i,
2046
2078
  ...a.length == 0 ? {} : { boundaryKeys: a }
2047
2079
  };
2048
2080
  }
2049
- function Ht(e, t, n) {
2081
+ function nn(e, t, n) {
2050
2082
  let r = e.changeType == "created" ? "createdTime" : "modifiedTime", i = [
2051
- `'${Zt(e.folderId)}' in parents`,
2083
+ `'${fn(e.folderId)}' in parents`,
2052
2084
  "trashed = false",
2053
- `${r} >= '${new Date(Ut(t, n)).toISOString()}'`
2085
+ `${r} >= '${new Date(rn(t, n)).toISOString()}'`
2054
2086
  ];
2055
- return e.itemTypes.has("folder") ? e.itemTypes.has("file") || i.push(`mimeType = '${z}'`) : i.push(`mimeType != '${z}'`), e.mimeTypes.length > 0 && i.push(`(${e.mimeTypes.map((e) => `mimeType = '${Zt(e)}'`).join(" or ")})`), e.namePrefix.length > 0 && i.push(`name contains '${Zt(e.namePrefix)}'`), i.join(" and ");
2087
+ return e.itemTypes.has("folder") ? e.itemTypes.has("file") || i.push(`mimeType = '${Wt}'`) : i.push(`mimeType != '${Wt}'`), e.mimeTypes.length > 0 && i.push(`(${e.mimeTypes.map((e) => `mimeType = '${fn(e)}'`).join(" or ")})`), e.namePrefix.length > 0 && i.push(`name contains '${fn(e.namePrefix)}'`), i.join(" and ");
2056
2088
  }
2057
- function Ut(e, t) {
2089
+ function rn(e, t) {
2058
2090
  let n = Date.parse(e) - 6e4, r = t == null ? NaN : Date.parse(t);
2059
2091
  return Number.isNaN(r) ? n : Math.max(n, r);
2060
2092
  }
2061
- function Wt(e, t) {
2093
+ function an(e, t) {
2062
2094
  return e == null || Number.isNaN(Date.parse(e)) || Date.parse(t) - 6e4 >= Date.parse(e) ? {} : { floor: e };
2063
2095
  }
2064
- function Gt(e, t) {
2096
+ function on(e, t) {
2065
2097
  let n = t == "created" ? e.createdTime : e.modifiedTime;
2066
2098
  return n == null || n.length == 0 || Number.isNaN(Date.parse(n)) ? void 0 : n;
2067
2099
  }
2068
- function Kt(e, t, n, r) {
2069
- let i = e.mimeType == z ? "folder" : "file", a = e.lastModifyingUser;
2100
+ function sn(e, t, n, r) {
2101
+ let i = e.mimeType == Wt ? "folder" : "file", a = e.lastModifyingUser;
2070
2102
  return {
2071
2103
  dedupeKey: `${t}:${n}`,
2072
2104
  payload: {
@@ -2088,7 +2120,7 @@ function Kt(e, t, n, r) {
2088
2120
  }
2089
2121
  };
2090
2122
  }
2091
- async function qt(e, t, r) {
2123
+ async function cn(e, t, r) {
2092
2124
  try {
2093
2125
  return await e.connector.execute({
2094
2126
  endpoint: t,
@@ -2099,48 +2131,48 @@ async function qt(e, t, r) {
2099
2131
  throw new n(`Google Drive proxy request to ${t} failed.`, { cause: e });
2100
2132
  }
2101
2133
  }
2102
- function Jt(r, i) {
2134
+ function ln(r, i) {
2103
2135
  if (!(r.status >= 200 && r.status < 300)) {
2104
- if (r.status == 400 || r.status == 404) throw new t(`Google Drive ${i} rejected the configuration.`);
2105
- if (r.status == 401) throw new e(`Google Drive ${i} rejected the Connection.`);
2136
+ if (r.status == 400 || r.status == 404) throw new e(`Google Drive ${i} rejected the configuration.`);
2137
+ if (r.status == 401) throw new t(`Google Drive ${i} rejected the Connection.`);
2106
2138
  if (r.status == 403) {
2107
- let a = Yt(r.data);
2108
- if (a.some((e) => Mt.has(e))) throw new n(`Google Drive ${i} was rate limited.`);
2109
- if (a.some((e) => Nt.has(e))) throw new t(`Google Drive ${i} was rejected by an ACL.`);
2110
- if (Xt(r.data)) throw new e(`Google Drive ${i} needs additional scopes.`);
2139
+ let a = un(r.data);
2140
+ if (a.some((e) => Kt.has(e))) throw new n(`Google Drive ${i} was rate limited.`);
2141
+ if (a.some((e) => qt.has(e))) throw new e(`Google Drive ${i} was rejected by an ACL.`);
2142
+ if (dn(r.data)) throw new t(`Google Drive ${i} needs additional scopes.`);
2111
2143
  }
2112
2144
  throw new n(`Google Drive ${i} failed with status ${r.status}.`);
2113
2145
  }
2114
2146
  }
2115
- function Yt(e) {
2116
- let t = B(B(e)?.error);
2117
- return [...[t?.errors, t?.details].flatMap((e) => Array.isArray(e) ? e : []).map((e) => B(e)?.reason), t?.status].filter((e) => typeof e == "string");
2147
+ function un(e) {
2148
+ let t = F(F(e)?.error);
2149
+ return [...[t?.errors, t?.details].flatMap((e) => Array.isArray(e) ? e : []).map((e) => F(e)?.reason), t?.status].filter((e) => typeof e == "string");
2118
2150
  }
2119
- function Xt(e) {
2120
- if (Yt(e).includes("ACCESS_TOKEN_SCOPE_INSUFFICIENT")) return !0;
2121
- let t = B(B(e)?.error)?.message;
2151
+ function dn(e) {
2152
+ if (un(e).includes("ACCESS_TOKEN_SCOPE_INSUFFICIENT")) return !0;
2153
+ let t = F(F(e)?.error)?.message;
2122
2154
  return typeof t == "string" && t.toLowerCase().includes("insufficient authentication scopes");
2123
2155
  }
2124
- function Zt(e) {
2156
+ function fn(e) {
2125
2157
  return e.replaceAll("\\", "\\\\").replaceAll("'", "\\'");
2126
2158
  }
2127
- function Qt(e, t) {
2159
+ function pn(e, t) {
2128
2160
  let n = Date.parse(e);
2129
2161
  return Number.isNaN(n) ? !1 : t == null || Number.isNaN(Date.parse(t)) || n > Date.parse(t);
2130
2162
  }
2131
- function B(e) {
2163
+ function F(e) {
2132
2164
  return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
2133
2165
  }
2134
2166
  //#endregion
2135
2167
  //#region src/trigger/providers/google-sheets/on-row-added.ts
2136
- var $t = [
2168
+ var mn = [
2137
2169
  "permission_denied",
2138
2170
  "accessnotconfigured",
2139
2171
  "insufficientfilepermissions",
2140
2172
  "appnotauthorizedtofile",
2141
2173
  "the caller does not have permission",
2142
2174
  "has not been used in project"
2143
- ], en = ["ratelimitexceeded", "dailylimitexceeded"], tn = {
2175
+ ], hn = ["ratelimitexceeded", "dailylimitexceeded"], gn = {
2144
2176
  snapshot: {
2145
2177
  configSchema: {
2146
2178
  additionalProperties: !1,
@@ -2234,19 +2266,19 @@ var $t = [
2234
2266
  type: "poll"
2235
2267
  },
2236
2268
  async poll(e) {
2237
- let t = nn(e.config);
2269
+ let t = _n(e.config);
2238
2270
  if (e.checkpoint === null) return {
2239
- checkpoint: await on(e, t, await an(e, t)),
2271
+ checkpoint: await bn(e, t, await yn(e, t)),
2240
2272
  events: []
2241
2273
  };
2242
- let n = rn(e.checkpoint), r = await an(e, t);
2274
+ let n = vn(e.checkpoint), r = await yn(e, t);
2243
2275
  if (n.spreadsheetId !== t.spreadsheetId || n.sheetId !== r.sheetId || n.lastRowNumber > r.rowCount) return {
2244
- checkpoint: await on(e, t, r),
2276
+ checkpoint: await bn(e, t, r),
2245
2277
  events: []
2246
2278
  };
2247
- let i = await cn(e, t, r), a = Math.min(Math.max(t.firstDataRow, n.lastRowNumber), r.rowCount), o = Math.min(a + t.maxRowsPerPoll, r.rowCount), s = await ln(e, t, r, a, o, "row window fetch");
2279
+ let i = await Sn(e, t, r), a = Math.min(Math.max(t.firstDataRow, n.lastRowNumber), r.rowCount), o = Math.min(a + t.maxRowsPerPoll, r.rowCount), s = await Cn(e, t, r, a, o, "row window fetch");
2248
2280
  if (s.length == 0 && n.lastRowNumber >= t.firstDataRow) return {
2249
- checkpoint: await on(e, t, r),
2281
+ checkpoint: await bn(e, t, r),
2250
2282
  events: []
2251
2283
  };
2252
2284
  let c = a + s.length - 1;
@@ -2258,11 +2290,11 @@ var $t = [
2258
2290
  for (let [e, o] of s.entries()) {
2259
2291
  let s = a + e;
2260
2292
  if (!(s <= n.lastRowNumber)) {
2261
- if (s == t.headerRow || dn(o)) {
2293
+ if (s == t.headerRow || Tn(o)) {
2262
2294
  u += 1;
2263
2295
  continue;
2264
2296
  }
2265
- l.push(await fn(t, r, s, o, i));
2297
+ l.push(await En(t, r, s, o, i));
2266
2298
  }
2267
2299
  }
2268
2300
  let d = c == o && o < r.rowCount;
@@ -2278,7 +2310,7 @@ var $t = [
2278
2310
  };
2279
2311
  }
2280
2312
  };
2281
- function nn(e) {
2313
+ function _n(e) {
2282
2314
  let t = (e.columnRange ?? "A:ZZZ").trim(), n = t.indexOf(":"), r = n < 0 ? t : t.slice(0, n), i = n < 0 ? t : t.slice(n + 1), a = e.spreadsheetId.trim();
2283
2315
  return {
2284
2316
  colEnd: i,
@@ -2292,22 +2324,22 @@ function nn(e) {
2292
2324
  valueRender: e.valueRender ?? "UNFORMATTED_VALUE"
2293
2325
  };
2294
2326
  }
2295
- function rn(e) {
2296
- let n = V(e);
2297
- if (typeof n?.spreadsheetId != "string" || !Number.isInteger(n.sheetId) || !Number.isInteger(n.lastRowNumber)) throw new t("Google Sheets checkpoint is invalid; recreate the Trigger.");
2327
+ function vn(t) {
2328
+ let n = I(t);
2329
+ if (typeof n?.spreadsheetId != "string" || !Number.isInteger(n.sheetId) || !Number.isInteger(n.lastRowNumber)) throw new e("Google Sheets checkpoint is invalid; recreate the Trigger.");
2298
2330
  return {
2299
2331
  lastRowNumber: n.lastRowNumber,
2300
2332
  sheetId: n.sheetId,
2301
2333
  spreadsheetId: n.spreadsheetId
2302
2334
  };
2303
2335
  }
2304
- async function an(e, r) {
2305
- let i = await mn(e, `/spreadsheets/${encodeURIComponent(r.spreadsheetId)}`, { fields: "sheets.properties(sheetId,title,sheetType,gridProperties)" });
2306
- if (i.status == 404) throw new t("The Google Sheets spreadsheet was not found.");
2307
- hn(i, "spreadsheet metadata fetch");
2308
- let a = V(i.data)?.sheets, o = (Array.isArray(a) ? a.map((e) => V(V(e)?.properties)) : []).filter((e) => e != null), s = (/^\d+$/.test(r.sheet) ? o.find(({ sheetId: e }) => e === Number(r.sheet)) : void 0) ?? o.find(({ title: e }) => e === r.sheet);
2309
- if (s == null) throw new t(`Google Sheets tab "${r.sheet}" does not exist.`);
2310
- if (s.sheetType != null && s.sheetType !== "GRID") throw new t("The Google Sheets tab is not a grid sheet.");
2336
+ async function yn(t, r) {
2337
+ let i = await On(t, `/spreadsheets/${encodeURIComponent(r.spreadsheetId)}`, { fields: "sheets.properties(sheetId,title,sheetType,gridProperties)" });
2338
+ if (i.status == 404) throw new e("The Google Sheets spreadsheet was not found.");
2339
+ kn(i, "spreadsheet metadata fetch");
2340
+ let a = I(i.data)?.sheets, o = (Array.isArray(a) ? a.map((e) => I(I(e)?.properties)) : []).filter((e) => e != null), s = (/^\d+$/.test(r.sheet) ? o.find(({ sheetId: e }) => e === Number(r.sheet)) : void 0) ?? o.find(({ title: e }) => e === r.sheet);
2341
+ if (s == null) throw new e(`Google Sheets tab "${r.sheet}" does not exist.`);
2342
+ if (s.sheetType != null && s.sheetType !== "GRID") throw new e("The Google Sheets tab is not a grid sheet.");
2311
2343
  let c = s.gridProperties?.rowCount;
2312
2344
  if (s.sheetId == null || s.title == null || c == null) throw new n("Google Sheets tab metadata is incomplete.");
2313
2345
  return {
@@ -2316,45 +2348,45 @@ async function an(e, r) {
2316
2348
  title: s.title
2317
2349
  };
2318
2350
  }
2319
- async function on(e, t, n) {
2351
+ async function bn(e, t, n) {
2320
2352
  return {
2321
- lastRowNumber: await sn(e, t, n),
2353
+ lastRowNumber: await xn(e, t, n),
2322
2354
  sheetId: n.sheetId,
2323
2355
  spreadsheetId: t.spreadsheetId
2324
2356
  };
2325
2357
  }
2326
- async function sn(e, t, n) {
2358
+ async function xn(e, t, n) {
2327
2359
  if (n.rowCount < t.firstDataRow) return t.firstDataRow - 1;
2328
- let r = await ln(e, t, n, t.firstDataRow, n.rowCount, "full-range scan");
2360
+ let r = await Cn(e, t, n, t.firstDataRow, n.rowCount, "full-range scan");
2329
2361
  return r.length == 0 ? t.firstDataRow - 1 : t.firstDataRow + r.length - 1;
2330
2362
  }
2331
- async function cn(e, t, n) {
2332
- let r = await mn(e, pn(t, n, t.headerRow, t.headerRow), {
2363
+ async function Sn(e, t, n) {
2364
+ let r = await On(e, Dn(t, n, t.headerRow, t.headerRow), {
2333
2365
  majorDimension: "ROWS",
2334
2366
  valueRenderOption: "FORMATTED_VALUE"
2335
2367
  });
2336
- return hn(r, "header row fetch"), un(r.data)[0] ?? [];
2368
+ return kn(r, "header row fetch"), wn(r.data)[0] ?? [];
2337
2369
  }
2338
- async function ln(e, t, n, r, i, a) {
2339
- let o = await mn(e, pn(t, n, r, i), {
2370
+ async function Cn(e, t, n, r, i, a) {
2371
+ let o = await On(e, Dn(t, n, r, i), {
2340
2372
  dateTimeRenderOption: t.dateTimeRender,
2341
2373
  majorDimension: "ROWS",
2342
2374
  valueRenderOption: t.valueRender
2343
2375
  });
2344
- return hn(o, a), un(o.data);
2376
+ return kn(o, a), wn(o.data);
2345
2377
  }
2346
- function un(e) {
2347
- let t = V(e)?.values;
2378
+ function wn(e) {
2379
+ let t = I(e)?.values;
2348
2380
  return Array.isArray(t) ? t : [];
2349
2381
  }
2350
- function dn(e) {
2382
+ function Tn(e) {
2351
2383
  return e.every((e) => e === "" || e == null);
2352
2384
  }
2353
- async function fn(e, t, n, r, i) {
2354
- let a = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify(r))), o = [...new Uint8Array(a)].slice(0, 8).map((e) => e.toString(16).padStart(2, "0")).join(""), s = {}, c = gn(e.colStart);
2385
+ async function En(e, t, n, r, i) {
2386
+ let a = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify(r))), o = [...new Uint8Array(a)].slice(0, 8).map((e) => e.toString(16).padStart(2, "0")).join(""), s = {}, c = An(e.colStart);
2355
2387
  for (let [e, t] of r.entries()) {
2356
2388
  let n = i[e];
2357
- s[typeof n == "string" && n.length > 0 ? n : _n(c + e)] = t;
2389
+ s[typeof n == "string" && n.length > 0 ? n : jn(c + e)] = t;
2358
2390
  }
2359
2391
  return {
2360
2392
  dedupeKey: `${t.sheetId}:${n}:${o}`,
@@ -2368,11 +2400,11 @@ async function fn(e, t, n, r, i) {
2368
2400
  }
2369
2401
  };
2370
2402
  }
2371
- function pn(e, t, n, r) {
2403
+ function Dn(e, t, n, r) {
2372
2404
  let i = encodeURIComponent(`'${t.title.replaceAll("'", "''")}'`);
2373
2405
  return `/spreadsheets/${encodeURIComponent(e.spreadsheetId)}/values/${i}!${e.colStart}${n}:${e.colEnd}${r}`;
2374
2406
  }
2375
- async function mn(e, t, r) {
2407
+ async function On(e, t, r) {
2376
2408
  try {
2377
2409
  return await e.connector.execute({
2378
2410
  endpoint: t,
@@ -2383,30 +2415,30 @@ async function mn(e, t, r) {
2383
2415
  throw new n(`Google Sheets proxy request to ${t} failed.`, { cause: e });
2384
2416
  }
2385
2417
  }
2386
- function hn(r, i) {
2418
+ function kn(r, i) {
2387
2419
  if (r.status >= 200 && r.status < 300) return;
2388
- if (r.status == 401) throw new e(`Google Sheets ${i} rejected the Connection.`);
2420
+ if (r.status == 401) throw new t(`Google Sheets ${i} rejected the Connection.`);
2389
2421
  let a = JSON.stringify(r.data ?? null).toLowerCase();
2390
2422
  if (r.status == 403) {
2391
- if (en.some((e) => a.includes(e))) throw new n(`Google Sheets ${i} was rate limited.`);
2392
- if ($t.some((e) => a.includes(e))) throw new e(`Google Sheets ${i} rejected the Connection.`);
2423
+ if (hn.some((e) => a.includes(e))) throw new n(`Google Sheets ${i} was rate limited.`);
2424
+ if (mn.some((e) => a.includes(e))) throw new t(`Google Sheets ${i} rejected the Connection.`);
2393
2425
  }
2394
- throw r.status == 400 && a.includes("unable to parse range") ? new t("Google Sheets rejected the configured range.") : r.status == 413 ? new t("Google Sheets response is too large; narrow columnRange.") : new n(`Google Sheets ${i} failed with status ${r.status}.`);
2426
+ throw r.status == 400 && a.includes("unable to parse range") ? new e("Google Sheets rejected the configured range.") : r.status == 413 ? new e("Google Sheets response is too large; narrow columnRange.") : new n(`Google Sheets ${i} failed with status ${r.status}.`);
2395
2427
  }
2396
- function gn(e) {
2428
+ function An(e) {
2397
2429
  let t = 0;
2398
2430
  for (let n of e.toUpperCase()) t = t * 26 + n.charCodeAt(0) - 64;
2399
2431
  return t;
2400
2432
  }
2401
- function _n(e) {
2433
+ function jn(e) {
2402
2434
  let t = "";
2403
2435
  for (let n = e; n > 0; n = Math.floor((n - 1) / 26)) t = String.fromCharCode(65 + (n - 1) % 26) + t;
2404
2436
  return t;
2405
2437
  }
2406
- function V(e) {
2438
+ function I(e) {
2407
2439
  return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
2408
2440
  }
2409
- var vn = {
2441
+ var Mn = {
2410
2442
  snapshot: {
2411
2443
  configSchema: {
2412
2444
  additionalProperties: !1,
@@ -2495,13 +2527,13 @@ var vn = {
2495
2527
  type: "poll"
2496
2528
  },
2497
2529
  async poll(e) {
2498
- let t = yn(e.config);
2499
- if (e.checkpoint === null) return bn(e, t);
2500
- let n = Sn(e.checkpoint);
2501
- return n.target === Pn(t) ? Tn(e, t, wn(n, Cn(t.events))) : bn(e, t);
2530
+ let t = Nn(e.config);
2531
+ if (e.checkpoint === null) return Pn(e, t);
2532
+ let n = In(e.checkpoint);
2533
+ return n.target === Jn(t) ? zn(e, t, Rn(n, Ln(t.events))) : Pn(e, t);
2502
2534
  }
2503
2535
  };
2504
- function yn(e) {
2536
+ function Nn(e) {
2505
2537
  return {
2506
2538
  dataSourceId: e.dataSourceId ?? "",
2507
2539
  databaseId: e.databaseId,
@@ -2510,9 +2542,9 @@ function yn(e) {
2510
2542
  maxItemsPerPoll: e.maxItemsPerPoll ?? 25
2511
2543
  };
2512
2544
  }
2513
- async function bn(e, t) {
2514
- let n = await xn(e, t), r = Cn(t.events);
2515
- return Nn(await Mn(e, {
2545
+ async function Pn(e, t) {
2546
+ let n = await Fn(e, t), r = Ln(t.events);
2547
+ return qn(await Kn(e, {
2516
2548
  body: {
2517
2549
  page_size: 1,
2518
2550
  sorts: [{
@@ -2527,32 +2559,32 @@ async function bn(e, t) {
2527
2559
  cursorField: r,
2528
2560
  dataSourceId: n,
2529
2561
  since: (/* @__PURE__ */ new Date(Math.ceil(e.now.getTime() / 6e4) * 6e4)).toISOString(),
2530
- target: Pn(t)
2562
+ target: Jn(t)
2531
2563
  },
2532
2564
  events: []
2533
2565
  };
2534
2566
  }
2535
- async function xn(e, n) {
2536
- let r = await Mn(e, {
2567
+ async function Fn(t, n) {
2568
+ let r = await Kn(t, {
2537
2569
  endpoint: `/databases/${encodeURIComponent(n.databaseId)}`,
2538
2570
  method: "GET"
2539
2571
  });
2540
- Nn(r, "database resolve");
2541
- let i = H(r.data)?.data_sources, a = Array.isArray(i) ? i.flatMap((e) => {
2542
- let t = H(e)?.id;
2572
+ qn(r, "database resolve");
2573
+ let i = L(r.data)?.data_sources, a = Array.isArray(i) ? i.flatMap((e) => {
2574
+ let t = L(e)?.id;
2543
2575
  return typeof t == "string" && t.length > 0 ? [t] : [];
2544
2576
  }) : [];
2545
2577
  if (n.dataSourceId.length > 0) {
2546
- let e = Fn(n.dataSourceId), r = a.find((t) => Fn(t) == e);
2547
- if (r == null) throw new t("The Notion data source does not belong to the configured database.");
2578
+ let t = Yn(n.dataSourceId), r = a.find((e) => Yn(e) == t);
2579
+ if (r == null) throw new e("The Notion data source does not belong to the configured database.");
2548
2580
  return r;
2549
2581
  }
2550
2582
  if (a.length == 1) return a[0];
2551
- throw a.length == 0 ? new t("The Notion database has no data sources.") : new t("The Notion database has multiple data sources; configure dataSourceId.");
2583
+ throw a.length == 0 ? new e("The Notion database has no data sources.") : new e("The Notion database has multiple data sources; configure dataSourceId.");
2552
2584
  }
2553
- function Sn(e) {
2554
- let n = H(e), r = n?.cursorField;
2555
- if (typeof n?.dataSourceId != "string" || n.dataSourceId.length == 0 || r !== "created_time" && r !== "last_edited_time" || typeof n.since != "string" || n.since.length == 0) throw new t("Notion checkpoint is invalid; recreate the Trigger.");
2585
+ function In(t) {
2586
+ let n = L(t), r = n?.cursorField;
2587
+ if (typeof n?.dataSourceId != "string" || n.dataSourceId.length == 0 || r !== "created_time" && r !== "last_edited_time" || typeof n.since != "string" || n.since.length == 0) throw new e("Notion checkpoint is invalid; recreate the Trigger.");
2556
2588
  return {
2557
2589
  cursorField: r,
2558
2590
  dataSourceId: n.dataSourceId,
@@ -2563,10 +2595,10 @@ function Sn(e) {
2563
2595
  ...n.sinceOnly === !0 ? { sinceOnly: !0 } : {}
2564
2596
  };
2565
2597
  }
2566
- function Cn(e) {
2598
+ function Ln(e) {
2567
2599
  return e.length == 1 && e[0] == "page_added" ? "created_time" : "last_edited_time";
2568
2600
  }
2569
- function wn(e, t) {
2601
+ function Rn(e, t) {
2570
2602
  return e.cursorField == t ? e : {
2571
2603
  cursorField: t,
2572
2604
  dataSourceId: e.dataSourceId,
@@ -2574,11 +2606,11 @@ function wn(e, t) {
2574
2606
  target: e.target
2575
2607
  };
2576
2608
  }
2577
- async function Tn(e, t, n) {
2609
+ async function zn(e, t, n) {
2578
2610
  let r = [], i = 0, a = 0, o = null, s = n.startCursor, c = null;
2579
2611
  for (let l = 0; l < 5; l += 1) {
2580
- let l = await Mn(e, {
2581
- body: On(n, t.maxItemsPerPoll - a, s),
2612
+ let l = await Kn(e, {
2613
+ body: Hn(n, t.maxItemsPerPoll - a, s),
2582
2614
  endpoint: `/data_sources/${encodeURIComponent(n.dataSourceId)}/query`,
2583
2615
  method: "POST"
2584
2616
  });
@@ -2586,14 +2618,14 @@ async function Tn(e, t, n) {
2586
2618
  c = "restarted";
2587
2619
  break;
2588
2620
  }
2589
- Nn(l, "data source query");
2590
- let u = H(l.data) ?? {};
2621
+ qn(l, "data source query");
2622
+ let u = L(l.data) ?? {};
2591
2623
  for (let e of u.results ?? []) {
2592
2624
  a += 1;
2593
2625
  let s = n.cursorField == "created_time" ? e.created_time : e.last_edited_time;
2594
- s != null && s.length > 0 && (o = Ln(o, s));
2595
- let c = kn(e);
2596
- t.events.includes(c) ? r.push(An(e, c, t, n)) : i += 1;
2626
+ s != null && s.length > 0 && (o = Zn(o, s));
2627
+ let c = Un(e);
2628
+ t.events.includes(c) ? r.push(Wn(e, c, t, n)) : i += 1;
2597
2629
  }
2598
2630
  if (u.request_status?.type == "incomplete") {
2599
2631
  c = "truncated";
@@ -2619,36 +2651,36 @@ async function Tn(e, t, n) {
2619
2651
  ...l,
2620
2652
  since: n.since,
2621
2653
  startCursor: c.nextCursor,
2622
- ...Dn(n)
2654
+ ...Vn(n)
2623
2655
  } : {
2624
2656
  ...l,
2625
- ...En(n, c, o, e.now)
2657
+ ...Bn(n, c, o, e.now)
2626
2658
  },
2627
2659
  events: r,
2628
2660
  filtered: i,
2629
2661
  ...c == "complete" ? {} : { hasMore: !0 }
2630
2662
  };
2631
2663
  }
2632
- function En(e, t, n, r) {
2664
+ function Bn(e, t, n, r) {
2633
2665
  let i = {
2634
2666
  since: e.since,
2635
- ...Dn(e)
2667
+ ...Vn(e)
2636
2668
  }, a = Date.parse(e.since) + 6e4 <= r.getTime() ? {
2637
2669
  since: e.since,
2638
2670
  sinceExclusive: !0
2639
2671
  } : i;
2640
- return n != null && Rn(n, e.since) ? { since: n } : t == "restarted" ? i : t == "complete" ? e.sinceOnly === !0 || n != null ? a : i : n == null ? i : e.sinceOnly === !0 ? a : {
2672
+ return n != null && Qn(n, e.since) ? { since: n } : t == "restarted" ? i : t == "complete" ? e.sinceOnly === !0 || n != null ? a : i : n == null ? i : e.sinceOnly === !0 ? a : {
2641
2673
  since: e.since,
2642
2674
  sinceOnly: !0
2643
2675
  };
2644
2676
  }
2645
- function Dn(e) {
2677
+ function Vn(e) {
2646
2678
  return {
2647
2679
  ...e.sinceExclusive === !0 ? { sinceExclusive: !0 } : {},
2648
2680
  ...e.sinceOnly === !0 ? { sinceOnly: !0 } : {}
2649
2681
  };
2650
2682
  }
2651
- function On(e, t, n) {
2683
+ function Hn(e, t, n) {
2652
2684
  let r = e.cursorField;
2653
2685
  return {
2654
2686
  filter: e.sinceOnly === !0 ? { and: [{
@@ -2669,70 +2701,70 @@ function On(e, t, n) {
2669
2701
  ...n == null ? {} : { start_cursor: n }
2670
2702
  };
2671
2703
  }
2672
- function kn(e) {
2673
- return zn(e.created_time) === zn(e.last_edited_time) ? "page_added" : "page_updated";
2704
+ function Un(e) {
2705
+ return $n(e.created_time) === $n(e.last_edited_time) ? "page_added" : "page_updated";
2674
2706
  }
2675
- function An(e, t, n, r) {
2707
+ function Wn(e, t, n, r) {
2676
2708
  return {
2677
- dedupeKey: t == "page_added" ? `added:${e.id}` : `updated:${e.id}:${zn(e.last_edited_time) ?? e.last_edited_time ?? ""}`,
2709
+ dedupeKey: t == "page_added" ? `added:${e.id}` : `updated:${e.id}:${$n(e.last_edited_time) ?? e.last_edited_time ?? ""}`,
2678
2710
  payload: {
2679
2711
  createdBy: { id: e.created_by?.id ?? "" },
2680
2712
  createdTime: e.created_time ?? "",
2681
2713
  dataSourceId: r.dataSourceId,
2682
- databaseId: In(n.databaseId),
2714
+ databaseId: Xn(n.databaseId),
2683
2715
  event: t,
2684
2716
  lastEditedBy: { id: e.last_edited_by?.id ?? "" },
2685
2717
  lastEditedTime: e.last_edited_time ?? "",
2686
2718
  pageId: e.id,
2687
2719
  ...n.includeProperties ? { properties: e.properties ?? {} } : {},
2688
- title: jn(e.properties ?? {}),
2720
+ title: Gn(e.properties ?? {}),
2689
2721
  url: e.url ?? ""
2690
2722
  }
2691
2723
  };
2692
2724
  }
2693
- function jn(e) {
2725
+ function Gn(e) {
2694
2726
  for (let t of Object.values(e)) {
2695
- let e = H(t);
2696
- if (!(e?.type !== "title" || !Array.isArray(e.title))) return e.title.map((e) => typeof H(e)?.plain_text == "string" ? H(e).plain_text : "").join("");
2727
+ let e = L(t);
2728
+ if (!(e?.type !== "title" || !Array.isArray(e.title))) return e.title.map((e) => typeof L(e)?.plain_text == "string" ? L(e).plain_text : "").join("");
2697
2729
  }
2698
2730
  return "";
2699
2731
  }
2700
- async function Mn(e, t) {
2732
+ async function Kn(e, t) {
2701
2733
  try {
2702
2734
  return await e.connector.execute(t, e.signal);
2703
2735
  } catch (e) {
2704
2736
  throw new n(`Notion proxy request to ${t.endpoint} failed.`, { cause: e });
2705
2737
  }
2706
2738
  }
2707
- function Nn(r, i) {
2708
- if (!(r.status >= 200 && r.status < 300)) throw r.status == 401 || r.status == 403 ? new e(`Notion ${i} rejected the Connection.`) : r.status == 404 ? new t("The Notion target was not found or is not shared with the Connection.") : r.status == 400 ? new t(`Notion ${i} rejected the configuration.`) : new n(`Notion ${i} failed with status ${r.status}.`);
2739
+ function qn(r, i) {
2740
+ if (!(r.status >= 200 && r.status < 300)) throw r.status == 401 || r.status == 403 ? new t(`Notion ${i} rejected the Connection.`) : r.status == 404 ? new e("The Notion target was not found or is not shared with the Connection.") : r.status == 400 ? new e(`Notion ${i} rejected the configuration.`) : new n(`Notion ${i} failed with status ${r.status}.`);
2709
2741
  }
2710
- function Pn(e) {
2742
+ function Jn(e) {
2711
2743
  return `${e.databaseId}|${e.dataSourceId}`;
2712
2744
  }
2713
- function Fn(e) {
2745
+ function Yn(e) {
2714
2746
  return e.replaceAll("-", "").toLowerCase();
2715
2747
  }
2716
- function In(e) {
2717
- let t = Fn(e);
2748
+ function Xn(e) {
2749
+ let t = Yn(e);
2718
2750
  return `${t.slice(0, 8)}-${t.slice(8, 12)}-${t.slice(12, 16)}-${t.slice(16, 20)}-${t.slice(20)}`;
2719
2751
  }
2720
- function Ln(e, t) {
2752
+ function Zn(e, t) {
2721
2753
  let n = Date.parse(t);
2722
2754
  return Number.isNaN(n) || e != null && n < Date.parse(e) ? e : t;
2723
2755
  }
2724
- function Rn(e, t) {
2756
+ function Qn(e, t) {
2725
2757
  return !Number.isNaN(Date.parse(e)) && !Number.isNaN(Date.parse(t)) && Date.parse(e) > Date.parse(t);
2726
2758
  }
2727
- function zn(e) {
2759
+ function $n(e) {
2728
2760
  if (e == null || e.length == 0) return null;
2729
2761
  let t = Date.parse(e);
2730
2762
  return Number.isNaN(t) ? null : new Date(t).toISOString();
2731
2763
  }
2732
- function H(e) {
2764
+ function L(e) {
2733
2765
  return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
2734
2766
  }
2735
- var Bn = {
2767
+ var er = {
2736
2768
  snapshot: {
2737
2769
  configSchema: {
2738
2770
  additionalProperties: !1,
@@ -2839,14 +2871,14 @@ var Bn = {
2839
2871
  type: "poll"
2840
2872
  },
2841
2873
  async poll(e) {
2842
- let t = Vn(e.config);
2874
+ let t = tr(e.config);
2843
2875
  if (e.checkpoint === null) return {
2844
- checkpoint: await Hn(e, t),
2876
+ checkpoint: await nr(e, t),
2845
2877
  events: []
2846
2878
  };
2847
- let n = Wn(e.checkpoint), { items: r, next: i } = await Gn(e, n, t.maxItemsPerPoll), a = [], o = 0;
2879
+ let n = ir(e.checkpoint), { items: r, next: i } = await ar(e, n, t.maxItemsPerPoll), a = [], o = 0;
2848
2880
  for (let [e, i] of r) {
2849
- let r = Kn(e, i, t, new Date(n.lastPolledAt));
2881
+ let r = or(e, i, t, new Date(n.lastPolledAt));
2850
2882
  r != "structural" && (r == "filtered" ? o += 1 : a.push(r));
2851
2883
  }
2852
2884
  return {
@@ -2857,7 +2889,7 @@ var Bn = {
2857
2889
  };
2858
2890
  }
2859
2891
  };
2860
- function Vn(e) {
2892
+ function tr(e) {
2861
2893
  return {
2862
2894
  events: e.events ?? ["created", "updated"],
2863
2895
  itemId: (e.itemId ?? "").trim(),
@@ -2866,54 +2898,54 @@ function Vn(e) {
2866
2898
  parentFolderId: (e.parentFolderId ?? "").trim()
2867
2899
  };
2868
2900
  }
2869
- async function Hn(e, r) {
2870
- let i = await Yn(e, "/me/drive/root/delta", { token: "latest" });
2871
- if (i.status == 404) throw new t("OneDrive is not provisioned for this account.");
2872
- Zn(i, "delta seeding");
2873
- let a = U(i.data)?.["@odata.deltaLink"], o = a == null ? null : er(a);
2901
+ async function nr(t, r) {
2902
+ let i = await lr(t, "/me/drive/root/delta", { token: "latest" });
2903
+ if (i.status == 404) throw new e("OneDrive is not provisioned for this account.");
2904
+ dr(i, "delta seeding");
2905
+ let a = R(i.data)?.["@odata.deltaLink"], o = a == null ? null : mr(a);
2874
2906
  if (o == null) throw new n("OneDrive delta seeding response has no delta token.");
2875
- return await Un(e, "parentFolderId", r.parentFolderId), await Un(e, "itemId", r.itemId), {
2907
+ return await rr(t, "parentFolderId", r.parentFolderId), await rr(t, "itemId", r.itemId), {
2876
2908
  deltaToken: o,
2877
- lastPolledAt: e.now.toISOString()
2909
+ lastPolledAt: t.now.toISOString()
2878
2910
  };
2879
2911
  }
2880
- async function Un(e, n, r) {
2912
+ async function rr(t, n, r) {
2881
2913
  if (r.length == 0) return;
2882
- let i = await Yn(e, `/me/drive/items/${encodeURIComponent(r)}`, {});
2883
- if (i.status == 400 || i.status == 404) throw new t(`OneDrive ${n} does not identify an item in this drive.`);
2884
- Zn(i, `${n} validation`);
2914
+ let i = await lr(t, `/me/drive/items/${encodeURIComponent(r)}`, {});
2915
+ if (i.status == 400 || i.status == 404) throw new e(`OneDrive ${n} does not identify an item in this drive.`);
2916
+ dr(i, `${n} validation`);
2885
2917
  }
2886
- function Wn(e) {
2887
- let n = U(e);
2888
- if (typeof n?.deltaToken != "string" || n.deltaToken.length == 0 || typeof n.lastPolledAt != "string" || Number.isNaN(Date.parse(n.lastPolledAt))) throw new t("OneDrive checkpoint is invalid; recreate the Trigger.");
2918
+ function ir(t) {
2919
+ let n = R(t);
2920
+ if (typeof n?.deltaToken != "string" || n.deltaToken.length == 0 || typeof n.lastPolledAt != "string" || Number.isNaN(Date.parse(n.lastPolledAt))) throw new e("OneDrive checkpoint is invalid; recreate the Trigger.");
2889
2921
  return {
2890
2922
  deltaToken: n.deltaToken,
2891
2923
  lastPolledAt: n.lastPolledAt,
2892
2924
  ...typeof n.pageToken == "string" && n.pageToken.length > 0 ? { pageToken: n.pageToken } : {}
2893
2925
  };
2894
2926
  }
2895
- async function Gn(e, t, r) {
2927
+ async function ar(e, t, r) {
2896
2928
  let i = /* @__PURE__ */ new Map(), a = t.pageToken ?? t.deltaToken;
2897
2929
  for (let t = 0; t < 5; t += 1) {
2898
- let t = await Yn(e, "/me/drive/root/delta", {
2930
+ let t = await lr(e, "/me/drive/root/delta", {
2899
2931
  $top: r,
2900
2932
  token: a
2901
2933
  });
2902
- Xn(t);
2903
- let o = U(t.data) ?? {};
2934
+ ur(t);
2935
+ let o = R(t.data) ?? {};
2904
2936
  for (let e of o.value ?? []) e.id != null && e.id.length > 0 && i.set(e.id, e);
2905
2937
  if (o["@odata.deltaLink"]) return {
2906
2938
  items: i,
2907
2939
  next: {
2908
2940
  checkpoint: {
2909
- deltaToken: $n(o["@odata.deltaLink"]),
2941
+ deltaToken: pr(o["@odata.deltaLink"]),
2910
2942
  lastPolledAt: e.now.toISOString()
2911
2943
  },
2912
2944
  hasMore: !1
2913
2945
  }
2914
2946
  };
2915
2947
  if (!o["@odata.nextLink"]) throw new n("OneDrive delta response has no continuation link.");
2916
- a = $n(o["@odata.nextLink"]);
2948
+ a = pr(o["@odata.nextLink"]);
2917
2949
  }
2918
2950
  return {
2919
2951
  items: i,
@@ -2927,17 +2959,17 @@ async function Gn(e, t, r) {
2927
2959
  }
2928
2960
  };
2929
2961
  }
2930
- function Kn(e, t, n, r) {
2962
+ function or(e, t, n, r) {
2931
2963
  if (t.root != null) return "structural";
2932
- let i = qn(t);
2964
+ let i = sr(t);
2933
2965
  if (i == null) return "structural";
2934
- let a = t.deleted == null ? tr(t.createdDateTime, r) ? "created" : "updated" : "deleted";
2935
- return !n.events.includes(a) || !n.itemTypes.includes(i) || n.parentFolderId.length > 0 && t.parentReference?.id !== n.parentFolderId || n.itemId.length > 0 && e !== n.itemId ? "filtered" : Jn(e, t, a, i);
2966
+ let a = t.deleted == null ? hr(t.createdDateTime, r) ? "created" : "updated" : "deleted";
2967
+ return !n.events.includes(a) || !n.itemTypes.includes(i) || n.parentFolderId.length > 0 && t.parentReference?.id !== n.parentFolderId || n.itemId.length > 0 && e !== n.itemId ? "filtered" : cr(e, t, a, i);
2936
2968
  }
2937
- function qn(e) {
2969
+ function sr(e) {
2938
2970
  return e.file == null ? e.folder == null ? e.deleted == null ? null : "file" : "folder" : "file";
2939
2971
  }
2940
- function Jn(e, t, n, r) {
2972
+ function cr(e, t, n, r) {
2941
2973
  return {
2942
2974
  dedupeKey: t.deleted == null ? `${e}:${t.eTag ?? t.lastModifiedDateTime}` : `${e}:deleted`,
2943
2975
  payload: {
@@ -2956,7 +2988,7 @@ function Jn(e, t, n, r) {
2956
2988
  }
2957
2989
  };
2958
2990
  }
2959
- async function Yn(e, t, r) {
2991
+ async function lr(e, t, r) {
2960
2992
  try {
2961
2993
  return await e.connector.execute({
2962
2994
  endpoint: t,
@@ -2967,31 +2999,31 @@ async function Yn(e, t, r) {
2967
2999
  throw new n(`OneDrive proxy request to ${t} failed.`, { cause: e });
2968
3000
  }
2969
3001
  }
2970
- function Xn(e) {
2971
- if (e.status == 410 && Qn(e.data)) throw new t("OneDrive delta token expired; recreate the Trigger.");
2972
- if (e.status == 404) throw new t("OneDrive is not provisioned for this account.");
2973
- if (e.status == 400) throw new t("OneDrive rejected the delta token; recreate the Trigger.");
2974
- Zn(e, "delta list");
3002
+ function ur(t) {
3003
+ if (t.status == 410 && fr(t.data)) throw new e("OneDrive delta token expired; recreate the Trigger.");
3004
+ if (t.status == 404) throw new e("OneDrive is not provisioned for this account.");
3005
+ if (t.status == 400) throw new e("OneDrive rejected the delta token; recreate the Trigger.");
3006
+ dr(t, "delta list");
2975
3007
  }
2976
- function Zn(t, r) {
2977
- if (!(t.status >= 200 && t.status < 300)) throw t.status == 401 || t.status == 403 ? new e(`OneDrive ${r} rejected the Connection.`) : new n(`OneDrive ${r} failed with status ${t.status}.`);
3008
+ function dr(e, r) {
3009
+ if (!(e.status >= 200 && e.status < 300)) throw e.status == 401 || e.status == 403 ? new t(`OneDrive ${r} rejected the Connection.`) : new n(`OneDrive ${r} failed with status ${e.status}.`);
2978
3010
  }
2979
- function Qn(e) {
2980
- let t = U(e)?.error;
3011
+ function fr(e) {
3012
+ let t = R(e)?.error;
2981
3013
  for (; t != null;) {
2982
- let e = U(t);
3014
+ let e = R(t);
2983
3015
  if (e == null) break;
2984
3016
  if (e.code == "resyncChangesApplyDifferences" || e.code == "resyncChangesUploadDifferences") return !0;
2985
3017
  t = e.innerError ?? e.innererror;
2986
3018
  }
2987
3019
  return !1;
2988
3020
  }
2989
- function $n(e) {
2990
- let t = er(e);
3021
+ function pr(e) {
3022
+ let t = mr(e);
2991
3023
  if (t == null) throw new n("OneDrive delta link has no token.");
2992
3024
  return t;
2993
3025
  }
2994
- function er(e) {
3026
+ function mr(e) {
2995
3027
  let t = /[?&]token=([^&#]+)/.exec(e)?.[1] ?? /\(token='([^']+)'\)/.exec(e)?.[1];
2996
3028
  if (t == null) return null;
2997
3029
  try {
@@ -3000,24 +3032,24 @@ function er(e) {
3000
3032
  return t;
3001
3033
  }
3002
3034
  }
3003
- function tr(e, t) {
3035
+ function hr(e, t) {
3004
3036
  if (e == null || e.length == 0) return !1;
3005
3037
  let n = new Date(e);
3006
3038
  return !Number.isNaN(n.getTime()) && n >= t;
3007
3039
  }
3008
- function U(e) {
3040
+ function R(e) {
3009
3041
  return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
3010
3042
  }
3011
3043
  //#endregion
3012
3044
  //#region src/trigger/providers/outlook/on-message-received.ts
3013
- var nr = "inbox", rr = 25, ir = 100, ar = "1970-01-01T00:00:00Z", or = "id,internetMessageId,conversationId,subject,bodyPreview,from,toRecipients,receivedDateTime,hasAttachments,isRead,isDraft,importance,categories,parentFolderId,webLink", sr = {
3045
+ var gr = "inbox", _r = 25, vr = 100, yr = "1970-01-01T00:00:00Z", br = "id,internetMessageId,conversationId,subject,bodyPreview,from,toRecipients,receivedDateTime,hasAttachments,isRead,isDraft,importance,categories,parentFolderId,webLink", xr = {
3014
3046
  snapshot: {
3015
3047
  configSchema: {
3016
3048
  additionalProperties: !1,
3017
3049
  description: "Configuration for outlook.on_message_received. Every configured matching field must match.",
3018
3050
  properties: {
3019
3051
  folder: {
3020
- default: nr,
3052
+ default: gr,
3021
3053
  description: "A well-known mail folder name, folder ID, or an empty string for the whole mailbox.",
3022
3054
  pattern: "^[A-Za-z0-9_=-]*$",
3023
3055
  type: "string"
@@ -3027,7 +3059,7 @@ var nr = "inbox", rr = 25, ir = 100, ar = "1970-01-01T00:00:00Z", or = "id,inter
3027
3059
  type: "boolean"
3028
3060
  },
3029
3061
  maxMessagesPerPoll: {
3030
- default: rr,
3062
+ default: _r,
3031
3063
  maximum: 100,
3032
3064
  minimum: 1,
3033
3065
  type: "integer"
@@ -3122,40 +3154,40 @@ var nr = "inbox", rr = 25, ir = 100, ar = "1970-01-01T00:00:00Z", or = "id,inter
3122
3154
  provider: "outlook",
3123
3155
  type: "poll"
3124
3156
  },
3125
- async poll(e) {
3126
- let n = cr(e.config);
3127
- if (e.checkpoint === null) return {
3128
- checkpoint: await lr(e, n),
3157
+ async poll(t) {
3158
+ let n = Sr(t.config);
3159
+ if (t.checkpoint === null) return {
3160
+ checkpoint: await Cr(t, n),
3129
3161
  events: []
3130
3162
  };
3131
- let r = ur(e.checkpoint), i = await hr(e, dr(n.folder), {
3132
- $filter: fr(n, r.lastReceivedDateTime),
3163
+ let r = wr(t.checkpoint), i = await kr(t, Tr(n.folder), {
3164
+ $filter: Er(n, r.lastReceivedDateTime),
3133
3165
  $orderby: "receivedDateTime asc",
3134
- $select: or,
3166
+ $select: br,
3135
3167
  $top: n.maxMessagesPerPoll
3136
3168
  });
3137
- gr(i, "message list");
3138
- let a = vr(i.data);
3169
+ Ar(i, "message list");
3170
+ let a = Mr(i.data);
3139
3171
  if (a.length == 0) return {
3140
3172
  checkpoint: r,
3141
3173
  events: []
3142
3174
  };
3143
3175
  let o = Date.parse(r.lastReceivedDateTime), s = o, c = r.lastReceivedDateTime;
3144
3176
  for (let e of a) {
3145
- let t = W(e.receivedDateTime);
3177
+ let t = z(e.receivedDateTime);
3146
3178
  e.receivedDateTime != null && t != null && t > s && (s = t, c = e.receivedDateTime);
3147
3179
  }
3148
3180
  let l = s > o, u = new Set(r.boundaryMessageIds), d = a.length >= n.maxMessagesPerPoll;
3149
- if (d && !l && a.every((e) => typeof e.id == "string" && u.has(e.id))) throw new t("Outlook cursor is stuck on a full timestamp boundary; increase maxMessagesPerPoll and resume the Trigger.");
3181
+ if (d && !l && a.every((e) => typeof e.id == "string" && u.has(e.id))) throw new e("Outlook cursor is stuck on a full timestamp boundary; increase maxMessagesPerPoll and resume the Trigger.");
3150
3182
  let f = new Set(l ? [] : r.boundaryMessageIds), p = [], m = 0;
3151
- for (let e of a) if (e.id != null && e.id.length != 0 && (W(e.receivedDateTime) == s && f.add(e.id), !u.has(e.id))) {
3152
- if (!pr(e, n)) {
3183
+ for (let e of a) if (e.id != null && e.id.length != 0 && (z(e.receivedDateTime) == s && f.add(e.id), !u.has(e.id))) {
3184
+ if (!Dr(e, n)) {
3153
3185
  m += 1;
3154
3186
  continue;
3155
3187
  }
3156
- p.push(mr(e, e.id));
3188
+ p.push(Or(e, e.id));
3157
3189
  }
3158
- let h = d && (l || p.length > 0);
3190
+ let ee = d && (l || p.length > 0);
3159
3191
  return {
3160
3192
  checkpoint: {
3161
3193
  boundaryMessageIds: [...f],
@@ -3163,38 +3195,38 @@ var nr = "inbox", rr = 25, ir = 100, ar = "1970-01-01T00:00:00Z", or = "id,inter
3163
3195
  },
3164
3196
  events: p,
3165
3197
  filtered: m,
3166
- ...h ? { hasMore: !0 } : {}
3198
+ ...ee ? { hasMore: !0 } : {}
3167
3199
  };
3168
3200
  }
3169
3201
  };
3170
- function cr(e) {
3202
+ function Sr(e) {
3171
3203
  return {
3172
- folder: e.folder ?? nr,
3204
+ folder: e.folder ?? gr,
3173
3205
  includeDrafts: e.includeDrafts ?? !1,
3174
- maxMessagesPerPoll: e.maxMessagesPerPoll ?? rr,
3206
+ maxMessagesPerPoll: e.maxMessagesPerPoll ?? _r,
3175
3207
  readStatus: e.readStatus ?? "All",
3176
3208
  senderAddress: (e.senderAddress ?? "").trim(),
3177
3209
  subjectContains: (e.subjectContains ?? "").trim(),
3178
3210
  withAttachmentsOnly: e.withAttachmentsOnly ?? !1
3179
3211
  };
3180
3212
  }
3181
- async function lr(e, t) {
3182
- let n = await hr(e, dr(t.folder), {
3213
+ async function Cr(e, t) {
3214
+ let n = await kr(e, Tr(t.folder), {
3183
3215
  $orderby: "receivedDateTime desc",
3184
3216
  $select: "id,receivedDateTime",
3185
- $top: ir
3217
+ $top: vr
3186
3218
  });
3187
- gr(n, "seed marker fetch"), gr(await hr(e, dr(t.folder), {
3188
- $filter: fr(t, ar),
3219
+ Ar(n, "seed marker fetch"), Ar(await kr(e, Tr(t.folder), {
3220
+ $filter: Er(t, yr),
3189
3221
  $orderby: "receivedDateTime desc",
3190
3222
  $top: 1
3191
3223
  }), "seed filter shape check");
3192
- let r = yr(vr(n.data));
3224
+ let r = Nr(Mr(n.data));
3193
3225
  if (r == null) return {
3194
3226
  boundaryMessageIds: [],
3195
3227
  lastReceivedDateTime: e.now.toISOString()
3196
3228
  };
3197
- let i = vr(n.data).filter((e) => W(e.receivedDateTime) == r.ms);
3229
+ let i = Mr(n.data).filter((e) => z(e.receivedDateTime) == r.ms);
3198
3230
  return i.length >= t.maxMessagesPerPoll ? {
3199
3231
  boundaryMessageIds: [],
3200
3232
  lastReceivedDateTime: new Date(r.ms + 1e3).toISOString()
@@ -3203,26 +3235,26 @@ async function lr(e, t) {
3203
3235
  lastReceivedDateTime: r.iso
3204
3236
  };
3205
3237
  }
3206
- function ur(e) {
3207
- let n = G(e), r = n?.lastReceivedDateTime;
3208
- if (typeof r != "string" || W(r) == null) throw new t("Outlook checkpoint is invalid; recreate the Trigger.");
3238
+ function wr(t) {
3239
+ let n = B(t), r = n?.lastReceivedDateTime;
3240
+ if (typeof r != "string" || z(r) == null) throw new e("Outlook checkpoint is invalid; recreate the Trigger.");
3209
3241
  let i = n?.boundaryMessageIds;
3210
3242
  return {
3211
3243
  boundaryMessageIds: Array.isArray(i) ? i.filter((e) => typeof e == "string" && e.length > 0) : [],
3212
3244
  lastReceivedDateTime: r
3213
3245
  };
3214
3246
  }
3215
- function dr(e) {
3247
+ function Tr(e) {
3216
3248
  return e.length == 0 ? "/me/messages" : `/me/mailFolders/${encodeURIComponent(e)}/messages`;
3217
3249
  }
3218
- function fr(e, t) {
3250
+ function Er(e, t) {
3219
3251
  let n = [`receivedDateTime ge ${t}`];
3220
3252
  return e.readStatus == "Unread" && n.push("isRead eq false"), e.readStatus == "Read" && n.push("isRead eq true"), e.withAttachmentsOnly && n.push("hasAttachments eq true"), e.senderAddress.length > 0 && n.push(`from/emailAddress/address eq '${e.senderAddress.replaceAll("'", "''")}'`), n.join(" and ");
3221
3253
  }
3222
- function pr(e, t) {
3254
+ function Dr(e, t) {
3223
3255
  return e.isDraft === !0 && !t.includeDrafts ? !1 : t.subjectContains.length == 0 || (e.subject ?? "").toLowerCase().includes(t.subjectContains.toLowerCase());
3224
3256
  }
3225
- function mr(e, t) {
3257
+ function Or(e, t) {
3226
3258
  return {
3227
3259
  dedupeKey: t,
3228
3260
  payload: {
@@ -3245,7 +3277,7 @@ function mr(e, t) {
3245
3277
  }
3246
3278
  };
3247
3279
  }
3248
- async function hr(e, t, r) {
3280
+ async function kr(e, t, r) {
3249
3281
  try {
3250
3282
  return await e.connector.execute({
3251
3283
  endpoint: t,
@@ -3257,28 +3289,28 @@ async function hr(e, t, r) {
3257
3289
  throw new n(`Outlook proxy request to ${t} failed.`, { cause: e });
3258
3290
  }
3259
3291
  }
3260
- function gr(r, i) {
3292
+ function Ar(r, i) {
3261
3293
  if (r.status >= 200 && r.status < 300) return;
3262
- let a = _r(r.data);
3263
- throw r.status == 401 ? new e(`Outlook ${i} rejected the Connection.`) : r.status == 403 && a.has("mailboxnotenabledforrestapi") ? new t("The Outlook mailbox is not reachable through the Graph mail APIs.") : r.status == 403 && (a.has("accessdenied") || a.has("erroraccessdenied")) ? new e(`Outlook ${i} rejected the Connection.`) : r.status == 404 && (a.has("erroritemnotfound") || a.has("itemnotfound")) ? new t("The configured Outlook folder does not exist.") : r.status == 400 && (a.has("errorinvalididmalformed") || a.has("inefficientfilter")) ? new t("Outlook rejected the configured folder or filters.") : new n(`Outlook ${i} failed with status ${r.status}.`);
3294
+ let a = jr(r.data);
3295
+ throw r.status == 401 ? new t(`Outlook ${i} rejected the Connection.`) : r.status == 403 && a.has("mailboxnotenabledforrestapi") ? new e("The Outlook mailbox is not reachable through the Graph mail APIs.") : r.status == 403 && (a.has("accessdenied") || a.has("erroraccessdenied")) ? new t(`Outlook ${i} rejected the Connection.`) : r.status == 404 && (a.has("erroritemnotfound") || a.has("itemnotfound")) ? new e("The configured Outlook folder does not exist.") : r.status == 400 && (a.has("errorinvalididmalformed") || a.has("inefficientfilter")) ? new e("Outlook rejected the configured folder or filters.") : new n(`Outlook ${i} failed with status ${r.status}.`);
3264
3296
  }
3265
- function _r(e) {
3266
- let t = /* @__PURE__ */ new Set(), n = G(e)?.error;
3297
+ function jr(e) {
3298
+ let t = /* @__PURE__ */ new Set(), n = B(e)?.error;
3267
3299
  for (let e = 0; e < 4; e += 1) {
3268
- let e = G(n);
3300
+ let e = B(n);
3269
3301
  if (e == null) break;
3270
3302
  typeof e.code == "string" && e.code.length > 0 && t.add(e.code.toLowerCase()), n = e.innerError ?? e.innererror;
3271
3303
  }
3272
3304
  return t;
3273
3305
  }
3274
- function vr(e) {
3275
- let t = G(e)?.value;
3306
+ function Mr(e) {
3307
+ let t = B(e)?.value;
3276
3308
  return Array.isArray(t) ? t : [];
3277
3309
  }
3278
- function yr(e) {
3310
+ function Nr(e) {
3279
3311
  let t = null;
3280
3312
  for (let n of e) {
3281
- let e = W(n.receivedDateTime);
3313
+ let e = z(n.receivedDateTime);
3282
3314
  n.receivedDateTime != null && e != null && (t == null || e > t.ms) && (t = {
3283
3315
  iso: n.receivedDateTime,
3284
3316
  ms: e
@@ -3286,15 +3318,15 @@ function yr(e) {
3286
3318
  }
3287
3319
  return t;
3288
3320
  }
3289
- function W(e) {
3321
+ function z(e) {
3290
3322
  if (e == null || e.length == 0) return null;
3291
3323
  let t = Date.parse(e);
3292
3324
  return Number.isNaN(t) ? null : t;
3293
3325
  }
3294
- function G(e) {
3326
+ function B(e) {
3295
3327
  return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
3296
3328
  }
3297
- var br = {
3329
+ var Pr = {
3298
3330
  initialState: {
3299
3331
  checkpoint: null,
3300
3332
  subscription: {}
@@ -3316,7 +3348,7 @@ var br = {
3316
3348
  title: "Shopify Store Event Config",
3317
3349
  type: "object"
3318
3350
  },
3319
- definitionVersion: 1,
3351
+ definitionVersion: 2,
3320
3352
  description: "Triggers when selected Shopify webhook topics occur in the connected store.",
3321
3353
  displayName: "Shopify: Store Event",
3322
3354
  endpoint: {
@@ -3357,12 +3389,18 @@ var br = {
3357
3389
  type: "integration"
3358
3390
  },
3359
3391
  receive(e) {
3392
+ if (!fe(e.query("open_flow_callback"), e.callbackSecret)) return {
3393
+ body: "",
3394
+ contentType: "text/plain",
3395
+ outcome: "respond",
3396
+ status: 404
3397
+ };
3360
3398
  let t = e.header("x-shopify-topic")?.trim();
3361
3399
  if (!t) return {
3362
3400
  outcome: "ignored",
3363
3401
  reason: "Shopify topic header is missing."
3364
3402
  };
3365
- if (!xr(e.config).includes(t)) return {
3403
+ if (!Fr(e.config).includes(t)) return {
3366
3404
  outcome: "ignored",
3367
3405
  reason: "Shopify topic is not subscribed."
3368
3406
  };
@@ -3382,39 +3420,39 @@ var br = {
3382
3420
  };
3383
3421
  },
3384
3422
  async reconcile(e) {
3385
- let t = Or(e.state), n = await Cr(e);
3423
+ let t = Ur(e.state), n = await Lr(e);
3386
3424
  if (n == null) {
3387
3425
  if (!e.active) return { outcome: "ready" };
3388
- throw new y("The Shopify store or webhook resource is unavailable.");
3426
+ throw new i("The Shopify store or webhook resource is unavailable.");
3389
3427
  }
3390
3428
  if (!e.active) {
3391
- for (let t of n.values()) await wr(e, t);
3392
- return await t.saveSubscription({}, kr(e.now)), { outcome: "ready" };
3429
+ for (let t of n.values()) await zr(e, t);
3430
+ return await t.saveSubscription({}, Wr(e.now)), { outcome: "ready" };
3393
3431
  }
3394
- let r = xr(e.config), i = [], a = [];
3432
+ let r = Fr(e.config), a = [], o = [];
3395
3433
  try {
3396
3434
  for (let t of r) {
3397
3435
  let r = n.get(t);
3398
- if (r != null) i.push(r);
3436
+ if (r != null) a.push(r);
3399
3437
  else {
3400
- let n = await Sr(e, t);
3401
- i.push(n.id), n.created && a.push(n.id);
3438
+ let n = await Ir(e, t);
3439
+ a.push(n.id), n.created && o.push(n.id);
3402
3440
  }
3403
3441
  }
3404
3442
  } catch (t) {
3405
- throw await Promise.allSettled(a.map((t) => wr(e, t))), t;
3443
+ throw await Promise.allSettled(o.map((t) => zr(e, t))), t;
3406
3444
  }
3407
- for (let [t, i] of n) r.includes(t) || await wr(e, i);
3408
- return await t.saveSubscription({ webhookIds: i }, kr(e.now)), { outcome: "ready" };
3445
+ for (let [t, i] of n) r.includes(t) || await zr(e, i);
3446
+ return await t.saveSubscription({ webhookIds: a }, Wr(e.now)), { outcome: "ready" };
3409
3447
  }
3410
3448
  };
3411
- function xr(e) {
3449
+ function Fr(e) {
3412
3450
  return [...new Set(e.topics)];
3413
3451
  }
3414
- async function Sr(e, t) {
3415
- let n = await Tr(e, "subscription create", {
3452
+ async function Ir(e, t) {
3453
+ let n = await Br(e, "subscription create", {
3416
3454
  body: { webhook: {
3417
- address: e.endpointUrl,
3455
+ address: Rr(e),
3418
3456
  format: "json",
3419
3457
  topic: t
3420
3458
  } },
@@ -3422,90 +3460,94 @@ async function Sr(e, t) {
3422
3460
  method: "POST"
3423
3461
  });
3424
3462
  if (n.status == 422) {
3425
- let n = (await Cr(e))?.get(t);
3463
+ let n = (await Lr(e))?.get(t);
3426
3464
  if (n != null) return {
3427
3465
  created: !1,
3428
3466
  id: n
3429
3467
  };
3430
3468
  }
3431
- Er(n, "subscription create");
3432
- let r = Dr(K(K(n.data)?.webhook)?.id);
3433
- if (r == null) throw new b("Shopify subscription response is missing its ID.");
3469
+ Vr(n, "subscription create");
3470
+ let r = Hr(V(V(n.data)?.webhook)?.id);
3471
+ if (r == null) throw new a("Shopify subscription response is missing its ID.");
3434
3472
  return {
3435
3473
  created: !0,
3436
3474
  id: r
3437
3475
  };
3438
3476
  }
3439
- async function Cr(e) {
3440
- let t = await Tr(e, "subscription list", {
3477
+ async function Lr(e) {
3478
+ let t = Rr(e), n = await Br(e, "subscription list", {
3441
3479
  endpoint: "/webhooks.json",
3442
3480
  method: "GET",
3443
3481
  query: {
3444
- address: e.endpointUrl,
3482
+ address: t,
3445
3483
  limit: 250
3446
3484
  }
3447
3485
  });
3448
- if (t.status == 404) return null;
3449
- Er(t, "subscription list");
3450
- let n = K(t.data)?.webhooks, r = /* @__PURE__ */ new Map();
3451
- if (!Array.isArray(n)) return r;
3452
- for (let t of n) {
3453
- let n = K(t), i = Dr(n?.id);
3454
- n?.address === e.endpointUrl && typeof n.topic == "string" && i != null && r.set(n.topic, i);
3486
+ if (n.status == 404) return null;
3487
+ Vr(n, "subscription list");
3488
+ let r = V(n.data)?.webhooks, i = /* @__PURE__ */ new Map();
3489
+ if (!Array.isArray(r)) return i;
3490
+ for (let e of r) {
3491
+ let n = V(e), r = Hr(n?.id);
3492
+ n?.address === t && typeof n.topic == "string" && r != null && i.set(n.topic, r);
3455
3493
  }
3456
- return r;
3494
+ return i;
3457
3495
  }
3458
- async function wr(e, t) {
3459
- let n = await Tr(e, "subscription delete", {
3496
+ function Rr(e) {
3497
+ let t = new URL(e.endpointUrl);
3498
+ return t.searchParams.set("open_flow_callback", e.callbackSecret), t.href;
3499
+ }
3500
+ async function zr(e, t) {
3501
+ let n = await Br(e, "subscription delete", {
3460
3502
  endpoint: `/webhooks/${encodeURIComponent(t)}.json`,
3461
3503
  method: "DELETE"
3462
3504
  });
3463
- n.status != 404 && Er(n, "subscription delete");
3505
+ n.status != 404 && Vr(n, "subscription delete");
3464
3506
  }
3465
- async function Tr(e, t, n) {
3507
+ async function Br(e, t, n) {
3466
3508
  try {
3467
3509
  return await e.connector.execute(n, e.signal);
3468
3510
  } catch (e) {
3469
- throw e instanceof v ? e : new b(`Shopify ${t} request failed.`, { cause: e });
3511
+ throw e instanceof r ? e : new a(`Shopify ${t} request failed.`, { cause: e });
3470
3512
  }
3471
3513
  }
3472
- function Er(e, t) {
3473
- if (!(e.status >= 200 && e.status < 300)) throw e.status == 401 || e.status == 403 ? new v(`Shopify ${t} rejected the Connection.`) : [
3514
+ function Vr(e, t) {
3515
+ if (!(e.status >= 200 && e.status < 300)) throw e.status == 401 || e.status == 403 ? new r(`Shopify ${t} rejected the Connection.`) : [
3474
3516
  402,
3475
3517
  404,
3476
3518
  422,
3477
3519
  423,
3478
3520
  501
3479
- ].includes(e.status) ? new y(`Shopify ${t} rejected the subscription.`) : new b(`Shopify ${t} failed with status ${e.status}.`);
3521
+ ].includes(e.status) ? new i(`Shopify ${t} rejected the subscription.`) : new a(`Shopify ${t} failed with status ${e.status}.`);
3480
3522
  }
3481
- function Dr(e) {
3523
+ function Hr(e) {
3482
3524
  return typeof e == "string" ? e.trim().length == 0 ? null : e : typeof e == "number" && Number.isFinite(e) ? String(e) : null;
3483
3525
  }
3484
- function Or(e) {
3485
- if (e == null) throw new y("Shopify Integration state is missing.");
3526
+ function Ur(e) {
3527
+ if (e == null) throw new i("Shopify Integration state is missing.");
3486
3528
  return e;
3487
3529
  }
3488
- function kr(e) {
3530
+ function Wr(e) {
3489
3531
  return new Date(e.getTime() + 2592e6);
3490
3532
  }
3491
- function K(e) {
3533
+ function V(e) {
3492
3534
  return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
3493
3535
  }
3494
3536
  //#endregion
3495
3537
  //#region src/trigger/providers/slack/on-message-posted.ts
3496
- var Ar = 15, jr = 6e4, Mr = /* @__PURE__ */ new Set([
3538
+ var Gr = 15, Kr = 6e4, qr = /* @__PURE__ */ new Set([
3497
3539
  "file_share",
3498
3540
  "thread_broadcast",
3499
3541
  "me_message",
3500
3542
  "bot_message"
3501
- ]), Nr = /* @__PURE__ */ new Set([
3543
+ ]), Jr = /* @__PURE__ */ new Set([
3502
3544
  "invalid_auth",
3503
3545
  "not_authed",
3504
3546
  "token_revoked",
3505
3547
  "token_expired",
3506
3548
  "account_inactive",
3507
3549
  "two_factor_setup_required"
3508
- ]), Pr = /* @__PURE__ */ new Set([
3550
+ ]), Yr = /* @__PURE__ */ new Set([
3509
3551
  "channel_not_found",
3510
3552
  "not_in_channel",
3511
3553
  "missing_scope",
@@ -3521,7 +3563,7 @@ var Ar = 15, jr = 6e4, Mr = /* @__PURE__ */ new Set([
3521
3563
  "method_deprecated",
3522
3564
  "deprecated_endpoint",
3523
3565
  "accesslimited"
3524
- ]), Fr = {
3566
+ ]), Xr = {
3525
3567
  snapshot: {
3526
3568
  configSchema: {
3527
3569
  additionalProperties: !1,
@@ -3561,7 +3603,7 @@ var Ar = 15, jr = 6e4, Mr = /* @__PURE__ */ new Set([
3561
3603
  type: "boolean"
3562
3604
  },
3563
3605
  maxMessagesPerPoll: {
3564
- default: Ar,
3606
+ default: Gr,
3565
3607
  description: "Maximum number of messages processed per poll.",
3566
3608
  maximum: 100,
3567
3609
  minimum: 1,
@@ -3635,69 +3677,69 @@ var Ar = 15, jr = 6e4, Mr = /* @__PURE__ */ new Set([
3635
3677
  type: "poll"
3636
3678
  },
3637
3679
  async poll(e) {
3638
- let t = Ir(e.config);
3680
+ let t = Zr(e.config);
3639
3681
  if (e.checkpoint === null) return {
3640
- checkpoint: { lastTs: await Lr(e, t.channelId) },
3682
+ checkpoint: { lastTs: await Qr(e, t.channelId) },
3641
3683
  events: []
3642
3684
  };
3643
- let n = Rr(e.checkpoint), r = await zr(e, t, n), i = Hr(r), a = [], o = 0;
3685
+ let n = $r(e.checkpoint), r = await ei(e, t, n), i = ri(r), a = [], o = 0;
3644
3686
  for (let e of i.toReversed()) {
3645
- if (!Wr(e.message, t)) {
3687
+ if (!ai(e.message, t)) {
3646
3688
  o += 1;
3647
3689
  continue;
3648
3690
  }
3649
- a.push(Gr(e, t.channelId));
3691
+ a.push(oi(e, t.channelId));
3650
3692
  }
3651
3693
  return {
3652
- checkpoint: Ur(n, r, i),
3694
+ checkpoint: ii(n, r, i),
3653
3695
  events: a,
3654
3696
  filtered: o
3655
3697
  };
3656
3698
  }
3657
3699
  };
3658
- function Ir(e) {
3700
+ function Zr(e) {
3659
3701
  return {
3660
3702
  channelId: e.channelId,
3661
3703
  fromUserIds: e.fromUserIds ?? [],
3662
3704
  ignoreUserIds: e.ignoreUserIds ?? [],
3663
3705
  includeBotMessages: e.includeBotMessages ?? !1,
3664
3706
  includeSystemMessages: e.includeSystemMessages ?? !1,
3665
- maxMessagesPerPoll: e.maxMessagesPerPoll ?? Ar,
3707
+ maxMessagesPerPoll: e.maxMessagesPerPoll ?? Gr,
3666
3708
  textContains: e.textContains ?? ""
3667
3709
  };
3668
3710
  }
3669
- async function Lr(e, t) {
3670
- let n = await Br(e, {
3711
+ async function Qr(e, t) {
3712
+ let n = await ti(e, {
3671
3713
  channel: t,
3672
3714
  limit: 1
3673
3715
  });
3674
- Vr(n, "baseline history fetch");
3716
+ ni(n, "baseline history fetch");
3675
3717
  let r = n.data.messages?.[0]?.ts;
3676
- return r != null && Kr(r) ? r : `${Math.floor((e.now.getTime() - jr) / 1e3)}.000000`;
3718
+ return r != null && si(r) ? r : `${Math.floor((e.now.getTime() - Kr) / 1e3)}.000000`;
3677
3719
  }
3678
- function Rr(e) {
3679
- let n = e;
3680
- if (typeof n.lastTs != "string" || n.lastTs.length == 0) throw new t("Slack checkpoint lastTs is missing.");
3720
+ function $r(t) {
3721
+ let n = t;
3722
+ if (typeof n.lastTs != "string" || n.lastTs.length == 0) throw new e("Slack checkpoint lastTs is missing.");
3681
3723
  let r = n.drainLatest, i = n.pendingHighTs;
3682
3724
  if (r == null && i == null) return { lastTs: n.lastTs };
3683
- if (typeof r != "string" || r.length == 0 || typeof i != "string" || i.length == 0) throw new t("Slack checkpoint drain fields are incomplete.");
3725
+ if (typeof r != "string" || r.length == 0 || typeof i != "string" || i.length == 0) throw new e("Slack checkpoint drain fields are incomplete.");
3684
3726
  return {
3685
3727
  drainLatest: r,
3686
3728
  lastTs: n.lastTs,
3687
3729
  pendingHighTs: i
3688
3730
  };
3689
3731
  }
3690
- async function zr(e, t, n) {
3691
- let r = await Br(e, {
3732
+ async function ei(e, t, n) {
3733
+ let r = await ti(e, {
3692
3734
  channel: t.channelId,
3693
3735
  inclusive: "false",
3694
3736
  latest: n.drainLatest,
3695
3737
  limit: t.maxMessagesPerPoll,
3696
3738
  oldest: n.lastTs
3697
3739
  });
3698
- return Vr(r, "history list"), r.data;
3740
+ return ni(r, "history list"), r.data;
3699
3741
  }
3700
- async function Br(e, t) {
3742
+ async function ti(e, t) {
3701
3743
  try {
3702
3744
  return await e.connector.execute({
3703
3745
  endpoint: "/conversations.history",
@@ -3708,19 +3750,19 @@ async function Br(e, t) {
3708
3750
  throw new n("Slack proxy request failed.", { cause: e });
3709
3751
  }
3710
3752
  }
3711
- function Vr(r, i) {
3753
+ function ni(r, i) {
3712
3754
  let a = r.data;
3713
3755
  if (r.status >= 200 && r.status < 300 && a.ok === !0) return;
3714
3756
  let o = typeof a.error == "string" ? a.error : "";
3715
- throw Nr.has(o) ? new e(`Slack ${i} rejected with ${o}.`) : Pr.has(o) ? new t(`Slack ${i} rejected with ${o}.`) : new n(`Slack ${i} failed with ${o || `status ${r.status}`}.`);
3757
+ throw Jr.has(o) ? new t(`Slack ${i} rejected with ${o}.`) : Yr.has(o) ? new e(`Slack ${i} rejected with ${o}.`) : new n(`Slack ${i} failed with ${o || `status ${r.status}`}.`);
3716
3758
  }
3717
- function Hr(e) {
3718
- return (e.messages ?? []).flatMap((e) => e.ts != null && Kr(e.ts) ? [{
3759
+ function ri(e) {
3760
+ return (e.messages ?? []).flatMap((e) => e.ts != null && si(e.ts) ? [{
3719
3761
  message: e,
3720
3762
  ts: e.ts
3721
3763
  }] : []);
3722
3764
  }
3723
- function Ur(e, t, r) {
3765
+ function ii(e, t, r) {
3724
3766
  let i = r[0]?.ts, a = r.at(-1)?.ts;
3725
3767
  if (t.has_more === !0) {
3726
3768
  if (i == null || a == null) throw new n("Slack history reports has_more without a usable timestamp.");
@@ -3732,10 +3774,10 @@ function Ur(e, t, r) {
3732
3774
  }
3733
3775
  return e.pendingHighTs == null ? { lastTs: i ?? e.lastTs } : { lastTs: e.pendingHighTs };
3734
3776
  }
3735
- function Wr(e, t) {
3736
- return !t.includeBotMessages && (e.bot_id != null || e.subtype == "bot_message") || !t.includeSystemMessages && e.subtype != null && !Mr.has(e.subtype) || t.fromUserIds.length > 0 && (e.user == null || !t.fromUserIds.includes(e.user)) || e.user != null && t.ignoreUserIds.includes(e.user) ? !1 : t.textContains.length == 0 || (e.text ?? "").toLowerCase().includes(t.textContains.toLowerCase());
3777
+ function ai(e, t) {
3778
+ return !t.includeBotMessages && (e.bot_id != null || e.subtype == "bot_message") || !t.includeSystemMessages && e.subtype != null && !qr.has(e.subtype) || t.fromUserIds.length > 0 && (e.user == null || !t.fromUserIds.includes(e.user)) || e.user != null && t.ignoreUserIds.includes(e.user) ? !1 : t.textContains.length == 0 || (e.text ?? "").toLowerCase().includes(t.textContains.toLowerCase());
3737
3779
  }
3738
- function Gr(e, t) {
3780
+ function oi(e, t) {
3739
3781
  return {
3740
3782
  dedupeKey: `${t}:${e.ts}`,
3741
3783
  payload: {
@@ -3754,12 +3796,12 @@ function Gr(e, t) {
3754
3796
  }
3755
3797
  };
3756
3798
  }
3757
- function Kr(e) {
3799
+ function si(e) {
3758
3800
  return /^\d+(?:\.\d+)?$/.test(e) && !Number.isNaN(new Date(Math.round(Number(e) * 1e3)).getTime());
3759
3801
  }
3760
3802
  //#endregion
3761
3803
  //#region src/trigger/providers/stripe/on-event.ts
3762
- var q = "/v1/webhook_endpoints", qr = { "Content-Type": "application/x-www-form-urlencoded" }, Jr = {
3804
+ var ci = 300, H = "/v1/webhook_endpoints", li = { "Content-Type": "application/x-www-form-urlencoded" }, ui = {
3763
3805
  initialState: {
3764
3806
  checkpoint: null,
3765
3807
  subscription: {}
@@ -3792,7 +3834,7 @@ var q = "/v1/webhook_endpoints", qr = { "Content-Type": "application/x-www-form-
3792
3834
  title: "Stripe Event Config",
3793
3835
  type: "object"
3794
3836
  },
3795
- definitionVersion: 1,
3837
+ definitionVersion: 2,
3796
3838
  description: "Triggers when selected Stripe events happen on the connected account.",
3797
3839
  displayName: "Stripe: Account Event",
3798
3840
  endpoint: {
@@ -3826,151 +3868,186 @@ var q = "/v1/webhook_endpoints", qr = { "Content-Type": "application/x-www-form-
3826
3868
  provider: "stripe",
3827
3869
  type: "integration"
3828
3870
  },
3829
- receive(e) {
3871
+ async receive(e) {
3872
+ let t = vi(e.state);
3873
+ if (t == null || !await yi(e.header("stripe-signature"), t, e.rawBody, e.now)) return {
3874
+ body: "",
3875
+ contentType: "text/plain",
3876
+ outcome: "respond",
3877
+ status: 404
3878
+ };
3830
3879
  if (e.payload == null || typeof e.payload != "object" || Array.isArray(e.payload)) return {
3831
3880
  outcome: "ignored",
3832
3881
  reason: "Stripe event body is missing."
3833
3882
  };
3834
- let t = e.payload, n = t.type, r = t.id;
3835
- if (typeof n != "string" || typeof r != "string") return {
3883
+ let n = e.payload, r = n.type, i = n.id;
3884
+ if (typeof r != "string" || typeof i != "string") return {
3836
3885
  outcome: "ignored",
3837
3886
  reason: "Stripe event identity is missing."
3838
3887
  };
3839
- let i = Yr(e.config);
3840
- return !i.events.includes("*") && !i.events.includes(n) ? {
3888
+ let a = di(e.config);
3889
+ return !a.events.includes("*") && !a.events.includes(r) ? {
3841
3890
  outcome: "ignored",
3842
3891
  reason: "Stripe event is not subscribed."
3843
3892
  } : {
3844
- dedupeKey: r,
3893
+ dedupeKey: i,
3845
3894
  outcome: "event",
3846
3895
  payload: {
3847
- body: t,
3848
- event: n,
3849
- eventId: r,
3850
- livemode: t.livemode === !0
3896
+ body: n,
3897
+ event: r,
3898
+ eventId: i,
3899
+ livemode: n.livemode === !0
3851
3900
  }
3852
3901
  };
3853
3902
  },
3854
3903
  async reconcile(e) {
3855
- let t = ei(e.state), n = Yr(e.config), r = ti(t);
3904
+ let t = gi(e.state), n = di(e.config), r = _i(t), i = vi(t);
3856
3905
  if (!e.active) {
3857
- if (r ??= await Qr(e), r != null) {
3858
- let t = await J(e, "endpoint delete", {
3859
- endpoint: `${q}/${r}`,
3906
+ if (r ??= await mi(e), r != null) {
3907
+ let t = await U(e, "endpoint delete", {
3908
+ endpoint: `${H}/${r}`,
3860
3909
  method: "DELETE"
3861
3910
  });
3862
- t.status != 404 && Y(t, "endpoint delete");
3911
+ t.status != 404 && W(t, "endpoint delete");
3863
3912
  }
3864
- return await t.saveSubscription({}, ni(e.now)), { outcome: "ready" };
3913
+ return await t.saveSubscription({}, bi(e.now)), { outcome: "ready" };
3865
3914
  }
3866
- if (r ??= await Qr(e), r == null) {
3867
- let t = await J(e, "endpoint create", {
3868
- body: Xr(e.endpointUrl, n),
3869
- endpoint: q,
3870
- headers: qr,
3915
+ if (r ??= await mi(e), r != null && i == null) {
3916
+ let t = await U(e, "endpoint delete", {
3917
+ endpoint: `${H}/${r}`,
3918
+ method: "DELETE"
3919
+ });
3920
+ t.status != 404 && W(t, "endpoint delete"), r = null;
3921
+ }
3922
+ if (r == null) {
3923
+ let t = await U(e, "endpoint create", {
3924
+ body: fi(e.endpointUrl, n),
3925
+ endpoint: H,
3926
+ headers: li,
3871
3927
  method: "POST"
3872
3928
  });
3873
- Y(t, "endpoint create"), r = $r(t.data);
3929
+ W(t, "endpoint create");
3930
+ let a = hi(t.data);
3931
+ r = a.id, i = a.secret;
3874
3932
  }
3875
- let i = await J(e, "endpoint update", {
3876
- body: Zr([
3933
+ let a = await U(e, "endpoint update", {
3934
+ body: pi([
3877
3935
  ...n.events.map((e, t) => [`enabled_events[${t}]`, e]),
3878
3936
  ["disabled", "false"],
3879
3937
  ["description", "Managed by Open Flow."]
3880
3938
  ]),
3881
- endpoint: `${q}/${r}`,
3882
- headers: qr,
3939
+ endpoint: `${H}/${r}`,
3940
+ headers: li,
3883
3941
  method: "POST"
3884
3942
  });
3885
- return i.status == 404 ? (await t.saveSubscription({}, e.now), { outcome: "pending" }) : (Y(i, "endpoint update"), await t.saveSubscription({ endpointId: r }, ni(e.now)), { outcome: "ready" });
3943
+ return a.status == 404 ? (await t.saveSubscription({}, e.now), { outcome: "pending" }) : (W(a, "endpoint update"), await t.saveSubscription({
3944
+ endpointId: r,
3945
+ signingSecret: i
3946
+ }, bi(e.now)), { outcome: "ready" });
3886
3947
  }
3887
3948
  };
3888
- function Yr(e) {
3949
+ function di(e) {
3889
3950
  return {
3890
3951
  apiVersion: e.apiVersion ?? "",
3891
3952
  events: [...new Set(e.events)],
3892
3953
  includeConnectedAccounts: e.includeConnectedAccounts ?? !1
3893
3954
  };
3894
3955
  }
3895
- function Xr(e, t) {
3956
+ function fi(e, t) {
3896
3957
  let n = [
3897
3958
  ["url", e],
3898
3959
  ...t.events.map((e, t) => [`enabled_events[${t}]`, e]),
3899
3960
  ["description", "Managed by Open Flow."]
3900
3961
  ];
3901
- return t.includeConnectedAccounts && n.push(["connect", "true"]), t.apiVersion.length > 0 && n.push(["api_version", t.apiVersion]), Zr(n);
3962
+ return t.includeConnectedAccounts && n.push(["connect", "true"]), t.apiVersion.length > 0 && n.push(["api_version", t.apiVersion]), pi(n);
3902
3963
  }
3903
- function Zr(e) {
3964
+ function pi(e) {
3904
3965
  let t = new URLSearchParams();
3905
3966
  for (let [n, r] of e) t.append(n, r);
3906
3967
  return t.toString();
3907
3968
  }
3908
- async function Qr(e) {
3969
+ async function mi(e) {
3909
3970
  let t;
3910
3971
  for (let n = 0; n < 10; n += 1) {
3911
- let n = await J(e, "endpoint list", {
3912
- endpoint: q,
3972
+ let n = await U(e, "endpoint list", {
3973
+ endpoint: H,
3913
3974
  method: "GET",
3914
3975
  query: {
3915
3976
  limit: 100,
3916
3977
  ...t == null ? {} : { starting_after: t }
3917
3978
  }
3918
3979
  });
3919
- Y(n, "endpoint list");
3920
- let r = X(n.data), i = Array.isArray(r?.data) ? r.data : [];
3980
+ W(n, "endpoint list");
3981
+ let r = G(n.data), i = Array.isArray(r?.data) ? r.data : [];
3921
3982
  for (let t of i) {
3922
- let n = X(t);
3983
+ let n = G(t);
3923
3984
  if (n?.url === e.endpointUrl && typeof n.id == "string") return n.id;
3924
3985
  }
3925
- let a = X(i.at(-1))?.id;
3986
+ let a = G(i.at(-1))?.id;
3926
3987
  if (r?.has_more !== !0 || typeof a != "string") return null;
3927
3988
  t = a;
3928
3989
  }
3929
3990
  return null;
3930
3991
  }
3931
- async function J(e, t, n) {
3992
+ async function U(e, t, n) {
3932
3993
  try {
3933
3994
  return await e.connector.execute(n, e.signal);
3934
3995
  } catch (e) {
3935
- throw e instanceof v ? e : new b(`Stripe ${t} request failed.`, { cause: e });
3996
+ throw e instanceof r ? e : new a(`Stripe ${t} request failed.`, { cause: e });
3936
3997
  }
3937
3998
  }
3938
- function Y(e, t) {
3999
+ function W(e, t) {
3939
4000
  if (!(e.status >= 200 && e.status < 300)) {
3940
- if (e.status == 401 || e.status == 403) throw new v(`Stripe ${t} rejected the Connection.`);
4001
+ if (e.status == 401 || e.status == 403) throw new r(`Stripe ${t} rejected the Connection.`);
3941
4002
  if (e.status == 400 || e.status == 404) {
3942
- let n = X(X(e.data)?.error)?.message;
3943
- throw new y(`Stripe ${t} rejected the subscription${typeof n == "string" ? `: ${n}` : "."}`);
4003
+ let n = G(G(e.data)?.error)?.message;
4004
+ throw new i(`Stripe ${t} rejected the subscription${typeof n == "string" ? `: ${n}` : "."}`);
3944
4005
  }
3945
- throw new b(`Stripe ${t} failed with status ${e.status}.`);
4006
+ throw new a(`Stripe ${t} failed with status ${e.status}.`);
3946
4007
  }
3947
4008
  }
3948
- function $r(e) {
3949
- let t = X(e)?.id;
3950
- if (typeof t != "string") throw new b("Stripe endpoint response is missing its ID.");
3951
- return t;
4009
+ function hi(e) {
4010
+ let t = G(e);
4011
+ if (typeof t?.id != "string" || typeof t.secret != "string" || t.secret.length == 0) throw new a("Stripe endpoint response is missing its ID or signing secret.");
4012
+ return {
4013
+ id: t.id,
4014
+ secret: t.secret
4015
+ };
3952
4016
  }
3953
- function ei(e) {
3954
- if (e == null) throw new y("Stripe Integration state is missing.");
4017
+ function gi(e) {
4018
+ if (e == null) throw new i("Stripe Integration state is missing.");
3955
4019
  return e;
3956
4020
  }
3957
- function ti(e) {
4021
+ function _i(e) {
3958
4022
  let t = e.subscription.endpointId;
3959
4023
  return typeof t == "string" && t.length > 0 ? t : null;
3960
4024
  }
3961
- function ni(e) {
4025
+ function vi(e) {
4026
+ let t = e?.subscription.signingSecret;
4027
+ return typeof t == "string" && t.length > 0 ? t : null;
4028
+ }
4029
+ async function yi(e, t, n, r) {
4030
+ if (e == null) return !1;
4031
+ let i = e.split(",").map((e) => e.trim().split("=", 2)), a = i.find(([e]) => e == "t")?.[1];
4032
+ if (a == null || !/^\d+$/.test(a)) return !1;
4033
+ let o = Number(a);
4034
+ if (!Number.isSafeInteger(o) || Math.abs(Math.floor(r.getTime() / 1e3) - o) > ci) return !1;
4035
+ let s = i.filter(([e, t]) => e == "v1" && t != null).map(([, e]) => e), c = [de(`${a}.`), n];
4036
+ return (await Promise.all(s.map((e) => me(t, c, e)))).some(Boolean);
4037
+ }
4038
+ function bi(e) {
3962
4039
  return new Date(e.getTime() + 2592e6);
3963
4040
  }
3964
- function X(e) {
4041
+ function G(e) {
3965
4042
  return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
3966
4043
  }
3967
4044
  //#endregion
3968
4045
  //#region src/trigger/providers/telegram/on-update.ts
3969
- var ri = /* @__PURE__ */ new Set([
4046
+ var xi = /* @__PURE__ */ new Set([
3970
4047
  "chat_member",
3971
4048
  "message_reaction",
3972
4049
  "message_reaction_count"
3973
- ]), ii = /* @__PURE__ */ "*.message.edited_message.channel_post.edited_channel_post.business_connection.business_message.edited_business_message.deleted_business_messages.guest_message.message_reaction.message_reaction_count.inline_query.chosen_inline_result.callback_query.shipping_query.pre_checkout_query.purchased_paid_media.poll.poll_answer.my_chat_member.chat_member.chat_join_request.chat_boost.removed_chat_boost.managed_bot.subscription".split("."), ai = ii.filter((e) => e != "*" && !ri.has(e)), oi = {
4050
+ ]), Si = /* @__PURE__ */ "*.message.edited_message.channel_post.edited_channel_post.business_connection.business_message.edited_business_message.deleted_business_messages.guest_message.message_reaction.message_reaction_count.inline_query.chosen_inline_result.callback_query.shipping_query.pre_checkout_query.purchased_paid_media.poll.poll_answer.my_chat_member.chat_member.chat_join_request.chat_boost.removed_chat_boost.managed_bot.subscription".split("."), Ci = Si.filter((e) => e != "*" && !xi.has(e)), wi = {
3974
4051
  snapshot: {
3975
4052
  configSchema: {
3976
4053
  additionalProperties: !1,
@@ -3994,7 +4071,7 @@ var ri = /* @__PURE__ */ new Set([
3994
4071
  },
3995
4072
  updates: {
3996
4073
  description: "Telegram update types that trigger a Run. Use * for the Telegram default set.",
3997
- items: { enum: ii },
4074
+ items: { enum: Si },
3998
4075
  minItems: 1,
3999
4076
  type: "array",
4000
4077
  uniqueItems: !0
@@ -4048,13 +4125,13 @@ var ri = /* @__PURE__ */ new Set([
4048
4125
  type: "integration"
4049
4126
  },
4050
4127
  receive(e) {
4051
- if (!li(e.header("x-telegram-bot-api-secret-token"), e.callbackSecret)) return {
4128
+ if (!Di(e.header("x-telegram-bot-api-secret-token"), e.callbackSecret)) return {
4052
4129
  body: "",
4053
4130
  contentType: "text/plain",
4054
4131
  outcome: "respond",
4055
4132
  status: 404
4056
4133
  };
4057
- if (!Z(e.payload) || !Number.isSafeInteger(e.payload.update_id)) return {
4134
+ if (!K(e.payload) || !Number.isSafeInteger(e.payload.update_id)) return {
4058
4135
  outcome: "ignored",
4059
4136
  reason: "Telegram update_id is missing."
4060
4137
  };
@@ -4063,21 +4140,21 @@ var ri = /* @__PURE__ */ new Set([
4063
4140
  outcome: "ignored",
4064
4141
  reason: "Telegram update body is missing."
4065
4142
  };
4066
- let n = si(e.config);
4067
- if (!(ci(n) ?? ai).includes(t)) return {
4143
+ let n = Ti(e.config);
4144
+ if (!(Ei(n) ?? Ci).includes(t)) return {
4068
4145
  outcome: "ignored",
4069
4146
  reason: "Telegram update type is not subscribed."
4070
4147
  };
4071
4148
  let r = e.payload[t];
4072
4149
  if (n.chatIds.length > 0) {
4073
- let e = ui(r);
4150
+ let e = Oi(r);
4074
4151
  if (e == null || !n.chatIds.includes(e)) return {
4075
4152
  outcome: "ignored",
4076
4153
  reason: "Telegram chat does not match."
4077
4154
  };
4078
4155
  }
4079
4156
  if (n.userIds.length > 0) {
4080
- let e = di(r);
4157
+ let e = ki(r);
4081
4158
  if (e == null || !n.userIds.includes(e)) return {
4082
4159
  outcome: "ignored",
4083
4160
  reason: "Telegram user does not match."
@@ -4095,19 +4172,19 @@ var ri = /* @__PURE__ */ new Set([
4095
4172
  };
4096
4173
  },
4097
4174
  async reconcile(e) {
4098
- let t = await fi(e);
4099
- if (!e.active) return t == e.endpointUrl && await pi(e), { outcome: "ready" };
4100
- if (t != "" && t != e.endpointUrl) throw new y(`The Telegram bot already sends updates to ${hi(t)}.`);
4101
- let n = si(e.config);
4102
- return await mi(e, "setWebhook", {
4103
- allowed_updates: ci(n) ?? [],
4175
+ let t = await Ai(e);
4176
+ if (!e.active) return t == e.endpointUrl && await ji(e), { outcome: "ready" };
4177
+ if (t != "" && t != e.endpointUrl) throw new i(`The Telegram bot already sends updates to ${Ni(t)}.`);
4178
+ let n = Ti(e.config);
4179
+ return await Mi(e, "setWebhook", {
4180
+ allowed_updates: Ei(n) ?? [],
4104
4181
  drop_pending_updates: t == "" && n.dropPendingUpdates,
4105
4182
  secret_token: e.callbackSecret,
4106
4183
  url: e.endpointUrl
4107
4184
  }), { outcome: "ready" };
4108
4185
  }
4109
4186
  };
4110
- function si(e) {
4187
+ function Ti(e) {
4111
4188
  return {
4112
4189
  chatIds: e.chatIds ?? [],
4113
4190
  dropPendingUpdates: e.dropPendingUpdates ?? !0,
@@ -4115,61 +4192,61 @@ function si(e) {
4115
4192
  userIds: e.userIds ?? []
4116
4193
  };
4117
4194
  }
4118
- function ci(e) {
4195
+ function Ei(e) {
4119
4196
  if (!e.updates.includes("*")) return e.updates;
4120
4197
  let t = e.updates.filter((e) => e != "*");
4121
- return t.length == 0 ? null : [.../* @__PURE__ */ new Set([...ai, ...t])];
4198
+ return t.length == 0 ? null : [.../* @__PURE__ */ new Set([...Ci, ...t])];
4122
4199
  }
4123
- function li(e, t) {
4200
+ function Di(e, t) {
4124
4201
  if (e == null || e.length != t.length) return !1;
4125
4202
  let n = 0;
4126
4203
  for (let r = 0; r < t.length; r += 1) n |= e.charCodeAt(r) ^ t.charCodeAt(r);
4127
4204
  return n == 0;
4128
4205
  }
4129
- function Z(e) {
4206
+ function K(e) {
4130
4207
  return typeof e == "object" && !!e && !Array.isArray(e);
4131
4208
  }
4132
- function Q(e) {
4133
- if (Z(e)) return typeof e.id == "string" || typeof e.id == "number" ? String(e.id) : void 0;
4209
+ function q(e) {
4210
+ if (K(e)) return typeof e.id == "string" || typeof e.id == "number" ? String(e.id) : void 0;
4134
4211
  }
4135
- function ui(e) {
4136
- if (Z(e)) return Q(e.chat) ?? (Z(e.message) ? Q(e.message.chat) : void 0);
4212
+ function Oi(e) {
4213
+ if (K(e)) return q(e.chat) ?? (K(e.message) ? q(e.message.chat) : void 0);
4137
4214
  }
4138
- function di(e) {
4139
- if (Z(e)) return Q(e.from) ?? Q(e.user);
4215
+ function ki(e) {
4216
+ if (K(e)) return q(e.from) ?? q(e.user);
4140
4217
  }
4141
- async function fi(e) {
4142
- let t = await mi(e, "getWebhookInfo"), n = Z(t.result) ? t.result.url : void 0;
4143
- if (typeof n != "string") throw new b("Telegram getWebhookInfo response is missing result.url.");
4218
+ async function Ai(e) {
4219
+ let t = await Mi(e, "getWebhookInfo"), n = K(t.result) ? t.result.url : void 0;
4220
+ if (typeof n != "string") throw new a("Telegram getWebhookInfo response is missing result.url.");
4144
4221
  return n;
4145
4222
  }
4146
- async function pi(e) {
4147
- await mi(e, "deleteWebhook", { drop_pending_updates: !1 });
4223
+ async function ji(e) {
4224
+ await Mi(e, "deleteWebhook", { drop_pending_updates: !1 });
4148
4225
  }
4149
- async function mi(e, t, n) {
4150
- let r;
4226
+ async function Mi(e, t, n) {
4227
+ let o;
4151
4228
  try {
4152
- r = await e.connector.execute({
4229
+ o = await e.connector.execute({
4153
4230
  ...n == null ? {} : { body: n },
4154
4231
  endpoint: `/${t}`,
4155
4232
  method: n == null ? "GET" : "POST"
4156
4233
  }, e.signal);
4157
4234
  } catch (e) {
4158
- throw e instanceof v ? e : new b(`Telegram ${t} request failed.`, { cause: e });
4235
+ throw e instanceof r ? e : new a(`Telegram ${t} request failed.`, { cause: e });
4159
4236
  }
4160
- let i = Z(r.data) ? r.data : {};
4161
- if (r.status >= 200 && r.status < 300 && i.ok === !0) return i;
4162
- let a = typeof i.description == "string" ? i.description : `HTTP ${r.status}`;
4163
- throw r.status == 401 || r.status == 403 ? new v(`Telegram ${t} rejected the Connection.`) : r.status >= 400 && r.status < 500 && r.status != 429 ? new y(`Telegram ${t} rejected the subscription: ${a}`) : new b(`Telegram ${t} failed: ${a}`);
4237
+ let s = K(o.data) ? o.data : {};
4238
+ if (o.status >= 200 && o.status < 300 && s.ok === !0) return s;
4239
+ let c = typeof s.description == "string" ? s.description : `HTTP ${o.status}`;
4240
+ throw o.status == 401 || o.status == 403 ? new r(`Telegram ${t} rejected the Connection.`) : o.status >= 400 && o.status < 500 && o.status != 429 ? new i(`Telegram ${t} rejected the subscription: ${c}`) : new a(`Telegram ${t} failed: ${c}`);
4164
4241
  }
4165
- function hi(e) {
4242
+ function Ni(e) {
4166
4243
  try {
4167
4244
  return new URL(e).host;
4168
4245
  } catch {
4169
4246
  return "an invalid URL";
4170
4247
  }
4171
4248
  }
4172
- var gi = {
4249
+ var Pi = {
4173
4250
  initialState: {
4174
4251
  checkpoint: null,
4175
4252
  subscription: {}
@@ -4216,7 +4293,7 @@ var gi = {
4216
4293
  title: "WooCommerce Store Event Config",
4217
4294
  type: "object"
4218
4295
  },
4219
- definitionVersion: 1,
4296
+ definitionVersion: 2,
4220
4297
  description: "Triggers when selected WooCommerce store events occur.",
4221
4298
  displayName: "WooCommerce: Store Event",
4222
4299
  endpoint: {
@@ -4256,13 +4333,19 @@ var gi = {
4256
4333
  provider: "woocommerce",
4257
4334
  type: "integration"
4258
4335
  },
4259
- receive(e) {
4336
+ async receive(e) {
4337
+ if (!await pe(e.callbackSecret, [e.rawBody], e.header("x-wc-webhook-signature"))) return {
4338
+ body: "",
4339
+ contentType: "text/plain",
4340
+ outcome: "respond",
4341
+ status: 404
4342
+ };
4260
4343
  let t = e.header("x-wc-webhook-topic")?.trim();
4261
4344
  if (!t) return {
4262
4345
  outcome: "ignored",
4263
4346
  reason: "WooCommerce topic header is missing."
4264
4347
  };
4265
- if (!_i(e.config).events.includes(t)) return {
4348
+ if (!Fi(e.config).events.includes(t)) return {
4266
4349
  outcome: "ignored",
4267
4350
  reason: "WooCommerce topic is not subscribed."
4268
4351
  };
@@ -4282,57 +4365,59 @@ var gi = {
4282
4365
  };
4283
4366
  },
4284
4367
  async reconcile(e) {
4285
- let t = Oi(e.state), n = _i(e.config), r = await bi(e);
4368
+ let t = Wi(e.state), n = Fi(e.config), r = await Ri(e);
4286
4369
  if (!e.active) {
4287
- for (let t of r) await xi(e, t.id);
4288
- return await t.saveSubscription({}, ki(e.now)), { outcome: "ready" };
4370
+ for (let t of r) await zi(e, t.id);
4371
+ return await t.saveSubscription({}, Gi(e.now)), { outcome: "ready" };
4289
4372
  }
4290
4373
  let i = /* @__PURE__ */ new Map();
4291
4374
  for (let e of r) n.events.includes(e.topic) && !i.has(e.topic) && i.set(e.topic, e.id);
4292
4375
  let a = new Set(i.values());
4293
- for (let t of r) a.has(t.id) || await xi(e, t.id);
4376
+ for (let t of r) a.has(t.id) || await zi(e, t.id);
4294
4377
  let o = [];
4295
4378
  for (let t of n.events) {
4296
4379
  let r = i.get(t);
4297
- o.push(r == null ? await vi(e, n, t) : await yi(e, r, t));
4380
+ o.push(r == null ? await Ii(e, n, t) : await Li(e, r, t));
4298
4381
  }
4299
- return await t.saveSubscription({ webhookIds: o }, ki(e.now)), { outcome: "ready" };
4382
+ return await t.saveSubscription({ webhookIds: o }, Gi(e.now)), { outcome: "ready" };
4300
4383
  }
4301
4384
  };
4302
- function _i(e) {
4385
+ function Fi(e) {
4303
4386
  return {
4304
4387
  events: [...new Set(e.events)],
4305
4388
  webhookName: e.webhookName ?? "OOMOL Trigger"
4306
4389
  };
4307
4390
  }
4308
- async function vi(e, t, n) {
4309
- let r = await Si(e, `webhook create (${n})`, {
4391
+ async function Ii(e, t, n) {
4392
+ let r = await J(e, `webhook create (${n})`, {
4310
4393
  body: {
4311
4394
  delivery_url: e.endpointUrl,
4312
4395
  name: `${t.webhookName} - ${n}`,
4396
+ secret: e.callbackSecret,
4313
4397
  topic: n
4314
4398
  },
4315
4399
  endpoint: "/webhooks",
4316
4400
  method: "POST"
4317
4401
  });
4318
- return Ci(r, `webhook create (${n})`), Ei(r.data);
4402
+ return Y(r, `webhook create (${n})`), Hi(r.data);
4319
4403
  }
4320
- async function yi(e, t, n) {
4321
- let r = await Si(e, `webhook update (${n})`, {
4404
+ async function Li(e, t, n) {
4405
+ let r = await J(e, `webhook update (${n})`, {
4322
4406
  body: {
4323
4407
  delivery_url: e.endpointUrl,
4408
+ secret: e.callbackSecret,
4324
4409
  status: "active",
4325
4410
  topic: n
4326
4411
  },
4327
4412
  endpoint: `/webhooks/${t}`,
4328
4413
  method: "PUT"
4329
4414
  });
4330
- return wi(r) ? vi(e, _i(e.config), n) : (Ci(r, `webhook update (${n})`), t);
4415
+ return Bi(r) ? Ii(e, Fi(e.config), n) : (Y(r, `webhook update (${n})`), t);
4331
4416
  }
4332
- async function bi(e) {
4417
+ async function Ri(e) {
4333
4418
  let t = [];
4334
4419
  for (let n = 1; n <= 10; n += 1) {
4335
- let r = await Si(e, "webhook list", {
4420
+ let r = await J(e, "webhook list", {
4336
4421
  endpoint: "/webhooks",
4337
4422
  method: "GET",
4338
4423
  query: {
@@ -4342,12 +4427,12 @@ async function bi(e) {
4342
4427
  status: "all"
4343
4428
  }
4344
4429
  });
4345
- Ci(r, "webhook list");
4430
+ Y(r, "webhook list");
4346
4431
  let i = Array.isArray(r.data) ? r.data : [];
4347
4432
  for (let n of i) {
4348
- let r = Ai(n);
4433
+ let r = Ki(n);
4349
4434
  if (r?.delivery_url !== e.endpointUrl || typeof r.topic != "string") continue;
4350
- let i = Di(r.id);
4435
+ let i = Ui(r.id);
4351
4436
  i != null && t.push({
4352
4437
  id: i,
4353
4438
  topic: r.topic
@@ -4355,56 +4440,56 @@ async function bi(e) {
4355
4440
  }
4356
4441
  if (i.length < 100) return t;
4357
4442
  }
4358
- throw new b("WooCommerce webhook list did not finish within ten pages.");
4443
+ throw new a("WooCommerce webhook list did not finish within ten pages.");
4359
4444
  }
4360
- async function xi(e, t) {
4361
- let n = await Si(e, "webhook delete", {
4445
+ async function zi(e, t) {
4446
+ let n = await J(e, "webhook delete", {
4362
4447
  endpoint: `/webhooks/${t}`,
4363
4448
  method: "DELETE",
4364
4449
  query: { force: "true" }
4365
4450
  });
4366
- n.status != 404 && Ci(n, "webhook delete");
4451
+ n.status != 404 && Y(n, "webhook delete");
4367
4452
  }
4368
- async function Si(e, t, n) {
4453
+ async function J(e, t, n) {
4369
4454
  try {
4370
4455
  return await e.connector.execute(n, e.signal);
4371
4456
  } catch (e) {
4372
- throw e instanceof v ? e : new b(`WooCommerce ${t} request failed.`, { cause: e });
4457
+ throw e instanceof r ? e : new a(`WooCommerce ${t} request failed.`, { cause: e });
4373
4458
  }
4374
4459
  }
4375
- function Ci(e, t) {
4460
+ function Y(e, t) {
4376
4461
  if (e.status >= 200 && e.status < 300) return;
4377
- let n = Ti(e.data);
4378
- throw e.status == 401 || e.status == 403 ? new v(`WooCommerce ${t} rejected the Connection.`) : e.status == 404 || e.status == 400 && (n.endsWith("_invalid_topic") || n.endsWith("_invalid_delivery_url")) || e.status == 501 && n == "woocommerce_rest_trash_not_supported" ? new y(`WooCommerce ${t} rejected the subscription.`) : new b(`WooCommerce ${t} failed with status ${e.status}.`);
4462
+ let n = Vi(e.data);
4463
+ throw e.status == 401 || e.status == 403 ? new r(`WooCommerce ${t} rejected the Connection.`) : e.status == 404 || e.status == 400 && (n.endsWith("_invalid_topic") || n.endsWith("_invalid_delivery_url")) || e.status == 501 && n == "woocommerce_rest_trash_not_supported" ? new i(`WooCommerce ${t} rejected the subscription.`) : new a(`WooCommerce ${t} failed with status ${e.status}.`);
4379
4464
  }
4380
- function wi(e) {
4381
- return e.status == 400 && Ti(e.data) == "woocommerce_rest_webhook_invalid_id";
4465
+ function Bi(e) {
4466
+ return e.status == 400 && Vi(e.data) == "woocommerce_rest_webhook_invalid_id";
4382
4467
  }
4383
- function Ti(e) {
4384
- let t = Ai(e)?.code;
4468
+ function Vi(e) {
4469
+ let t = Ki(e)?.code;
4385
4470
  return typeof t == "string" ? t : "";
4386
4471
  }
4387
- function Ei(e) {
4388
- let t = Di(Ai(e)?.id);
4389
- if (t == null) throw new b("WooCommerce webhook response is missing its ID.");
4472
+ function Hi(e) {
4473
+ let t = Ui(Ki(e)?.id);
4474
+ if (t == null) throw new a("WooCommerce webhook response is missing its ID.");
4390
4475
  return t;
4391
4476
  }
4392
- function Di(e) {
4477
+ function Ui(e) {
4393
4478
  return typeof e == "string" && e.length > 0 ? e : typeof e == "number" && Number.isFinite(e) ? String(e) : null;
4394
4479
  }
4395
- function Oi(e) {
4396
- if (e == null) throw new y("WooCommerce Integration state is missing.");
4480
+ function Wi(e) {
4481
+ if (e == null) throw new i("WooCommerce Integration state is missing.");
4397
4482
  return e;
4398
4483
  }
4399
- function ki(e) {
4484
+ function Gi(e) {
4400
4485
  return new Date(e.getTime() + 2592e6);
4401
4486
  }
4402
- function Ai(e) {
4487
+ function Ki(e) {
4403
4488
  return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
4404
4489
  }
4405
4490
  //#endregion
4406
4491
  //#region src/trigger/providers/zendesk/on-event.ts
4407
- var ji = /* @__PURE__ */ "zen:event-type:ticket.agent_assignment_changed,zen:event-type:ticket.attachment_linked_to_comment,zen:event-type:ticket.attachment_redacted_from_comment,zen:event-type:ticket.brand_changed,zen:event-type:ticket.comment_added,zen:event-type:ticket.comment_made_private,zen:event-type:ticket.comment_redacted,zen:event-type:ticket.created,zen:event-type:ticket.csat_received,zen:event-type:ticket.csat_requested,zen:event-type:ticket.custom_field_changed,zen:event-type:ticket.custom_status_changed,zen:event-type:ticket.description_changed,zen:event-type:ticket.email_ccs_changed,zen:event-type:ticket.external_id_changed,zen:event-type:ticket.followers_changed,zen:event-type:ticket.form_changed,zen:event-type:ticket.group_assignment_changed,zen:event-type:ticket.marked_as_spam,zen:event-type:ticket.merged,zen:event-type:ticket.next_sla_breach_changed,zen:event-type:ticket.ola_policy_changed,zen:event-type:ticket.organization_changed,zen:event-type:ticket.permanently_deleted,zen:event-type:ticket.priority_changed,zen:event-type:ticket.problem_link_changed,zen:event-type:ticket.requester_changed,zen:event-type:ticket.schedule_changed,zen:event-type:ticket.sla_policy_changed,zen:event-type:ticket.soft_deleted,zen:event-type:ticket.status_changed,zen:event-type:ticket.subject_changed,zen:event-type:ticket.submitter_changed,zen:event-type:ticket.tags_changed,zen:event-type:ticket.task_due_at_changed,zen:event-type:ticket.type_changed,zen:event-type:ticket.undeleted,zen:event-type:organization.created,zen:event-type:organization.custom_field_changed,zen:event-type:organization.deleted,zen:event-type:organization.external_id_changed,zen:event-type:organization.name_changed,zen:event-type:organization.tags_changed,zen:event-type:user.active_changed,zen:event-type:user.alias_changed,zen:event-type:user.created,zen:event-type:user.custom_field_changed,zen:event-type:user.custom_role_changed,zen:event-type:user.default_group_changed,zen:event-type:user.deleted,zen:event-type:user.details_changed,zen:event-type:user.external_id_changed,zen:event-type:user.group_membership_created,zen:event-type:user.group_membership_deleted,zen:event-type:user.identity_changed,zen:event-type:user.identity_created,zen:event-type:user.identity_deleted,zen:event-type:user.last_login_changed,zen:event-type:user.merged,zen:event-type:user.name_changed,zen:event-type:user.notes_changed,zen:event-type:user.only_private_comments_changed,zen:event-type:user.organization_membership_created,zen:event-type:user.organization_membership_deleted,zen:event-type:user.password_changed,zen:event-type:user.photo_changed,zen:event-type:user.role_changed,zen:event-type:user.suspended_changed,zen:event-type:user.tags_changed,zen:event-type:user.time_zone_changed".split(","), Mi = "/api/v2/webhooks", Ni = {
4492
+ var qi = 3e5, Ji = /* @__PURE__ */ "zen:event-type:ticket.agent_assignment_changed,zen:event-type:ticket.attachment_linked_to_comment,zen:event-type:ticket.attachment_redacted_from_comment,zen:event-type:ticket.brand_changed,zen:event-type:ticket.comment_added,zen:event-type:ticket.comment_made_private,zen:event-type:ticket.comment_redacted,zen:event-type:ticket.created,zen:event-type:ticket.csat_received,zen:event-type:ticket.csat_requested,zen:event-type:ticket.custom_field_changed,zen:event-type:ticket.custom_status_changed,zen:event-type:ticket.description_changed,zen:event-type:ticket.email_ccs_changed,zen:event-type:ticket.external_id_changed,zen:event-type:ticket.followers_changed,zen:event-type:ticket.form_changed,zen:event-type:ticket.group_assignment_changed,zen:event-type:ticket.marked_as_spam,zen:event-type:ticket.merged,zen:event-type:ticket.next_sla_breach_changed,zen:event-type:ticket.ola_policy_changed,zen:event-type:ticket.organization_changed,zen:event-type:ticket.permanently_deleted,zen:event-type:ticket.priority_changed,zen:event-type:ticket.problem_link_changed,zen:event-type:ticket.requester_changed,zen:event-type:ticket.schedule_changed,zen:event-type:ticket.sla_policy_changed,zen:event-type:ticket.soft_deleted,zen:event-type:ticket.status_changed,zen:event-type:ticket.subject_changed,zen:event-type:ticket.submitter_changed,zen:event-type:ticket.tags_changed,zen:event-type:ticket.task_due_at_changed,zen:event-type:ticket.type_changed,zen:event-type:ticket.undeleted,zen:event-type:organization.created,zen:event-type:organization.custom_field_changed,zen:event-type:organization.deleted,zen:event-type:organization.external_id_changed,zen:event-type:organization.name_changed,zen:event-type:organization.tags_changed,zen:event-type:user.active_changed,zen:event-type:user.alias_changed,zen:event-type:user.created,zen:event-type:user.custom_field_changed,zen:event-type:user.custom_role_changed,zen:event-type:user.default_group_changed,zen:event-type:user.deleted,zen:event-type:user.details_changed,zen:event-type:user.external_id_changed,zen:event-type:user.group_membership_created,zen:event-type:user.group_membership_deleted,zen:event-type:user.identity_changed,zen:event-type:user.identity_created,zen:event-type:user.identity_deleted,zen:event-type:user.last_login_changed,zen:event-type:user.merged,zen:event-type:user.name_changed,zen:event-type:user.notes_changed,zen:event-type:user.only_private_comments_changed,zen:event-type:user.organization_membership_created,zen:event-type:user.organization_membership_deleted,zen:event-type:user.password_changed,zen:event-type:user.photo_changed,zen:event-type:user.role_changed,zen:event-type:user.suspended_changed,zen:event-type:user.tags_changed,zen:event-type:user.time_zone_changed".split(","), X = "/api/v2/webhooks", Yi = {
4408
4493
  initialState: {
4409
4494
  checkpoint: null,
4410
4495
  subscription: {}
@@ -4414,7 +4499,7 @@ var ji = /* @__PURE__ */ "zen:event-type:ticket.agent_assignment_changed,zen:eve
4414
4499
  additionalProperties: !1,
4415
4500
  properties: { events: {
4416
4501
  items: {
4417
- enum: ji,
4502
+ enum: Ji,
4418
4503
  type: "string"
4419
4504
  },
4420
4505
  minItems: 1,
@@ -4425,7 +4510,7 @@ var ji = /* @__PURE__ */ "zen:event-type:ticket.agent_assignment_changed,zen:eve
4425
4510
  title: "Zendesk Event Subscription Config",
4426
4511
  type: "object"
4427
4512
  },
4428
- definitionVersion: 1,
4513
+ definitionVersion: 2,
4429
4514
  description: "Triggers when one of the selected Zendesk account events occurs.",
4430
4515
  displayName: "Zendesk: Event Subscription",
4431
4516
  endpoint: {
@@ -4458,83 +4543,93 @@ var ji = /* @__PURE__ */ "zen:event-type:ticket.agent_assignment_changed,zen:eve
4458
4543
  provider: "zendesk",
4459
4544
  type: "integration"
4460
4545
  },
4461
- receive(e) {
4546
+ async receive(e) {
4547
+ let t = ra(e.state), n = e.header("x-zendesk-webhook-signature-timestamp"), r = n == null ? NaN : Date.parse(n);
4548
+ if (t == null || n == null || !Number.isFinite(r) || Math.abs(e.now.getTime() - r) > qi || !await pe(t, [de(n), e.rawBody], e.header("x-zendesk-webhook-signature"))) return {
4549
+ body: "",
4550
+ contentType: "text/plain",
4551
+ outcome: "respond",
4552
+ status: 404
4553
+ };
4462
4554
  if (e.payload == null || typeof e.payload != "object" || Array.isArray(e.payload)) return {
4463
4555
  outcome: "ignored",
4464
4556
  reason: "Zendesk event body is missing."
4465
4557
  };
4466
- let t = e.payload, n = t.type;
4467
- if (typeof n != "string" || n.length == 0) return {
4558
+ let i = e.payload, a = i.type;
4559
+ if (typeof a != "string" || a.length == 0) return {
4468
4560
  outcome: "ignored",
4469
4561
  reason: "Zendesk event type is missing."
4470
4562
  };
4471
- if (!e.config.events.includes(n)) return {
4563
+ if (!e.config.events.includes(a)) return {
4472
4564
  outcome: "ignored",
4473
4565
  reason: "Zendesk event is not subscribed."
4474
4566
  };
4475
- let r = typeof t.id == "string" ? t.id : "", i = t.subject;
4567
+ let o = typeof i.id == "string" ? i.id : "", s = i.subject;
4476
4568
  return {
4477
- dedupeKey: r.length == 0 ? void 0 : r,
4569
+ dedupeKey: o.length == 0 ? void 0 : o,
4478
4570
  outcome: "event",
4479
4571
  payload: {
4480
- body: t,
4481
- deliveryId: r,
4482
- event: n,
4483
- ...typeof i == "string" ? { subject: i } : {}
4572
+ body: i,
4573
+ deliveryId: o,
4574
+ event: a,
4575
+ ...typeof s == "string" ? { subject: s } : {}
4484
4576
  }
4485
4577
  };
4486
4578
  },
4487
4579
  async reconcile(e) {
4488
- let t = Vi(e.state), n = await Fi(e), r = Hi(t);
4580
+ let t = ta(e.state), n = await Zi(e), r = na(t);
4489
4581
  if (!e.active) {
4490
- for (let t of r == null ? n : [.../* @__PURE__ */ new Set([r, ...n])]) await Ii(e, t);
4491
- return await t.saveSubscription({}, Ui(e.now)), { outcome: "ready" };
4582
+ for (let t of r == null ? n : [.../* @__PURE__ */ new Set([r, ...n])]) await Qi(e, t);
4583
+ return await t.saveSubscription({}, aa(e.now)), { outcome: "ready" };
4492
4584
  }
4493
4585
  let i = r ?? n[0];
4494
4586
  if (i == null) {
4495
- let t = await Li(e, "webhook create", {
4496
- body: Pi(e),
4497
- endpoint: Mi,
4587
+ let t = await Z(e, "webhook create", {
4588
+ body: Xi(e),
4589
+ endpoint: X,
4498
4590
  method: "POST"
4499
4591
  });
4500
- Ri(t, "webhook create"), i = Bi($(t.data)?.webhook);
4592
+ Q(t, "webhook create"), i = ea($(t.data)?.webhook);
4501
4593
  } else {
4502
- let n = await Li(e, "webhook update", {
4503
- body: Pi(e),
4504
- endpoint: `${Mi}/${i}`,
4594
+ let n = await Z(e, "webhook update", {
4595
+ body: Xi(e),
4596
+ endpoint: `${X}/${i}`,
4505
4597
  method: "PUT"
4506
4598
  });
4507
4599
  if (n.status == 404) return await t.saveSubscription({}, e.now), { outcome: "pending" };
4508
- Ri(n, "webhook update");
4600
+ Q(n, "webhook update");
4509
4601
  }
4510
- for (let t of n.filter((e) => e != i)) await Ii(e, t);
4511
- return await t.saveSubscription({ webhookId: i }, Ui(e.now)), { outcome: "ready" };
4602
+ for (let t of n.filter((e) => e != i)) await Qi(e, t);
4603
+ return await t.saveSubscription({
4604
+ signingSecret: await ia(e, i),
4605
+ webhookId: i
4606
+ }, aa(e.now)), { outcome: "ready" };
4512
4607
  }
4513
4608
  };
4514
- function Pi(e) {
4609
+ function Xi(e) {
4515
4610
  return { webhook: {
4516
4611
  description: "Managed by Open Flow. Do not edit.",
4517
4612
  endpoint: e.endpointUrl,
4518
4613
  http_method: "POST",
4519
- name: zi(e.endpointUrl),
4614
+ name: $i(e.endpointUrl),
4520
4615
  request_format: "json",
4521
4616
  status: "active",
4522
4617
  subscriptions: [...new Set(e.config.events)]
4523
4618
  } };
4524
4619
  }
4525
- async function Fi(e) {
4620
+ async function Zi(e) {
4526
4621
  let t = [], n;
4527
4622
  for (let r = 0; r < 10; r += 1) {
4528
- let r = await Li(e, "webhook list", {
4529
- endpoint: Mi,
4623
+ let r = await Z(e, "webhook list", {
4624
+ endpoint: X,
4530
4625
  method: "GET",
4531
4626
  query: {
4532
- "filter[name_contains]": zi(e.endpointUrl),
4627
+ "filter[name_contains]": $i(e.endpointUrl),
4533
4628
  "page[size]": "100",
4534
4629
  ...n == null ? {} : { "page[after]": n }
4535
4630
  }
4536
4631
  });
4537
- Ri(r, "webhook list");
4632
+ Q(r, "webhook list");
4538
4633
  let i = $(r.data), a = Array.isArray(i?.webhooks) ? i.webhooks : [];
4539
4634
  for (let n of a) {
4540
4635
  let r = $(n);
@@ -4546,44 +4641,58 @@ async function Fi(e) {
4546
4641
  }
4547
4642
  return t;
4548
4643
  }
4549
- async function Ii(e, t) {
4550
- let n = await Li(e, "webhook delete", {
4551
- endpoint: `${Mi}/${t}`,
4644
+ async function Qi(e, t) {
4645
+ let n = await Z(e, "webhook delete", {
4646
+ endpoint: `${X}/${t}`,
4552
4647
  method: "DELETE"
4553
4648
  });
4554
- n.status != 404 && Ri(n, "webhook delete");
4649
+ n.status != 404 && Q(n, "webhook delete");
4555
4650
  }
4556
- async function Li(e, t, n) {
4651
+ async function Z(e, t, n) {
4557
4652
  try {
4558
4653
  return await e.connector.execute(n, e.signal);
4559
4654
  } catch (e) {
4560
- throw e instanceof v ? e : new b(`Zendesk ${t} request failed.`, { cause: e });
4655
+ throw e instanceof r ? e : new a(`Zendesk ${t} request failed.`, { cause: e });
4561
4656
  }
4562
4657
  }
4563
- function Ri(e, t) {
4564
- if (!(e.status >= 200 && e.status < 300)) throw e.status == 401 || e.status == 403 ? new v(`Zendesk ${t} rejected the Connection.`) : [
4658
+ function Q(e, t) {
4659
+ if (!(e.status >= 200 && e.status < 300)) throw e.status == 401 || e.status == 403 ? new r(`Zendesk ${t} rejected the Connection.`) : [
4565
4660
  400,
4566
4661
  404,
4567
4662
  422
4568
- ].includes(e.status) ? new y(`Zendesk ${t} rejected the subscription.`) : new b(`Zendesk ${t} failed with status ${e.status}.`);
4663
+ ].includes(e.status) ? new i(`Zendesk ${t} rejected the subscription.`) : new a(`Zendesk ${t} failed with status ${e.status}.`);
4569
4664
  }
4570
- function zi(e) {
4665
+ function $i(e) {
4571
4666
  return `open-flow-${e.slice(e.lastIndexOf("/") + 1)}`;
4572
4667
  }
4573
- function Bi(e) {
4668
+ function ea(e) {
4574
4669
  let t = $(e)?.id;
4575
- if (typeof t != "string") throw new b("Zendesk webhook response is missing its ID.");
4670
+ if (typeof t != "string") throw new a("Zendesk webhook response is missing its ID.");
4576
4671
  return t;
4577
4672
  }
4578
- function Vi(e) {
4579
- if (e == null) throw new y("Zendesk Integration state is missing.");
4673
+ function ta(e) {
4674
+ if (e == null) throw new i("Zendesk Integration state is missing.");
4580
4675
  return e;
4581
4676
  }
4582
- function Hi(e) {
4677
+ function na(e) {
4583
4678
  let t = e.subscription.webhookId;
4584
4679
  return typeof t == "string" && t.length > 0 ? t : null;
4585
4680
  }
4586
- function Ui(e) {
4681
+ function ra(e) {
4682
+ let t = e?.subscription.signingSecret;
4683
+ return typeof t == "string" && t.length > 0 ? t : null;
4684
+ }
4685
+ async function ia(e, t) {
4686
+ let n = await Z(e, "webhook signing secret", {
4687
+ endpoint: `${X}/${t}/signing_secret`,
4688
+ method: "GET"
4689
+ });
4690
+ Q(n, "webhook signing secret");
4691
+ let r = $($(n.data)?.signing_secret)?.secret;
4692
+ if (typeof r != "string" || r.length == 0) throw new a("Zendesk webhook signing secret response is invalid.");
4693
+ return r;
4694
+ }
4695
+ function aa(e) {
4587
4696
  return new Date(e.getTime() + 2592e6);
4588
4697
  }
4589
4698
  function $(e) {
@@ -4591,24 +4700,24 @@ function $(e) {
4591
4700
  }
4592
4701
  //#endregion
4593
4702
  //#region src/trigger/providers/definitions.ts
4594
- var Wi = [
4595
- i,
4596
- Ae,
4597
- ce,
4598
- ve,
4599
- We,
4600
- pt,
4601
- Pt,
4602
- tn,
4603
- vn,
4604
- Bn,
4605
- sr,
4606
- br,
4607
- Fr,
4608
- Jr,
4609
- oi,
4610
- gi,
4611
- Ni
4612
- ], Gi = Wi.filter((e) => e.snapshot.type == "poll"), Ki = Wi.filter((e) => e.snapshot.type == "integration");
4703
+ var oa = [
4704
+ s,
4705
+ Ue,
4706
+ ye,
4707
+ je,
4708
+ rt,
4709
+ Et,
4710
+ Jt,
4711
+ gn,
4712
+ Mn,
4713
+ er,
4714
+ xr,
4715
+ Pr,
4716
+ Xr,
4717
+ ui,
4718
+ wi,
4719
+ Pi,
4720
+ Yi
4721
+ ], sa = oa.filter((e) => e.snapshot.type == "poll"), ca = oa.filter((e) => e.snapshot.type == "integration");
4613
4722
  //#endregion
4614
- export { Ki as integrationDefinitions, Gi as pollDefinitions, Wi as triggerDefinitions };
4723
+ export { ca as integrationDefinitions, sa as pollDefinitions, oa as triggerDefinitions };