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