@oomol-lab/open-flow 0.1.0-alpha.1 → 0.1.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/provider-triggers.js +857 -880
- package/package.json +1 -1
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 =
|
|
95
|
+
let t = c(e.config);
|
|
106
96
|
if (e.checkpoint === null) return {
|
|
107
|
-
checkpoint: await
|
|
97
|
+
checkpoint: await d(e, t),
|
|
108
98
|
events: []
|
|
109
99
|
};
|
|
110
|
-
let n =
|
|
100
|
+
let n = l(e.checkpoint), r = await f(e, t, n), i = [], a = 0;
|
|
111
101
|
for (let e of r.records) {
|
|
112
|
-
let n =
|
|
113
|
-
n == null ?
|
|
102
|
+
let n = _(e.fields?.[t.triggerField]);
|
|
103
|
+
n == null ? a += 1 : i.push({
|
|
114
104
|
record: e,
|
|
115
105
|
value: n
|
|
116
106
|
});
|
|
117
107
|
}
|
|
118
|
-
let
|
|
108
|
+
let o = i.flatMap(({ record: e, value: r }) => r == n.cursor && n.boundaryIds.includes(e.id) ? [] : [te(t, e, r)]), s = p(n, r, i);
|
|
119
109
|
return {
|
|
120
|
-
checkpoint:
|
|
121
|
-
events:
|
|
122
|
-
filtered:
|
|
123
|
-
...
|
|
110
|
+
checkpoint: s.checkpoint,
|
|
111
|
+
events: o,
|
|
112
|
+
filtered: a,
|
|
113
|
+
...s.hasMore ? { hasMore: !0 } : {}
|
|
124
114
|
};
|
|
125
115
|
}
|
|
126
116
|
};
|
|
127
|
-
function
|
|
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
|
|
139
|
-
let n =
|
|
140
|
-
if (r == null || !Array.isArray(i) || i.some((e) => typeof e != "string")) throw new
|
|
141
|
-
let a =
|
|
128
|
+
function l(t) {
|
|
129
|
+
let n = v(t), r = _(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,25 +137,25 @@ function o(e) {
|
|
|
147
137
|
...a == null ? {} : { pending: a }
|
|
148
138
|
};
|
|
149
139
|
}
|
|
150
|
-
function
|
|
151
|
-
let t =
|
|
140
|
+
function u(e) {
|
|
141
|
+
let t = v(e), n = _(t?.cursor), r = t?.boundaryIds;
|
|
152
142
|
return n == null || !Array.isArray(r) || r.some((e) => typeof e != "string") ? null : {
|
|
153
143
|
boundaryIds: r,
|
|
154
144
|
cursor: n,
|
|
155
145
|
...t?.cursorExclusive === !0 ? { cursorExclusive: !0 } : {}
|
|
156
146
|
};
|
|
157
147
|
}
|
|
158
|
-
async function
|
|
159
|
-
let r = await
|
|
160
|
-
|
|
161
|
-
let i =
|
|
148
|
+
async function d(t, n) {
|
|
149
|
+
let r = await oe(t, n, ne(n));
|
|
150
|
+
se(r, "seed list");
|
|
151
|
+
let i = ce(r.data);
|
|
162
152
|
if (i.records.length == 0) return {
|
|
163
153
|
boundaryIds: [],
|
|
164
|
-
cursor:
|
|
154
|
+
cursor: t.now.toISOString()
|
|
165
155
|
};
|
|
166
|
-
let a =
|
|
167
|
-
if (a == null) throw new
|
|
168
|
-
let o = i.records.filter((e) =>
|
|
156
|
+
let a = _(i.records[0]?.fields?.[n.triggerField]);
|
|
157
|
+
if (a == null) throw new e("The Airtable trigger field is not a time field.");
|
|
158
|
+
let o = i.records.filter((e) => _(e.fields?.[n.triggerField]) === a).map(({ id: e }) => e);
|
|
169
159
|
return o.length == i.records.length && i.offset ? {
|
|
170
160
|
boundaryIds: [],
|
|
171
161
|
cursor: a,
|
|
@@ -175,29 +165,29 @@ async function c(e, n) {
|
|
|
175
165
|
cursor: a
|
|
176
166
|
};
|
|
177
167
|
}
|
|
178
|
-
async function
|
|
179
|
-
let
|
|
180
|
-
for (let s = 0; s <
|
|
181
|
-
let
|
|
182
|
-
if (
|
|
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 oe(e, t, re(t, n, i));
|
|
172
|
+
if (i != null && a.status == 422 && le(a.data) == o) return {
|
|
183
173
|
offsetWentStale: !0,
|
|
184
|
-
records:
|
|
174
|
+
records: r
|
|
185
175
|
};
|
|
186
|
-
|
|
187
|
-
let s =
|
|
188
|
-
if (
|
|
176
|
+
se(a, "record list");
|
|
177
|
+
let s = ce(a.data);
|
|
178
|
+
if (r.push(...s.records), !s.offset) return {
|
|
189
179
|
offsetWentStale: !1,
|
|
190
|
-
records:
|
|
180
|
+
records: r
|
|
191
181
|
};
|
|
192
|
-
|
|
182
|
+
i = s.offset;
|
|
193
183
|
}
|
|
194
184
|
return {
|
|
195
|
-
offset:
|
|
185
|
+
offset: i,
|
|
196
186
|
offsetWentStale: !1,
|
|
197
|
-
records:
|
|
187
|
+
records: r
|
|
198
188
|
};
|
|
199
189
|
}
|
|
200
|
-
function
|
|
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 =
|
|
200
|
+
let i = h(e.pending, m(n));
|
|
211
201
|
return t.offset == null ? {
|
|
212
|
-
checkpoint: i == null ? r :
|
|
202
|
+
checkpoint: i == null ? r : g(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
|
|
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
|
|
216
|
+
return ee(t, e.filter(({ value: e }) => e == t).map(({ record: e }) => e.id));
|
|
227
217
|
}
|
|
228
|
-
function
|
|
229
|
-
return e == null ? t : t == null ? e :
|
|
218
|
+
function h(e, t) {
|
|
219
|
+
return e == null ? t : t == null ? e : g(e, t);
|
|
230
220
|
}
|
|
231
|
-
function
|
|
221
|
+
function g(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
|
-
} :
|
|
226
|
+
} : ee(e.cursor, [.../* @__PURE__ */ new Set([...e.boundaryIds, ...t.boundaryIds])]);
|
|
237
227
|
}
|
|
238
|
-
function
|
|
228
|
+
function ee(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
|
|
238
|
+
function te(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
|
|
252
|
+
function ne(e) {
|
|
263
253
|
return {
|
|
264
254
|
fields: [e.triggerField],
|
|
265
|
-
filterByFormula:
|
|
255
|
+
filterByFormula: ae([ie(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
|
|
264
|
+
function re(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:
|
|
278
|
-
|
|
267
|
+
filterByFormula: ae([
|
|
268
|
+
ie(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
|
|
282
|
+
function ie(e) {
|
|
293
283
|
return `NOT({${e}} = BLANK())`;
|
|
294
284
|
}
|
|
295
|
-
function
|
|
285
|
+
function ae(e) {
|
|
296
286
|
return `AND(${e.join(", ")})`;
|
|
297
287
|
}
|
|
298
|
-
async function
|
|
288
|
+
async function oe(e, t, r) {
|
|
299
289
|
let i = `/${t.baseId}/${encodeURIComponent(t.tableIdOrName)}/listRecords`;
|
|
300
290
|
try {
|
|
301
291
|
return await e.connector.execute({
|
|
@@ -307,44 +297,31 @@ 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
|
|
311
|
-
if (!(
|
|
300
|
+
function se(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 && le(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
|
|
314
|
-
let t =
|
|
303
|
+
function ce(e) {
|
|
304
|
+
let t = v(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
|
|
321
|
-
let t =
|
|
310
|
+
function le(e) {
|
|
311
|
+
let t = v(e)?.error;
|
|
322
312
|
if (typeof t == "string") return t;
|
|
323
|
-
let n =
|
|
313
|
+
let n = v(t)?.type;
|
|
324
314
|
return typeof n == "string" ? n : "";
|
|
325
315
|
}
|
|
326
|
-
function
|
|
316
|
+
function _(e) {
|
|
327
317
|
if (typeof e != "string" || e.length == 0) return null;
|
|
328
318
|
let t = new Date(e);
|
|
329
319
|
return Number.isNaN(t.getTime()) ? null : t.toISOString();
|
|
330
320
|
}
|
|
331
|
-
function
|
|
321
|
+
function v(e) {
|
|
332
322
|
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
333
323
|
}
|
|
334
|
-
|
|
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";
|
|
346
|
-
}
|
|
347
|
-
}, ce = {
|
|
324
|
+
var ue = {
|
|
348
325
|
initialState: {
|
|
349
326
|
checkpoint: null,
|
|
350
327
|
subscription: {}
|
|
@@ -425,7 +402,7 @@ var v = class extends Error {
|
|
|
425
402
|
outcome: "ignored",
|
|
426
403
|
reason: "GitHub ping handshake."
|
|
427
404
|
};
|
|
428
|
-
let n =
|
|
405
|
+
let n = de(e.config);
|
|
429
406
|
if (!n.events.includes("*") && !n.events.includes(t)) return {
|
|
430
407
|
outcome: "ignored",
|
|
431
408
|
reason: "GitHub event is not subscribed."
|
|
@@ -442,38 +419,38 @@ var v = class extends Error {
|
|
|
442
419
|
};
|
|
443
420
|
},
|
|
444
421
|
async reconcile(e) {
|
|
445
|
-
let t =
|
|
422
|
+
let t = he(e.state), n = de(e.config), r = ge(t);
|
|
446
423
|
if (!e.active) {
|
|
447
|
-
if (r ??= await
|
|
448
|
-
let t = await
|
|
449
|
-
endpoint: `${
|
|
424
|
+
if (r ??= await pe(e, n), r != null) {
|
|
425
|
+
let t = await b(e, "hook delete", {
|
|
426
|
+
endpoint: `${y(n)}/${r}`,
|
|
450
427
|
method: "DELETE"
|
|
451
428
|
});
|
|
452
|
-
t.status != 404 &&
|
|
429
|
+
t.status != 404 && x(t, "hook delete");
|
|
453
430
|
}
|
|
454
|
-
return await t.saveSubscription({},
|
|
431
|
+
return await t.saveSubscription({}, _e(e.now)), { outcome: "ready" };
|
|
455
432
|
}
|
|
456
|
-
let
|
|
433
|
+
let o = fe(e.endpointUrl, n);
|
|
457
434
|
if (r == null) {
|
|
458
|
-
let t = await
|
|
459
|
-
body:
|
|
460
|
-
endpoint:
|
|
435
|
+
let t = await b(e, "hook create", {
|
|
436
|
+
body: o,
|
|
437
|
+
endpoint: y(n),
|
|
461
438
|
method: "POST"
|
|
462
439
|
});
|
|
463
|
-
if (t.status == 201) r =
|
|
440
|
+
if (t.status == 201) r = me(t.data);
|
|
464
441
|
else if (t.status == 422) {
|
|
465
|
-
if (r = await
|
|
466
|
-
} else throw
|
|
442
|
+
if (r = await pe(e, n), r == null) throw new i("GitHub rejected the webhook configuration.");
|
|
443
|
+
} else throw x(t, "hook create"), new a(`GitHub hook create returned unexpected status ${t.status}.`);
|
|
467
444
|
}
|
|
468
|
-
let
|
|
469
|
-
body:
|
|
470
|
-
endpoint: `${
|
|
445
|
+
let s = await b(e, "hook update", {
|
|
446
|
+
body: o,
|
|
447
|
+
endpoint: `${y(n)}/${r}`,
|
|
471
448
|
method: "PATCH"
|
|
472
449
|
});
|
|
473
|
-
return
|
|
450
|
+
return s.status == 404 ? (await t.saveSubscription({}, e.now), { outcome: "pending" }) : (x(s, "hook update"), await t.saveSubscription({ hookId: r }, _e(e.now)), { outcome: "ready" });
|
|
474
451
|
}
|
|
475
452
|
};
|
|
476
|
-
function
|
|
453
|
+
function de(e) {
|
|
477
454
|
return {
|
|
478
455
|
events: [...new Set(e.events)],
|
|
479
456
|
insecureSsl: e.insecureSsl ?? !1,
|
|
@@ -481,10 +458,10 @@ function le(e) {
|
|
|
481
458
|
repo: e.repo
|
|
482
459
|
};
|
|
483
460
|
}
|
|
484
|
-
function
|
|
461
|
+
function y(e) {
|
|
485
462
|
return `/repos/${encodeURIComponent(e.owner)}/${encodeURIComponent(e.repo)}/hooks`;
|
|
486
463
|
}
|
|
487
|
-
function
|
|
464
|
+
function fe(e, t) {
|
|
488
465
|
return {
|
|
489
466
|
active: !0,
|
|
490
467
|
config: {
|
|
@@ -496,10 +473,10 @@ function ue(e, t) {
|
|
|
496
473
|
name: "web"
|
|
497
474
|
};
|
|
498
475
|
}
|
|
499
|
-
async function
|
|
476
|
+
async function pe(e, t) {
|
|
500
477
|
for (let n = 1; n <= 10; n += 1) {
|
|
501
|
-
let r = await
|
|
502
|
-
endpoint:
|
|
478
|
+
let r = await b(e, "hook list", {
|
|
479
|
+
endpoint: y(t),
|
|
503
480
|
method: "GET",
|
|
504
481
|
query: {
|
|
505
482
|
page: n,
|
|
@@ -507,50 +484,50 @@ async function de(e, t) {
|
|
|
507
484
|
}
|
|
508
485
|
});
|
|
509
486
|
if (r.status == 404) return null;
|
|
510
|
-
|
|
487
|
+
x(r, "hook list");
|
|
511
488
|
let i = Array.isArray(r.data) ? r.data : [];
|
|
512
489
|
for (let t of i) {
|
|
513
|
-
let n =
|
|
514
|
-
if (
|
|
490
|
+
let n = S(t);
|
|
491
|
+
if (S(n?.config)?.url === e.endpointUrl && (typeof n?.id == "number" || typeof n?.id == "string")) return String(n.id);
|
|
515
492
|
}
|
|
516
493
|
if (i.length < 100) return null;
|
|
517
494
|
}
|
|
518
495
|
return null;
|
|
519
496
|
}
|
|
520
|
-
async function
|
|
497
|
+
async function b(e, t, n) {
|
|
521
498
|
try {
|
|
522
499
|
return await e.connector.execute(n, e.signal);
|
|
523
500
|
} catch (e) {
|
|
524
|
-
throw e instanceof
|
|
501
|
+
throw e instanceof r ? e : new a(`GitHub ${t} request failed.`, { cause: e });
|
|
525
502
|
}
|
|
526
503
|
}
|
|
527
|
-
function
|
|
504
|
+
function x(e, t) {
|
|
528
505
|
if (e.status >= 200 && e.status < 300) return;
|
|
529
|
-
let n =
|
|
530
|
-
throw e.status == 403 && typeof n == "string" && /rate limit/i.test(n) ? new
|
|
506
|
+
let n = S(e.data)?.message;
|
|
507
|
+
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
508
|
}
|
|
532
|
-
function
|
|
533
|
-
let t =
|
|
534
|
-
if (typeof t != "number" && typeof t != "string") throw new
|
|
509
|
+
function me(e) {
|
|
510
|
+
let t = S(e)?.id;
|
|
511
|
+
if (typeof t != "number" && typeof t != "string") throw new a("GitHub hook response is missing its ID.");
|
|
535
512
|
return String(t);
|
|
536
513
|
}
|
|
537
|
-
function
|
|
538
|
-
if (e == null) throw new
|
|
514
|
+
function he(e) {
|
|
515
|
+
if (e == null) throw new i("GitHub Integration state is missing.");
|
|
539
516
|
return e;
|
|
540
517
|
}
|
|
541
|
-
function
|
|
518
|
+
function ge(e) {
|
|
542
519
|
let t = e.subscription.hookId;
|
|
543
520
|
return typeof t == "string" && t.length > 0 ? t : null;
|
|
544
521
|
}
|
|
545
|
-
function
|
|
522
|
+
function _e(e) {
|
|
546
523
|
return new Date(e.getTime() + 2592e6);
|
|
547
524
|
}
|
|
548
|
-
function
|
|
525
|
+
function S(e) {
|
|
549
526
|
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
550
527
|
}
|
|
551
528
|
//#endregion
|
|
552
529
|
//#region src/trigger/providers/gitlab/on-project-event.ts
|
|
553
|
-
var
|
|
530
|
+
var ve = [
|
|
554
531
|
"push",
|
|
555
532
|
"tag_push",
|
|
556
533
|
"issues",
|
|
@@ -568,7 +545,7 @@ var ge = [
|
|
|
568
545
|
"emoji",
|
|
569
546
|
"resource_access_token",
|
|
570
547
|
"resource_deploy_token"
|
|
571
|
-
],
|
|
548
|
+
], ye = /* @__PURE__ */ new Map([
|
|
572
549
|
["Push Hook", "push"],
|
|
573
550
|
["Tag Push Hook", "tag_push"],
|
|
574
551
|
["Issue Hook", "issues"],
|
|
@@ -586,7 +563,7 @@ var ge = [
|
|
|
586
563
|
["Emoji Hook", "emoji"],
|
|
587
564
|
["Resource Access Token Hook", "resource_access_token"],
|
|
588
565
|
["Resource Deploy Token Hook", "resource_deploy_token"]
|
|
589
|
-
]),
|
|
566
|
+
]), be = {
|
|
590
567
|
initialState: {
|
|
591
568
|
checkpoint: null,
|
|
592
569
|
subscription: {}
|
|
@@ -597,7 +574,7 @@ var ge = [
|
|
|
597
574
|
properties: {
|
|
598
575
|
events: {
|
|
599
576
|
items: {
|
|
600
|
-
enum:
|
|
577
|
+
enum: ve,
|
|
601
578
|
type: "string"
|
|
602
579
|
},
|
|
603
580
|
minItems: 1,
|
|
@@ -664,12 +641,12 @@ var ge = [
|
|
|
664
641
|
outcome: "ignored",
|
|
665
642
|
reason: "GitLab event header is missing."
|
|
666
643
|
};
|
|
667
|
-
let n =
|
|
644
|
+
let n = ye.get(t);
|
|
668
645
|
if (n == null) return {
|
|
669
646
|
outcome: "ignored",
|
|
670
647
|
reason: "GitLab event header is unknown."
|
|
671
648
|
};
|
|
672
|
-
if (!
|
|
649
|
+
if (!xe(e.config).events.includes(n)) return {
|
|
673
650
|
outcome: "ignored",
|
|
674
651
|
reason: "GitLab event is not subscribed."
|
|
675
652
|
};
|
|
@@ -686,36 +663,36 @@ var ge = [
|
|
|
686
663
|
};
|
|
687
664
|
},
|
|
688
665
|
async reconcile(e) {
|
|
689
|
-
let t =
|
|
666
|
+
let t = Ee(e.state), n = xe(e.config), r = De(t);
|
|
690
667
|
if (!e.active) {
|
|
691
|
-
let i = r == null ? await
|
|
692
|
-
for (let t of i ?? []) await
|
|
693
|
-
return await t.saveSubscription({},
|
|
668
|
+
let i = r == null ? await Ce(e, n) : [r];
|
|
669
|
+
for (let t of i ?? []) await we(e, n, t);
|
|
670
|
+
return await t.saveSubscription({}, Oe(e.now)), { outcome: "ready" };
|
|
694
671
|
}
|
|
695
|
-
let
|
|
696
|
-
if (
|
|
697
|
-
let
|
|
698
|
-
if (
|
|
699
|
-
let t = await
|
|
700
|
-
body:
|
|
701
|
-
endpoint:
|
|
672
|
+
let a = await Ce(e, n);
|
|
673
|
+
if (a == null) throw new i("The GitLab project does not exist or is not visible.");
|
|
674
|
+
let o = r ?? a[0];
|
|
675
|
+
if (o == null) {
|
|
676
|
+
let t = await w(e, "hook create", {
|
|
677
|
+
body: Se(e.endpointUrl, n),
|
|
678
|
+
endpoint: C(n),
|
|
702
679
|
method: "POST"
|
|
703
680
|
});
|
|
704
|
-
|
|
681
|
+
T(t, "hook create"), o = Te(t.data);
|
|
705
682
|
} else {
|
|
706
|
-
let r = await
|
|
707
|
-
body:
|
|
708
|
-
endpoint: `${
|
|
683
|
+
let r = await w(e, "hook update", {
|
|
684
|
+
body: Se(e.endpointUrl, n),
|
|
685
|
+
endpoint: `${C(n)}/${o}`,
|
|
709
686
|
method: "PUT"
|
|
710
687
|
});
|
|
711
688
|
if (r.status == 404) return await t.saveSubscription({}, e.now), { outcome: "pending" };
|
|
712
|
-
|
|
689
|
+
T(r, "hook update");
|
|
713
690
|
}
|
|
714
|
-
for (let t of
|
|
715
|
-
return await t.saveSubscription({ hookId:
|
|
691
|
+
for (let t of a.filter((e) => e != o)) await we(e, n, t);
|
|
692
|
+
return await t.saveSubscription({ hookId: o }, Oe(e.now)), { outcome: "ready" };
|
|
716
693
|
}
|
|
717
694
|
};
|
|
718
|
-
function
|
|
695
|
+
function xe(e) {
|
|
719
696
|
return {
|
|
720
697
|
events: e.events,
|
|
721
698
|
insecureSsl: e.insecureSsl ?? !1,
|
|
@@ -723,10 +700,10 @@ function ye(e) {
|
|
|
723
700
|
pushBranchFilter: e.pushBranchFilter ?? ""
|
|
724
701
|
};
|
|
725
702
|
}
|
|
726
|
-
function
|
|
703
|
+
function C(e) {
|
|
727
704
|
return `/projects/${encodeURIComponent(e.project)}/hooks`;
|
|
728
705
|
}
|
|
729
|
-
function
|
|
706
|
+
function Se(e, t) {
|
|
730
707
|
return {
|
|
731
708
|
branch_filter_strategy: "wildcard",
|
|
732
709
|
description: "Managed by Open Flow.",
|
|
@@ -734,14 +711,14 @@ function be(e, t) {
|
|
|
734
711
|
name: `Open Flow ${e.slice(e.lastIndexOf("/") + 1)}`,
|
|
735
712
|
push_events_branch_filter: t.pushBranchFilter,
|
|
736
713
|
url: e,
|
|
737
|
-
...Object.fromEntries(
|
|
714
|
+
...Object.fromEntries(ve.map((e) => [`${e}_events`, t.events.includes(e)]))
|
|
738
715
|
};
|
|
739
716
|
}
|
|
740
|
-
async function
|
|
717
|
+
async function Ce(e, t) {
|
|
741
718
|
let n = [];
|
|
742
719
|
for (let r = 1; r <= 10; r += 1) {
|
|
743
|
-
let i = await
|
|
744
|
-
endpoint:
|
|
720
|
+
let i = await w(e, "hook list", {
|
|
721
|
+
endpoint: C(t),
|
|
745
722
|
method: "GET",
|
|
746
723
|
query: {
|
|
747
724
|
page: r,
|
|
@@ -749,59 +726,59 @@ async function xe(e, t) {
|
|
|
749
726
|
}
|
|
750
727
|
});
|
|
751
728
|
if (i.status == 404) return null;
|
|
752
|
-
|
|
729
|
+
T(i, "hook list");
|
|
753
730
|
let a = Array.isArray(i.data) ? i.data : [];
|
|
754
731
|
for (let t of a) {
|
|
755
|
-
let r =
|
|
732
|
+
let r = ke(t);
|
|
756
733
|
r?.url === e.endpointUrl && (typeof r.id == "number" || typeof r.id == "string") && n.push(String(r.id));
|
|
757
734
|
}
|
|
758
735
|
if (a.length < 100) break;
|
|
759
736
|
}
|
|
760
737
|
return n;
|
|
761
738
|
}
|
|
762
|
-
async function
|
|
763
|
-
let r = await
|
|
764
|
-
endpoint: `${
|
|
739
|
+
async function we(e, t, n) {
|
|
740
|
+
let r = await w(e, "hook delete", {
|
|
741
|
+
endpoint: `${C(t)}/${n}`,
|
|
765
742
|
method: "DELETE"
|
|
766
743
|
});
|
|
767
|
-
r.status != 404 &&
|
|
744
|
+
r.status != 404 && T(r, "hook delete");
|
|
768
745
|
}
|
|
769
|
-
async function
|
|
746
|
+
async function w(e, t, n) {
|
|
770
747
|
try {
|
|
771
748
|
return await e.connector.execute(n, e.signal);
|
|
772
749
|
} catch (e) {
|
|
773
|
-
throw e instanceof
|
|
750
|
+
throw e instanceof r ? e : new a(`GitLab ${t} request failed.`, { cause: e });
|
|
774
751
|
}
|
|
775
752
|
}
|
|
776
|
-
function
|
|
777
|
-
if (!(e.status >= 200 && e.status < 300)) throw e.status == 401 || e.status == 403 ? new
|
|
753
|
+
function T(e, t) {
|
|
754
|
+
if (!(e.status >= 200 && e.status < 300)) throw e.status == 401 || e.status == 403 ? new r(`GitLab ${t} rejected the Connection.`) : [
|
|
778
755
|
400,
|
|
779
756
|
404,
|
|
780
757
|
422
|
|
781
|
-
].includes(e.status) ? new
|
|
758
|
+
].includes(e.status) ? new i(`GitLab ${t} rejected the subscription.`) : new a(`GitLab ${t} failed with status ${e.status}.`);
|
|
782
759
|
}
|
|
783
|
-
function
|
|
784
|
-
let t =
|
|
785
|
-
if (typeof t != "number" && typeof t != "string") throw new
|
|
760
|
+
function Te(e) {
|
|
761
|
+
let t = ke(e)?.id;
|
|
762
|
+
if (typeof t != "number" && typeof t != "string") throw new a("GitLab hook response is missing its ID.");
|
|
786
763
|
return String(t);
|
|
787
764
|
}
|
|
788
|
-
function
|
|
789
|
-
if (e == null) throw new
|
|
765
|
+
function Ee(e) {
|
|
766
|
+
if (e == null) throw new i("GitLab Integration state is missing.");
|
|
790
767
|
return e;
|
|
791
768
|
}
|
|
792
|
-
function
|
|
769
|
+
function De(e) {
|
|
793
770
|
let t = e.subscription.hookId;
|
|
794
771
|
return typeof t == "string" && t.length > 0 ? t : null;
|
|
795
772
|
}
|
|
796
|
-
function
|
|
773
|
+
function Oe(e) {
|
|
797
774
|
return new Date(e.getTime() + 2592e6);
|
|
798
775
|
}
|
|
799
|
-
function
|
|
776
|
+
function ke(e) {
|
|
800
777
|
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
801
778
|
}
|
|
802
779
|
//#endregion
|
|
803
780
|
//#region src/trigger/providers/gmail/on-message-received.ts
|
|
804
|
-
var
|
|
781
|
+
var Ae = 25, je = 5, Me = {
|
|
805
782
|
snapshot: {
|
|
806
783
|
configSchema: {
|
|
807
784
|
additionalProperties: !1,
|
|
@@ -826,7 +803,7 @@ var Oe = 25, ke = 5, Ae = {
|
|
|
826
803
|
type: "array"
|
|
827
804
|
},
|
|
828
805
|
maxMessagesPerPoll: {
|
|
829
|
-
default:
|
|
806
|
+
default: Ae,
|
|
830
807
|
maximum: 100,
|
|
831
808
|
minimum: 1,
|
|
832
809
|
type: "integer"
|
|
@@ -897,20 +874,20 @@ var Oe = 25, ke = 5, Ae = {
|
|
|
897
874
|
type: "poll"
|
|
898
875
|
},
|
|
899
876
|
async poll(e) {
|
|
900
|
-
let t =
|
|
877
|
+
let t = Ne(e.config);
|
|
901
878
|
if (e.checkpoint === null) return {
|
|
902
|
-
checkpoint: { historyId: await
|
|
879
|
+
checkpoint: { historyId: await Pe(e) },
|
|
903
880
|
events: []
|
|
904
881
|
};
|
|
905
|
-
let n =
|
|
882
|
+
let n = Fe(e.checkpoint), r = await Ie(e, t.labelNamesOrIds), { candidates: i, lastPage: a } = await Le(e, n, r, t.maxMessagesPerPoll), o = Re(n.historyId, a), s = [], c = 0;
|
|
906
883
|
for (let n of i) {
|
|
907
|
-
let i = await
|
|
884
|
+
let i = await ze(e, n.id);
|
|
908
885
|
if (i != null) {
|
|
909
|
-
if (!await
|
|
886
|
+
if (!await Be(e, i, t, r)) {
|
|
910
887
|
c += 1;
|
|
911
888
|
continue;
|
|
912
889
|
}
|
|
913
|
-
s.push(
|
|
890
|
+
s.push(Ue(i));
|
|
914
891
|
}
|
|
915
892
|
}
|
|
916
893
|
return {
|
|
@@ -921,59 +898,59 @@ var Oe = 25, ke = 5, Ae = {
|
|
|
921
898
|
};
|
|
922
899
|
}
|
|
923
900
|
};
|
|
924
|
-
function
|
|
901
|
+
function Ne(e) {
|
|
925
902
|
return {
|
|
926
903
|
includeDrafts: e.includeDrafts ?? !1,
|
|
927
904
|
includeSpamAndTrash: e.includeSpamAndTrash ?? !1,
|
|
928
905
|
labelNamesOrIds: e.labelNamesOrIds ?? [],
|
|
929
|
-
maxMessagesPerPoll: e.maxMessagesPerPoll ??
|
|
906
|
+
maxMessagesPerPoll: e.maxMessagesPerPoll ?? Ae,
|
|
930
907
|
readStatus: e.readStatus ?? "All",
|
|
931
908
|
search: (e.search ?? "").trim(),
|
|
932
909
|
sender: (e.sender ?? "").trim()
|
|
933
910
|
};
|
|
934
911
|
}
|
|
935
|
-
async function
|
|
936
|
-
let t = await
|
|
937
|
-
|
|
938
|
-
let r =
|
|
912
|
+
async function Pe(e) {
|
|
913
|
+
let t = await E(e, "/users/me/profile");
|
|
914
|
+
D(t, "profile fetch");
|
|
915
|
+
let r = k(t.data)?.historyId;
|
|
939
916
|
if (typeof r != "string" || r.length == 0) throw new n("Gmail profile historyId is missing.");
|
|
940
917
|
return r;
|
|
941
918
|
}
|
|
942
|
-
function
|
|
943
|
-
let n =
|
|
944
|
-
if (typeof n?.historyId != "string" || n.historyId.length == 0) throw new
|
|
919
|
+
function Fe(t) {
|
|
920
|
+
let n = k(t);
|
|
921
|
+
if (typeof n?.historyId != "string" || n.historyId.length == 0) throw new e("Gmail checkpoint historyId is missing; recreate the Trigger.");
|
|
945
922
|
return {
|
|
946
923
|
historyId: n.historyId,
|
|
947
924
|
...typeof n.pageToken == "string" ? { pageToken: n.pageToken } : {}
|
|
948
925
|
};
|
|
949
926
|
}
|
|
950
|
-
async function
|
|
927
|
+
async function Ie(t, n) {
|
|
951
928
|
if (n.length == 0) return [];
|
|
952
|
-
let r = await
|
|
953
|
-
|
|
954
|
-
let i =
|
|
929
|
+
let r = await E(t, "/users/me/labels");
|
|
930
|
+
D(r, "labels list");
|
|
931
|
+
let i = k(r.data)?.labels, a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map();
|
|
955
932
|
if (Array.isArray(i)) for (let e of i) {
|
|
956
|
-
let t =
|
|
933
|
+
let t = k(e);
|
|
957
934
|
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
935
|
}
|
|
959
|
-
return [...new Set(n.map((
|
|
960
|
-
let n = a.has(
|
|
961
|
-
if (n == null) throw new
|
|
936
|
+
return [...new Set(n.map((t) => {
|
|
937
|
+
let n = a.has(t) ? t : o.get(t.toLowerCase());
|
|
938
|
+
if (n == null) throw new e(`Gmail label "${t}" does not exist.`);
|
|
962
939
|
return n;
|
|
963
940
|
}))];
|
|
964
941
|
}
|
|
965
|
-
async function
|
|
942
|
+
async function Le(t, n, r, i) {
|
|
966
943
|
let a = /* @__PURE__ */ new Map(), o = n.pageToken, s = {};
|
|
967
|
-
for (let c = 0; c <
|
|
968
|
-
let c = await
|
|
944
|
+
for (let c = 0; c < je; c += 1) {
|
|
945
|
+
let c = await E(t, "/users/me/history", {
|
|
969
946
|
historyTypes: "messageAdded",
|
|
970
947
|
labelId: r[0],
|
|
971
948
|
maxResults: i,
|
|
972
949
|
pageToken: o,
|
|
973
950
|
startHistoryId: n.historyId
|
|
974
951
|
});
|
|
975
|
-
if (c.status == 404) throw new
|
|
976
|
-
|
|
952
|
+
if (c.status == 404) throw new e("Gmail history checkpoint expired; recreate the Trigger.");
|
|
953
|
+
D(c, "history list"), s = k(c.data) ?? {};
|
|
977
954
|
for (let e of s.history ?? []) for (let t of e.messagesAdded ?? []) {
|
|
978
955
|
let e = t.message?.id;
|
|
979
956
|
e != null && e.length > 0 && !a.has(e) && a.set(e, { id: e });
|
|
@@ -985,7 +962,7 @@ async function Fe(e, n, r, i) {
|
|
|
985
962
|
lastPage: s
|
|
986
963
|
};
|
|
987
964
|
}
|
|
988
|
-
function
|
|
965
|
+
function Re(e, t) {
|
|
989
966
|
if (t.nextPageToken) return {
|
|
990
967
|
checkpoint: {
|
|
991
968
|
historyId: e,
|
|
@@ -999,32 +976,32 @@ function Ie(e, t) {
|
|
|
999
976
|
hasMore: !1
|
|
1000
977
|
};
|
|
1001
978
|
}
|
|
1002
|
-
async function
|
|
1003
|
-
let n = await
|
|
1004
|
-
return n.status == 404 ? null : (
|
|
979
|
+
async function ze(e, t) {
|
|
980
|
+
let n = await E(e, `/users/me/messages/${encodeURIComponent(t)}`, { format: "metadata" });
|
|
981
|
+
return n.status == 404 ? null : (D(n, "message metadata fetch"), k(n.data) ?? null);
|
|
1005
982
|
}
|
|
1006
|
-
async function
|
|
983
|
+
async function Be(e, t, n, r) {
|
|
1007
984
|
let i = t.labelIds ?? [];
|
|
1008
985
|
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 =
|
|
1010
|
-
return a.length == 0 || await
|
|
986
|
+
let a = Ve(n);
|
|
987
|
+
return a.length == 0 || await He(e, t, a, n.includeSpamAndTrash);
|
|
1011
988
|
}
|
|
1012
|
-
function
|
|
989
|
+
function Ve(e) {
|
|
1013
990
|
let t = e.search.length == 0 ? [] : [e.search], n = e.sender.replaceAll("\"", "").trim();
|
|
1014
991
|
return n.length > 0 && t.push(`from:${/\s/.test(n) ? `"${n}"` : n}`), t.join(" ");
|
|
1015
992
|
}
|
|
1016
|
-
async function
|
|
1017
|
-
let i =
|
|
993
|
+
async function He(e, t, n, r) {
|
|
994
|
+
let i = O(t.payload?.headers ?? [], "Message-ID").replace(/^</, "").replace(/>$/, "");
|
|
1018
995
|
if (i.length == 0) return !1;
|
|
1019
|
-
let a = await
|
|
996
|
+
let a = await E(e, "/users/me/messages", {
|
|
1020
997
|
includeSpamTrash: r ? "true" : void 0,
|
|
1021
998
|
q: `${n} rfc822msgid:${i}`
|
|
1022
999
|
});
|
|
1023
|
-
|
|
1024
|
-
let o =
|
|
1025
|
-
return Array.isArray(o) && o.some((e) =>
|
|
1000
|
+
D(a, "query match");
|
|
1001
|
+
let o = k(a.data)?.messages;
|
|
1002
|
+
return Array.isArray(o) && o.some((e) => k(e)?.id === t.id);
|
|
1026
1003
|
}
|
|
1027
|
-
function
|
|
1004
|
+
function Ue(e) {
|
|
1028
1005
|
let t = e.payload?.headers ?? [];
|
|
1029
1006
|
return {
|
|
1030
1007
|
dedupeKey: e.id,
|
|
@@ -1032,15 +1009,15 @@ function Ve(e) {
|
|
|
1032
1009
|
historyId: e.historyId ?? null,
|
|
1033
1010
|
labelIds: e.labelIds ?? [],
|
|
1034
1011
|
messageId: e.id,
|
|
1035
|
-
messageTimestamp:
|
|
1036
|
-
sender:
|
|
1037
|
-
subject:
|
|
1012
|
+
messageTimestamp: We(e.internalDate, O(t, "Date")),
|
|
1013
|
+
sender: O(t, "From"),
|
|
1014
|
+
subject: O(t, "Subject"),
|
|
1038
1015
|
threadId: e.threadId ?? "",
|
|
1039
|
-
to:
|
|
1016
|
+
to: O(t, "To")
|
|
1040
1017
|
}
|
|
1041
1018
|
};
|
|
1042
1019
|
}
|
|
1043
|
-
async function
|
|
1020
|
+
async function E(e, t, r = {}) {
|
|
1044
1021
|
try {
|
|
1045
1022
|
return await e.connector.execute({
|
|
1046
1023
|
endpoint: t,
|
|
@@ -1051,13 +1028,13 @@ async function O(e, t, r = {}) {
|
|
|
1051
1028
|
throw new n(`Gmail proxy request to ${t} failed.`, { cause: e });
|
|
1052
1029
|
}
|
|
1053
1030
|
}
|
|
1054
|
-
function
|
|
1055
|
-
if (!(
|
|
1031
|
+
function D(e, r) {
|
|
1032
|
+
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
1033
|
}
|
|
1057
|
-
function
|
|
1034
|
+
function O(e, t) {
|
|
1058
1035
|
return e.find((e) => e.name.toLowerCase() == t.toLowerCase())?.value ?? "";
|
|
1059
1036
|
}
|
|
1060
|
-
function
|
|
1037
|
+
function We(e, t) {
|
|
1061
1038
|
let n = e == null ? NaN : Number(e);
|
|
1062
1039
|
if (Number.isFinite(n)) {
|
|
1063
1040
|
let e = new Date(n);
|
|
@@ -1066,21 +1043,21 @@ function He(e, t) {
|
|
|
1066
1043
|
let r = Date.parse(t);
|
|
1067
1044
|
return Number.isNaN(r) ? "" : new Date(r).toISOString();
|
|
1068
1045
|
}
|
|
1069
|
-
function
|
|
1046
|
+
function k(e) {
|
|
1070
1047
|
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
1071
1048
|
}
|
|
1072
1049
|
//#endregion
|
|
1073
1050
|
//#region src/trigger/providers/google-calendar/on-event-changed.ts
|
|
1074
|
-
var
|
|
1051
|
+
var A = [
|
|
1075
1052
|
"created",
|
|
1076
1053
|
"updated",
|
|
1077
1054
|
"cancelled"
|
|
1078
|
-
],
|
|
1055
|
+
], Ge = /* @__PURE__ */ new Set([
|
|
1079
1056
|
"rateLimitExceeded",
|
|
1080
1057
|
"userRateLimitExceeded",
|
|
1081
1058
|
"quotaExceeded",
|
|
1082
1059
|
"usageLimits"
|
|
1083
|
-
]),
|
|
1060
|
+
]), Ke = {
|
|
1084
1061
|
snapshot: {
|
|
1085
1062
|
configSchema: {
|
|
1086
1063
|
additionalProperties: !1,
|
|
@@ -1091,9 +1068,9 @@ var M = [
|
|
|
1091
1068
|
type: "string"
|
|
1092
1069
|
},
|
|
1093
1070
|
changes: {
|
|
1094
|
-
default:
|
|
1071
|
+
default: A,
|
|
1095
1072
|
items: {
|
|
1096
|
-
enum:
|
|
1073
|
+
enum: A,
|
|
1097
1074
|
type: "string"
|
|
1098
1075
|
},
|
|
1099
1076
|
minItems: 1,
|
|
@@ -1132,7 +1109,7 @@ var M = [
|
|
|
1132
1109
|
},
|
|
1133
1110
|
calendarId: { type: "string" },
|
|
1134
1111
|
changeType: {
|
|
1135
|
-
enum:
|
|
1112
|
+
enum: A,
|
|
1136
1113
|
type: "string"
|
|
1137
1114
|
},
|
|
1138
1115
|
created: { type: ["string", "null"] },
|
|
@@ -1183,22 +1160,22 @@ var M = [
|
|
|
1183
1160
|
type: "poll"
|
|
1184
1161
|
},
|
|
1185
1162
|
async poll(e) {
|
|
1186
|
-
let t =
|
|
1187
|
-
if (e.checkpoint === null) return
|
|
1188
|
-
let n =
|
|
1189
|
-
return n.calendarId === t.calendarId ? "seedTimeMin" in n ?
|
|
1163
|
+
let t = qe(e.config);
|
|
1164
|
+
if (e.checkpoint === null) return Ye(e, t, e.now.toISOString());
|
|
1165
|
+
let n = Je(e.checkpoint);
|
|
1166
|
+
return n.calendarId === t.calendarId ? "seedTimeMin" in n ? Ye(e, t, n.seedTimeMin, n.pageToken) : Xe(e, t, n) : Ye(e, t, e.now.toISOString());
|
|
1190
1167
|
}
|
|
1191
1168
|
};
|
|
1192
|
-
function
|
|
1169
|
+
function qe(e) {
|
|
1193
1170
|
return {
|
|
1194
1171
|
calendarId: e.calendarId,
|
|
1195
|
-
changes: new Set(e.changes ??
|
|
1172
|
+
changes: new Set(e.changes ?? A),
|
|
1196
1173
|
matchTerm: (e.matchTerm ?? "").trim(),
|
|
1197
1174
|
maxEventsPerPoll: e.maxEventsPerPoll ?? 100
|
|
1198
1175
|
};
|
|
1199
1176
|
}
|
|
1200
|
-
function
|
|
1201
|
-
let n =
|
|
1177
|
+
function Je(t) {
|
|
1178
|
+
let n = j(t), r = typeof n?.pageToken == "string" ? n.pageToken : void 0, i = typeof n?.calendarId == "string" ? n.calendarId : void 0;
|
|
1202
1179
|
if (typeof n?.syncToken == "string" && n.syncToken.length > 0) return {
|
|
1203
1180
|
calendarId: i,
|
|
1204
1181
|
...r == null ? {} : { pageToken: r },
|
|
@@ -1209,27 +1186,27 @@ function Ke(e) {
|
|
|
1209
1186
|
...r == null ? {} : { pageToken: r },
|
|
1210
1187
|
seedTimeMin: n.seedTimeMin
|
|
1211
1188
|
};
|
|
1212
|
-
throw new
|
|
1189
|
+
throw new e("Google Calendar checkpoint is invalid; recreate the Trigger.");
|
|
1213
1190
|
}
|
|
1214
|
-
async function
|
|
1191
|
+
async function Ye(e, t, r, i) {
|
|
1215
1192
|
let a = i;
|
|
1216
1193
|
for (let i = 0; i < 2; i += 1) {
|
|
1217
|
-
let i = await
|
|
1194
|
+
let i = await et(e, t.calendarId, {
|
|
1218
1195
|
maxResults: 2500,
|
|
1219
1196
|
pageToken: a,
|
|
1220
1197
|
showDeleted: "true",
|
|
1221
1198
|
singleEvents: "false",
|
|
1222
1199
|
timeMin: r
|
|
1223
1200
|
});
|
|
1224
|
-
if (a != null &&
|
|
1201
|
+
if (a != null && nt(i)) return {
|
|
1225
1202
|
checkpoint: {
|
|
1226
1203
|
calendarId: t.calendarId,
|
|
1227
1204
|
seedTimeMin: r
|
|
1228
1205
|
},
|
|
1229
1206
|
events: []
|
|
1230
1207
|
};
|
|
1231
|
-
|
|
1232
|
-
let o =
|
|
1208
|
+
tt(e, i, "seed full sync");
|
|
1209
|
+
let o = j(i.data) ?? {};
|
|
1233
1210
|
if (o.nextSyncToken) return {
|
|
1234
1211
|
checkpoint: {
|
|
1235
1212
|
calendarId: t.calendarId,
|
|
@@ -1250,17 +1227,17 @@ async function qe(e, t, r, i) {
|
|
|
1250
1227
|
hasMore: !0
|
|
1251
1228
|
};
|
|
1252
1229
|
}
|
|
1253
|
-
async function
|
|
1230
|
+
async function Xe(e, t, r) {
|
|
1254
1231
|
let i = [], a = 0, o = r.pageToken;
|
|
1255
1232
|
for (let s = 0; s < 5; s += 1) {
|
|
1256
|
-
let s = await
|
|
1233
|
+
let s = await et(e, t.calendarId, {
|
|
1257
1234
|
maxResults: t.maxEventsPerPoll,
|
|
1258
1235
|
pageToken: o,
|
|
1259
1236
|
showDeleted: "true",
|
|
1260
1237
|
singleEvents: "false",
|
|
1261
1238
|
syncToken: r.syncToken
|
|
1262
1239
|
});
|
|
1263
|
-
if (o != null &&
|
|
1240
|
+
if (o != null && nt(s)) return {
|
|
1264
1241
|
checkpoint: {
|
|
1265
1242
|
calendarId: t.calendarId,
|
|
1266
1243
|
syncToken: r.syncToken
|
|
@@ -1268,16 +1245,16 @@ async function Je(e, t, r) {
|
|
|
1268
1245
|
events: i,
|
|
1269
1246
|
filtered: a
|
|
1270
1247
|
};
|
|
1271
|
-
|
|
1272
|
-
let c =
|
|
1248
|
+
tt(e, s, "incremental sync");
|
|
1249
|
+
let c = j(s.data) ?? {};
|
|
1273
1250
|
for (let e of c.items ?? []) {
|
|
1274
1251
|
if (e.id == null || e.id.length == 0) continue;
|
|
1275
|
-
let n =
|
|
1276
|
-
if (!t.changes.has(n) || !
|
|
1252
|
+
let n = Ze(e);
|
|
1253
|
+
if (!t.changes.has(n) || !Qe(e, t.matchTerm)) {
|
|
1277
1254
|
a += 1;
|
|
1278
1255
|
continue;
|
|
1279
1256
|
}
|
|
1280
|
-
i.push(
|
|
1257
|
+
i.push($e(e, e.id, n, t.calendarId));
|
|
1281
1258
|
}
|
|
1282
1259
|
if (c.nextSyncToken) return {
|
|
1283
1260
|
checkpoint: {
|
|
@@ -1301,12 +1278,12 @@ async function Je(e, t, r) {
|
|
|
1301
1278
|
hasMore: !0
|
|
1302
1279
|
};
|
|
1303
1280
|
}
|
|
1304
|
-
function
|
|
1281
|
+
function Ze(e) {
|
|
1305
1282
|
if (e.status == "cancelled") return "cancelled";
|
|
1306
|
-
let t =
|
|
1283
|
+
let t = ot(e.created), n = ot(e.updated);
|
|
1307
1284
|
return t != null && t == n ? "created" : "updated";
|
|
1308
1285
|
}
|
|
1309
|
-
function
|
|
1286
|
+
function Qe(e, t) {
|
|
1310
1287
|
if (t.length == 0) return !0;
|
|
1311
1288
|
let n = t.toLowerCase();
|
|
1312
1289
|
return [
|
|
@@ -1316,14 +1293,14 @@ function Xe(e, t) {
|
|
|
1316
1293
|
...(e.attendees ?? []).map(({ email: e }) => e)
|
|
1317
1294
|
].some((e) => typeof e == "string" && e.toLowerCase().includes(n));
|
|
1318
1295
|
}
|
|
1319
|
-
function
|
|
1296
|
+
function $e(e, t, n, r) {
|
|
1320
1297
|
return {
|
|
1321
1298
|
dedupeKey: `${t}:${e.updated ?? e.etag ?? ""}`,
|
|
1322
1299
|
payload: {
|
|
1323
1300
|
attendeeEmails: (e.attendees ?? []).flatMap(({ email: e }) => e == null || e.length == 0 ? [] : [e]),
|
|
1324
1301
|
calendarId: r,
|
|
1325
1302
|
changeType: n,
|
|
1326
|
-
created:
|
|
1303
|
+
created: at(e.created),
|
|
1327
1304
|
creatorEmail: e.creator?.email ?? null,
|
|
1328
1305
|
description: e.description ?? null,
|
|
1329
1306
|
end: e.end ?? null,
|
|
@@ -1337,11 +1314,11 @@ function Ze(e, t, n, r) {
|
|
|
1337
1314
|
start: e.start ?? null,
|
|
1338
1315
|
status: e.status ?? "",
|
|
1339
1316
|
summary: e.summary ?? null,
|
|
1340
|
-
updated:
|
|
1317
|
+
updated: at(e.updated)
|
|
1341
1318
|
}
|
|
1342
1319
|
};
|
|
1343
1320
|
}
|
|
1344
|
-
async function
|
|
1321
|
+
async function et(e, t, r) {
|
|
1345
1322
|
let i = `/calendars/${encodeURIComponent(t)}/events`;
|
|
1346
1323
|
try {
|
|
1347
1324
|
return await e.connector.execute({
|
|
@@ -1353,40 +1330,40 @@ async function Qe(e, t, r) {
|
|
|
1353
1330
|
throw new n(`Google Calendar proxy request to ${i} failed.`, { cause: e });
|
|
1354
1331
|
}
|
|
1355
1332
|
}
|
|
1356
|
-
function
|
|
1357
|
-
if (!(i.status >= 200 && i.status < 300)) throw i.status == 410 || i.status == 400 &&
|
|
1333
|
+
function tt(r, i, a) {
|
|
1334
|
+
if (!(i.status >= 200 && i.status < 300)) throw i.status == 410 || i.status == 400 && it(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 ? rt(i.data).some((e) => Ge.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
1335
|
}
|
|
1359
|
-
function
|
|
1360
|
-
return e.status == 400 && !
|
|
1336
|
+
function nt(e) {
|
|
1337
|
+
return e.status == 400 && !it(e.data);
|
|
1361
1338
|
}
|
|
1362
|
-
function
|
|
1363
|
-
let t =
|
|
1339
|
+
function rt(e) {
|
|
1340
|
+
let t = j(j(e)?.error)?.errors;
|
|
1364
1341
|
return Array.isArray(t) ? t.flatMap((e) => {
|
|
1365
|
-
let t =
|
|
1342
|
+
let t = j(e)?.reason;
|
|
1366
1343
|
return typeof t == "string" ? [t] : [];
|
|
1367
1344
|
}) : [];
|
|
1368
1345
|
}
|
|
1369
|
-
function
|
|
1370
|
-
if (
|
|
1371
|
-
let t =
|
|
1346
|
+
function it(e) {
|
|
1347
|
+
if (rt(e).includes("fullSyncRequired")) return !0;
|
|
1348
|
+
let t = j(j(e)?.error)?.message;
|
|
1372
1349
|
return typeof t == "string" && t.includes("fullSyncRequired");
|
|
1373
1350
|
}
|
|
1374
|
-
function
|
|
1351
|
+
function at(e) {
|
|
1375
1352
|
if (e == null || e.length == 0) return null;
|
|
1376
1353
|
let t = Date.parse(e);
|
|
1377
1354
|
return Number.isNaN(t) ? null : new Date(t).toISOString();
|
|
1378
1355
|
}
|
|
1379
|
-
function
|
|
1356
|
+
function ot(e) {
|
|
1380
1357
|
if (e == null || e.length == 0) return null;
|
|
1381
1358
|
let t = Date.parse(e);
|
|
1382
1359
|
return Number.isNaN(t) ? null : Math.floor(t / 1e3);
|
|
1383
1360
|
}
|
|
1384
|
-
function
|
|
1361
|
+
function j(e) {
|
|
1385
1362
|
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
1386
1363
|
}
|
|
1387
1364
|
//#endregion
|
|
1388
1365
|
//#region src/trigger/providers/google-drive/changes.ts
|
|
1389
|
-
var
|
|
1366
|
+
var st = 6012e5, ct = 36e5, lt = 6e4, ut = 6e4, dt = 2, ft = 100, pt = new TextEncoder(), mt = "nextPageToken,newStartPageToken,changes(fileId,kind,changeType,removed,time,driveId,file(id,name,mimeType,webViewLink,createdTime,modifiedTime,size,driveId,parents,shared,starred,trashed))", ht = {
|
|
1390
1367
|
initialState: {
|
|
1391
1368
|
checkpoint: null,
|
|
1392
1369
|
subscription: { channels: [] }
|
|
@@ -1418,7 +1395,7 @@ var at = 6012e5, ot = 36e5, st = 6e4, ct = 6e4, lt = 2, ut = 100, dt = new TextE
|
|
|
1418
1395
|
type: "boolean"
|
|
1419
1396
|
},
|
|
1420
1397
|
pageSize: {
|
|
1421
|
-
default:
|
|
1398
|
+
default: ft,
|
|
1422
1399
|
description: "Maximum changes included in one Flow Run.",
|
|
1423
1400
|
maximum: 100,
|
|
1424
1401
|
minimum: 1,
|
|
@@ -1502,24 +1479,24 @@ var at = 6012e5, ot = 36e5, st = 6e4, ct = 6e4, lt = 2, ut = 100, dt = new TextE
|
|
|
1502
1479
|
type: "integration"
|
|
1503
1480
|
},
|
|
1504
1481
|
async receive(e) {
|
|
1505
|
-
let t =
|
|
1506
|
-
if (n == null || r == null || i == null ||
|
|
1482
|
+
let t = M(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");
|
|
1483
|
+
if (n == null || r == null || i == null || o == null) return {
|
|
1507
1484
|
body: "",
|
|
1508
1485
|
contentType: "text/plain",
|
|
1509
1486
|
outcome: "respond",
|
|
1510
1487
|
status: 404
|
|
1511
1488
|
};
|
|
1512
|
-
let
|
|
1513
|
-
if (
|
|
1489
|
+
let s = vt(t), c = s.find((t) => t.id == n && Date.parse(t.expiration) > e.now.getTime());
|
|
1490
|
+
if (c == null || !jt(o, await At(e.callbackSecret, n)) || c.resourceId != null && c.resourceId != r) return {
|
|
1514
1491
|
body: "",
|
|
1515
1492
|
contentType: "text/plain",
|
|
1516
1493
|
outcome: "respond",
|
|
1517
1494
|
status: 404
|
|
1518
1495
|
};
|
|
1519
|
-
if (
|
|
1496
|
+
if (c.resourceId ?? (s = s.map((e) => e.id == n ? {
|
|
1520
1497
|
...e,
|
|
1521
1498
|
resourceId: r
|
|
1522
|
-
} : e), await
|
|
1499
|
+
} : e), await N(t, s, e.now)), i != "sync" && i != "change") return {
|
|
1523
1500
|
outcome: "ignored",
|
|
1524
1501
|
reason: "Google Drive notification state is not actionable."
|
|
1525
1502
|
};
|
|
@@ -1536,86 +1513,86 @@ var at = 6012e5, ot = 36e5, st = 6e4, ct = 6e4, lt = 2, ut = 100, dt = new TextE
|
|
|
1536
1513
|
outcome: "ignored",
|
|
1537
1514
|
reason: "The Team cannot admit Trigger events."
|
|
1538
1515
|
};
|
|
1539
|
-
let
|
|
1540
|
-
if (
|
|
1541
|
-
let
|
|
1516
|
+
let l = gt(e.config), u = _t(t.checkpoint), d = await Ct(e, l, u), f = F(d.nextPageToken), p = f ?? F(d.newStartPageToken);
|
|
1517
|
+
if (p == null) throw new a("Google Drive changes response is missing its next checkpoint.");
|
|
1518
|
+
let m = {
|
|
1542
1519
|
changedTypes: (e.header("x-goog-changed") ?? "").split(",").map((e) => e.trim()).filter((e) => e.length > 0),
|
|
1543
1520
|
messageNumber: e.header("x-goog-message-number") ?? null,
|
|
1544
1521
|
resourceState: i,
|
|
1545
1522
|
resourceUri: e.header("x-goog-resource-uri") ?? null
|
|
1546
|
-
},
|
|
1547
|
-
checkpoint: { pageToken:
|
|
1548
|
-
continue:
|
|
1549
|
-
dedupeKey: `${
|
|
1523
|
+
}, h = (d.changes ?? []).map((e) => kt(e, m)), g = {
|
|
1524
|
+
checkpoint: { pageToken: p },
|
|
1525
|
+
continue: f != null,
|
|
1526
|
+
dedupeKey: `${l.driveId ?? "my-drive"}:${u}`
|
|
1550
1527
|
};
|
|
1551
|
-
return
|
|
1552
|
-
...
|
|
1528
|
+
return h.length == 0 ? {
|
|
1529
|
+
...g,
|
|
1553
1530
|
outcome: "ignored",
|
|
1554
1531
|
reason: "Google Drive change page is empty."
|
|
1555
1532
|
} : {
|
|
1556
|
-
...
|
|
1533
|
+
...g,
|
|
1557
1534
|
outcome: "event",
|
|
1558
|
-
payload: { events:
|
|
1535
|
+
payload: { events: h }
|
|
1559
1536
|
};
|
|
1560
1537
|
},
|
|
1561
1538
|
async reconcile(e) {
|
|
1562
|
-
let t =
|
|
1563
|
-
if (i.length != n.length && (n = i, await
|
|
1539
|
+
let t = M(e.state), n = vt(t), r = e.now.getTime(), i = n.filter((e) => Date.parse(e.expiration) > r);
|
|
1540
|
+
if (i.length != n.length && (n = i, await N(t, n, e.now)), !e.active) return await bt(e, n);
|
|
1564
1541
|
let a = n.filter((e) => e.state == "creating" && e.resourceId != null).toSorted((e, t) => Date.parse(t.createdAt) - Date.parse(e.createdAt))[0];
|
|
1565
1542
|
a != null && (n = n.map((e) => ({
|
|
1566
1543
|
...e,
|
|
1567
1544
|
state: e.id == a.id ? "active" : "retiring"
|
|
1568
|
-
})), await
|
|
1569
|
-
let o = n.find((e) => e.state == "active"), s = n.filter((e) => e.state == "creating").filter((e) => Date.parse(e.createdAt) +
|
|
1545
|
+
})), await N(t, n, e.now));
|
|
1546
|
+
let o = n.find((e) => e.state == "active"), s = n.filter((e) => e.state == "creating").filter((e) => Date.parse(e.createdAt) + lt <= r);
|
|
1570
1547
|
if (s.length > 0) {
|
|
1571
1548
|
let r = new Set(s.map((e) => e.id));
|
|
1572
1549
|
n = n.map((e) => r.has(e.id) ? {
|
|
1573
1550
|
...e,
|
|
1574
1551
|
state: "retiring"
|
|
1575
|
-
} : e), await
|
|
1552
|
+
} : e), await N(t, n, e.now);
|
|
1576
1553
|
}
|
|
1577
1554
|
if (o = n.find((e) => e.state == "active"), o != null) {
|
|
1578
1555
|
try {
|
|
1579
|
-
n = await
|
|
1556
|
+
n = await xt(e, n);
|
|
1580
1557
|
} catch {
|
|
1581
1558
|
return { outcome: "ready" };
|
|
1582
1559
|
}
|
|
1583
|
-
if (o = n.find((e) => e.state == "active"), o != null && Date.parse(o.expiration) -
|
|
1560
|
+
if (o = n.find((e) => e.state == "active"), o != null && Date.parse(o.expiration) - ct > r) return await N(t, n, P(n, e.now)), { outcome: "ready" };
|
|
1584
1561
|
}
|
|
1585
|
-
return n.some((e) => e.state == "creating") || n.filter((e) => e.resourceId == null).length >=
|
|
1562
|
+
return n.some((e) => e.state == "creating") || n.filter((e) => e.resourceId == null).length >= dt ? (await N(t, n, P(n, e.now)), { outcome: o == null ? "pending" : "ready" }) : await yt(e, n);
|
|
1586
1563
|
}
|
|
1587
1564
|
};
|
|
1588
|
-
function
|
|
1589
|
-
if (e == null) throw new
|
|
1565
|
+
function M(e) {
|
|
1566
|
+
if (e == null) throw new i("Google Drive Integration state is missing.");
|
|
1590
1567
|
return e;
|
|
1591
1568
|
}
|
|
1592
|
-
function
|
|
1569
|
+
function gt(e) {
|
|
1593
1570
|
return {
|
|
1594
1571
|
...typeof e.driveId == "string" ? { driveId: e.driveId } : {},
|
|
1595
1572
|
includeCorpusRemovals: e.includeCorpusRemovals ?? !1,
|
|
1596
1573
|
includeItemsFromAllDrives: e.includeItemsFromAllDrives ?? !0,
|
|
1597
1574
|
includeRemoved: e.includeRemoved ?? !0,
|
|
1598
|
-
pageSize: e.pageSize ??
|
|
1575
|
+
pageSize: e.pageSize ?? ft,
|
|
1599
1576
|
restrictToMyDrive: e.restrictToMyDrive ?? !1
|
|
1600
1577
|
};
|
|
1601
1578
|
}
|
|
1602
|
-
function
|
|
1603
|
-
let t =
|
|
1604
|
-
if (t == null) throw new
|
|
1579
|
+
function _t(e) {
|
|
1580
|
+
let t = I(e) ? F(e.pageToken) : void 0;
|
|
1581
|
+
if (t == null) throw new i("Google Drive checkpoint pageToken is missing.");
|
|
1605
1582
|
return t;
|
|
1606
1583
|
}
|
|
1607
|
-
function
|
|
1584
|
+
function vt(e) {
|
|
1608
1585
|
let t = e.subscription.channels;
|
|
1609
|
-
if (!Array.isArray(t)) throw new
|
|
1586
|
+
if (!Array.isArray(t)) throw new i("Google Drive channel state is invalid.");
|
|
1610
1587
|
let n = t.map((e) => {
|
|
1611
|
-
if (typeof e != "object" || !e || Array.isArray(e)) throw new
|
|
1588
|
+
if (typeof e != "object" || !e || Array.isArray(e)) throw new i("Google Drive channel is invalid.");
|
|
1612
1589
|
let t = e;
|
|
1613
1590
|
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
1591
|
"active",
|
|
1615
1592
|
"creating",
|
|
1616
1593
|
"retiring",
|
|
1617
1594
|
"stopping"
|
|
1618
|
-
].includes(String(t.state)) || t.resourceId != null && typeof t.resourceId != "string") throw new
|
|
1595
|
+
].includes(String(t.state)) || t.resourceId != null && typeof t.resourceId != "string") throw new i("Google Drive channel fields are invalid.");
|
|
1619
1596
|
let n = {
|
|
1620
1597
|
createdAt: t.createdAt,
|
|
1621
1598
|
expiration: t.expiration,
|
|
@@ -1624,99 +1601,99 @@ function gt(e) {
|
|
|
1624
1601
|
};
|
|
1625
1602
|
return typeof t.resourceId == "string" ? Object.assign(n, { resourceId: t.resourceId }) : n;
|
|
1626
1603
|
});
|
|
1627
|
-
if (new Set(n.map((e) => e.id)).size != n.length) throw new
|
|
1604
|
+
if (new Set(n.map((e) => e.id)).size != n.length) throw new i("Google Drive channel IDs are duplicated.");
|
|
1628
1605
|
return n;
|
|
1629
1606
|
}
|
|
1630
|
-
async function
|
|
1631
|
-
let n =
|
|
1632
|
-
n.checkpoint === null ? (
|
|
1633
|
-
let
|
|
1607
|
+
async function yt(e, t) {
|
|
1608
|
+
let n = M(e.state), o = gt(e.config), s;
|
|
1609
|
+
n.checkpoint === null ? (s = await St(e, o), await n.saveCheckpoint({ pageToken: s })) : s = _t(n.checkpoint);
|
|
1610
|
+
let c = {
|
|
1634
1611
|
createdAt: e.now.toISOString(),
|
|
1635
|
-
expiration: new Date(e.now.getTime() +
|
|
1612
|
+
expiration: new Date(e.now.getTime() + st).toISOString(),
|
|
1636
1613
|
id: crypto.randomUUID(),
|
|
1637
1614
|
state: "creating"
|
|
1638
1615
|
};
|
|
1639
|
-
t = [...t,
|
|
1640
|
-
let
|
|
1616
|
+
t = [...t, c], await N(n, t, new Date(e.now.getTime() + lt));
|
|
1617
|
+
let l;
|
|
1641
1618
|
try {
|
|
1642
|
-
|
|
1619
|
+
l = await Tt(e, {
|
|
1643
1620
|
body: {
|
|
1644
1621
|
address: e.endpointUrl,
|
|
1645
|
-
expiration: String(Date.parse(
|
|
1646
|
-
id:
|
|
1647
|
-
token: await
|
|
1622
|
+
expiration: String(Date.parse(c.expiration)),
|
|
1623
|
+
id: c.id,
|
|
1624
|
+
token: await At(e.callbackSecret, c.id),
|
|
1648
1625
|
type: "web_hook"
|
|
1649
1626
|
},
|
|
1650
1627
|
endpoint: "/changes/watch",
|
|
1651
1628
|
method: "POST",
|
|
1652
1629
|
query: {
|
|
1653
|
-
...
|
|
1654
|
-
includeItemsFromAllDrives:
|
|
1655
|
-
pageToken:
|
|
1656
|
-
restrictToMyDrive:
|
|
1630
|
+
...o.driveId == null ? {} : { driveId: o.driveId },
|
|
1631
|
+
includeItemsFromAllDrives: o.driveId != null || o.includeItemsFromAllDrives,
|
|
1632
|
+
pageToken: s,
|
|
1633
|
+
restrictToMyDrive: o.restrictToMyDrive,
|
|
1657
1634
|
supportsAllDrives: !0
|
|
1658
1635
|
}
|
|
1659
1636
|
}, "changes.watch");
|
|
1660
|
-
} catch (
|
|
1661
|
-
throw (
|
|
1637
|
+
} catch (a) {
|
|
1638
|
+
throw (a instanceof r || a instanceof i) && await N(n, t.filter((e) => e.id != c.id), e.now), a;
|
|
1662
1639
|
}
|
|
1663
|
-
let
|
|
1664
|
-
if (
|
|
1665
|
-
let
|
|
1666
|
-
t = t.map((e) => e.id ==
|
|
1640
|
+
let u = F(l.resourceId);
|
|
1641
|
+
if (u == null) throw new a("Google Drive changes.watch response is missing resourceId.");
|
|
1642
|
+
let d = Mt(l.expiration) ?? c.expiration;
|
|
1643
|
+
t = t.map((e) => e.id == c.id ? {
|
|
1667
1644
|
...e,
|
|
1668
|
-
expiration:
|
|
1669
|
-
resourceId:
|
|
1645
|
+
expiration: d,
|
|
1646
|
+
resourceId: u,
|
|
1670
1647
|
state: "active"
|
|
1671
1648
|
} : e.state == "active" ? {
|
|
1672
1649
|
...e,
|
|
1673
1650
|
state: "retiring"
|
|
1674
|
-
} : e), await
|
|
1651
|
+
} : e), await N(n, t, P(t, e.now));
|
|
1675
1652
|
try {
|
|
1676
|
-
t = await
|
|
1653
|
+
t = await xt(e, t);
|
|
1677
1654
|
} catch {
|
|
1678
1655
|
return { outcome: "ready" };
|
|
1679
1656
|
}
|
|
1680
|
-
return await
|
|
1657
|
+
return await N(n, t, P(t, e.now)), { outcome: "ready" };
|
|
1681
1658
|
}
|
|
1682
|
-
async function
|
|
1683
|
-
let n =
|
|
1659
|
+
async function bt(e, t) {
|
|
1660
|
+
let n = M(e.state);
|
|
1684
1661
|
return t.some((e) => e.state == "active" || e.state == "creating") && (t = t.map((e) => ({
|
|
1685
1662
|
...e,
|
|
1686
1663
|
state: "retiring"
|
|
1687
|
-
})), await
|
|
1664
|
+
})), await N(n, t, e.now)), t = await xt(e, t), t.length == 0 ? { outcome: "ready" } : (await N(n, t, P(t, e.now)), { outcome: "pending" });
|
|
1688
1665
|
}
|
|
1689
|
-
async function
|
|
1690
|
-
let n =
|
|
1666
|
+
async function xt(e, t) {
|
|
1667
|
+
let n = M(e.state);
|
|
1691
1668
|
for (let r of t) {
|
|
1692
1669
|
if (r.state != "retiring" && r.state != "stopping" || r.resourceId == null) continue;
|
|
1693
1670
|
let i = t.map((e) => e.id == r.id ? {
|
|
1694
1671
|
...e,
|
|
1695
1672
|
state: "stopping"
|
|
1696
1673
|
} : e);
|
|
1697
|
-
await
|
|
1674
|
+
await N(n, i, new Date(e.now.getTime() + ut)), await wt(e, r), t = i.filter((e) => e.id != r.id), await N(n, t, e.now);
|
|
1698
1675
|
}
|
|
1699
1676
|
return t;
|
|
1700
1677
|
}
|
|
1701
|
-
async function
|
|
1702
|
-
let n = await
|
|
1678
|
+
async function St(e, t) {
|
|
1679
|
+
let n = await Tt(e, {
|
|
1703
1680
|
endpoint: "/changes/startPageToken",
|
|
1704
1681
|
method: "GET",
|
|
1705
1682
|
query: {
|
|
1706
1683
|
...t.driveId == null ? {} : { driveId: t.driveId },
|
|
1707
1684
|
supportsAllDrives: !0
|
|
1708
1685
|
}
|
|
1709
|
-
}, "changes.getStartPageToken"), r =
|
|
1710
|
-
if (r == null) throw new
|
|
1686
|
+
}, "changes.getStartPageToken"), r = I(n) ? F(n.startPageToken) : void 0;
|
|
1687
|
+
if (r == null) throw new a("Google Drive startPageToken response is invalid.");
|
|
1711
1688
|
return r;
|
|
1712
1689
|
}
|
|
1713
|
-
async function
|
|
1714
|
-
return await
|
|
1690
|
+
async function Ct(e, t, n) {
|
|
1691
|
+
return await Tt(e, {
|
|
1715
1692
|
endpoint: "/changes",
|
|
1716
1693
|
method: "GET",
|
|
1717
1694
|
query: {
|
|
1718
1695
|
...t.driveId == null ? {} : { driveId: t.driveId },
|
|
1719
|
-
fields:
|
|
1696
|
+
fields: mt,
|
|
1720
1697
|
includeCorpusRemovals: t.includeCorpusRemovals,
|
|
1721
1698
|
includeItemsFromAllDrives: t.driveId != null || t.includeItemsFromAllDrives,
|
|
1722
1699
|
includeRemoved: t.includeCorpusRemovals || t.includeRemoved,
|
|
@@ -1727,8 +1704,8 @@ async function xt(e, t, n) {
|
|
|
1727
1704
|
}
|
|
1728
1705
|
}, "changes.list");
|
|
1729
1706
|
}
|
|
1730
|
-
async function
|
|
1731
|
-
let n = await
|
|
1707
|
+
async function wt(e, t) {
|
|
1708
|
+
let n = await Et(e, {
|
|
1732
1709
|
body: {
|
|
1733
1710
|
id: t.id,
|
|
1734
1711
|
resourceId: t.resourceId
|
|
@@ -1736,31 +1713,31 @@ async function St(e, t) {
|
|
|
1736
1713
|
endpoint: "/channels/stop",
|
|
1737
1714
|
method: "POST"
|
|
1738
1715
|
});
|
|
1739
|
-
n.status >= 200 && n.status < 300 || n.status == 404 ||
|
|
1716
|
+
n.status >= 200 && n.status < 300 || n.status == 404 || Dt(n, "channels.stop");
|
|
1740
1717
|
}
|
|
1741
|
-
async function
|
|
1742
|
-
let r = await
|
|
1743
|
-
if (r.status >= 200 && r.status < 300 &&
|
|
1744
|
-
|
|
1718
|
+
async function Tt(e, t, n) {
|
|
1719
|
+
let r = await Et(e, t);
|
|
1720
|
+
if (r.status >= 200 && r.status < 300 && I(r.data)) return r.data;
|
|
1721
|
+
Dt(r, n);
|
|
1745
1722
|
}
|
|
1746
|
-
async function
|
|
1723
|
+
async function Et(e, t) {
|
|
1747
1724
|
try {
|
|
1748
1725
|
return await e.connector.execute(t, e.signal);
|
|
1749
1726
|
} catch (e) {
|
|
1750
|
-
throw e instanceof
|
|
1727
|
+
throw e instanceof r ? e : new a("Google Drive proxy request failed.", { cause: e });
|
|
1751
1728
|
}
|
|
1752
1729
|
}
|
|
1753
|
-
function
|
|
1754
|
-
let n =
|
|
1755
|
-
throw e.status == 401 || e.status == 403 && !n.toLowerCase().includes("ratelimit") ? new
|
|
1730
|
+
function Dt(e, t) {
|
|
1731
|
+
let n = Ot(e.data);
|
|
1732
|
+
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
1733
|
}
|
|
1757
|
-
function
|
|
1758
|
-
if (!
|
|
1734
|
+
function Ot(e) {
|
|
1735
|
+
if (!I(e) || !I(e.error)) return "";
|
|
1759
1736
|
let t = e.error.errors;
|
|
1760
|
-
return Array.isArray(t) &&
|
|
1737
|
+
return Array.isArray(t) && I(t[0]) && typeof t[0].reason == "string" ? t[0].reason : typeof e.error.status == "string" ? e.error.status : "";
|
|
1761
1738
|
}
|
|
1762
|
-
function
|
|
1763
|
-
let n =
|
|
1739
|
+
function kt(e, t) {
|
|
1740
|
+
let n = F(e.driveId), r = F(e.fileId), i = F(e.time), a = F(e.changeType), o = e.removed === !0;
|
|
1764
1741
|
return {
|
|
1765
1742
|
changeId: [
|
|
1766
1743
|
n ?? "my-drive",
|
|
@@ -1771,51 +1748,51 @@ function Dt(e, t) {
|
|
|
1771
1748
|
].join(":"),
|
|
1772
1749
|
changeType: a ?? null,
|
|
1773
1750
|
driveId: n ?? null,
|
|
1774
|
-
file:
|
|
1751
|
+
file: I(e.file) ? e.file : null,
|
|
1775
1752
|
fileId: r ?? null,
|
|
1776
1753
|
notification: t,
|
|
1777
1754
|
removed: o,
|
|
1778
1755
|
time: i ?? null
|
|
1779
1756
|
};
|
|
1780
1757
|
}
|
|
1781
|
-
async function
|
|
1758
|
+
async function N(e, t, n) {
|
|
1782
1759
|
await e.saveSubscription({ channels: t }, n);
|
|
1783
1760
|
}
|
|
1784
|
-
function
|
|
1785
|
-
let n = e.map((e) => e.state == "active" ? Date.parse(e.expiration) -
|
|
1761
|
+
function P(e, t) {
|
|
1762
|
+
let n = e.map((e) => e.state == "active" ? Date.parse(e.expiration) - ct : e.state == "creating" ? Date.parse(e.createdAt) + lt : e.resourceId == null ? Date.parse(e.expiration) : t.getTime() + ut), r = n.length == 0 ? t.getTime() + ut : Math.min(...n);
|
|
1786
1763
|
return new Date(Math.max(t.getTime(), r));
|
|
1787
1764
|
}
|
|
1788
|
-
async function
|
|
1789
|
-
let n = await crypto.subtle.importKey("raw",
|
|
1765
|
+
async function At(e, t) {
|
|
1766
|
+
let n = await crypto.subtle.importKey("raw", pt.encode(e), {
|
|
1790
1767
|
hash: "SHA-256",
|
|
1791
1768
|
name: "HMAC"
|
|
1792
|
-
}, !1, ["sign"]), r = new Uint8Array(await crypto.subtle.sign("HMAC", n,
|
|
1769
|
+
}, !1, ["sign"]), r = new Uint8Array(await crypto.subtle.sign("HMAC", n, pt.encode(`google-drive-channel/v1/${t}`)));
|
|
1793
1770
|
return btoa(String.fromCharCode(...r)).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
|
|
1794
1771
|
}
|
|
1795
|
-
function
|
|
1772
|
+
function jt(e, t) {
|
|
1796
1773
|
if (e.length != t.length) return !1;
|
|
1797
1774
|
let n = 0;
|
|
1798
1775
|
for (let r = 0; r < t.length; r += 1) n |= e.charCodeAt(r) ^ t.charCodeAt(r);
|
|
1799
1776
|
return n == 0;
|
|
1800
1777
|
}
|
|
1801
|
-
function
|
|
1778
|
+
function Mt(e) {
|
|
1802
1779
|
let t = typeof e == "string" || typeof e == "number" ? Number(e) : NaN;
|
|
1803
1780
|
return Number.isFinite(t) && t > 0 ? new Date(t).toISOString() : void 0;
|
|
1804
1781
|
}
|
|
1805
|
-
function
|
|
1782
|
+
function F(e) {
|
|
1806
1783
|
return typeof e == "string" && e.length > 0 ? e : void 0;
|
|
1807
1784
|
}
|
|
1808
|
-
function
|
|
1785
|
+
function I(e) {
|
|
1809
1786
|
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
1810
1787
|
}
|
|
1811
1788
|
//#endregion
|
|
1812
1789
|
//#region src/trigger/providers/google-drive/on-file-change.ts
|
|
1813
|
-
var
|
|
1790
|
+
var Nt = "application/vnd.google-apps.folder", Pt = "nextPageToken,incompleteSearch,files(id,name,mimeType,createdTime,modifiedTime,parents,trashed,webViewLink,driveId,size,version,lastModifyingUser(displayName,emailAddress))", Ft = /* @__PURE__ */ new Set([
|
|
1814
1791
|
"rateLimitExceeded",
|
|
1815
1792
|
"userRateLimitExceeded",
|
|
1816
1793
|
"dailyLimitExceeded",
|
|
1817
1794
|
"sharingRateLimitExceeded"
|
|
1818
|
-
]),
|
|
1795
|
+
]), It = /* @__PURE__ */ new Set(["insufficientFilePermissions", "appNotAuthorizedToFile"]), Lt = {
|
|
1819
1796
|
snapshot: {
|
|
1820
1797
|
configSchema: {
|
|
1821
1798
|
additionalProperties: !1,
|
|
@@ -1929,16 +1906,16 @@ var z = "application/vnd.google-apps.folder", jt = "nextPageToken,incompleteSear
|
|
|
1929
1906
|
type: "poll"
|
|
1930
1907
|
},
|
|
1931
1908
|
async poll(e) {
|
|
1932
|
-
let t =
|
|
1933
|
-
if (e.checkpoint === null) return
|
|
1934
|
-
let n =
|
|
1935
|
-
return n.changeType === t.changeType ?
|
|
1936
|
-
checkpoint:
|
|
1909
|
+
let t = Rt(e.config);
|
|
1910
|
+
if (e.checkpoint === null) return Bt(e, t);
|
|
1911
|
+
let n = zt(e.checkpoint);
|
|
1912
|
+
return n.changeType === t.changeType ? Ht(e, t, n) : {
|
|
1913
|
+
checkpoint: Vt(e.now, t.changeType),
|
|
1937
1914
|
events: []
|
|
1938
1915
|
};
|
|
1939
1916
|
}
|
|
1940
1917
|
};
|
|
1941
|
-
function
|
|
1918
|
+
function Rt(e) {
|
|
1942
1919
|
return {
|
|
1943
1920
|
changeType: e.changeType,
|
|
1944
1921
|
driveId: e.driveId ?? "",
|
|
@@ -1949,9 +1926,9 @@ function Ft(e) {
|
|
|
1949
1926
|
namePrefix: e.namePrefix ?? ""
|
|
1950
1927
|
};
|
|
1951
1928
|
}
|
|
1952
|
-
function
|
|
1953
|
-
let n =
|
|
1954
|
-
if (typeof n?.since != "string" || Number.isNaN(Date.parse(n.since))) throw new
|
|
1929
|
+
function zt(t) {
|
|
1930
|
+
let n = L(t);
|
|
1931
|
+
if (typeof n?.since != "string" || Number.isNaN(Date.parse(n.since))) throw new e("Google Drive checkpoint is invalid; recreate the Trigger.");
|
|
1955
1932
|
let r = n.boundaryKeys;
|
|
1956
1933
|
return {
|
|
1957
1934
|
since: n.since,
|
|
@@ -1963,23 +1940,23 @@ function It(e) {
|
|
|
1963
1940
|
...Array.isArray(r) ? { boundaryKeys: r.filter((e) => typeof e == "string") } : {}
|
|
1964
1941
|
};
|
|
1965
1942
|
}
|
|
1966
|
-
async function
|
|
1967
|
-
let i = await
|
|
1943
|
+
async function Bt(t, r) {
|
|
1944
|
+
let i = await Xt(t, `/drive/v3/files/${encodeURIComponent(r.folderId)}`, {
|
|
1968
1945
|
fields: "id,name,mimeType,driveId,trashed",
|
|
1969
1946
|
supportsAllDrives: "true"
|
|
1970
1947
|
});
|
|
1971
|
-
|
|
1972
|
-
let a =
|
|
1948
|
+
Zt(i, "folder probe");
|
|
1949
|
+
let a = L(i.data);
|
|
1973
1950
|
if (a == null) throw new n("Google Drive folder probe returned no payload.");
|
|
1974
|
-
if (a.mimeType !==
|
|
1975
|
-
if (a.trashed === !0) throw new
|
|
1976
|
-
if (r.driveId.length > 0 && (a.driveId ?? "") !== r.driveId) throw new
|
|
1951
|
+
if (a.mimeType !== Nt) throw new e("Google Drive folderId does not point to a folder.");
|
|
1952
|
+
if (a.trashed === !0) throw new e("The Google Drive folder is in the trash.");
|
|
1953
|
+
if (r.driveId.length > 0 && (a.driveId ?? "") !== r.driveId) throw new e("The configured Google Drive shared drive does not contain this folder.");
|
|
1977
1954
|
return {
|
|
1978
|
-
checkpoint:
|
|
1955
|
+
checkpoint: Vt(t.now, r.changeType),
|
|
1979
1956
|
events: []
|
|
1980
1957
|
};
|
|
1981
1958
|
}
|
|
1982
|
-
function
|
|
1959
|
+
function Vt(e, t) {
|
|
1983
1960
|
let n = e.toISOString();
|
|
1984
1961
|
return {
|
|
1985
1962
|
changeType: t,
|
|
@@ -1987,11 +1964,11 @@ function Rt(e, t) {
|
|
|
1987
1964
|
since: n
|
|
1988
1965
|
};
|
|
1989
1966
|
}
|
|
1990
|
-
async function
|
|
1991
|
-
let r =
|
|
1967
|
+
async function Ht(e, t, n) {
|
|
1968
|
+
let r = Gt(t, n.since, n.floor), i = `${t.driveId}|${r}`, a = n.pageQuery == i ? n.pageToken : void 0, o = await Xt(e, "/drive/v3/files", {
|
|
1992
1969
|
corpora: t.driveId.length == 0 ? "allDrives" : "drive",
|
|
1993
1970
|
driveId: t.driveId.length == 0 ? void 0 : t.driveId,
|
|
1994
|
-
fields:
|
|
1971
|
+
fields: Pt,
|
|
1995
1972
|
includeItemsFromAllDrives: "true",
|
|
1996
1973
|
pageSize: t.maxFilesPerPoll,
|
|
1997
1974
|
pageToken: a,
|
|
@@ -1999,74 +1976,74 @@ async function zt(e, t, n) {
|
|
|
1999
1976
|
spaces: "drive",
|
|
2000
1977
|
supportsAllDrives: "true"
|
|
2001
1978
|
});
|
|
2002
|
-
|
|
2003
|
-
let s =
|
|
1979
|
+
Zt(o, "files list");
|
|
1980
|
+
let s = L(o.data) ?? {}, c = new Set(n.boundaryKeys ?? []), l = [], u = [], d = a == null ? void 0 : n.maxSeen;
|
|
2004
1981
|
for (let e of s.files ?? []) {
|
|
2005
1982
|
if (e.id == null || e.id.length == 0) continue;
|
|
2006
|
-
let n =
|
|
1983
|
+
let n = Jt(e, t.changeType);
|
|
2007
1984
|
if (n == null) continue;
|
|
2008
|
-
let r =
|
|
2009
|
-
u.push(r.dedupeKey),
|
|
1985
|
+
let r = Yt(e, e.id, n, t.changeType);
|
|
1986
|
+
u.push(r.dedupeKey), tn(n, d) && (d = n), c.has(r.dedupeKey) || l.push(r);
|
|
2010
1987
|
}
|
|
2011
1988
|
if (s.incompleteSearch === !0) {
|
|
2012
|
-
let e = a == null ? {} :
|
|
1989
|
+
let e = a == null ? {} : Ut(a, i, d);
|
|
2013
1990
|
return {
|
|
2014
|
-
checkpoint:
|
|
1991
|
+
checkpoint: Wt(n, t.changeType, n.since, u, e),
|
|
2015
1992
|
events: l
|
|
2016
1993
|
};
|
|
2017
1994
|
}
|
|
2018
1995
|
if (s.nextPageToken) return {
|
|
2019
|
-
checkpoint:
|
|
1996
|
+
checkpoint: Wt(n, t.changeType, n.since, u, Ut(s.nextPageToken, i, d)),
|
|
2020
1997
|
events: l,
|
|
2021
1998
|
hasMore: !0
|
|
2022
1999
|
};
|
|
2023
2000
|
let f = d ?? n.since;
|
|
2024
2001
|
return {
|
|
2025
|
-
checkpoint:
|
|
2002
|
+
checkpoint: Wt(n, t.changeType, f, u),
|
|
2026
2003
|
events: l
|
|
2027
2004
|
};
|
|
2028
2005
|
}
|
|
2029
|
-
function
|
|
2006
|
+
function Ut(e, t, n) {
|
|
2030
2007
|
return {
|
|
2031
2008
|
pageQuery: t,
|
|
2032
2009
|
pageToken: e,
|
|
2033
2010
|
...n == null ? {} : { maxSeen: n }
|
|
2034
2011
|
};
|
|
2035
2012
|
}
|
|
2036
|
-
function
|
|
2013
|
+
function Wt(e, t, n, r, i = {}) {
|
|
2037
2014
|
let a = [.../* @__PURE__ */ new Set([...e.boundaryKeys ?? [], ...r])].map((e) => ({
|
|
2038
2015
|
at: Date.parse(e.slice(e.indexOf(":") + 1)),
|
|
2039
2016
|
key: e
|
|
2040
|
-
})).filter(({ at: t }) => t >=
|
|
2017
|
+
})).filter(({ at: t }) => t >= Kt(n, e.floor)).toSorted((e, t) => t.at - e.at).slice(0, 200).map(({ key: e }) => e);
|
|
2041
2018
|
return {
|
|
2042
2019
|
changeType: t,
|
|
2043
2020
|
since: n,
|
|
2044
|
-
...
|
|
2021
|
+
...qt(e.floor, n),
|
|
2045
2022
|
...i,
|
|
2046
2023
|
...a.length == 0 ? {} : { boundaryKeys: a }
|
|
2047
2024
|
};
|
|
2048
2025
|
}
|
|
2049
|
-
function
|
|
2026
|
+
function Gt(e, t, n) {
|
|
2050
2027
|
let r = e.changeType == "created" ? "createdTime" : "modifiedTime", i = [
|
|
2051
|
-
`'${
|
|
2028
|
+
`'${en(e.folderId)}' in parents`,
|
|
2052
2029
|
"trashed = false",
|
|
2053
|
-
`${r} >= '${new Date(
|
|
2030
|
+
`${r} >= '${new Date(Kt(t, n)).toISOString()}'`
|
|
2054
2031
|
];
|
|
2055
|
-
return e.itemTypes.has("folder") ? e.itemTypes.has("file") || i.push(`mimeType = '${
|
|
2032
|
+
return e.itemTypes.has("folder") ? e.itemTypes.has("file") || i.push(`mimeType = '${Nt}'`) : i.push(`mimeType != '${Nt}'`), e.mimeTypes.length > 0 && i.push(`(${e.mimeTypes.map((e) => `mimeType = '${en(e)}'`).join(" or ")})`), e.namePrefix.length > 0 && i.push(`name contains '${en(e.namePrefix)}'`), i.join(" and ");
|
|
2056
2033
|
}
|
|
2057
|
-
function
|
|
2034
|
+
function Kt(e, t) {
|
|
2058
2035
|
let n = Date.parse(e) - 6e4, r = t == null ? NaN : Date.parse(t);
|
|
2059
2036
|
return Number.isNaN(r) ? n : Math.max(n, r);
|
|
2060
2037
|
}
|
|
2061
|
-
function
|
|
2038
|
+
function qt(e, t) {
|
|
2062
2039
|
return e == null || Number.isNaN(Date.parse(e)) || Date.parse(t) - 6e4 >= Date.parse(e) ? {} : { floor: e };
|
|
2063
2040
|
}
|
|
2064
|
-
function
|
|
2041
|
+
function Jt(e, t) {
|
|
2065
2042
|
let n = t == "created" ? e.createdTime : e.modifiedTime;
|
|
2066
2043
|
return n == null || n.length == 0 || Number.isNaN(Date.parse(n)) ? void 0 : n;
|
|
2067
2044
|
}
|
|
2068
|
-
function
|
|
2069
|
-
let i = e.mimeType ==
|
|
2045
|
+
function Yt(e, t, n, r) {
|
|
2046
|
+
let i = e.mimeType == Nt ? "folder" : "file", a = e.lastModifyingUser;
|
|
2070
2047
|
return {
|
|
2071
2048
|
dedupeKey: `${t}:${n}`,
|
|
2072
2049
|
payload: {
|
|
@@ -2088,7 +2065,7 @@ function Kt(e, t, n, r) {
|
|
|
2088
2065
|
}
|
|
2089
2066
|
};
|
|
2090
2067
|
}
|
|
2091
|
-
async function
|
|
2068
|
+
async function Xt(e, t, r) {
|
|
2092
2069
|
try {
|
|
2093
2070
|
return await e.connector.execute({
|
|
2094
2071
|
endpoint: t,
|
|
@@ -2099,48 +2076,48 @@ async function qt(e, t, r) {
|
|
|
2099
2076
|
throw new n(`Google Drive proxy request to ${t} failed.`, { cause: e });
|
|
2100
2077
|
}
|
|
2101
2078
|
}
|
|
2102
|
-
function
|
|
2079
|
+
function Zt(r, i) {
|
|
2103
2080
|
if (!(r.status >= 200 && r.status < 300)) {
|
|
2104
|
-
if (r.status == 400 || r.status == 404) throw new
|
|
2105
|
-
if (r.status == 401) throw new
|
|
2081
|
+
if (r.status == 400 || r.status == 404) throw new e(`Google Drive ${i} rejected the configuration.`);
|
|
2082
|
+
if (r.status == 401) throw new t(`Google Drive ${i} rejected the Connection.`);
|
|
2106
2083
|
if (r.status == 403) {
|
|
2107
|
-
let a =
|
|
2108
|
-
if (a.some((e) =>
|
|
2109
|
-
if (a.some((e) =>
|
|
2110
|
-
if (
|
|
2084
|
+
let a = Qt(r.data);
|
|
2085
|
+
if (a.some((e) => Ft.has(e))) throw new n(`Google Drive ${i} was rate limited.`);
|
|
2086
|
+
if (a.some((e) => It.has(e))) throw new e(`Google Drive ${i} was rejected by an ACL.`);
|
|
2087
|
+
if ($t(r.data)) throw new t(`Google Drive ${i} needs additional scopes.`);
|
|
2111
2088
|
}
|
|
2112
2089
|
throw new n(`Google Drive ${i} failed with status ${r.status}.`);
|
|
2113
2090
|
}
|
|
2114
2091
|
}
|
|
2115
|
-
function
|
|
2116
|
-
let t =
|
|
2117
|
-
return [...[t?.errors, t?.details].flatMap((e) => Array.isArray(e) ? e : []).map((e) =>
|
|
2092
|
+
function Qt(e) {
|
|
2093
|
+
let t = L(L(e)?.error);
|
|
2094
|
+
return [...[t?.errors, t?.details].flatMap((e) => Array.isArray(e) ? e : []).map((e) => L(e)?.reason), t?.status].filter((e) => typeof e == "string");
|
|
2118
2095
|
}
|
|
2119
|
-
function
|
|
2120
|
-
if (
|
|
2121
|
-
let t =
|
|
2096
|
+
function $t(e) {
|
|
2097
|
+
if (Qt(e).includes("ACCESS_TOKEN_SCOPE_INSUFFICIENT")) return !0;
|
|
2098
|
+
let t = L(L(e)?.error)?.message;
|
|
2122
2099
|
return typeof t == "string" && t.toLowerCase().includes("insufficient authentication scopes");
|
|
2123
2100
|
}
|
|
2124
|
-
function
|
|
2101
|
+
function en(e) {
|
|
2125
2102
|
return e.replaceAll("\\", "\\\\").replaceAll("'", "\\'");
|
|
2126
2103
|
}
|
|
2127
|
-
function
|
|
2104
|
+
function tn(e, t) {
|
|
2128
2105
|
let n = Date.parse(e);
|
|
2129
2106
|
return Number.isNaN(n) ? !1 : t == null || Number.isNaN(Date.parse(t)) || n > Date.parse(t);
|
|
2130
2107
|
}
|
|
2131
|
-
function
|
|
2108
|
+
function L(e) {
|
|
2132
2109
|
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
2133
2110
|
}
|
|
2134
2111
|
//#endregion
|
|
2135
2112
|
//#region src/trigger/providers/google-sheets/on-row-added.ts
|
|
2136
|
-
var
|
|
2113
|
+
var nn = [
|
|
2137
2114
|
"permission_denied",
|
|
2138
2115
|
"accessnotconfigured",
|
|
2139
2116
|
"insufficientfilepermissions",
|
|
2140
2117
|
"appnotauthorizedtofile",
|
|
2141
2118
|
"the caller does not have permission",
|
|
2142
2119
|
"has not been used in project"
|
|
2143
|
-
],
|
|
2120
|
+
], rn = ["ratelimitexceeded", "dailylimitexceeded"], an = {
|
|
2144
2121
|
snapshot: {
|
|
2145
2122
|
configSchema: {
|
|
2146
2123
|
additionalProperties: !1,
|
|
@@ -2234,19 +2211,19 @@ var $t = [
|
|
|
2234
2211
|
type: "poll"
|
|
2235
2212
|
},
|
|
2236
2213
|
async poll(e) {
|
|
2237
|
-
let t =
|
|
2214
|
+
let t = on(e.config);
|
|
2238
2215
|
if (e.checkpoint === null) return {
|
|
2239
|
-
checkpoint: await
|
|
2216
|
+
checkpoint: await ln(e, t, await cn(e, t)),
|
|
2240
2217
|
events: []
|
|
2241
2218
|
};
|
|
2242
|
-
let n =
|
|
2219
|
+
let n = sn(e.checkpoint), r = await cn(e, t);
|
|
2243
2220
|
if (n.spreadsheetId !== t.spreadsheetId || n.sheetId !== r.sheetId || n.lastRowNumber > r.rowCount) return {
|
|
2244
|
-
checkpoint: await
|
|
2221
|
+
checkpoint: await ln(e, t, r),
|
|
2245
2222
|
events: []
|
|
2246
2223
|
};
|
|
2247
|
-
let i = await
|
|
2224
|
+
let i = await dn(e, t, r), a = Math.min(Math.max(t.firstDataRow, n.lastRowNumber), r.rowCount), o = Math.min(a + t.maxRowsPerPoll, r.rowCount), s = await fn(e, t, r, a, o, "row window fetch");
|
|
2248
2225
|
if (s.length == 0 && n.lastRowNumber >= t.firstDataRow) return {
|
|
2249
|
-
checkpoint: await
|
|
2226
|
+
checkpoint: await ln(e, t, r),
|
|
2250
2227
|
events: []
|
|
2251
2228
|
};
|
|
2252
2229
|
let c = a + s.length - 1;
|
|
@@ -2258,11 +2235,11 @@ var $t = [
|
|
|
2258
2235
|
for (let [e, o] of s.entries()) {
|
|
2259
2236
|
let s = a + e;
|
|
2260
2237
|
if (!(s <= n.lastRowNumber)) {
|
|
2261
|
-
if (s == t.headerRow ||
|
|
2238
|
+
if (s == t.headerRow || mn(o)) {
|
|
2262
2239
|
u += 1;
|
|
2263
2240
|
continue;
|
|
2264
2241
|
}
|
|
2265
|
-
l.push(await
|
|
2242
|
+
l.push(await hn(t, r, s, o, i));
|
|
2266
2243
|
}
|
|
2267
2244
|
}
|
|
2268
2245
|
let d = c == o && o < r.rowCount;
|
|
@@ -2278,7 +2255,7 @@ var $t = [
|
|
|
2278
2255
|
};
|
|
2279
2256
|
}
|
|
2280
2257
|
};
|
|
2281
|
-
function
|
|
2258
|
+
function on(e) {
|
|
2282
2259
|
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
2260
|
return {
|
|
2284
2261
|
colEnd: i,
|
|
@@ -2292,22 +2269,22 @@ function nn(e) {
|
|
|
2292
2269
|
valueRender: e.valueRender ?? "UNFORMATTED_VALUE"
|
|
2293
2270
|
};
|
|
2294
2271
|
}
|
|
2295
|
-
function
|
|
2296
|
-
let n =
|
|
2297
|
-
if (typeof n?.spreadsheetId != "string" || !Number.isInteger(n.sheetId) || !Number.isInteger(n.lastRowNumber)) throw new
|
|
2272
|
+
function sn(t) {
|
|
2273
|
+
let n = R(t);
|
|
2274
|
+
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
2275
|
return {
|
|
2299
2276
|
lastRowNumber: n.lastRowNumber,
|
|
2300
2277
|
sheetId: n.sheetId,
|
|
2301
2278
|
spreadsheetId: n.spreadsheetId
|
|
2302
2279
|
};
|
|
2303
2280
|
}
|
|
2304
|
-
async function
|
|
2305
|
-
let i = await
|
|
2306
|
-
if (i.status == 404) throw new
|
|
2307
|
-
|
|
2308
|
-
let a =
|
|
2309
|
-
if (s == null) throw new
|
|
2310
|
-
if (s.sheetType != null && s.sheetType !== "GRID") throw new
|
|
2281
|
+
async function cn(t, r) {
|
|
2282
|
+
let i = await _n(t, `/spreadsheets/${encodeURIComponent(r.spreadsheetId)}`, { fields: "sheets.properties(sheetId,title,sheetType,gridProperties)" });
|
|
2283
|
+
if (i.status == 404) throw new e("The Google Sheets spreadsheet was not found.");
|
|
2284
|
+
vn(i, "spreadsheet metadata fetch");
|
|
2285
|
+
let a = R(i.data)?.sheets, o = (Array.isArray(a) ? a.map((e) => R(R(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);
|
|
2286
|
+
if (s == null) throw new e(`Google Sheets tab "${r.sheet}" does not exist.`);
|
|
2287
|
+
if (s.sheetType != null && s.sheetType !== "GRID") throw new e("The Google Sheets tab is not a grid sheet.");
|
|
2311
2288
|
let c = s.gridProperties?.rowCount;
|
|
2312
2289
|
if (s.sheetId == null || s.title == null || c == null) throw new n("Google Sheets tab metadata is incomplete.");
|
|
2313
2290
|
return {
|
|
@@ -2316,45 +2293,45 @@ async function an(e, r) {
|
|
|
2316
2293
|
title: s.title
|
|
2317
2294
|
};
|
|
2318
2295
|
}
|
|
2319
|
-
async function
|
|
2296
|
+
async function ln(e, t, n) {
|
|
2320
2297
|
return {
|
|
2321
|
-
lastRowNumber: await
|
|
2298
|
+
lastRowNumber: await un(e, t, n),
|
|
2322
2299
|
sheetId: n.sheetId,
|
|
2323
2300
|
spreadsheetId: t.spreadsheetId
|
|
2324
2301
|
};
|
|
2325
2302
|
}
|
|
2326
|
-
async function
|
|
2303
|
+
async function un(e, t, n) {
|
|
2327
2304
|
if (n.rowCount < t.firstDataRow) return t.firstDataRow - 1;
|
|
2328
|
-
let r = await
|
|
2305
|
+
let r = await fn(e, t, n, t.firstDataRow, n.rowCount, "full-range scan");
|
|
2329
2306
|
return r.length == 0 ? t.firstDataRow - 1 : t.firstDataRow + r.length - 1;
|
|
2330
2307
|
}
|
|
2331
|
-
async function
|
|
2332
|
-
let r = await
|
|
2308
|
+
async function dn(e, t, n) {
|
|
2309
|
+
let r = await _n(e, gn(t, n, t.headerRow, t.headerRow), {
|
|
2333
2310
|
majorDimension: "ROWS",
|
|
2334
2311
|
valueRenderOption: "FORMATTED_VALUE"
|
|
2335
2312
|
});
|
|
2336
|
-
return
|
|
2313
|
+
return vn(r, "header row fetch"), pn(r.data)[0] ?? [];
|
|
2337
2314
|
}
|
|
2338
|
-
async function
|
|
2339
|
-
let o = await
|
|
2315
|
+
async function fn(e, t, n, r, i, a) {
|
|
2316
|
+
let o = await _n(e, gn(t, n, r, i), {
|
|
2340
2317
|
dateTimeRenderOption: t.dateTimeRender,
|
|
2341
2318
|
majorDimension: "ROWS",
|
|
2342
2319
|
valueRenderOption: t.valueRender
|
|
2343
2320
|
});
|
|
2344
|
-
return
|
|
2321
|
+
return vn(o, a), pn(o.data);
|
|
2345
2322
|
}
|
|
2346
|
-
function
|
|
2347
|
-
let t =
|
|
2323
|
+
function pn(e) {
|
|
2324
|
+
let t = R(e)?.values;
|
|
2348
2325
|
return Array.isArray(t) ? t : [];
|
|
2349
2326
|
}
|
|
2350
|
-
function
|
|
2327
|
+
function mn(e) {
|
|
2351
2328
|
return e.every((e) => e === "" || e == null);
|
|
2352
2329
|
}
|
|
2353
|
-
async function
|
|
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 =
|
|
2330
|
+
async function hn(e, t, n, r, i) {
|
|
2331
|
+
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 = yn(e.colStart);
|
|
2355
2332
|
for (let [e, t] of r.entries()) {
|
|
2356
2333
|
let n = i[e];
|
|
2357
|
-
s[typeof n == "string" && n.length > 0 ? n :
|
|
2334
|
+
s[typeof n == "string" && n.length > 0 ? n : bn(c + e)] = t;
|
|
2358
2335
|
}
|
|
2359
2336
|
return {
|
|
2360
2337
|
dedupeKey: `${t.sheetId}:${n}:${o}`,
|
|
@@ -2368,11 +2345,11 @@ async function fn(e, t, n, r, i) {
|
|
|
2368
2345
|
}
|
|
2369
2346
|
};
|
|
2370
2347
|
}
|
|
2371
|
-
function
|
|
2348
|
+
function gn(e, t, n, r) {
|
|
2372
2349
|
let i = encodeURIComponent(`'${t.title.replaceAll("'", "''")}'`);
|
|
2373
2350
|
return `/spreadsheets/${encodeURIComponent(e.spreadsheetId)}/values/${i}!${e.colStart}${n}:${e.colEnd}${r}`;
|
|
2374
2351
|
}
|
|
2375
|
-
async function
|
|
2352
|
+
async function _n(e, t, r) {
|
|
2376
2353
|
try {
|
|
2377
2354
|
return await e.connector.execute({
|
|
2378
2355
|
endpoint: t,
|
|
@@ -2383,30 +2360,30 @@ async function mn(e, t, r) {
|
|
|
2383
2360
|
throw new n(`Google Sheets proxy request to ${t} failed.`, { cause: e });
|
|
2384
2361
|
}
|
|
2385
2362
|
}
|
|
2386
|
-
function
|
|
2363
|
+
function vn(r, i) {
|
|
2387
2364
|
if (r.status >= 200 && r.status < 300) return;
|
|
2388
|
-
if (r.status == 401) throw new
|
|
2365
|
+
if (r.status == 401) throw new t(`Google Sheets ${i} rejected the Connection.`);
|
|
2389
2366
|
let a = JSON.stringify(r.data ?? null).toLowerCase();
|
|
2390
2367
|
if (r.status == 403) {
|
|
2391
|
-
if (
|
|
2392
|
-
if (
|
|
2368
|
+
if (rn.some((e) => a.includes(e))) throw new n(`Google Sheets ${i} was rate limited.`);
|
|
2369
|
+
if (nn.some((e) => a.includes(e))) throw new t(`Google Sheets ${i} rejected the Connection.`);
|
|
2393
2370
|
}
|
|
2394
|
-
throw r.status == 400 && a.includes("unable to parse range") ? new
|
|
2371
|
+
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
2372
|
}
|
|
2396
|
-
function
|
|
2373
|
+
function yn(e) {
|
|
2397
2374
|
let t = 0;
|
|
2398
2375
|
for (let n of e.toUpperCase()) t = t * 26 + n.charCodeAt(0) - 64;
|
|
2399
2376
|
return t;
|
|
2400
2377
|
}
|
|
2401
|
-
function
|
|
2378
|
+
function bn(e) {
|
|
2402
2379
|
let t = "";
|
|
2403
2380
|
for (let n = e; n > 0; n = Math.floor((n - 1) / 26)) t = String.fromCharCode(65 + (n - 1) % 26) + t;
|
|
2404
2381
|
return t;
|
|
2405
2382
|
}
|
|
2406
|
-
function
|
|
2383
|
+
function R(e) {
|
|
2407
2384
|
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
2408
2385
|
}
|
|
2409
|
-
var
|
|
2386
|
+
var xn = {
|
|
2410
2387
|
snapshot: {
|
|
2411
2388
|
configSchema: {
|
|
2412
2389
|
additionalProperties: !1,
|
|
@@ -2495,13 +2472,13 @@ var vn = {
|
|
|
2495
2472
|
type: "poll"
|
|
2496
2473
|
},
|
|
2497
2474
|
async poll(e) {
|
|
2498
|
-
let t =
|
|
2499
|
-
if (e.checkpoint === null) return
|
|
2500
|
-
let n =
|
|
2501
|
-
return n.target ===
|
|
2475
|
+
let t = Sn(e.config);
|
|
2476
|
+
if (e.checkpoint === null) return Cn(e, t);
|
|
2477
|
+
let n = Tn(e.checkpoint);
|
|
2478
|
+
return n.target === Ln(t) ? On(e, t, Dn(n, En(t.events))) : Cn(e, t);
|
|
2502
2479
|
}
|
|
2503
2480
|
};
|
|
2504
|
-
function
|
|
2481
|
+
function Sn(e) {
|
|
2505
2482
|
return {
|
|
2506
2483
|
dataSourceId: e.dataSourceId ?? "",
|
|
2507
2484
|
databaseId: e.databaseId,
|
|
@@ -2510,9 +2487,9 @@ function yn(e) {
|
|
|
2510
2487
|
maxItemsPerPoll: e.maxItemsPerPoll ?? 25
|
|
2511
2488
|
};
|
|
2512
2489
|
}
|
|
2513
|
-
async function
|
|
2514
|
-
let n = await
|
|
2515
|
-
return
|
|
2490
|
+
async function Cn(e, t) {
|
|
2491
|
+
let n = await wn(e, t), r = En(t.events);
|
|
2492
|
+
return In(await Fn(e, {
|
|
2516
2493
|
body: {
|
|
2517
2494
|
page_size: 1,
|
|
2518
2495
|
sorts: [{
|
|
@@ -2527,32 +2504,32 @@ async function bn(e, t) {
|
|
|
2527
2504
|
cursorField: r,
|
|
2528
2505
|
dataSourceId: n,
|
|
2529
2506
|
since: (/* @__PURE__ */ new Date(Math.ceil(e.now.getTime() / 6e4) * 6e4)).toISOString(),
|
|
2530
|
-
target:
|
|
2507
|
+
target: Ln(t)
|
|
2531
2508
|
},
|
|
2532
2509
|
events: []
|
|
2533
2510
|
};
|
|
2534
2511
|
}
|
|
2535
|
-
async function
|
|
2536
|
-
let r = await
|
|
2512
|
+
async function wn(t, n) {
|
|
2513
|
+
let r = await Fn(t, {
|
|
2537
2514
|
endpoint: `/databases/${encodeURIComponent(n.databaseId)}`,
|
|
2538
2515
|
method: "GET"
|
|
2539
2516
|
});
|
|
2540
|
-
|
|
2541
|
-
let i =
|
|
2542
|
-
let t =
|
|
2517
|
+
In(r, "database resolve");
|
|
2518
|
+
let i = z(r.data)?.data_sources, a = Array.isArray(i) ? i.flatMap((e) => {
|
|
2519
|
+
let t = z(e)?.id;
|
|
2543
2520
|
return typeof t == "string" && t.length > 0 ? [t] : [];
|
|
2544
2521
|
}) : [];
|
|
2545
2522
|
if (n.dataSourceId.length > 0) {
|
|
2546
|
-
let
|
|
2547
|
-
if (r == null) throw new
|
|
2523
|
+
let t = Rn(n.dataSourceId), r = a.find((e) => Rn(e) == t);
|
|
2524
|
+
if (r == null) throw new e("The Notion data source does not belong to the configured database.");
|
|
2548
2525
|
return r;
|
|
2549
2526
|
}
|
|
2550
2527
|
if (a.length == 1) return a[0];
|
|
2551
|
-
throw a.length == 0 ? new
|
|
2528
|
+
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
2529
|
}
|
|
2553
|
-
function
|
|
2554
|
-
let n =
|
|
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
|
|
2530
|
+
function Tn(t) {
|
|
2531
|
+
let n = z(t), r = n?.cursorField;
|
|
2532
|
+
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
2533
|
return {
|
|
2557
2534
|
cursorField: r,
|
|
2558
2535
|
dataSourceId: n.dataSourceId,
|
|
@@ -2563,10 +2540,10 @@ function Sn(e) {
|
|
|
2563
2540
|
...n.sinceOnly === !0 ? { sinceOnly: !0 } : {}
|
|
2564
2541
|
};
|
|
2565
2542
|
}
|
|
2566
|
-
function
|
|
2543
|
+
function En(e) {
|
|
2567
2544
|
return e.length == 1 && e[0] == "page_added" ? "created_time" : "last_edited_time";
|
|
2568
2545
|
}
|
|
2569
|
-
function
|
|
2546
|
+
function Dn(e, t) {
|
|
2570
2547
|
return e.cursorField == t ? e : {
|
|
2571
2548
|
cursorField: t,
|
|
2572
2549
|
dataSourceId: e.dataSourceId,
|
|
@@ -2574,11 +2551,11 @@ function wn(e, t) {
|
|
|
2574
2551
|
target: e.target
|
|
2575
2552
|
};
|
|
2576
2553
|
}
|
|
2577
|
-
async function
|
|
2554
|
+
async function On(e, t, n) {
|
|
2578
2555
|
let r = [], i = 0, a = 0, o = null, s = n.startCursor, c = null;
|
|
2579
2556
|
for (let l = 0; l < 5; l += 1) {
|
|
2580
|
-
let l = await
|
|
2581
|
-
body:
|
|
2557
|
+
let l = await Fn(e, {
|
|
2558
|
+
body: jn(n, t.maxItemsPerPoll - a, s),
|
|
2582
2559
|
endpoint: `/data_sources/${encodeURIComponent(n.dataSourceId)}/query`,
|
|
2583
2560
|
method: "POST"
|
|
2584
2561
|
});
|
|
@@ -2586,14 +2563,14 @@ async function Tn(e, t, n) {
|
|
|
2586
2563
|
c = "restarted";
|
|
2587
2564
|
break;
|
|
2588
2565
|
}
|
|
2589
|
-
|
|
2590
|
-
let u =
|
|
2566
|
+
In(l, "data source query");
|
|
2567
|
+
let u = z(l.data) ?? {};
|
|
2591
2568
|
for (let e of u.results ?? []) {
|
|
2592
2569
|
a += 1;
|
|
2593
2570
|
let s = n.cursorField == "created_time" ? e.created_time : e.last_edited_time;
|
|
2594
|
-
s != null && s.length > 0 && (o =
|
|
2595
|
-
let c =
|
|
2596
|
-
t.events.includes(c) ? r.push(
|
|
2571
|
+
s != null && s.length > 0 && (o = Bn(o, s));
|
|
2572
|
+
let c = Mn(e);
|
|
2573
|
+
t.events.includes(c) ? r.push(Nn(e, c, t, n)) : i += 1;
|
|
2597
2574
|
}
|
|
2598
2575
|
if (u.request_status?.type == "incomplete") {
|
|
2599
2576
|
c = "truncated";
|
|
@@ -2619,36 +2596,36 @@ async function Tn(e, t, n) {
|
|
|
2619
2596
|
...l,
|
|
2620
2597
|
since: n.since,
|
|
2621
2598
|
startCursor: c.nextCursor,
|
|
2622
|
-
...
|
|
2599
|
+
...An(n)
|
|
2623
2600
|
} : {
|
|
2624
2601
|
...l,
|
|
2625
|
-
...
|
|
2602
|
+
...kn(n, c, o, e.now)
|
|
2626
2603
|
},
|
|
2627
2604
|
events: r,
|
|
2628
2605
|
filtered: i,
|
|
2629
2606
|
...c == "complete" ? {} : { hasMore: !0 }
|
|
2630
2607
|
};
|
|
2631
2608
|
}
|
|
2632
|
-
function
|
|
2609
|
+
function kn(e, t, n, r) {
|
|
2633
2610
|
let i = {
|
|
2634
2611
|
since: e.since,
|
|
2635
|
-
...
|
|
2612
|
+
...An(e)
|
|
2636
2613
|
}, a = Date.parse(e.since) + 6e4 <= r.getTime() ? {
|
|
2637
2614
|
since: e.since,
|
|
2638
2615
|
sinceExclusive: !0
|
|
2639
2616
|
} : i;
|
|
2640
|
-
return n != null &&
|
|
2617
|
+
return n != null && Vn(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
2618
|
since: e.since,
|
|
2642
2619
|
sinceOnly: !0
|
|
2643
2620
|
};
|
|
2644
2621
|
}
|
|
2645
|
-
function
|
|
2622
|
+
function An(e) {
|
|
2646
2623
|
return {
|
|
2647
2624
|
...e.sinceExclusive === !0 ? { sinceExclusive: !0 } : {},
|
|
2648
2625
|
...e.sinceOnly === !0 ? { sinceOnly: !0 } : {}
|
|
2649
2626
|
};
|
|
2650
2627
|
}
|
|
2651
|
-
function
|
|
2628
|
+
function jn(e, t, n) {
|
|
2652
2629
|
let r = e.cursorField;
|
|
2653
2630
|
return {
|
|
2654
2631
|
filter: e.sinceOnly === !0 ? { and: [{
|
|
@@ -2669,70 +2646,70 @@ function On(e, t, n) {
|
|
|
2669
2646
|
...n == null ? {} : { start_cursor: n }
|
|
2670
2647
|
};
|
|
2671
2648
|
}
|
|
2672
|
-
function
|
|
2673
|
-
return
|
|
2649
|
+
function Mn(e) {
|
|
2650
|
+
return Hn(e.created_time) === Hn(e.last_edited_time) ? "page_added" : "page_updated";
|
|
2674
2651
|
}
|
|
2675
|
-
function
|
|
2652
|
+
function Nn(e, t, n, r) {
|
|
2676
2653
|
return {
|
|
2677
|
-
dedupeKey: t == "page_added" ? `added:${e.id}` : `updated:${e.id}:${
|
|
2654
|
+
dedupeKey: t == "page_added" ? `added:${e.id}` : `updated:${e.id}:${Hn(e.last_edited_time) ?? e.last_edited_time ?? ""}`,
|
|
2678
2655
|
payload: {
|
|
2679
2656
|
createdBy: { id: e.created_by?.id ?? "" },
|
|
2680
2657
|
createdTime: e.created_time ?? "",
|
|
2681
2658
|
dataSourceId: r.dataSourceId,
|
|
2682
|
-
databaseId:
|
|
2659
|
+
databaseId: zn(n.databaseId),
|
|
2683
2660
|
event: t,
|
|
2684
2661
|
lastEditedBy: { id: e.last_edited_by?.id ?? "" },
|
|
2685
2662
|
lastEditedTime: e.last_edited_time ?? "",
|
|
2686
2663
|
pageId: e.id,
|
|
2687
2664
|
...n.includeProperties ? { properties: e.properties ?? {} } : {},
|
|
2688
|
-
title:
|
|
2665
|
+
title: Pn(e.properties ?? {}),
|
|
2689
2666
|
url: e.url ?? ""
|
|
2690
2667
|
}
|
|
2691
2668
|
};
|
|
2692
2669
|
}
|
|
2693
|
-
function
|
|
2670
|
+
function Pn(e) {
|
|
2694
2671
|
for (let t of Object.values(e)) {
|
|
2695
|
-
let e =
|
|
2696
|
-
if (!(e?.type !== "title" || !Array.isArray(e.title))) return e.title.map((e) => typeof
|
|
2672
|
+
let e = z(t);
|
|
2673
|
+
if (!(e?.type !== "title" || !Array.isArray(e.title))) return e.title.map((e) => typeof z(e)?.plain_text == "string" ? z(e).plain_text : "").join("");
|
|
2697
2674
|
}
|
|
2698
2675
|
return "";
|
|
2699
2676
|
}
|
|
2700
|
-
async function
|
|
2677
|
+
async function Fn(e, t) {
|
|
2701
2678
|
try {
|
|
2702
2679
|
return await e.connector.execute(t, e.signal);
|
|
2703
2680
|
} catch (e) {
|
|
2704
2681
|
throw new n(`Notion proxy request to ${t.endpoint} failed.`, { cause: e });
|
|
2705
2682
|
}
|
|
2706
2683
|
}
|
|
2707
|
-
function
|
|
2708
|
-
if (!(r.status >= 200 && r.status < 300)) throw r.status == 401 || r.status == 403 ? new
|
|
2684
|
+
function In(r, i) {
|
|
2685
|
+
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
2686
|
}
|
|
2710
|
-
function
|
|
2687
|
+
function Ln(e) {
|
|
2711
2688
|
return `${e.databaseId}|${e.dataSourceId}`;
|
|
2712
2689
|
}
|
|
2713
|
-
function
|
|
2690
|
+
function Rn(e) {
|
|
2714
2691
|
return e.replaceAll("-", "").toLowerCase();
|
|
2715
2692
|
}
|
|
2716
|
-
function
|
|
2717
|
-
let t =
|
|
2693
|
+
function zn(e) {
|
|
2694
|
+
let t = Rn(e);
|
|
2718
2695
|
return `${t.slice(0, 8)}-${t.slice(8, 12)}-${t.slice(12, 16)}-${t.slice(16, 20)}-${t.slice(20)}`;
|
|
2719
2696
|
}
|
|
2720
|
-
function
|
|
2697
|
+
function Bn(e, t) {
|
|
2721
2698
|
let n = Date.parse(t);
|
|
2722
2699
|
return Number.isNaN(n) || e != null && n < Date.parse(e) ? e : t;
|
|
2723
2700
|
}
|
|
2724
|
-
function
|
|
2701
|
+
function Vn(e, t) {
|
|
2725
2702
|
return !Number.isNaN(Date.parse(e)) && !Number.isNaN(Date.parse(t)) && Date.parse(e) > Date.parse(t);
|
|
2726
2703
|
}
|
|
2727
|
-
function
|
|
2704
|
+
function Hn(e) {
|
|
2728
2705
|
if (e == null || e.length == 0) return null;
|
|
2729
2706
|
let t = Date.parse(e);
|
|
2730
2707
|
return Number.isNaN(t) ? null : new Date(t).toISOString();
|
|
2731
2708
|
}
|
|
2732
|
-
function
|
|
2709
|
+
function z(e) {
|
|
2733
2710
|
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
2734
2711
|
}
|
|
2735
|
-
var
|
|
2712
|
+
var Un = {
|
|
2736
2713
|
snapshot: {
|
|
2737
2714
|
configSchema: {
|
|
2738
2715
|
additionalProperties: !1,
|
|
@@ -2839,14 +2816,14 @@ var Bn = {
|
|
|
2839
2816
|
type: "poll"
|
|
2840
2817
|
},
|
|
2841
2818
|
async poll(e) {
|
|
2842
|
-
let t =
|
|
2819
|
+
let t = Wn(e.config);
|
|
2843
2820
|
if (e.checkpoint === null) return {
|
|
2844
|
-
checkpoint: await
|
|
2821
|
+
checkpoint: await Gn(e, t),
|
|
2845
2822
|
events: []
|
|
2846
2823
|
};
|
|
2847
|
-
let n =
|
|
2824
|
+
let n = qn(e.checkpoint), { items: r, next: i } = await Jn(e, n, t.maxItemsPerPoll), a = [], o = 0;
|
|
2848
2825
|
for (let [e, i] of r) {
|
|
2849
|
-
let r =
|
|
2826
|
+
let r = Yn(e, i, t, new Date(n.lastPolledAt));
|
|
2850
2827
|
r != "structural" && (r == "filtered" ? o += 1 : a.push(r));
|
|
2851
2828
|
}
|
|
2852
2829
|
return {
|
|
@@ -2857,7 +2834,7 @@ var Bn = {
|
|
|
2857
2834
|
};
|
|
2858
2835
|
}
|
|
2859
2836
|
};
|
|
2860
|
-
function
|
|
2837
|
+
function Wn(e) {
|
|
2861
2838
|
return {
|
|
2862
2839
|
events: e.events ?? ["created", "updated"],
|
|
2863
2840
|
itemId: (e.itemId ?? "").trim(),
|
|
@@ -2866,54 +2843,54 @@ function Vn(e) {
|
|
|
2866
2843
|
parentFolderId: (e.parentFolderId ?? "").trim()
|
|
2867
2844
|
};
|
|
2868
2845
|
}
|
|
2869
|
-
async function
|
|
2870
|
-
let i = await
|
|
2871
|
-
if (i.status == 404) throw new
|
|
2872
|
-
|
|
2873
|
-
let a =
|
|
2846
|
+
async function Gn(t, r) {
|
|
2847
|
+
let i = await Qn(t, "/me/drive/root/delta", { token: "latest" });
|
|
2848
|
+
if (i.status == 404) throw new e("OneDrive is not provisioned for this account.");
|
|
2849
|
+
er(i, "delta seeding");
|
|
2850
|
+
let a = B(i.data)?.["@odata.deltaLink"], o = a == null ? null : rr(a);
|
|
2874
2851
|
if (o == null) throw new n("OneDrive delta seeding response has no delta token.");
|
|
2875
|
-
return await
|
|
2852
|
+
return await Kn(t, "parentFolderId", r.parentFolderId), await Kn(t, "itemId", r.itemId), {
|
|
2876
2853
|
deltaToken: o,
|
|
2877
|
-
lastPolledAt:
|
|
2854
|
+
lastPolledAt: t.now.toISOString()
|
|
2878
2855
|
};
|
|
2879
2856
|
}
|
|
2880
|
-
async function
|
|
2857
|
+
async function Kn(t, n, r) {
|
|
2881
2858
|
if (r.length == 0) return;
|
|
2882
|
-
let i = await
|
|
2883
|
-
if (i.status == 400 || i.status == 404) throw new
|
|
2884
|
-
|
|
2859
|
+
let i = await Qn(t, `/me/drive/items/${encodeURIComponent(r)}`, {});
|
|
2860
|
+
if (i.status == 400 || i.status == 404) throw new e(`OneDrive ${n} does not identify an item in this drive.`);
|
|
2861
|
+
er(i, `${n} validation`);
|
|
2885
2862
|
}
|
|
2886
|
-
function
|
|
2887
|
-
let n =
|
|
2888
|
-
if (typeof n?.deltaToken != "string" || n.deltaToken.length == 0 || typeof n.lastPolledAt != "string" || Number.isNaN(Date.parse(n.lastPolledAt))) throw new
|
|
2863
|
+
function qn(t) {
|
|
2864
|
+
let n = B(t);
|
|
2865
|
+
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
2866
|
return {
|
|
2890
2867
|
deltaToken: n.deltaToken,
|
|
2891
2868
|
lastPolledAt: n.lastPolledAt,
|
|
2892
2869
|
...typeof n.pageToken == "string" && n.pageToken.length > 0 ? { pageToken: n.pageToken } : {}
|
|
2893
2870
|
};
|
|
2894
2871
|
}
|
|
2895
|
-
async function
|
|
2872
|
+
async function Jn(e, t, r) {
|
|
2896
2873
|
let i = /* @__PURE__ */ new Map(), a = t.pageToken ?? t.deltaToken;
|
|
2897
2874
|
for (let t = 0; t < 5; t += 1) {
|
|
2898
|
-
let t = await
|
|
2875
|
+
let t = await Qn(e, "/me/drive/root/delta", {
|
|
2899
2876
|
$top: r,
|
|
2900
2877
|
token: a
|
|
2901
2878
|
});
|
|
2902
|
-
|
|
2903
|
-
let o =
|
|
2879
|
+
$n(t);
|
|
2880
|
+
let o = B(t.data) ?? {};
|
|
2904
2881
|
for (let e of o.value ?? []) e.id != null && e.id.length > 0 && i.set(e.id, e);
|
|
2905
2882
|
if (o["@odata.deltaLink"]) return {
|
|
2906
2883
|
items: i,
|
|
2907
2884
|
next: {
|
|
2908
2885
|
checkpoint: {
|
|
2909
|
-
deltaToken:
|
|
2886
|
+
deltaToken: nr(o["@odata.deltaLink"]),
|
|
2910
2887
|
lastPolledAt: e.now.toISOString()
|
|
2911
2888
|
},
|
|
2912
2889
|
hasMore: !1
|
|
2913
2890
|
}
|
|
2914
2891
|
};
|
|
2915
2892
|
if (!o["@odata.nextLink"]) throw new n("OneDrive delta response has no continuation link.");
|
|
2916
|
-
a =
|
|
2893
|
+
a = nr(o["@odata.nextLink"]);
|
|
2917
2894
|
}
|
|
2918
2895
|
return {
|
|
2919
2896
|
items: i,
|
|
@@ -2927,17 +2904,17 @@ async function Gn(e, t, r) {
|
|
|
2927
2904
|
}
|
|
2928
2905
|
};
|
|
2929
2906
|
}
|
|
2930
|
-
function
|
|
2907
|
+
function Yn(e, t, n, r) {
|
|
2931
2908
|
if (t.root != null) return "structural";
|
|
2932
|
-
let i =
|
|
2909
|
+
let i = Xn(t);
|
|
2933
2910
|
if (i == null) return "structural";
|
|
2934
|
-
let a = t.deleted == null ?
|
|
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" :
|
|
2911
|
+
let a = t.deleted == null ? ir(t.createdDateTime, r) ? "created" : "updated" : "deleted";
|
|
2912
|
+
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" : Zn(e, t, a, i);
|
|
2936
2913
|
}
|
|
2937
|
-
function
|
|
2914
|
+
function Xn(e) {
|
|
2938
2915
|
return e.file == null ? e.folder == null ? e.deleted == null ? null : "file" : "folder" : "file";
|
|
2939
2916
|
}
|
|
2940
|
-
function
|
|
2917
|
+
function Zn(e, t, n, r) {
|
|
2941
2918
|
return {
|
|
2942
2919
|
dedupeKey: t.deleted == null ? `${e}:${t.eTag ?? t.lastModifiedDateTime}` : `${e}:deleted`,
|
|
2943
2920
|
payload: {
|
|
@@ -2956,7 +2933,7 @@ function Jn(e, t, n, r) {
|
|
|
2956
2933
|
}
|
|
2957
2934
|
};
|
|
2958
2935
|
}
|
|
2959
|
-
async function
|
|
2936
|
+
async function Qn(e, t, r) {
|
|
2960
2937
|
try {
|
|
2961
2938
|
return await e.connector.execute({
|
|
2962
2939
|
endpoint: t,
|
|
@@ -2967,31 +2944,31 @@ async function Yn(e, t, r) {
|
|
|
2967
2944
|
throw new n(`OneDrive proxy request to ${t} failed.`, { cause: e });
|
|
2968
2945
|
}
|
|
2969
2946
|
}
|
|
2970
|
-
function
|
|
2971
|
-
if (
|
|
2972
|
-
if (
|
|
2973
|
-
if (
|
|
2974
|
-
|
|
2947
|
+
function $n(t) {
|
|
2948
|
+
if (t.status == 410 && tr(t.data)) throw new e("OneDrive delta token expired; recreate the Trigger.");
|
|
2949
|
+
if (t.status == 404) throw new e("OneDrive is not provisioned for this account.");
|
|
2950
|
+
if (t.status == 400) throw new e("OneDrive rejected the delta token; recreate the Trigger.");
|
|
2951
|
+
er(t, "delta list");
|
|
2975
2952
|
}
|
|
2976
|
-
function
|
|
2977
|
-
if (!(
|
|
2953
|
+
function er(e, r) {
|
|
2954
|
+
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
2955
|
}
|
|
2979
|
-
function
|
|
2980
|
-
let t =
|
|
2956
|
+
function tr(e) {
|
|
2957
|
+
let t = B(e)?.error;
|
|
2981
2958
|
for (; t != null;) {
|
|
2982
|
-
let e =
|
|
2959
|
+
let e = B(t);
|
|
2983
2960
|
if (e == null) break;
|
|
2984
2961
|
if (e.code == "resyncChangesApplyDifferences" || e.code == "resyncChangesUploadDifferences") return !0;
|
|
2985
2962
|
t = e.innerError ?? e.innererror;
|
|
2986
2963
|
}
|
|
2987
2964
|
return !1;
|
|
2988
2965
|
}
|
|
2989
|
-
function
|
|
2990
|
-
let t =
|
|
2966
|
+
function nr(e) {
|
|
2967
|
+
let t = rr(e);
|
|
2991
2968
|
if (t == null) throw new n("OneDrive delta link has no token.");
|
|
2992
2969
|
return t;
|
|
2993
2970
|
}
|
|
2994
|
-
function
|
|
2971
|
+
function rr(e) {
|
|
2995
2972
|
let t = /[?&]token=([^&#]+)/.exec(e)?.[1] ?? /\(token='([^']+)'\)/.exec(e)?.[1];
|
|
2996
2973
|
if (t == null) return null;
|
|
2997
2974
|
try {
|
|
@@ -3000,24 +2977,24 @@ function er(e) {
|
|
|
3000
2977
|
return t;
|
|
3001
2978
|
}
|
|
3002
2979
|
}
|
|
3003
|
-
function
|
|
2980
|
+
function ir(e, t) {
|
|
3004
2981
|
if (e == null || e.length == 0) return !1;
|
|
3005
2982
|
let n = new Date(e);
|
|
3006
2983
|
return !Number.isNaN(n.getTime()) && n >= t;
|
|
3007
2984
|
}
|
|
3008
|
-
function
|
|
2985
|
+
function B(e) {
|
|
3009
2986
|
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
3010
2987
|
}
|
|
3011
2988
|
//#endregion
|
|
3012
2989
|
//#region src/trigger/providers/outlook/on-message-received.ts
|
|
3013
|
-
var
|
|
2990
|
+
var ar = "inbox", or = 25, sr = 100, cr = "1970-01-01T00:00:00Z", lr = "id,internetMessageId,conversationId,subject,bodyPreview,from,toRecipients,receivedDateTime,hasAttachments,isRead,isDraft,importance,categories,parentFolderId,webLink", ur = {
|
|
3014
2991
|
snapshot: {
|
|
3015
2992
|
configSchema: {
|
|
3016
2993
|
additionalProperties: !1,
|
|
3017
2994
|
description: "Configuration for outlook.on_message_received. Every configured matching field must match.",
|
|
3018
2995
|
properties: {
|
|
3019
2996
|
folder: {
|
|
3020
|
-
default:
|
|
2997
|
+
default: ar,
|
|
3021
2998
|
description: "A well-known mail folder name, folder ID, or an empty string for the whole mailbox.",
|
|
3022
2999
|
pattern: "^[A-Za-z0-9_=-]*$",
|
|
3023
3000
|
type: "string"
|
|
@@ -3027,7 +3004,7 @@ var nr = "inbox", rr = 25, ir = 100, ar = "1970-01-01T00:00:00Z", or = "id,inter
|
|
|
3027
3004
|
type: "boolean"
|
|
3028
3005
|
},
|
|
3029
3006
|
maxMessagesPerPoll: {
|
|
3030
|
-
default:
|
|
3007
|
+
default: or,
|
|
3031
3008
|
maximum: 100,
|
|
3032
3009
|
minimum: 1,
|
|
3033
3010
|
type: "integer"
|
|
@@ -3122,38 +3099,38 @@ var nr = "inbox", rr = 25, ir = 100, ar = "1970-01-01T00:00:00Z", or = "id,inter
|
|
|
3122
3099
|
provider: "outlook",
|
|
3123
3100
|
type: "poll"
|
|
3124
3101
|
},
|
|
3125
|
-
async poll(
|
|
3126
|
-
let n =
|
|
3127
|
-
if (
|
|
3128
|
-
checkpoint: await
|
|
3102
|
+
async poll(t) {
|
|
3103
|
+
let n = dr(t.config);
|
|
3104
|
+
if (t.checkpoint === null) return {
|
|
3105
|
+
checkpoint: await fr(t, n),
|
|
3129
3106
|
events: []
|
|
3130
3107
|
};
|
|
3131
|
-
let r =
|
|
3132
|
-
$filter:
|
|
3108
|
+
let r = pr(t.checkpoint), i = await vr(t, mr(n.folder), {
|
|
3109
|
+
$filter: hr(n, r.lastReceivedDateTime),
|
|
3133
3110
|
$orderby: "receivedDateTime asc",
|
|
3134
|
-
$select:
|
|
3111
|
+
$select: lr,
|
|
3135
3112
|
$top: n.maxMessagesPerPoll
|
|
3136
3113
|
});
|
|
3137
|
-
|
|
3138
|
-
let a =
|
|
3114
|
+
yr(i, "message list");
|
|
3115
|
+
let a = xr(i.data);
|
|
3139
3116
|
if (a.length == 0) return {
|
|
3140
3117
|
checkpoint: r,
|
|
3141
3118
|
events: []
|
|
3142
3119
|
};
|
|
3143
3120
|
let o = Date.parse(r.lastReceivedDateTime), s = o, c = r.lastReceivedDateTime;
|
|
3144
3121
|
for (let e of a) {
|
|
3145
|
-
let t =
|
|
3122
|
+
let t = V(e.receivedDateTime);
|
|
3146
3123
|
e.receivedDateTime != null && t != null && t > s && (s = t, c = e.receivedDateTime);
|
|
3147
3124
|
}
|
|
3148
3125
|
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
|
|
3126
|
+
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
3127
|
let f = new Set(l ? [] : r.boundaryMessageIds), p = [], m = 0;
|
|
3151
|
-
for (let e of a) if (e.id != null && e.id.length != 0 && (
|
|
3152
|
-
if (!
|
|
3128
|
+
for (let e of a) if (e.id != null && e.id.length != 0 && (V(e.receivedDateTime) == s && f.add(e.id), !u.has(e.id))) {
|
|
3129
|
+
if (!gr(e, n)) {
|
|
3153
3130
|
m += 1;
|
|
3154
3131
|
continue;
|
|
3155
3132
|
}
|
|
3156
|
-
p.push(
|
|
3133
|
+
p.push(_r(e, e.id));
|
|
3157
3134
|
}
|
|
3158
3135
|
let h = d && (l || p.length > 0);
|
|
3159
3136
|
return {
|
|
@@ -3167,34 +3144,34 @@ var nr = "inbox", rr = 25, ir = 100, ar = "1970-01-01T00:00:00Z", or = "id,inter
|
|
|
3167
3144
|
};
|
|
3168
3145
|
}
|
|
3169
3146
|
};
|
|
3170
|
-
function
|
|
3147
|
+
function dr(e) {
|
|
3171
3148
|
return {
|
|
3172
|
-
folder: e.folder ??
|
|
3149
|
+
folder: e.folder ?? ar,
|
|
3173
3150
|
includeDrafts: e.includeDrafts ?? !1,
|
|
3174
|
-
maxMessagesPerPoll: e.maxMessagesPerPoll ??
|
|
3151
|
+
maxMessagesPerPoll: e.maxMessagesPerPoll ?? or,
|
|
3175
3152
|
readStatus: e.readStatus ?? "All",
|
|
3176
3153
|
senderAddress: (e.senderAddress ?? "").trim(),
|
|
3177
3154
|
subjectContains: (e.subjectContains ?? "").trim(),
|
|
3178
3155
|
withAttachmentsOnly: e.withAttachmentsOnly ?? !1
|
|
3179
3156
|
};
|
|
3180
3157
|
}
|
|
3181
|
-
async function
|
|
3182
|
-
let n = await
|
|
3158
|
+
async function fr(e, t) {
|
|
3159
|
+
let n = await vr(e, mr(t.folder), {
|
|
3183
3160
|
$orderby: "receivedDateTime desc",
|
|
3184
3161
|
$select: "id,receivedDateTime",
|
|
3185
|
-
$top:
|
|
3162
|
+
$top: sr
|
|
3186
3163
|
});
|
|
3187
|
-
|
|
3188
|
-
$filter:
|
|
3164
|
+
yr(n, "seed marker fetch"), yr(await vr(e, mr(t.folder), {
|
|
3165
|
+
$filter: hr(t, cr),
|
|
3189
3166
|
$orderby: "receivedDateTime desc",
|
|
3190
3167
|
$top: 1
|
|
3191
3168
|
}), "seed filter shape check");
|
|
3192
|
-
let r =
|
|
3169
|
+
let r = Sr(xr(n.data));
|
|
3193
3170
|
if (r == null) return {
|
|
3194
3171
|
boundaryMessageIds: [],
|
|
3195
3172
|
lastReceivedDateTime: e.now.toISOString()
|
|
3196
3173
|
};
|
|
3197
|
-
let i =
|
|
3174
|
+
let i = xr(n.data).filter((e) => V(e.receivedDateTime) == r.ms);
|
|
3198
3175
|
return i.length >= t.maxMessagesPerPoll ? {
|
|
3199
3176
|
boundaryMessageIds: [],
|
|
3200
3177
|
lastReceivedDateTime: new Date(r.ms + 1e3).toISOString()
|
|
@@ -3203,26 +3180,26 @@ async function lr(e, t) {
|
|
|
3203
3180
|
lastReceivedDateTime: r.iso
|
|
3204
3181
|
};
|
|
3205
3182
|
}
|
|
3206
|
-
function
|
|
3207
|
-
let n =
|
|
3208
|
-
if (typeof r != "string" ||
|
|
3183
|
+
function pr(t) {
|
|
3184
|
+
let n = H(t), r = n?.lastReceivedDateTime;
|
|
3185
|
+
if (typeof r != "string" || V(r) == null) throw new e("Outlook checkpoint is invalid; recreate the Trigger.");
|
|
3209
3186
|
let i = n?.boundaryMessageIds;
|
|
3210
3187
|
return {
|
|
3211
3188
|
boundaryMessageIds: Array.isArray(i) ? i.filter((e) => typeof e == "string" && e.length > 0) : [],
|
|
3212
3189
|
lastReceivedDateTime: r
|
|
3213
3190
|
};
|
|
3214
3191
|
}
|
|
3215
|
-
function
|
|
3192
|
+
function mr(e) {
|
|
3216
3193
|
return e.length == 0 ? "/me/messages" : `/me/mailFolders/${encodeURIComponent(e)}/messages`;
|
|
3217
3194
|
}
|
|
3218
|
-
function
|
|
3195
|
+
function hr(e, t) {
|
|
3219
3196
|
let n = [`receivedDateTime ge ${t}`];
|
|
3220
3197
|
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
3198
|
}
|
|
3222
|
-
function
|
|
3199
|
+
function gr(e, t) {
|
|
3223
3200
|
return e.isDraft === !0 && !t.includeDrafts ? !1 : t.subjectContains.length == 0 || (e.subject ?? "").toLowerCase().includes(t.subjectContains.toLowerCase());
|
|
3224
3201
|
}
|
|
3225
|
-
function
|
|
3202
|
+
function _r(e, t) {
|
|
3226
3203
|
return {
|
|
3227
3204
|
dedupeKey: t,
|
|
3228
3205
|
payload: {
|
|
@@ -3245,7 +3222,7 @@ function mr(e, t) {
|
|
|
3245
3222
|
}
|
|
3246
3223
|
};
|
|
3247
3224
|
}
|
|
3248
|
-
async function
|
|
3225
|
+
async function vr(e, t, r) {
|
|
3249
3226
|
try {
|
|
3250
3227
|
return await e.connector.execute({
|
|
3251
3228
|
endpoint: t,
|
|
@@ -3257,28 +3234,28 @@ async function hr(e, t, r) {
|
|
|
3257
3234
|
throw new n(`Outlook proxy request to ${t} failed.`, { cause: e });
|
|
3258
3235
|
}
|
|
3259
3236
|
}
|
|
3260
|
-
function
|
|
3237
|
+
function yr(r, i) {
|
|
3261
3238
|
if (r.status >= 200 && r.status < 300) return;
|
|
3262
|
-
let a =
|
|
3263
|
-
throw r.status == 401 ? new
|
|
3239
|
+
let a = br(r.data);
|
|
3240
|
+
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
3241
|
}
|
|
3265
|
-
function
|
|
3266
|
-
let t = /* @__PURE__ */ new Set(), n =
|
|
3242
|
+
function br(e) {
|
|
3243
|
+
let t = /* @__PURE__ */ new Set(), n = H(e)?.error;
|
|
3267
3244
|
for (let e = 0; e < 4; e += 1) {
|
|
3268
|
-
let e =
|
|
3245
|
+
let e = H(n);
|
|
3269
3246
|
if (e == null) break;
|
|
3270
3247
|
typeof e.code == "string" && e.code.length > 0 && t.add(e.code.toLowerCase()), n = e.innerError ?? e.innererror;
|
|
3271
3248
|
}
|
|
3272
3249
|
return t;
|
|
3273
3250
|
}
|
|
3274
|
-
function
|
|
3275
|
-
let t =
|
|
3251
|
+
function xr(e) {
|
|
3252
|
+
let t = H(e)?.value;
|
|
3276
3253
|
return Array.isArray(t) ? t : [];
|
|
3277
3254
|
}
|
|
3278
|
-
function
|
|
3255
|
+
function Sr(e) {
|
|
3279
3256
|
let t = null;
|
|
3280
3257
|
for (let n of e) {
|
|
3281
|
-
let e =
|
|
3258
|
+
let e = V(n.receivedDateTime);
|
|
3282
3259
|
n.receivedDateTime != null && e != null && (t == null || e > t.ms) && (t = {
|
|
3283
3260
|
iso: n.receivedDateTime,
|
|
3284
3261
|
ms: e
|
|
@@ -3286,15 +3263,15 @@ function yr(e) {
|
|
|
3286
3263
|
}
|
|
3287
3264
|
return t;
|
|
3288
3265
|
}
|
|
3289
|
-
function
|
|
3266
|
+
function V(e) {
|
|
3290
3267
|
if (e == null || e.length == 0) return null;
|
|
3291
3268
|
let t = Date.parse(e);
|
|
3292
3269
|
return Number.isNaN(t) ? null : t;
|
|
3293
3270
|
}
|
|
3294
|
-
function
|
|
3271
|
+
function H(e) {
|
|
3295
3272
|
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
3296
3273
|
}
|
|
3297
|
-
var
|
|
3274
|
+
var Cr = {
|
|
3298
3275
|
initialState: {
|
|
3299
3276
|
checkpoint: null,
|
|
3300
3277
|
subscription: {}
|
|
@@ -3362,7 +3339,7 @@ var br = {
|
|
|
3362
3339
|
outcome: "ignored",
|
|
3363
3340
|
reason: "Shopify topic header is missing."
|
|
3364
3341
|
};
|
|
3365
|
-
if (!
|
|
3342
|
+
if (!wr(e.config).includes(t)) return {
|
|
3366
3343
|
outcome: "ignored",
|
|
3367
3344
|
reason: "Shopify topic is not subscribed."
|
|
3368
3345
|
};
|
|
@@ -3382,37 +3359,37 @@ var br = {
|
|
|
3382
3359
|
};
|
|
3383
3360
|
},
|
|
3384
3361
|
async reconcile(e) {
|
|
3385
|
-
let t =
|
|
3362
|
+
let t = jr(e.state), n = await Er(e);
|
|
3386
3363
|
if (n == null) {
|
|
3387
3364
|
if (!e.active) return { outcome: "ready" };
|
|
3388
|
-
throw new
|
|
3365
|
+
throw new i("The Shopify store or webhook resource is unavailable.");
|
|
3389
3366
|
}
|
|
3390
3367
|
if (!e.active) {
|
|
3391
|
-
for (let t of n.values()) await
|
|
3392
|
-
return await t.saveSubscription({},
|
|
3368
|
+
for (let t of n.values()) await Dr(e, t);
|
|
3369
|
+
return await t.saveSubscription({}, Mr(e.now)), { outcome: "ready" };
|
|
3393
3370
|
}
|
|
3394
|
-
let r =
|
|
3371
|
+
let r = wr(e.config), a = [], o = [];
|
|
3395
3372
|
try {
|
|
3396
3373
|
for (let t of r) {
|
|
3397
3374
|
let r = n.get(t);
|
|
3398
|
-
if (r != null)
|
|
3375
|
+
if (r != null) a.push(r);
|
|
3399
3376
|
else {
|
|
3400
|
-
let n = await
|
|
3401
|
-
|
|
3377
|
+
let n = await Tr(e, t);
|
|
3378
|
+
a.push(n.id), n.created && o.push(n.id);
|
|
3402
3379
|
}
|
|
3403
3380
|
}
|
|
3404
3381
|
} catch (t) {
|
|
3405
|
-
throw await Promise.allSettled(
|
|
3382
|
+
throw await Promise.allSettled(o.map((t) => Dr(e, t))), t;
|
|
3406
3383
|
}
|
|
3407
|
-
for (let [t, i] of n) r.includes(t) || await
|
|
3408
|
-
return await t.saveSubscription({ webhookIds:
|
|
3384
|
+
for (let [t, i] of n) r.includes(t) || await Dr(e, i);
|
|
3385
|
+
return await t.saveSubscription({ webhookIds: a }, Mr(e.now)), { outcome: "ready" };
|
|
3409
3386
|
}
|
|
3410
3387
|
};
|
|
3411
|
-
function
|
|
3388
|
+
function wr(e) {
|
|
3412
3389
|
return [...new Set(e.topics)];
|
|
3413
3390
|
}
|
|
3414
|
-
async function
|
|
3415
|
-
let n = await
|
|
3391
|
+
async function Tr(e, t) {
|
|
3392
|
+
let n = await Or(e, "subscription create", {
|
|
3416
3393
|
body: { webhook: {
|
|
3417
3394
|
address: e.endpointUrl,
|
|
3418
3395
|
format: "json",
|
|
@@ -3422,22 +3399,22 @@ async function Sr(e, t) {
|
|
|
3422
3399
|
method: "POST"
|
|
3423
3400
|
});
|
|
3424
3401
|
if (n.status == 422) {
|
|
3425
|
-
let n = (await
|
|
3402
|
+
let n = (await Er(e))?.get(t);
|
|
3426
3403
|
if (n != null) return {
|
|
3427
3404
|
created: !1,
|
|
3428
3405
|
id: n
|
|
3429
3406
|
};
|
|
3430
3407
|
}
|
|
3431
|
-
|
|
3432
|
-
let r =
|
|
3433
|
-
if (r == null) throw new
|
|
3408
|
+
kr(n, "subscription create");
|
|
3409
|
+
let r = Ar(U(U(n.data)?.webhook)?.id);
|
|
3410
|
+
if (r == null) throw new a("Shopify subscription response is missing its ID.");
|
|
3434
3411
|
return {
|
|
3435
3412
|
created: !0,
|
|
3436
3413
|
id: r
|
|
3437
3414
|
};
|
|
3438
3415
|
}
|
|
3439
|
-
async function
|
|
3440
|
-
let t = await
|
|
3416
|
+
async function Er(e) {
|
|
3417
|
+
let t = await Or(e, "subscription list", {
|
|
3441
3418
|
endpoint: "/webhooks.json",
|
|
3442
3419
|
method: "GET",
|
|
3443
3420
|
query: {
|
|
@@ -3446,66 +3423,66 @@ async function Cr(e) {
|
|
|
3446
3423
|
}
|
|
3447
3424
|
});
|
|
3448
3425
|
if (t.status == 404) return null;
|
|
3449
|
-
|
|
3450
|
-
let n =
|
|
3426
|
+
kr(t, "subscription list");
|
|
3427
|
+
let n = U(t.data)?.webhooks, r = /* @__PURE__ */ new Map();
|
|
3451
3428
|
if (!Array.isArray(n)) return r;
|
|
3452
3429
|
for (let t of n) {
|
|
3453
|
-
let n =
|
|
3430
|
+
let n = U(t), i = Ar(n?.id);
|
|
3454
3431
|
n?.address === e.endpointUrl && typeof n.topic == "string" && i != null && r.set(n.topic, i);
|
|
3455
3432
|
}
|
|
3456
3433
|
return r;
|
|
3457
3434
|
}
|
|
3458
|
-
async function
|
|
3459
|
-
let n = await
|
|
3435
|
+
async function Dr(e, t) {
|
|
3436
|
+
let n = await Or(e, "subscription delete", {
|
|
3460
3437
|
endpoint: `/webhooks/${encodeURIComponent(t)}.json`,
|
|
3461
3438
|
method: "DELETE"
|
|
3462
3439
|
});
|
|
3463
|
-
n.status != 404 &&
|
|
3440
|
+
n.status != 404 && kr(n, "subscription delete");
|
|
3464
3441
|
}
|
|
3465
|
-
async function
|
|
3442
|
+
async function Or(e, t, n) {
|
|
3466
3443
|
try {
|
|
3467
3444
|
return await e.connector.execute(n, e.signal);
|
|
3468
3445
|
} catch (e) {
|
|
3469
|
-
throw e instanceof
|
|
3446
|
+
throw e instanceof r ? e : new a(`Shopify ${t} request failed.`, { cause: e });
|
|
3470
3447
|
}
|
|
3471
3448
|
}
|
|
3472
|
-
function
|
|
3473
|
-
if (!(e.status >= 200 && e.status < 300)) throw e.status == 401 || e.status == 403 ? new
|
|
3449
|
+
function kr(e, t) {
|
|
3450
|
+
if (!(e.status >= 200 && e.status < 300)) throw e.status == 401 || e.status == 403 ? new r(`Shopify ${t} rejected the Connection.`) : [
|
|
3474
3451
|
402,
|
|
3475
3452
|
404,
|
|
3476
3453
|
422,
|
|
3477
3454
|
423,
|
|
3478
3455
|
501
|
|
3479
|
-
].includes(e.status) ? new
|
|
3456
|
+
].includes(e.status) ? new i(`Shopify ${t} rejected the subscription.`) : new a(`Shopify ${t} failed with status ${e.status}.`);
|
|
3480
3457
|
}
|
|
3481
|
-
function
|
|
3458
|
+
function Ar(e) {
|
|
3482
3459
|
return typeof e == "string" ? e.trim().length == 0 ? null : e : typeof e == "number" && Number.isFinite(e) ? String(e) : null;
|
|
3483
3460
|
}
|
|
3484
|
-
function
|
|
3485
|
-
if (e == null) throw new
|
|
3461
|
+
function jr(e) {
|
|
3462
|
+
if (e == null) throw new i("Shopify Integration state is missing.");
|
|
3486
3463
|
return e;
|
|
3487
3464
|
}
|
|
3488
|
-
function
|
|
3465
|
+
function Mr(e) {
|
|
3489
3466
|
return new Date(e.getTime() + 2592e6);
|
|
3490
3467
|
}
|
|
3491
|
-
function
|
|
3468
|
+
function U(e) {
|
|
3492
3469
|
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
3493
3470
|
}
|
|
3494
3471
|
//#endregion
|
|
3495
3472
|
//#region src/trigger/providers/slack/on-message-posted.ts
|
|
3496
|
-
var
|
|
3473
|
+
var Nr = 15, Pr = 6e4, Fr = /* @__PURE__ */ new Set([
|
|
3497
3474
|
"file_share",
|
|
3498
3475
|
"thread_broadcast",
|
|
3499
3476
|
"me_message",
|
|
3500
3477
|
"bot_message"
|
|
3501
|
-
]),
|
|
3478
|
+
]), Ir = /* @__PURE__ */ new Set([
|
|
3502
3479
|
"invalid_auth",
|
|
3503
3480
|
"not_authed",
|
|
3504
3481
|
"token_revoked",
|
|
3505
3482
|
"token_expired",
|
|
3506
3483
|
"account_inactive",
|
|
3507
3484
|
"two_factor_setup_required"
|
|
3508
|
-
]),
|
|
3485
|
+
]), Lr = /* @__PURE__ */ new Set([
|
|
3509
3486
|
"channel_not_found",
|
|
3510
3487
|
"not_in_channel",
|
|
3511
3488
|
"missing_scope",
|
|
@@ -3521,7 +3498,7 @@ var Ar = 15, jr = 6e4, Mr = /* @__PURE__ */ new Set([
|
|
|
3521
3498
|
"method_deprecated",
|
|
3522
3499
|
"deprecated_endpoint",
|
|
3523
3500
|
"accesslimited"
|
|
3524
|
-
]),
|
|
3501
|
+
]), Rr = {
|
|
3525
3502
|
snapshot: {
|
|
3526
3503
|
configSchema: {
|
|
3527
3504
|
additionalProperties: !1,
|
|
@@ -3561,7 +3538,7 @@ var Ar = 15, jr = 6e4, Mr = /* @__PURE__ */ new Set([
|
|
|
3561
3538
|
type: "boolean"
|
|
3562
3539
|
},
|
|
3563
3540
|
maxMessagesPerPoll: {
|
|
3564
|
-
default:
|
|
3541
|
+
default: Nr,
|
|
3565
3542
|
description: "Maximum number of messages processed per poll.",
|
|
3566
3543
|
maximum: 100,
|
|
3567
3544
|
minimum: 1,
|
|
@@ -3635,69 +3612,69 @@ var Ar = 15, jr = 6e4, Mr = /* @__PURE__ */ new Set([
|
|
|
3635
3612
|
type: "poll"
|
|
3636
3613
|
},
|
|
3637
3614
|
async poll(e) {
|
|
3638
|
-
let t =
|
|
3615
|
+
let t = zr(e.config);
|
|
3639
3616
|
if (e.checkpoint === null) return {
|
|
3640
|
-
checkpoint: { lastTs: await
|
|
3617
|
+
checkpoint: { lastTs: await Br(e, t.channelId) },
|
|
3641
3618
|
events: []
|
|
3642
3619
|
};
|
|
3643
|
-
let n =
|
|
3620
|
+
let n = Vr(e.checkpoint), r = await Hr(e, t, n), i = Gr(r), a = [], o = 0;
|
|
3644
3621
|
for (let e of i.toReversed()) {
|
|
3645
|
-
if (!
|
|
3622
|
+
if (!qr(e.message, t)) {
|
|
3646
3623
|
o += 1;
|
|
3647
3624
|
continue;
|
|
3648
3625
|
}
|
|
3649
|
-
a.push(
|
|
3626
|
+
a.push(Jr(e, t.channelId));
|
|
3650
3627
|
}
|
|
3651
3628
|
return {
|
|
3652
|
-
checkpoint:
|
|
3629
|
+
checkpoint: Kr(n, r, i),
|
|
3653
3630
|
events: a,
|
|
3654
3631
|
filtered: o
|
|
3655
3632
|
};
|
|
3656
3633
|
}
|
|
3657
3634
|
};
|
|
3658
|
-
function
|
|
3635
|
+
function zr(e) {
|
|
3659
3636
|
return {
|
|
3660
3637
|
channelId: e.channelId,
|
|
3661
3638
|
fromUserIds: e.fromUserIds ?? [],
|
|
3662
3639
|
ignoreUserIds: e.ignoreUserIds ?? [],
|
|
3663
3640
|
includeBotMessages: e.includeBotMessages ?? !1,
|
|
3664
3641
|
includeSystemMessages: e.includeSystemMessages ?? !1,
|
|
3665
|
-
maxMessagesPerPoll: e.maxMessagesPerPoll ??
|
|
3642
|
+
maxMessagesPerPoll: e.maxMessagesPerPoll ?? Nr,
|
|
3666
3643
|
textContains: e.textContains ?? ""
|
|
3667
3644
|
};
|
|
3668
3645
|
}
|
|
3669
|
-
async function
|
|
3670
|
-
let n = await
|
|
3646
|
+
async function Br(e, t) {
|
|
3647
|
+
let n = await Ur(e, {
|
|
3671
3648
|
channel: t,
|
|
3672
3649
|
limit: 1
|
|
3673
3650
|
});
|
|
3674
|
-
|
|
3651
|
+
Wr(n, "baseline history fetch");
|
|
3675
3652
|
let r = n.data.messages?.[0]?.ts;
|
|
3676
|
-
return r != null &&
|
|
3653
|
+
return r != null && Yr(r) ? r : `${Math.floor((e.now.getTime() - Pr) / 1e3)}.000000`;
|
|
3677
3654
|
}
|
|
3678
|
-
function
|
|
3679
|
-
let n =
|
|
3680
|
-
if (typeof n.lastTs != "string" || n.lastTs.length == 0) throw new
|
|
3655
|
+
function Vr(t) {
|
|
3656
|
+
let n = t;
|
|
3657
|
+
if (typeof n.lastTs != "string" || n.lastTs.length == 0) throw new e("Slack checkpoint lastTs is missing.");
|
|
3681
3658
|
let r = n.drainLatest, i = n.pendingHighTs;
|
|
3682
3659
|
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
|
|
3660
|
+
if (typeof r != "string" || r.length == 0 || typeof i != "string" || i.length == 0) throw new e("Slack checkpoint drain fields are incomplete.");
|
|
3684
3661
|
return {
|
|
3685
3662
|
drainLatest: r,
|
|
3686
3663
|
lastTs: n.lastTs,
|
|
3687
3664
|
pendingHighTs: i
|
|
3688
3665
|
};
|
|
3689
3666
|
}
|
|
3690
|
-
async function
|
|
3691
|
-
let r = await
|
|
3667
|
+
async function Hr(e, t, n) {
|
|
3668
|
+
let r = await Ur(e, {
|
|
3692
3669
|
channel: t.channelId,
|
|
3693
3670
|
inclusive: "false",
|
|
3694
3671
|
latest: n.drainLatest,
|
|
3695
3672
|
limit: t.maxMessagesPerPoll,
|
|
3696
3673
|
oldest: n.lastTs
|
|
3697
3674
|
});
|
|
3698
|
-
return
|
|
3675
|
+
return Wr(r, "history list"), r.data;
|
|
3699
3676
|
}
|
|
3700
|
-
async function
|
|
3677
|
+
async function Ur(e, t) {
|
|
3701
3678
|
try {
|
|
3702
3679
|
return await e.connector.execute({
|
|
3703
3680
|
endpoint: "/conversations.history",
|
|
@@ -3708,19 +3685,19 @@ async function Br(e, t) {
|
|
|
3708
3685
|
throw new n("Slack proxy request failed.", { cause: e });
|
|
3709
3686
|
}
|
|
3710
3687
|
}
|
|
3711
|
-
function
|
|
3688
|
+
function Wr(r, i) {
|
|
3712
3689
|
let a = r.data;
|
|
3713
3690
|
if (r.status >= 200 && r.status < 300 && a.ok === !0) return;
|
|
3714
3691
|
let o = typeof a.error == "string" ? a.error : "";
|
|
3715
|
-
throw
|
|
3692
|
+
throw Ir.has(o) ? new t(`Slack ${i} rejected with ${o}.`) : Lr.has(o) ? new e(`Slack ${i} rejected with ${o}.`) : new n(`Slack ${i} failed with ${o || `status ${r.status}`}.`);
|
|
3716
3693
|
}
|
|
3717
|
-
function
|
|
3718
|
-
return (e.messages ?? []).flatMap((e) => e.ts != null &&
|
|
3694
|
+
function Gr(e) {
|
|
3695
|
+
return (e.messages ?? []).flatMap((e) => e.ts != null && Yr(e.ts) ? [{
|
|
3719
3696
|
message: e,
|
|
3720
3697
|
ts: e.ts
|
|
3721
3698
|
}] : []);
|
|
3722
3699
|
}
|
|
3723
|
-
function
|
|
3700
|
+
function Kr(e, t, r) {
|
|
3724
3701
|
let i = r[0]?.ts, a = r.at(-1)?.ts;
|
|
3725
3702
|
if (t.has_more === !0) {
|
|
3726
3703
|
if (i == null || a == null) throw new n("Slack history reports has_more without a usable timestamp.");
|
|
@@ -3732,10 +3709,10 @@ function Ur(e, t, r) {
|
|
|
3732
3709
|
}
|
|
3733
3710
|
return e.pendingHighTs == null ? { lastTs: i ?? e.lastTs } : { lastTs: e.pendingHighTs };
|
|
3734
3711
|
}
|
|
3735
|
-
function
|
|
3736
|
-
return !t.includeBotMessages && (e.bot_id != null || e.subtype == "bot_message") || !t.includeSystemMessages && e.subtype != null && !
|
|
3712
|
+
function qr(e, t) {
|
|
3713
|
+
return !t.includeBotMessages && (e.bot_id != null || e.subtype == "bot_message") || !t.includeSystemMessages && e.subtype != null && !Fr.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
3714
|
}
|
|
3738
|
-
function
|
|
3715
|
+
function Jr(e, t) {
|
|
3739
3716
|
return {
|
|
3740
3717
|
dedupeKey: `${t}:${e.ts}`,
|
|
3741
3718
|
payload: {
|
|
@@ -3754,12 +3731,12 @@ function Gr(e, t) {
|
|
|
3754
3731
|
}
|
|
3755
3732
|
};
|
|
3756
3733
|
}
|
|
3757
|
-
function
|
|
3734
|
+
function Yr(e) {
|
|
3758
3735
|
return /^\d+(?:\.\d+)?$/.test(e) && !Number.isNaN(new Date(Math.round(Number(e) * 1e3)).getTime());
|
|
3759
3736
|
}
|
|
3760
3737
|
//#endregion
|
|
3761
3738
|
//#region src/trigger/providers/stripe/on-event.ts
|
|
3762
|
-
var
|
|
3739
|
+
var W = "/v1/webhook_endpoints", Xr = { "Content-Type": "application/x-www-form-urlencoded" }, Zr = {
|
|
3763
3740
|
initialState: {
|
|
3764
3741
|
checkpoint: null,
|
|
3765
3742
|
subscription: {}
|
|
@@ -3836,7 +3813,7 @@ var q = "/v1/webhook_endpoints", qr = { "Content-Type": "application/x-www-form-
|
|
|
3836
3813
|
outcome: "ignored",
|
|
3837
3814
|
reason: "Stripe event identity is missing."
|
|
3838
3815
|
};
|
|
3839
|
-
let i =
|
|
3816
|
+
let i = Qr(e.config);
|
|
3840
3817
|
return !i.events.includes("*") && !i.events.includes(n) ? {
|
|
3841
3818
|
outcome: "ignored",
|
|
3842
3819
|
reason: "Stripe event is not subscribed."
|
|
@@ -3852,125 +3829,125 @@ var q = "/v1/webhook_endpoints", qr = { "Content-Type": "application/x-www-form-
|
|
|
3852
3829
|
};
|
|
3853
3830
|
},
|
|
3854
3831
|
async reconcile(e) {
|
|
3855
|
-
let t =
|
|
3832
|
+
let t = ri(e.state), n = Qr(e.config), r = ii(t);
|
|
3856
3833
|
if (!e.active) {
|
|
3857
|
-
if (r ??= await
|
|
3858
|
-
let t = await
|
|
3859
|
-
endpoint: `${
|
|
3834
|
+
if (r ??= await ti(e), r != null) {
|
|
3835
|
+
let t = await G(e, "endpoint delete", {
|
|
3836
|
+
endpoint: `${W}/${r}`,
|
|
3860
3837
|
method: "DELETE"
|
|
3861
3838
|
});
|
|
3862
|
-
t.status != 404 &&
|
|
3839
|
+
t.status != 404 && K(t, "endpoint delete");
|
|
3863
3840
|
}
|
|
3864
|
-
return await t.saveSubscription({},
|
|
3841
|
+
return await t.saveSubscription({}, ai(e.now)), { outcome: "ready" };
|
|
3865
3842
|
}
|
|
3866
|
-
if (r ??= await
|
|
3867
|
-
let t = await
|
|
3868
|
-
body:
|
|
3869
|
-
endpoint:
|
|
3870
|
-
headers:
|
|
3843
|
+
if (r ??= await ti(e), r == null) {
|
|
3844
|
+
let t = await G(e, "endpoint create", {
|
|
3845
|
+
body: $r(e.endpointUrl, n),
|
|
3846
|
+
endpoint: W,
|
|
3847
|
+
headers: Xr,
|
|
3871
3848
|
method: "POST"
|
|
3872
3849
|
});
|
|
3873
|
-
|
|
3850
|
+
K(t, "endpoint create"), r = ni(t.data);
|
|
3874
3851
|
}
|
|
3875
|
-
let i = await
|
|
3876
|
-
body:
|
|
3852
|
+
let i = await G(e, "endpoint update", {
|
|
3853
|
+
body: ei([
|
|
3877
3854
|
...n.events.map((e, t) => [`enabled_events[${t}]`, e]),
|
|
3878
3855
|
["disabled", "false"],
|
|
3879
3856
|
["description", "Managed by Open Flow."]
|
|
3880
3857
|
]),
|
|
3881
|
-
endpoint: `${
|
|
3882
|
-
headers:
|
|
3858
|
+
endpoint: `${W}/${r}`,
|
|
3859
|
+
headers: Xr,
|
|
3883
3860
|
method: "POST"
|
|
3884
3861
|
});
|
|
3885
|
-
return i.status == 404 ? (await t.saveSubscription({}, e.now), { outcome: "pending" }) : (
|
|
3862
|
+
return i.status == 404 ? (await t.saveSubscription({}, e.now), { outcome: "pending" }) : (K(i, "endpoint update"), await t.saveSubscription({ endpointId: r }, ai(e.now)), { outcome: "ready" });
|
|
3886
3863
|
}
|
|
3887
3864
|
};
|
|
3888
|
-
function
|
|
3865
|
+
function Qr(e) {
|
|
3889
3866
|
return {
|
|
3890
3867
|
apiVersion: e.apiVersion ?? "",
|
|
3891
3868
|
events: [...new Set(e.events)],
|
|
3892
3869
|
includeConnectedAccounts: e.includeConnectedAccounts ?? !1
|
|
3893
3870
|
};
|
|
3894
3871
|
}
|
|
3895
|
-
function
|
|
3872
|
+
function $r(e, t) {
|
|
3896
3873
|
let n = [
|
|
3897
3874
|
["url", e],
|
|
3898
3875
|
...t.events.map((e, t) => [`enabled_events[${t}]`, e]),
|
|
3899
3876
|
["description", "Managed by Open Flow."]
|
|
3900
3877
|
];
|
|
3901
|
-
return t.includeConnectedAccounts && n.push(["connect", "true"]), t.apiVersion.length > 0 && n.push(["api_version", t.apiVersion]),
|
|
3878
|
+
return t.includeConnectedAccounts && n.push(["connect", "true"]), t.apiVersion.length > 0 && n.push(["api_version", t.apiVersion]), ei(n);
|
|
3902
3879
|
}
|
|
3903
|
-
function
|
|
3880
|
+
function ei(e) {
|
|
3904
3881
|
let t = new URLSearchParams();
|
|
3905
3882
|
for (let [n, r] of e) t.append(n, r);
|
|
3906
3883
|
return t.toString();
|
|
3907
3884
|
}
|
|
3908
|
-
async function
|
|
3885
|
+
async function ti(e) {
|
|
3909
3886
|
let t;
|
|
3910
3887
|
for (let n = 0; n < 10; n += 1) {
|
|
3911
|
-
let n = await
|
|
3912
|
-
endpoint:
|
|
3888
|
+
let n = await G(e, "endpoint list", {
|
|
3889
|
+
endpoint: W,
|
|
3913
3890
|
method: "GET",
|
|
3914
3891
|
query: {
|
|
3915
3892
|
limit: 100,
|
|
3916
3893
|
...t == null ? {} : { starting_after: t }
|
|
3917
3894
|
}
|
|
3918
3895
|
});
|
|
3919
|
-
|
|
3920
|
-
let r =
|
|
3896
|
+
K(n, "endpoint list");
|
|
3897
|
+
let r = q(n.data), i = Array.isArray(r?.data) ? r.data : [];
|
|
3921
3898
|
for (let t of i) {
|
|
3922
|
-
let n =
|
|
3899
|
+
let n = q(t);
|
|
3923
3900
|
if (n?.url === e.endpointUrl && typeof n.id == "string") return n.id;
|
|
3924
3901
|
}
|
|
3925
|
-
let a =
|
|
3902
|
+
let a = q(i.at(-1))?.id;
|
|
3926
3903
|
if (r?.has_more !== !0 || typeof a != "string") return null;
|
|
3927
3904
|
t = a;
|
|
3928
3905
|
}
|
|
3929
3906
|
return null;
|
|
3930
3907
|
}
|
|
3931
|
-
async function
|
|
3908
|
+
async function G(e, t, n) {
|
|
3932
3909
|
try {
|
|
3933
3910
|
return await e.connector.execute(n, e.signal);
|
|
3934
3911
|
} catch (e) {
|
|
3935
|
-
throw e instanceof
|
|
3912
|
+
throw e instanceof r ? e : new a(`Stripe ${t} request failed.`, { cause: e });
|
|
3936
3913
|
}
|
|
3937
3914
|
}
|
|
3938
|
-
function
|
|
3915
|
+
function K(e, t) {
|
|
3939
3916
|
if (!(e.status >= 200 && e.status < 300)) {
|
|
3940
|
-
if (e.status == 401 || e.status == 403) throw new
|
|
3917
|
+
if (e.status == 401 || e.status == 403) throw new r(`Stripe ${t} rejected the Connection.`);
|
|
3941
3918
|
if (e.status == 400 || e.status == 404) {
|
|
3942
|
-
let n =
|
|
3943
|
-
throw new
|
|
3919
|
+
let n = q(q(e.data)?.error)?.message;
|
|
3920
|
+
throw new i(`Stripe ${t} rejected the subscription${typeof n == "string" ? `: ${n}` : "."}`);
|
|
3944
3921
|
}
|
|
3945
|
-
throw new
|
|
3922
|
+
throw new a(`Stripe ${t} failed with status ${e.status}.`);
|
|
3946
3923
|
}
|
|
3947
3924
|
}
|
|
3948
|
-
function
|
|
3949
|
-
let t =
|
|
3950
|
-
if (typeof t != "string") throw new
|
|
3925
|
+
function ni(e) {
|
|
3926
|
+
let t = q(e)?.id;
|
|
3927
|
+
if (typeof t != "string") throw new a("Stripe endpoint response is missing its ID.");
|
|
3951
3928
|
return t;
|
|
3952
3929
|
}
|
|
3953
|
-
function
|
|
3954
|
-
if (e == null) throw new
|
|
3930
|
+
function ri(e) {
|
|
3931
|
+
if (e == null) throw new i("Stripe Integration state is missing.");
|
|
3955
3932
|
return e;
|
|
3956
3933
|
}
|
|
3957
|
-
function
|
|
3934
|
+
function ii(e) {
|
|
3958
3935
|
let t = e.subscription.endpointId;
|
|
3959
3936
|
return typeof t == "string" && t.length > 0 ? t : null;
|
|
3960
3937
|
}
|
|
3961
|
-
function
|
|
3938
|
+
function ai(e) {
|
|
3962
3939
|
return new Date(e.getTime() + 2592e6);
|
|
3963
3940
|
}
|
|
3964
|
-
function
|
|
3941
|
+
function q(e) {
|
|
3965
3942
|
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
3966
3943
|
}
|
|
3967
3944
|
//#endregion
|
|
3968
3945
|
//#region src/trigger/providers/telegram/on-update.ts
|
|
3969
|
-
var
|
|
3946
|
+
var oi = /* @__PURE__ */ new Set([
|
|
3970
3947
|
"chat_member",
|
|
3971
3948
|
"message_reaction",
|
|
3972
3949
|
"message_reaction_count"
|
|
3973
|
-
]),
|
|
3950
|
+
]), 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 != "*" && !oi.has(e)), li = {
|
|
3974
3951
|
snapshot: {
|
|
3975
3952
|
configSchema: {
|
|
3976
3953
|
additionalProperties: !1,
|
|
@@ -3994,7 +3971,7 @@ var ri = /* @__PURE__ */ new Set([
|
|
|
3994
3971
|
},
|
|
3995
3972
|
updates: {
|
|
3996
3973
|
description: "Telegram update types that trigger a Run. Use * for the Telegram default set.",
|
|
3997
|
-
items: { enum:
|
|
3974
|
+
items: { enum: si },
|
|
3998
3975
|
minItems: 1,
|
|
3999
3976
|
type: "array",
|
|
4000
3977
|
uniqueItems: !0
|
|
@@ -4048,13 +4025,13 @@ var ri = /* @__PURE__ */ new Set([
|
|
|
4048
4025
|
type: "integration"
|
|
4049
4026
|
},
|
|
4050
4027
|
receive(e) {
|
|
4051
|
-
if (!
|
|
4028
|
+
if (!fi(e.header("x-telegram-bot-api-secret-token"), e.callbackSecret)) return {
|
|
4052
4029
|
body: "",
|
|
4053
4030
|
contentType: "text/plain",
|
|
4054
4031
|
outcome: "respond",
|
|
4055
4032
|
status: 404
|
|
4056
4033
|
};
|
|
4057
|
-
if (!
|
|
4034
|
+
if (!J(e.payload) || !Number.isSafeInteger(e.payload.update_id)) return {
|
|
4058
4035
|
outcome: "ignored",
|
|
4059
4036
|
reason: "Telegram update_id is missing."
|
|
4060
4037
|
};
|
|
@@ -4063,21 +4040,21 @@ var ri = /* @__PURE__ */ new Set([
|
|
|
4063
4040
|
outcome: "ignored",
|
|
4064
4041
|
reason: "Telegram update body is missing."
|
|
4065
4042
|
};
|
|
4066
|
-
let n =
|
|
4067
|
-
if (!(
|
|
4043
|
+
let n = ui(e.config);
|
|
4044
|
+
if (!(di(n) ?? ci).includes(t)) return {
|
|
4068
4045
|
outcome: "ignored",
|
|
4069
4046
|
reason: "Telegram update type is not subscribed."
|
|
4070
4047
|
};
|
|
4071
4048
|
let r = e.payload[t];
|
|
4072
4049
|
if (n.chatIds.length > 0) {
|
|
4073
|
-
let e =
|
|
4050
|
+
let e = pi(r);
|
|
4074
4051
|
if (e == null || !n.chatIds.includes(e)) return {
|
|
4075
4052
|
outcome: "ignored",
|
|
4076
4053
|
reason: "Telegram chat does not match."
|
|
4077
4054
|
};
|
|
4078
4055
|
}
|
|
4079
4056
|
if (n.userIds.length > 0) {
|
|
4080
|
-
let e =
|
|
4057
|
+
let e = mi(r);
|
|
4081
4058
|
if (e == null || !n.userIds.includes(e)) return {
|
|
4082
4059
|
outcome: "ignored",
|
|
4083
4060
|
reason: "Telegram user does not match."
|
|
@@ -4095,19 +4072,19 @@ var ri = /* @__PURE__ */ new Set([
|
|
|
4095
4072
|
};
|
|
4096
4073
|
},
|
|
4097
4074
|
async reconcile(e) {
|
|
4098
|
-
let t = await
|
|
4099
|
-
if (!e.active) return t == e.endpointUrl && await
|
|
4100
|
-
if (t != "" && t != e.endpointUrl) throw new
|
|
4101
|
-
let n =
|
|
4102
|
-
return await
|
|
4103
|
-
allowed_updates:
|
|
4075
|
+
let t = await hi(e);
|
|
4076
|
+
if (!e.active) return t == e.endpointUrl && await gi(e), { outcome: "ready" };
|
|
4077
|
+
if (t != "" && t != e.endpointUrl) throw new i(`The Telegram bot already sends updates to ${vi(t)}.`);
|
|
4078
|
+
let n = ui(e.config);
|
|
4079
|
+
return await _i(e, "setWebhook", {
|
|
4080
|
+
allowed_updates: di(n) ?? [],
|
|
4104
4081
|
drop_pending_updates: t == "" && n.dropPendingUpdates,
|
|
4105
4082
|
secret_token: e.callbackSecret,
|
|
4106
4083
|
url: e.endpointUrl
|
|
4107
4084
|
}), { outcome: "ready" };
|
|
4108
4085
|
}
|
|
4109
4086
|
};
|
|
4110
|
-
function
|
|
4087
|
+
function ui(e) {
|
|
4111
4088
|
return {
|
|
4112
4089
|
chatIds: e.chatIds ?? [],
|
|
4113
4090
|
dropPendingUpdates: e.dropPendingUpdates ?? !0,
|
|
@@ -4115,61 +4092,61 @@ function si(e) {
|
|
|
4115
4092
|
userIds: e.userIds ?? []
|
|
4116
4093
|
};
|
|
4117
4094
|
}
|
|
4118
|
-
function
|
|
4095
|
+
function di(e) {
|
|
4119
4096
|
if (!e.updates.includes("*")) return e.updates;
|
|
4120
4097
|
let t = e.updates.filter((e) => e != "*");
|
|
4121
|
-
return t.length == 0 ? null : [.../* @__PURE__ */ new Set([...
|
|
4098
|
+
return t.length == 0 ? null : [.../* @__PURE__ */ new Set([...ci, ...t])];
|
|
4122
4099
|
}
|
|
4123
|
-
function
|
|
4100
|
+
function fi(e, t) {
|
|
4124
4101
|
if (e == null || e.length != t.length) return !1;
|
|
4125
4102
|
let n = 0;
|
|
4126
4103
|
for (let r = 0; r < t.length; r += 1) n |= e.charCodeAt(r) ^ t.charCodeAt(r);
|
|
4127
4104
|
return n == 0;
|
|
4128
4105
|
}
|
|
4129
|
-
function
|
|
4106
|
+
function J(e) {
|
|
4130
4107
|
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
4131
4108
|
}
|
|
4132
|
-
function
|
|
4133
|
-
if (
|
|
4109
|
+
function Y(e) {
|
|
4110
|
+
if (J(e)) return typeof e.id == "string" || typeof e.id == "number" ? String(e.id) : void 0;
|
|
4134
4111
|
}
|
|
4135
|
-
function
|
|
4136
|
-
if (
|
|
4112
|
+
function pi(e) {
|
|
4113
|
+
if (J(e)) return Y(e.chat) ?? (J(e.message) ? Y(e.message.chat) : void 0);
|
|
4137
4114
|
}
|
|
4138
|
-
function
|
|
4139
|
-
if (
|
|
4115
|
+
function mi(e) {
|
|
4116
|
+
if (J(e)) return Y(e.from) ?? Y(e.user);
|
|
4140
4117
|
}
|
|
4141
|
-
async function
|
|
4142
|
-
let t = await
|
|
4143
|
-
if (typeof n != "string") throw new
|
|
4118
|
+
async function hi(e) {
|
|
4119
|
+
let t = await _i(e, "getWebhookInfo"), n = J(t.result) ? t.result.url : void 0;
|
|
4120
|
+
if (typeof n != "string") throw new a("Telegram getWebhookInfo response is missing result.url.");
|
|
4144
4121
|
return n;
|
|
4145
4122
|
}
|
|
4146
|
-
async function
|
|
4147
|
-
await
|
|
4123
|
+
async function gi(e) {
|
|
4124
|
+
await _i(e, "deleteWebhook", { drop_pending_updates: !1 });
|
|
4148
4125
|
}
|
|
4149
|
-
async function
|
|
4150
|
-
let
|
|
4126
|
+
async function _i(e, t, n) {
|
|
4127
|
+
let o;
|
|
4151
4128
|
try {
|
|
4152
|
-
|
|
4129
|
+
o = await e.connector.execute({
|
|
4153
4130
|
...n == null ? {} : { body: n },
|
|
4154
4131
|
endpoint: `/${t}`,
|
|
4155
4132
|
method: n == null ? "GET" : "POST"
|
|
4156
4133
|
}, e.signal);
|
|
4157
4134
|
} catch (e) {
|
|
4158
|
-
throw e instanceof
|
|
4135
|
+
throw e instanceof r ? e : new a(`Telegram ${t} request failed.`, { cause: e });
|
|
4159
4136
|
}
|
|
4160
|
-
let
|
|
4161
|
-
if (
|
|
4162
|
-
let
|
|
4163
|
-
throw
|
|
4137
|
+
let s = J(o.data) ? o.data : {};
|
|
4138
|
+
if (o.status >= 200 && o.status < 300 && s.ok === !0) return s;
|
|
4139
|
+
let c = typeof s.description == "string" ? s.description : `HTTP ${o.status}`;
|
|
4140
|
+
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
4141
|
}
|
|
4165
|
-
function
|
|
4142
|
+
function vi(e) {
|
|
4166
4143
|
try {
|
|
4167
4144
|
return new URL(e).host;
|
|
4168
4145
|
} catch {
|
|
4169
4146
|
return "an invalid URL";
|
|
4170
4147
|
}
|
|
4171
4148
|
}
|
|
4172
|
-
var
|
|
4149
|
+
var yi = {
|
|
4173
4150
|
initialState: {
|
|
4174
4151
|
checkpoint: null,
|
|
4175
4152
|
subscription: {}
|
|
@@ -4262,7 +4239,7 @@ var gi = {
|
|
|
4262
4239
|
outcome: "ignored",
|
|
4263
4240
|
reason: "WooCommerce topic header is missing."
|
|
4264
4241
|
};
|
|
4265
|
-
if (!
|
|
4242
|
+
if (!bi(e.config).events.includes(t)) return {
|
|
4266
4243
|
outcome: "ignored",
|
|
4267
4244
|
reason: "WooCommerce topic is not subscribed."
|
|
4268
4245
|
};
|
|
@@ -4282,31 +4259,31 @@ var gi = {
|
|
|
4282
4259
|
};
|
|
4283
4260
|
},
|
|
4284
4261
|
async reconcile(e) {
|
|
4285
|
-
let t =
|
|
4262
|
+
let t = ki(e.state), n = bi(e.config), r = await Ci(e);
|
|
4286
4263
|
if (!e.active) {
|
|
4287
|
-
for (let t of r) await
|
|
4288
|
-
return await t.saveSubscription({},
|
|
4264
|
+
for (let t of r) await wi(e, t.id);
|
|
4265
|
+
return await t.saveSubscription({}, Ai(e.now)), { outcome: "ready" };
|
|
4289
4266
|
}
|
|
4290
4267
|
let i = /* @__PURE__ */ new Map();
|
|
4291
4268
|
for (let e of r) n.events.includes(e.topic) && !i.has(e.topic) && i.set(e.topic, e.id);
|
|
4292
4269
|
let a = new Set(i.values());
|
|
4293
|
-
for (let t of r) a.has(t.id) || await
|
|
4270
|
+
for (let t of r) a.has(t.id) || await wi(e, t.id);
|
|
4294
4271
|
let o = [];
|
|
4295
4272
|
for (let t of n.events) {
|
|
4296
4273
|
let r = i.get(t);
|
|
4297
|
-
o.push(r == null ? await
|
|
4274
|
+
o.push(r == null ? await xi(e, n, t) : await Si(e, r, t));
|
|
4298
4275
|
}
|
|
4299
|
-
return await t.saveSubscription({ webhookIds: o },
|
|
4276
|
+
return await t.saveSubscription({ webhookIds: o }, Ai(e.now)), { outcome: "ready" };
|
|
4300
4277
|
}
|
|
4301
4278
|
};
|
|
4302
|
-
function
|
|
4279
|
+
function bi(e) {
|
|
4303
4280
|
return {
|
|
4304
4281
|
events: [...new Set(e.events)],
|
|
4305
4282
|
webhookName: e.webhookName ?? "OOMOL Trigger"
|
|
4306
4283
|
};
|
|
4307
4284
|
}
|
|
4308
|
-
async function
|
|
4309
|
-
let r = await
|
|
4285
|
+
async function xi(e, t, n) {
|
|
4286
|
+
let r = await X(e, `webhook create (${n})`, {
|
|
4310
4287
|
body: {
|
|
4311
4288
|
delivery_url: e.endpointUrl,
|
|
4312
4289
|
name: `${t.webhookName} - ${n}`,
|
|
@@ -4315,10 +4292,10 @@ async function vi(e, t, n) {
|
|
|
4315
4292
|
endpoint: "/webhooks",
|
|
4316
4293
|
method: "POST"
|
|
4317
4294
|
});
|
|
4318
|
-
return
|
|
4295
|
+
return Z(r, `webhook create (${n})`), Di(r.data);
|
|
4319
4296
|
}
|
|
4320
|
-
async function
|
|
4321
|
-
let r = await
|
|
4297
|
+
async function Si(e, t, n) {
|
|
4298
|
+
let r = await X(e, `webhook update (${n})`, {
|
|
4322
4299
|
body: {
|
|
4323
4300
|
delivery_url: e.endpointUrl,
|
|
4324
4301
|
status: "active",
|
|
@@ -4327,12 +4304,12 @@ async function yi(e, t, n) {
|
|
|
4327
4304
|
endpoint: `/webhooks/${t}`,
|
|
4328
4305
|
method: "PUT"
|
|
4329
4306
|
});
|
|
4330
|
-
return
|
|
4307
|
+
return Ti(r) ? xi(e, bi(e.config), n) : (Z(r, `webhook update (${n})`), t);
|
|
4331
4308
|
}
|
|
4332
|
-
async function
|
|
4309
|
+
async function Ci(e) {
|
|
4333
4310
|
let t = [];
|
|
4334
4311
|
for (let n = 1; n <= 10; n += 1) {
|
|
4335
|
-
let r = await
|
|
4312
|
+
let r = await X(e, "webhook list", {
|
|
4336
4313
|
endpoint: "/webhooks",
|
|
4337
4314
|
method: "GET",
|
|
4338
4315
|
query: {
|
|
@@ -4342,12 +4319,12 @@ async function bi(e) {
|
|
|
4342
4319
|
status: "all"
|
|
4343
4320
|
}
|
|
4344
4321
|
});
|
|
4345
|
-
|
|
4322
|
+
Z(r, "webhook list");
|
|
4346
4323
|
let i = Array.isArray(r.data) ? r.data : [];
|
|
4347
4324
|
for (let n of i) {
|
|
4348
|
-
let r =
|
|
4325
|
+
let r = ji(n);
|
|
4349
4326
|
if (r?.delivery_url !== e.endpointUrl || typeof r.topic != "string") continue;
|
|
4350
|
-
let i =
|
|
4327
|
+
let i = Oi(r.id);
|
|
4351
4328
|
i != null && t.push({
|
|
4352
4329
|
id: i,
|
|
4353
4330
|
topic: r.topic
|
|
@@ -4355,56 +4332,56 @@ async function bi(e) {
|
|
|
4355
4332
|
}
|
|
4356
4333
|
if (i.length < 100) return t;
|
|
4357
4334
|
}
|
|
4358
|
-
throw new
|
|
4335
|
+
throw new a("WooCommerce webhook list did not finish within ten pages.");
|
|
4359
4336
|
}
|
|
4360
|
-
async function
|
|
4361
|
-
let n = await
|
|
4337
|
+
async function wi(e, t) {
|
|
4338
|
+
let n = await X(e, "webhook delete", {
|
|
4362
4339
|
endpoint: `/webhooks/${t}`,
|
|
4363
4340
|
method: "DELETE",
|
|
4364
4341
|
query: { force: "true" }
|
|
4365
4342
|
});
|
|
4366
|
-
n.status != 404 &&
|
|
4343
|
+
n.status != 404 && Z(n, "webhook delete");
|
|
4367
4344
|
}
|
|
4368
|
-
async function
|
|
4345
|
+
async function X(e, t, n) {
|
|
4369
4346
|
try {
|
|
4370
4347
|
return await e.connector.execute(n, e.signal);
|
|
4371
4348
|
} catch (e) {
|
|
4372
|
-
throw e instanceof
|
|
4349
|
+
throw e instanceof r ? e : new a(`WooCommerce ${t} request failed.`, { cause: e });
|
|
4373
4350
|
}
|
|
4374
4351
|
}
|
|
4375
|
-
function
|
|
4352
|
+
function Z(e, t) {
|
|
4376
4353
|
if (e.status >= 200 && e.status < 300) return;
|
|
4377
|
-
let n =
|
|
4378
|
-
throw e.status == 401 || e.status == 403 ? new
|
|
4379
|
-
}
|
|
4380
|
-
function wi(e) {
|
|
4381
|
-
return e.status == 400 && Ti(e.data) == "woocommerce_rest_webhook_invalid_id";
|
|
4354
|
+
let n = Ei(e.data);
|
|
4355
|
+
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}.`);
|
|
4382
4356
|
}
|
|
4383
4357
|
function Ti(e) {
|
|
4384
|
-
|
|
4385
|
-
return typeof t == "string" ? t : "";
|
|
4358
|
+
return e.status == 400 && Ei(e.data) == "woocommerce_rest_webhook_invalid_id";
|
|
4386
4359
|
}
|
|
4387
4360
|
function Ei(e) {
|
|
4388
|
-
let t =
|
|
4389
|
-
|
|
4390
|
-
return t;
|
|
4361
|
+
let t = ji(e)?.code;
|
|
4362
|
+
return typeof t == "string" ? t : "";
|
|
4391
4363
|
}
|
|
4392
4364
|
function Di(e) {
|
|
4393
|
-
|
|
4365
|
+
let t = Oi(ji(e)?.id);
|
|
4366
|
+
if (t == null) throw new a("WooCommerce webhook response is missing its ID.");
|
|
4367
|
+
return t;
|
|
4394
4368
|
}
|
|
4395
4369
|
function Oi(e) {
|
|
4396
|
-
|
|
4397
|
-
return e;
|
|
4370
|
+
return typeof e == "string" && e.length > 0 ? e : typeof e == "number" && Number.isFinite(e) ? String(e) : null;
|
|
4398
4371
|
}
|
|
4399
4372
|
function ki(e) {
|
|
4400
|
-
|
|
4373
|
+
if (e == null) throw new i("WooCommerce Integration state is missing.");
|
|
4374
|
+
return e;
|
|
4401
4375
|
}
|
|
4402
4376
|
function Ai(e) {
|
|
4377
|
+
return new Date(e.getTime() + 2592e6);
|
|
4378
|
+
}
|
|
4379
|
+
function ji(e) {
|
|
4403
4380
|
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
4404
4381
|
}
|
|
4405
4382
|
//#endregion
|
|
4406
4383
|
//#region src/trigger/providers/zendesk/on-event.ts
|
|
4407
|
-
var
|
|
4384
|
+
var Mi = /* @__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(","), Q = "/api/v2/webhooks", Ni = {
|
|
4408
4385
|
initialState: {
|
|
4409
4386
|
checkpoint: null,
|
|
4410
4387
|
subscription: {}
|
|
@@ -4414,7 +4391,7 @@ var ji = /* @__PURE__ */ "zen:event-type:ticket.agent_assignment_changed,zen:eve
|
|
|
4414
4391
|
additionalProperties: !1,
|
|
4415
4392
|
properties: { events: {
|
|
4416
4393
|
items: {
|
|
4417
|
-
enum:
|
|
4394
|
+
enum: Mi,
|
|
4418
4395
|
type: "string"
|
|
4419
4396
|
},
|
|
4420
4397
|
minItems: 1,
|
|
@@ -4494,14 +4471,14 @@ var ji = /* @__PURE__ */ "zen:event-type:ticket.agent_assignment_changed,zen:eve
|
|
|
4494
4471
|
if (i == null) {
|
|
4495
4472
|
let t = await Li(e, "webhook create", {
|
|
4496
4473
|
body: Pi(e),
|
|
4497
|
-
endpoint:
|
|
4474
|
+
endpoint: Q,
|
|
4498
4475
|
method: "POST"
|
|
4499
4476
|
});
|
|
4500
4477
|
Ri(t, "webhook create"), i = Bi($(t.data)?.webhook);
|
|
4501
4478
|
} else {
|
|
4502
4479
|
let n = await Li(e, "webhook update", {
|
|
4503
4480
|
body: Pi(e),
|
|
4504
|
-
endpoint: `${
|
|
4481
|
+
endpoint: `${Q}/${i}`,
|
|
4505
4482
|
method: "PUT"
|
|
4506
4483
|
});
|
|
4507
4484
|
if (n.status == 404) return await t.saveSubscription({}, e.now), { outcome: "pending" };
|
|
@@ -4526,7 +4503,7 @@ async function Fi(e) {
|
|
|
4526
4503
|
let t = [], n;
|
|
4527
4504
|
for (let r = 0; r < 10; r += 1) {
|
|
4528
4505
|
let r = await Li(e, "webhook list", {
|
|
4529
|
-
endpoint:
|
|
4506
|
+
endpoint: Q,
|
|
4530
4507
|
method: "GET",
|
|
4531
4508
|
query: {
|
|
4532
4509
|
"filter[name_contains]": zi(e.endpointUrl),
|
|
@@ -4548,7 +4525,7 @@ async function Fi(e) {
|
|
|
4548
4525
|
}
|
|
4549
4526
|
async function Ii(e, t) {
|
|
4550
4527
|
let n = await Li(e, "webhook delete", {
|
|
4551
|
-
endpoint: `${
|
|
4528
|
+
endpoint: `${Q}/${t}`,
|
|
4552
4529
|
method: "DELETE"
|
|
4553
4530
|
});
|
|
4554
4531
|
n.status != 404 && Ri(n, "webhook delete");
|
|
@@ -4557,26 +4534,26 @@ async function Li(e, t, n) {
|
|
|
4557
4534
|
try {
|
|
4558
4535
|
return await e.connector.execute(n, e.signal);
|
|
4559
4536
|
} catch (e) {
|
|
4560
|
-
throw e instanceof
|
|
4537
|
+
throw e instanceof r ? e : new a(`Zendesk ${t} request failed.`, { cause: e });
|
|
4561
4538
|
}
|
|
4562
4539
|
}
|
|
4563
4540
|
function Ri(e, t) {
|
|
4564
|
-
if (!(e.status >= 200 && e.status < 300)) throw e.status == 401 || e.status == 403 ? new
|
|
4541
|
+
if (!(e.status >= 200 && e.status < 300)) throw e.status == 401 || e.status == 403 ? new r(`Zendesk ${t} rejected the Connection.`) : [
|
|
4565
4542
|
400,
|
|
4566
4543
|
404,
|
|
4567
4544
|
422
|
|
4568
|
-
].includes(e.status) ? new
|
|
4545
|
+
].includes(e.status) ? new i(`Zendesk ${t} rejected the subscription.`) : new a(`Zendesk ${t} failed with status ${e.status}.`);
|
|
4569
4546
|
}
|
|
4570
4547
|
function zi(e) {
|
|
4571
4548
|
return `open-flow-${e.slice(e.lastIndexOf("/") + 1)}`;
|
|
4572
4549
|
}
|
|
4573
4550
|
function Bi(e) {
|
|
4574
4551
|
let t = $(e)?.id;
|
|
4575
|
-
if (typeof t != "string") throw new
|
|
4552
|
+
if (typeof t != "string") throw new a("Zendesk webhook response is missing its ID.");
|
|
4576
4553
|
return t;
|
|
4577
4554
|
}
|
|
4578
4555
|
function Vi(e) {
|
|
4579
|
-
if (e == null) throw new
|
|
4556
|
+
if (e == null) throw new i("Zendesk Integration state is missing.");
|
|
4580
4557
|
return e;
|
|
4581
4558
|
}
|
|
4582
4559
|
function Hi(e) {
|
|
@@ -4592,22 +4569,22 @@ function $(e) {
|
|
|
4592
4569
|
//#endregion
|
|
4593
4570
|
//#region src/trigger/providers/definitions.ts
|
|
4594
4571
|
var Wi = [
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4572
|
+
s,
|
|
4573
|
+
Me,
|
|
4574
|
+
ue,
|
|
4575
|
+
be,
|
|
4576
|
+
Ke,
|
|
4577
|
+
ht,
|
|
4578
|
+
Lt,
|
|
4579
|
+
an,
|
|
4580
|
+
xn,
|
|
4581
|
+
Un,
|
|
4582
|
+
ur,
|
|
4583
|
+
Cr,
|
|
4584
|
+
Rr,
|
|
4585
|
+
Zr,
|
|
4586
|
+
li,
|
|
4587
|
+
yi,
|
|
4611
4588
|
Ni
|
|
4612
4589
|
], Gi = Wi.filter((e) => e.snapshot.type == "poll"), Ki = Wi.filter((e) => e.snapshot.type == "integration");
|
|
4613
4590
|
//#endregion
|