@oomol-lab/open-flow 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +47 -0
- package/README.md +18 -0
- package/dist/browser/_virtual_open-flow-twemoji-DJwKsM_w.js +5067 -0
- package/dist/browser/addNodeOptions-DqoIueCR.js +33746 -0
- package/dist/browser/assets/font-00b26ac825e20950.woff2 +0 -0
- package/dist/browser/assets/font-036d4e95149b69ff.woff2 +0 -0
- package/dist/browser/assets/font-07d8e303ce4fc12b.ttf +0 -0
- package/dist/browser/assets/font-08ce98e51b04d589.ttf +0 -0
- package/dist/browser/assets/font-0cdd387c9590a1a9.woff2 +0 -0
- package/dist/browser/assets/font-0d85ae7cc30f2379.ttf +0 -0
- package/dist/browser/assets/font-0f60d1b897938ec9.woff2 +0 -0
- package/dist/browser/assets/font-11e4dc8a6471ff6d.woff +0 -0
- package/dist/browser/assets/font-138ac28d1663b303.ttf +0 -0
- package/dist/browser/assets/font-1ae6bd7475590e97.woff +0 -0
- package/dist/browser/assets/font-1c67f068fea8bb09.ttf +0 -0
- package/dist/browser/assets/font-1e6f9579e90e2cac.ttf +0 -0
- package/dist/browser/assets/font-1ece03f79f95277d.ttf +0 -0
- package/dist/browser/assets/font-2014c523c3210bcc.woff +0 -0
- package/dist/browser/assets/font-30da91e84c893f87.woff +0 -0
- package/dist/browser/assets/font-3398dd02302557a7.woff +0 -0
- package/dist/browser/assets/font-3931dd81faed86ba.ttf +0 -0
- package/dist/browser/assets/font-500e04d54f0d5166.ttf +0 -0
- package/dist/browser/assets/font-51814d270d06ff02.woff2 +0 -0
- package/dist/browser/assets/font-5d53e70ad607c235.woff2 +0 -0
- package/dist/browser/assets/font-5e28753be717dac9.woff +0 -0
- package/dist/browser/assets/font-68534840bcfdd2bf.ttf +0 -0
- package/dist/browser/assets/font-68e8c73ef42afd3c.woff2 +0 -0
- package/dist/browser/assets/font-6ab6b62e9b62dae2.woff +0 -0
- package/dist/browser/assets/font-6b47c40166b6dbe2.woff2 +0 -0
- package/dist/browser/assets/font-70ee1f64a20f2048.ttf +0 -0
- package/dist/browser/assets/font-71d517d67827787c.woff2 +0 -0
- package/dist/browser/assets/font-73d591271b160496.woff2 +0 -0
- package/dist/browser/assets/font-74444efd593c005e.woff2 +0 -0
- package/dist/browser/assets/font-7af58c5ec8f132a2.woff2 +0 -0
- package/dist/browser/assets/font-850c0af5c2238497.woff +0 -0
- package/dist/browser/assets/font-8a8d244581371912.woff +0 -0
- package/dist/browser/assets/font-9163df9c7122432e.ttf +0 -0
- package/dist/browser/assets/font-91ee67500cc0129a.woff +0 -0
- package/dist/browser/assets/font-95b6d2f1a50173bf.ttf +0 -0
- package/dist/browser/assets/font-97479ca6cce906ab.woff2 +0 -0
- package/dist/browser/assets/font-99cd42a3c072d918.woff2 +0 -0
- package/dist/browser/assets/font-99f9c6750b489c94.woff +0 -0
- package/dist/browser/assets/font-9be7ceb88004ab8a.woff +0 -0
- package/dist/browser/assets/font-a4af7d414440a1c1.woff2 +0 -0
- package/dist/browser/assets/font-a6b2099fb555c60e.ttf +0 -0
- package/dist/browser/assets/font-a6f7ec0d846ac7ad.woff +0 -0
- package/dist/browser/assets/font-c2342cd8b869e017.woff2 +0 -0
- package/dist/browser/assets/font-c6368d87e8a1a3a5.woff +0 -0
- package/dist/browser/assets/font-c647367d1dd4e162.ttf +0 -0
- package/dist/browser/assets/font-c76c5d696297d51b.woff +0 -0
- package/dist/browser/assets/font-c943cc986384f59e.woff +0 -0
- package/dist/browser/assets/font-d0332f52868370fd.ttf +0 -0
- package/dist/browser/assets/font-d04c54219f9eaec6.woff2 +0 -0
- package/dist/browser/assets/font-d96cdf2b3bdd4d64.woff +0 -0
- package/dist/browser/assets/font-dc47344dbb6cb5b6.woff2 +0 -0
- package/dist/browser/assets/font-de7701e42cf1f4cf.woff2 +0 -0
- package/dist/browser/assets/font-e14fed02b1aba7ce.woff +0 -0
- package/dist/browser/assets/font-e99ae51144bf1232.woff2 +0 -0
- package/dist/browser/assets/font-ece03cfd83e22c21.woff +0 -0
- package/dist/browser/assets/font-ed0b74372feefcbb.ttf +0 -0
- package/dist/browser/assets/font-f01f3e87d9c6a61c.ttf +0 -0
- package/dist/browser/assets/font-f1d6ef86f3b11a52.woff +0 -0
- package/dist/browser/assets/font-f36ea897e19f4a2e.ttf +0 -0
- package/dist/browser/assets/font-f9377ab0271cda59.ttf +0 -0
- package/dist/browser/carbon-nMY84Amv.js +53 -0
- package/dist/browser/composite-7VwgfnXx.js +6088 -0
- package/dist/browser/createResourceDialog-ByuJWdSL.js +439 -0
- package/dist/browser/dist-7oZK9QXZ.js +50088 -0
- package/dist/browser/dist-B9OV3YTx.js +881 -0
- package/dist/browser/dist-BLk5M0uK.js +1816 -0
- package/dist/browser/dist-BbyiRq3c.js +3285 -0
- package/dist/browser/dist-CIq6ue3I.js +6646 -0
- package/dist/browser/dist-CLZJNoWB.js +89 -0
- package/dist/browser/dist-CvcmLAMW.js +1620 -0
- package/dist/browser/dist-DL0SDskM.js +2327 -0
- package/dist/browser/dist-Djd02JSy.js +1247 -0
- package/dist/browser/dist-aWSZx4q1.js +850 -0
- package/dist/browser/dist-n-z5HtaO.js +4 -0
- package/dist/browser/dist-o4dBuwiG.js +320 -0
- package/dist/browser/dist-zyY--HOV.js +1543 -0
- package/dist/browser/esm-DXw7EADW.js +218 -0
- package/dist/browser/favicon.svg +7 -0
- package/dist/browser/flowWorkspace-DwVMpcar.js +22092 -0
- package/dist/browser/lib-S4ccuMeT.js +7857 -0
- package/dist/browser/licenses.md +4973 -0
- package/dist/browser/markdownContent-ZZFfSRqO.js +44545 -0
- package/dist/browser/project-change.d.ts +311 -0
- package/dist/browser/project-change.js +259 -0
- package/dist/browser/project-notifications.d.ts +12 -0
- package/dist/browser/rolldown-runtime-CEFd7nDs.js +30 -0
- package/dist/browser/workbench-contract.d.ts +28 -0
- package/dist/browser/workbench.css +2 -0
- package/dist/browser/workbench.css.d.ts +1 -0
- package/dist/browser/workbench.d.ts +14 -0
- package/dist/browser/workbench.js +3364 -0
- package/dist/common/connector-action.d.ts +20 -0
- package/dist/common/connector-action.js +106 -0
- package/dist/common/connector-proxy.d.ts +14 -0
- package/dist/common/connector-proxy.js +0 -0
- package/dist/common/control-api-conformance.d.ts +13 -0
- package/dist/common/control-api-conformance.js +518 -0
- package/dist/common/control-api-errors.d.ts +121 -0
- package/dist/common/control-api.d.ts +349 -0
- package/dist/common/control-api.js +884 -0
- package/dist/common/cron-trigger.d.ts +21 -0
- package/dist/common/cron-trigger.js +834 -0
- package/dist/common/engine-contract.d.ts +7 -0
- package/dist/common/favicon.svg +7 -0
- package/dist/common/integration-trigger.d.ts +111 -0
- package/dist/common/integration-trigger.js +290 -0
- package/dist/common/licenses.md +27 -0
- package/dist/common/poll-trigger.d.ts +69 -0
- package/dist/common/poll-trigger.js +155 -0
- package/dist/common/project-encoding.d.ts +11 -0
- package/dist/common/project-encoding.js +242 -0
- package/dist/common/project-notifications.d.ts +12 -0
- package/dist/common/project-semantics.d.ts +55 -0
- package/dist/common/project-semantics.js +8687 -0
- package/dist/common/provider-triggers.d.ts +6 -0
- package/dist/common/provider-triggers.js +4614 -0
- package/dist/common/run-events.d.ts +9 -0
- package/dist/common/run-events.js +192 -0
- package/dist/common/run-lifecycle.d.ts +69 -0
- package/dist/common/run-lifecycle.js +169 -0
- package/dist/common/runtime-contract.d.ts +53 -0
- package/dist/common/runtime-contract.js +151 -0
- package/dist/common/scheduler.d.ts +99 -0
- package/dist/common/scheduler.js +379 -0
- package/dist/common/webhook-trigger.d.ts +22 -0
- package/dist/common/webhook-trigger.js +270 -0
- package/dist/index.d.ts +66 -0
- package/package.json +102 -0
|
@@ -0,0 +1,4614 @@
|
|
|
1
|
+
new TextEncoder();
|
|
2
|
+
var e = class extends Error {
|
|
3
|
+
constructor(...e) {
|
|
4
|
+
super(...e), this.name = "PollConnectionError";
|
|
5
|
+
}
|
|
6
|
+
}, t = class extends Error {
|
|
7
|
+
constructor(...e) {
|
|
8
|
+
super(...e), this.name = "PermanentPollError";
|
|
9
|
+
}
|
|
10
|
+
}, n = class extends Error {
|
|
11
|
+
constructor(...e) {
|
|
12
|
+
super(...e), this.name = "TransientPollError";
|
|
13
|
+
}
|
|
14
|
+
}, r = "LIST_RECORDS_ITERATOR_NOT_AVAILABLE", i = {
|
|
15
|
+
snapshot: {
|
|
16
|
+
configSchema: {
|
|
17
|
+
additionalProperties: !1,
|
|
18
|
+
properties: {
|
|
19
|
+
baseId: {
|
|
20
|
+
pattern: "^app[A-Za-z0-9]{14}$",
|
|
21
|
+
type: "string"
|
|
22
|
+
},
|
|
23
|
+
fields: {
|
|
24
|
+
default: [],
|
|
25
|
+
items: {
|
|
26
|
+
minLength: 1,
|
|
27
|
+
type: "string"
|
|
28
|
+
},
|
|
29
|
+
type: "array"
|
|
30
|
+
},
|
|
31
|
+
formula: {
|
|
32
|
+
default: "",
|
|
33
|
+
type: "string"
|
|
34
|
+
},
|
|
35
|
+
maxRecordsPerPoll: {
|
|
36
|
+
default: 200,
|
|
37
|
+
maximum: 1e3,
|
|
38
|
+
minimum: 1,
|
|
39
|
+
type: "integer"
|
|
40
|
+
},
|
|
41
|
+
tableIdOrName: {
|
|
42
|
+
maxLength: 255,
|
|
43
|
+
minLength: 1,
|
|
44
|
+
type: "string"
|
|
45
|
+
},
|
|
46
|
+
triggerField: {
|
|
47
|
+
maxLength: 255,
|
|
48
|
+
minLength: 1,
|
|
49
|
+
not: { pattern: "}" },
|
|
50
|
+
type: "string"
|
|
51
|
+
},
|
|
52
|
+
view: {
|
|
53
|
+
default: "",
|
|
54
|
+
type: "string"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
required: [
|
|
58
|
+
"baseId",
|
|
59
|
+
"tableIdOrName",
|
|
60
|
+
"triggerField"
|
|
61
|
+
],
|
|
62
|
+
title: "Airtable Record Change Config",
|
|
63
|
+
type: "object"
|
|
64
|
+
},
|
|
65
|
+
definitionVersion: 1,
|
|
66
|
+
description: "Polls an Airtable table and triggers when a record is created or updated, ordered by a time field.",
|
|
67
|
+
displayName: "Airtable: Record Created or Updated",
|
|
68
|
+
key: "airtable.on_record_changed",
|
|
69
|
+
name: "on_record_changed",
|
|
70
|
+
payloadSchema: {
|
|
71
|
+
additionalProperties: !1,
|
|
72
|
+
properties: { events: {
|
|
73
|
+
items: {
|
|
74
|
+
additionalProperties: !1,
|
|
75
|
+
properties: {
|
|
76
|
+
baseId: { type: "string" },
|
|
77
|
+
createdTime: { type: "string" },
|
|
78
|
+
fields: { type: "object" },
|
|
79
|
+
recordId: { type: "string" },
|
|
80
|
+
tableIdOrName: { type: "string" },
|
|
81
|
+
triggerField: { type: "string" },
|
|
82
|
+
triggerFieldValue: { type: "string" }
|
|
83
|
+
},
|
|
84
|
+
required: [
|
|
85
|
+
"baseId",
|
|
86
|
+
"tableIdOrName",
|
|
87
|
+
"recordId",
|
|
88
|
+
"createdTime",
|
|
89
|
+
"triggerField",
|
|
90
|
+
"triggerFieldValue",
|
|
91
|
+
"fields"
|
|
92
|
+
],
|
|
93
|
+
type: "object"
|
|
94
|
+
},
|
|
95
|
+
type: "array"
|
|
96
|
+
} },
|
|
97
|
+
required: ["events"],
|
|
98
|
+
title: "Airtable Record Change Payload",
|
|
99
|
+
type: "object"
|
|
100
|
+
},
|
|
101
|
+
provider: "airtable",
|
|
102
|
+
type: "poll"
|
|
103
|
+
},
|
|
104
|
+
async poll(e) {
|
|
105
|
+
let t = a(e.config);
|
|
106
|
+
if (e.checkpoint === null) return {
|
|
107
|
+
checkpoint: await c(e, t),
|
|
108
|
+
events: []
|
|
109
|
+
};
|
|
110
|
+
let n = o(e.checkpoint), r = await l(e, t, n), i = [], s = 0;
|
|
111
|
+
for (let e of r.records) {
|
|
112
|
+
let n = g(e.fields?.[t.triggerField]);
|
|
113
|
+
n == null ? s += 1 : i.push({
|
|
114
|
+
record: e,
|
|
115
|
+
value: n
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
let d = i.flatMap(({ record: e, value: r }) => r == n.cursor && n.boundaryIds.includes(e.id) ? [] : [h(t, e, r)]), f = u(n, r, i);
|
|
119
|
+
return {
|
|
120
|
+
checkpoint: f.checkpoint,
|
|
121
|
+
events: d,
|
|
122
|
+
filtered: s,
|
|
123
|
+
...f.hasMore ? { hasMore: !0 } : {}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
function a(e) {
|
|
128
|
+
return {
|
|
129
|
+
baseId: e.baseId,
|
|
130
|
+
fields: e.fields ?? [],
|
|
131
|
+
formula: (e.formula ?? "").trim(),
|
|
132
|
+
maxRecordsPerPoll: e.maxRecordsPerPoll ?? 200,
|
|
133
|
+
tableIdOrName: e.tableIdOrName,
|
|
134
|
+
triggerField: e.triggerField,
|
|
135
|
+
view: (e.view ?? "").trim()
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function o(e) {
|
|
139
|
+
let n = _(e), r = g(n?.cursor), i = n?.boundaryIds;
|
|
140
|
+
if (r == null || !Array.isArray(i) || i.some((e) => typeof e != "string")) throw new t("Airtable checkpoint is invalid; recreate the Trigger.");
|
|
141
|
+
let a = s(n?.pending);
|
|
142
|
+
return {
|
|
143
|
+
boundaryIds: i,
|
|
144
|
+
cursor: r,
|
|
145
|
+
...n?.cursorExclusive === !0 ? { cursorExclusive: !0 } : {},
|
|
146
|
+
...typeof n?.offset == "string" ? { offset: n.offset } : {},
|
|
147
|
+
...a == null ? {} : { pending: a }
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function s(e) {
|
|
151
|
+
let t = _(e), n = g(t?.cursor), r = t?.boundaryIds;
|
|
152
|
+
return n == null || !Array.isArray(r) || r.some((e) => typeof e != "string") ? null : {
|
|
153
|
+
boundaryIds: r,
|
|
154
|
+
cursor: n,
|
|
155
|
+
...t?.cursorExclusive === !0 ? { cursorExclusive: !0 } : {}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
async function c(e, n) {
|
|
159
|
+
let r = await ie(e, n, ee(n));
|
|
160
|
+
ae(r, "seed list");
|
|
161
|
+
let i = oe(r.data);
|
|
162
|
+
if (i.records.length == 0) return {
|
|
163
|
+
boundaryIds: [],
|
|
164
|
+
cursor: e.now.toISOString()
|
|
165
|
+
};
|
|
166
|
+
let a = g(i.records[0]?.fields?.[n.triggerField]);
|
|
167
|
+
if (a == null) throw new t("The Airtable trigger field is not a time field.");
|
|
168
|
+
let o = i.records.filter((e) => g(e.fields?.[n.triggerField]) === a).map(({ id: e }) => e);
|
|
169
|
+
return o.length == i.records.length && i.offset ? {
|
|
170
|
+
boundaryIds: [],
|
|
171
|
+
cursor: a,
|
|
172
|
+
cursorExclusive: !0
|
|
173
|
+
} : {
|
|
174
|
+
boundaryIds: o,
|
|
175
|
+
cursor: a
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
async function l(e, t, n) {
|
|
179
|
+
let i = [], a = n.offset, o = Math.min(Math.ceil(t.maxRecordsPerPoll / 100), 10);
|
|
180
|
+
for (let s = 0; s < o; s += 1) {
|
|
181
|
+
let o = await ie(e, t, te(t, n, a));
|
|
182
|
+
if (a != null && o.status == 422 && se(o.data) == r) return {
|
|
183
|
+
offsetWentStale: !0,
|
|
184
|
+
records: i
|
|
185
|
+
};
|
|
186
|
+
ae(o, "record list");
|
|
187
|
+
let s = oe(o.data);
|
|
188
|
+
if (i.push(...s.records), !s.offset) return {
|
|
189
|
+
offsetWentStale: !1,
|
|
190
|
+
records: i
|
|
191
|
+
};
|
|
192
|
+
a = s.offset;
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
offset: a,
|
|
196
|
+
offsetWentStale: !1,
|
|
197
|
+
records: i
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function u(e, t, n) {
|
|
201
|
+
let r = {
|
|
202
|
+
boundaryIds: e.boundaryIds,
|
|
203
|
+
cursor: e.cursor,
|
|
204
|
+
...e.cursorExclusive === !0 ? { cursorExclusive: !0 } : {}
|
|
205
|
+
};
|
|
206
|
+
if (t.offsetWentStale) return {
|
|
207
|
+
checkpoint: r,
|
|
208
|
+
hasMore: !1
|
|
209
|
+
};
|
|
210
|
+
let i = f(e.pending, d(n));
|
|
211
|
+
return t.offset == null ? {
|
|
212
|
+
checkpoint: i == null ? r : p(r, i),
|
|
213
|
+
hasMore: !1
|
|
214
|
+
} : {
|
|
215
|
+
checkpoint: {
|
|
216
|
+
...r,
|
|
217
|
+
offset: t.offset,
|
|
218
|
+
...i == null ? {} : { pending: i }
|
|
219
|
+
},
|
|
220
|
+
hasMore: !0
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function d(e) {
|
|
224
|
+
if (e.length == 0) return;
|
|
225
|
+
let t = e.reduce((e, t) => t.value > e ? t.value : e, e[0].value);
|
|
226
|
+
return m(t, e.filter(({ value: e }) => e == t).map(({ record: e }) => e.id));
|
|
227
|
+
}
|
|
228
|
+
function f(e, t) {
|
|
229
|
+
return e == null ? t : t == null ? e : p(e, t);
|
|
230
|
+
}
|
|
231
|
+
function p(e, t) {
|
|
232
|
+
return t.cursor > e.cursor ? t : e.cursor > t.cursor ? e : e.cursorExclusive === !0 || t.cursorExclusive === !0 ? {
|
|
233
|
+
boundaryIds: [],
|
|
234
|
+
cursor: e.cursor,
|
|
235
|
+
cursorExclusive: !0
|
|
236
|
+
} : m(e.cursor, [.../* @__PURE__ */ new Set([...e.boundaryIds, ...t.boundaryIds])]);
|
|
237
|
+
}
|
|
238
|
+
function m(e, t) {
|
|
239
|
+
return t.length > 200 ? {
|
|
240
|
+
boundaryIds: [],
|
|
241
|
+
cursor: e,
|
|
242
|
+
cursorExclusive: !0
|
|
243
|
+
} : {
|
|
244
|
+
boundaryIds: t,
|
|
245
|
+
cursor: e
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function h(e, t, n) {
|
|
249
|
+
return {
|
|
250
|
+
dedupeKey: `${t.id}:${n}`,
|
|
251
|
+
payload: {
|
|
252
|
+
baseId: e.baseId,
|
|
253
|
+
createdTime: t.createdTime ?? "",
|
|
254
|
+
fields: t.fields ?? {},
|
|
255
|
+
recordId: t.id,
|
|
256
|
+
tableIdOrName: e.tableIdOrName,
|
|
257
|
+
triggerField: e.triggerField,
|
|
258
|
+
triggerFieldValue: n
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function ee(e) {
|
|
263
|
+
return {
|
|
264
|
+
fields: [e.triggerField],
|
|
265
|
+
filterByFormula: re([ne(e.triggerField), ...e.formula.length == 0 ? [] : [e.formula]]),
|
|
266
|
+
pageSize: 100,
|
|
267
|
+
sort: [{
|
|
268
|
+
direction: "desc",
|
|
269
|
+
field: e.triggerField
|
|
270
|
+
}],
|
|
271
|
+
...e.view.length == 0 ? {} : { view: e.view }
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
function te(e, t, n) {
|
|
275
|
+
let r = `DATETIME_PARSE("${t.cursor}", "YYYY-MM-DDTHH:mm:ss.SSSZ")`, i = t.cursorExclusive === !0 ? `IS_AFTER({${e.triggerField}}, ${r})` : `NOT(IS_BEFORE({${e.triggerField}}, ${r}))`, a = e.fields.includes(e.triggerField) ? e.fields : [...e.fields, e.triggerField];
|
|
276
|
+
return {
|
|
277
|
+
filterByFormula: re([
|
|
278
|
+
ne(e.triggerField),
|
|
279
|
+
i,
|
|
280
|
+
...e.formula.length == 0 ? [] : [e.formula]
|
|
281
|
+
]),
|
|
282
|
+
pageSize: 100,
|
|
283
|
+
sort: [{
|
|
284
|
+
direction: "asc",
|
|
285
|
+
field: e.triggerField
|
|
286
|
+
}],
|
|
287
|
+
...e.fields.length == 0 ? {} : { fields: a },
|
|
288
|
+
...e.view.length == 0 ? {} : { view: e.view },
|
|
289
|
+
...n == null ? {} : { offset: n }
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
function ne(e) {
|
|
293
|
+
return `NOT({${e}} = BLANK())`;
|
|
294
|
+
}
|
|
295
|
+
function re(e) {
|
|
296
|
+
return `AND(${e.join(", ")})`;
|
|
297
|
+
}
|
|
298
|
+
async function ie(e, t, r) {
|
|
299
|
+
let i = `/${t.baseId}/${encodeURIComponent(t.tableIdOrName)}/listRecords`;
|
|
300
|
+
try {
|
|
301
|
+
return await e.connector.execute({
|
|
302
|
+
body: r,
|
|
303
|
+
endpoint: i,
|
|
304
|
+
method: "POST"
|
|
305
|
+
}, e.signal);
|
|
306
|
+
} catch (e) {
|
|
307
|
+
throw new n(`Airtable proxy request to ${i} failed.`, { cause: e });
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function ae(i, a) {
|
|
311
|
+
if (!(i.status >= 200 && i.status < 300)) throw i.status == 401 || i.status == 403 ? new e(`Airtable ${a} rejected the Connection.`) : i.status == 404 ? new t("The Airtable base or table was not found.") : i.status == 422 && se(i.data) !== r ? new t("Airtable rejected the trigger field, formula, or view.") : new n(`Airtable ${a} failed with status ${i.status}.`);
|
|
312
|
+
}
|
|
313
|
+
function oe(e) {
|
|
314
|
+
let t = _(e);
|
|
315
|
+
return {
|
|
316
|
+
records: Array.isArray(t?.records) ? t.records : [],
|
|
317
|
+
...typeof t?.offset == "string" ? { offset: t.offset } : {}
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
function se(e) {
|
|
321
|
+
let t = _(e)?.error;
|
|
322
|
+
if (typeof t == "string") return t;
|
|
323
|
+
let n = _(t)?.type;
|
|
324
|
+
return typeof n == "string" ? n : "";
|
|
325
|
+
}
|
|
326
|
+
function g(e) {
|
|
327
|
+
if (typeof e != "string" || e.length == 0) return null;
|
|
328
|
+
let t = new Date(e);
|
|
329
|
+
return Number.isNaN(t.getTime()) ? null : t.toISOString();
|
|
330
|
+
}
|
|
331
|
+
function _(e) {
|
|
332
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
333
|
+
}
|
|
334
|
+
new TextEncoder();
|
|
335
|
+
var v = class extends Error {
|
|
336
|
+
constructor(...e) {
|
|
337
|
+
super(...e), this.name = "IntegrationConnectionError";
|
|
338
|
+
}
|
|
339
|
+
}, y = class extends Error {
|
|
340
|
+
constructor(...e) {
|
|
341
|
+
super(...e), this.name = "PermanentIntegrationError";
|
|
342
|
+
}
|
|
343
|
+
}, b = class extends Error {
|
|
344
|
+
constructor(...e) {
|
|
345
|
+
super(...e), this.name = "TransientIntegrationError";
|
|
346
|
+
}
|
|
347
|
+
}, ce = {
|
|
348
|
+
initialState: {
|
|
349
|
+
checkpoint: null,
|
|
350
|
+
subscription: {}
|
|
351
|
+
},
|
|
352
|
+
snapshot: {
|
|
353
|
+
configSchema: {
|
|
354
|
+
additionalProperties: !1,
|
|
355
|
+
properties: {
|
|
356
|
+
events: {
|
|
357
|
+
items: {
|
|
358
|
+
enum: /* @__PURE__ */ "*.branch_protection_configuration.branch_protection_rule.check_run.check_suite.code_scanning_alert.commit_comment.create.custom_property_values.delete.dependabot_alert.deploy_key.deployment.deployment_status.discussion.discussion_comment.fork.gollum.issue_comment.issue_dependencies.issues.label.member.meta.milestone.package.page_build.project.project_card.project_column.public.pull_request.pull_request_review.pull_request_review_comment.pull_request_review_thread.push.registry_package.release.repository.repository_advisory.repository_import.repository_ruleset.repository_vulnerability_alert.secret_scanning_alert.secret_scanning_alert_location.secret_scanning_scan.security_and_analysis.star.status.sub_issues.team_add.watch.workflow_job.workflow_run".split("."),
|
|
359
|
+
type: "string"
|
|
360
|
+
},
|
|
361
|
+
minItems: 1,
|
|
362
|
+
type: "array",
|
|
363
|
+
uniqueItems: !0
|
|
364
|
+
},
|
|
365
|
+
insecureSsl: {
|
|
366
|
+
default: !1,
|
|
367
|
+
type: "boolean"
|
|
368
|
+
},
|
|
369
|
+
owner: {
|
|
370
|
+
pattern: "^[a-zA-Z0-9](?:[a-zA-Z0-9]|-(?=[a-zA-Z0-9])){0,38}$",
|
|
371
|
+
type: "string"
|
|
372
|
+
},
|
|
373
|
+
repo: {
|
|
374
|
+
pattern: "^(?!\\.{1,2}$)[a-zA-Z0-9._-]{1,100}$",
|
|
375
|
+
type: "string"
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
required: [
|
|
379
|
+
"owner",
|
|
380
|
+
"repo",
|
|
381
|
+
"events"
|
|
382
|
+
],
|
|
383
|
+
title: "GitHub Repo Event Config",
|
|
384
|
+
type: "object"
|
|
385
|
+
},
|
|
386
|
+
definitionVersion: 1,
|
|
387
|
+
description: "Triggers when selected GitHub webhook events occur in a repository.",
|
|
388
|
+
displayName: "GitHub: Repository Event",
|
|
389
|
+
endpoint: {
|
|
390
|
+
body: {
|
|
391
|
+
allowArray: !1,
|
|
392
|
+
allowEmpty: !1,
|
|
393
|
+
formats: ["json"]
|
|
394
|
+
},
|
|
395
|
+
methods: ["POST"],
|
|
396
|
+
successStatus: 202
|
|
397
|
+
},
|
|
398
|
+
key: "github.on_repo_event",
|
|
399
|
+
name: "on_repo_event",
|
|
400
|
+
payloadSchema: {
|
|
401
|
+
additionalProperties: !1,
|
|
402
|
+
properties: {
|
|
403
|
+
body: { type: "object" },
|
|
404
|
+
deliveryId: { type: "string" },
|
|
405
|
+
event: { type: "string" }
|
|
406
|
+
},
|
|
407
|
+
required: [
|
|
408
|
+
"event",
|
|
409
|
+
"deliveryId",
|
|
410
|
+
"body"
|
|
411
|
+
],
|
|
412
|
+
title: "GitHub Repo Event Payload",
|
|
413
|
+
type: "object"
|
|
414
|
+
},
|
|
415
|
+
provider: "github",
|
|
416
|
+
type: "integration"
|
|
417
|
+
},
|
|
418
|
+
receive(e) {
|
|
419
|
+
let t = e.header("x-github-event")?.trim();
|
|
420
|
+
if (!t) return {
|
|
421
|
+
outcome: "ignored",
|
|
422
|
+
reason: "GitHub event header is missing."
|
|
423
|
+
};
|
|
424
|
+
if (t == "ping") return {
|
|
425
|
+
outcome: "ignored",
|
|
426
|
+
reason: "GitHub ping handshake."
|
|
427
|
+
};
|
|
428
|
+
let n = le(e.config);
|
|
429
|
+
if (!n.events.includes("*") && !n.events.includes(t)) return {
|
|
430
|
+
outcome: "ignored",
|
|
431
|
+
reason: "GitHub event is not subscribed."
|
|
432
|
+
};
|
|
433
|
+
let r = e.header("x-github-delivery") ?? "";
|
|
434
|
+
return {
|
|
435
|
+
dedupeKey: r.length == 0 ? void 0 : r,
|
|
436
|
+
outcome: "event",
|
|
437
|
+
payload: {
|
|
438
|
+
body: e.payload,
|
|
439
|
+
deliveryId: r,
|
|
440
|
+
event: t
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
},
|
|
444
|
+
async reconcile(e) {
|
|
445
|
+
let t = pe(e.state), n = le(e.config), r = me(t);
|
|
446
|
+
if (!e.active) {
|
|
447
|
+
if (r ??= await de(e, n), r != null) {
|
|
448
|
+
let t = await S(e, "hook delete", {
|
|
449
|
+
endpoint: `${x(n)}/${r}`,
|
|
450
|
+
method: "DELETE"
|
|
451
|
+
});
|
|
452
|
+
t.status != 404 && C(t, "hook delete");
|
|
453
|
+
}
|
|
454
|
+
return await t.saveSubscription({}, he(e.now)), { outcome: "ready" };
|
|
455
|
+
}
|
|
456
|
+
let i = ue(e.endpointUrl, n);
|
|
457
|
+
if (r == null) {
|
|
458
|
+
let t = await S(e, "hook create", {
|
|
459
|
+
body: i,
|
|
460
|
+
endpoint: x(n),
|
|
461
|
+
method: "POST"
|
|
462
|
+
});
|
|
463
|
+
if (t.status == 201) r = fe(t.data);
|
|
464
|
+
else if (t.status == 422) {
|
|
465
|
+
if (r = await de(e, n), r == null) throw new y("GitHub rejected the webhook configuration.");
|
|
466
|
+
} else throw C(t, "hook create"), new b(`GitHub hook create returned unexpected status ${t.status}.`);
|
|
467
|
+
}
|
|
468
|
+
let a = await S(e, "hook update", {
|
|
469
|
+
body: i,
|
|
470
|
+
endpoint: `${x(n)}/${r}`,
|
|
471
|
+
method: "PATCH"
|
|
472
|
+
});
|
|
473
|
+
return a.status == 404 ? (await t.saveSubscription({}, e.now), { outcome: "pending" }) : (C(a, "hook update"), await t.saveSubscription({ hookId: r }, he(e.now)), { outcome: "ready" });
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
function le(e) {
|
|
477
|
+
return {
|
|
478
|
+
events: [...new Set(e.events)],
|
|
479
|
+
insecureSsl: e.insecureSsl ?? !1,
|
|
480
|
+
owner: e.owner,
|
|
481
|
+
repo: e.repo
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
function x(e) {
|
|
485
|
+
return `/repos/${encodeURIComponent(e.owner)}/${encodeURIComponent(e.repo)}/hooks`;
|
|
486
|
+
}
|
|
487
|
+
function ue(e, t) {
|
|
488
|
+
return {
|
|
489
|
+
active: !0,
|
|
490
|
+
config: {
|
|
491
|
+
content_type: "json",
|
|
492
|
+
insecure_ssl: t.insecureSsl ? "1" : "0",
|
|
493
|
+
url: e
|
|
494
|
+
},
|
|
495
|
+
events: t.events,
|
|
496
|
+
name: "web"
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
async function de(e, t) {
|
|
500
|
+
for (let n = 1; n <= 10; n += 1) {
|
|
501
|
+
let r = await S(e, "hook list", {
|
|
502
|
+
endpoint: x(t),
|
|
503
|
+
method: "GET",
|
|
504
|
+
query: {
|
|
505
|
+
page: n,
|
|
506
|
+
per_page: 100
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
if (r.status == 404) return null;
|
|
510
|
+
C(r, "hook list");
|
|
511
|
+
let i = Array.isArray(r.data) ? r.data : [];
|
|
512
|
+
for (let t of i) {
|
|
513
|
+
let n = w(t);
|
|
514
|
+
if (w(n?.config)?.url === e.endpointUrl && (typeof n?.id == "number" || typeof n?.id == "string")) return String(n.id);
|
|
515
|
+
}
|
|
516
|
+
if (i.length < 100) return null;
|
|
517
|
+
}
|
|
518
|
+
return null;
|
|
519
|
+
}
|
|
520
|
+
async function S(e, t, n) {
|
|
521
|
+
try {
|
|
522
|
+
return await e.connector.execute(n, e.signal);
|
|
523
|
+
} catch (e) {
|
|
524
|
+
throw e instanceof v ? e : new b(`GitHub ${t} request failed.`, { cause: e });
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
function C(e, t) {
|
|
528
|
+
if (e.status >= 200 && e.status < 300) return;
|
|
529
|
+
let n = w(e.data)?.message;
|
|
530
|
+
throw e.status == 403 && typeof n == "string" && /rate limit/i.test(n) ? new b(`GitHub ${t} was rate limited.`) : [401, 403].includes(e.status) ? new v(`GitHub ${t} rejected the Connection.`) : [404, 422].includes(e.status) ? new y(`GitHub ${t} rejected the subscription.`) : new b(`GitHub ${t} failed with status ${e.status}.`);
|
|
531
|
+
}
|
|
532
|
+
function fe(e) {
|
|
533
|
+
let t = w(e)?.id;
|
|
534
|
+
if (typeof t != "number" && typeof t != "string") throw new b("GitHub hook response is missing its ID.");
|
|
535
|
+
return String(t);
|
|
536
|
+
}
|
|
537
|
+
function pe(e) {
|
|
538
|
+
if (e == null) throw new y("GitHub Integration state is missing.");
|
|
539
|
+
return e;
|
|
540
|
+
}
|
|
541
|
+
function me(e) {
|
|
542
|
+
let t = e.subscription.hookId;
|
|
543
|
+
return typeof t == "string" && t.length > 0 ? t : null;
|
|
544
|
+
}
|
|
545
|
+
function he(e) {
|
|
546
|
+
return new Date(e.getTime() + 2592e6);
|
|
547
|
+
}
|
|
548
|
+
function w(e) {
|
|
549
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
550
|
+
}
|
|
551
|
+
//#endregion
|
|
552
|
+
//#region src/trigger/providers/gitlab/on-project-event.ts
|
|
553
|
+
var ge = [
|
|
554
|
+
"push",
|
|
555
|
+
"tag_push",
|
|
556
|
+
"issues",
|
|
557
|
+
"confidential_issues",
|
|
558
|
+
"note",
|
|
559
|
+
"confidential_note",
|
|
560
|
+
"merge_requests",
|
|
561
|
+
"job",
|
|
562
|
+
"pipeline",
|
|
563
|
+
"wiki_page",
|
|
564
|
+
"deployment",
|
|
565
|
+
"feature_flag",
|
|
566
|
+
"releases",
|
|
567
|
+
"milestone",
|
|
568
|
+
"emoji",
|
|
569
|
+
"resource_access_token",
|
|
570
|
+
"resource_deploy_token"
|
|
571
|
+
], _e = /* @__PURE__ */ new Map([
|
|
572
|
+
["Push Hook", "push"],
|
|
573
|
+
["Tag Push Hook", "tag_push"],
|
|
574
|
+
["Issue Hook", "issues"],
|
|
575
|
+
["Confidential Issue Hook", "confidential_issues"],
|
|
576
|
+
["Note Hook", "note"],
|
|
577
|
+
["Confidential Note Hook", "confidential_note"],
|
|
578
|
+
["Merge Request Hook", "merge_requests"],
|
|
579
|
+
["Job Hook", "job"],
|
|
580
|
+
["Pipeline Hook", "pipeline"],
|
|
581
|
+
["Wiki Page Hook", "wiki_page"],
|
|
582
|
+
["Deployment Hook", "deployment"],
|
|
583
|
+
["Feature Flag Hook", "feature_flag"],
|
|
584
|
+
["Release Hook", "releases"],
|
|
585
|
+
["Milestone Hook", "milestone"],
|
|
586
|
+
["Emoji Hook", "emoji"],
|
|
587
|
+
["Resource Access Token Hook", "resource_access_token"],
|
|
588
|
+
["Resource Deploy Token Hook", "resource_deploy_token"]
|
|
589
|
+
]), ve = {
|
|
590
|
+
initialState: {
|
|
591
|
+
checkpoint: null,
|
|
592
|
+
subscription: {}
|
|
593
|
+
},
|
|
594
|
+
snapshot: {
|
|
595
|
+
configSchema: {
|
|
596
|
+
additionalProperties: !1,
|
|
597
|
+
properties: {
|
|
598
|
+
events: {
|
|
599
|
+
items: {
|
|
600
|
+
enum: ge,
|
|
601
|
+
type: "string"
|
|
602
|
+
},
|
|
603
|
+
minItems: 1,
|
|
604
|
+
type: "array",
|
|
605
|
+
uniqueItems: !0
|
|
606
|
+
},
|
|
607
|
+
insecureSsl: {
|
|
608
|
+
default: !1,
|
|
609
|
+
type: "boolean"
|
|
610
|
+
},
|
|
611
|
+
project: {
|
|
612
|
+
maxLength: 255,
|
|
613
|
+
minLength: 1,
|
|
614
|
+
pattern: "^(?:[0-9]+|(?!\\.{1,2}(?:/|$))[A-Za-z0-9_.][A-Za-z0-9_.-]*(?:/(?!\\.{1,2}(?:/|$))[A-Za-z0-9_.][A-Za-z0-9_.-]*)*)$",
|
|
615
|
+
type: "string"
|
|
616
|
+
},
|
|
617
|
+
pushBranchFilter: {
|
|
618
|
+
default: "",
|
|
619
|
+
maxLength: 255,
|
|
620
|
+
type: "string"
|
|
621
|
+
}
|
|
622
|
+
},
|
|
623
|
+
required: ["project", "events"],
|
|
624
|
+
title: "GitLab Project Event Config",
|
|
625
|
+
type: "object"
|
|
626
|
+
},
|
|
627
|
+
definitionVersion: 1,
|
|
628
|
+
description: "Triggers when selected GitLab webhook events occur in a project.",
|
|
629
|
+
displayName: "GitLab: Project Event",
|
|
630
|
+
endpoint: {
|
|
631
|
+
body: {
|
|
632
|
+
allowArray: !1,
|
|
633
|
+
allowEmpty: !1,
|
|
634
|
+
formats: ["json"]
|
|
635
|
+
},
|
|
636
|
+
methods: ["POST"],
|
|
637
|
+
successStatus: 202
|
|
638
|
+
},
|
|
639
|
+
key: "gitlab.on_project_event",
|
|
640
|
+
name: "on_project_event",
|
|
641
|
+
payloadSchema: {
|
|
642
|
+
additionalProperties: !1,
|
|
643
|
+
properties: {
|
|
644
|
+
body: { type: "object" },
|
|
645
|
+
deliveryId: { type: "string" },
|
|
646
|
+
event: { type: "string" },
|
|
647
|
+
gitlabEvent: { type: "string" }
|
|
648
|
+
},
|
|
649
|
+
required: [
|
|
650
|
+
"event",
|
|
651
|
+
"gitlabEvent",
|
|
652
|
+
"deliveryId",
|
|
653
|
+
"body"
|
|
654
|
+
],
|
|
655
|
+
title: "GitLab Project Event Payload",
|
|
656
|
+
type: "object"
|
|
657
|
+
},
|
|
658
|
+
provider: "gitlab",
|
|
659
|
+
type: "integration"
|
|
660
|
+
},
|
|
661
|
+
receive(e) {
|
|
662
|
+
let t = e.header("x-gitlab-event")?.trim();
|
|
663
|
+
if (!t) return {
|
|
664
|
+
outcome: "ignored",
|
|
665
|
+
reason: "GitLab event header is missing."
|
|
666
|
+
};
|
|
667
|
+
let n = _e.get(t);
|
|
668
|
+
if (n == null) return {
|
|
669
|
+
outcome: "ignored",
|
|
670
|
+
reason: "GitLab event header is unknown."
|
|
671
|
+
};
|
|
672
|
+
if (!ye(e.config).events.includes(n)) return {
|
|
673
|
+
outcome: "ignored",
|
|
674
|
+
reason: "GitLab event is not subscribed."
|
|
675
|
+
};
|
|
676
|
+
let r = e.header("idempotency-key") ?? "";
|
|
677
|
+
return {
|
|
678
|
+
dedupeKey: r.length == 0 ? void 0 : r,
|
|
679
|
+
outcome: "event",
|
|
680
|
+
payload: {
|
|
681
|
+
body: e.payload,
|
|
682
|
+
deliveryId: r,
|
|
683
|
+
event: n,
|
|
684
|
+
gitlabEvent: t
|
|
685
|
+
}
|
|
686
|
+
};
|
|
687
|
+
},
|
|
688
|
+
async reconcile(e) {
|
|
689
|
+
let t = we(e.state), n = ye(e.config), r = Te(t);
|
|
690
|
+
if (!e.active) {
|
|
691
|
+
let i = r == null ? await xe(e, n) : [r];
|
|
692
|
+
for (let t of i ?? []) await Se(e, n, t);
|
|
693
|
+
return await t.saveSubscription({}, Ee(e.now)), { outcome: "ready" };
|
|
694
|
+
}
|
|
695
|
+
let i = await xe(e, n);
|
|
696
|
+
if (i == null) throw new y("The GitLab project does not exist or is not visible.");
|
|
697
|
+
let a = r ?? i[0];
|
|
698
|
+
if (a == null) {
|
|
699
|
+
let t = await E(e, "hook create", {
|
|
700
|
+
body: be(e.endpointUrl, n),
|
|
701
|
+
endpoint: T(n),
|
|
702
|
+
method: "POST"
|
|
703
|
+
});
|
|
704
|
+
D(t, "hook create"), a = Ce(t.data);
|
|
705
|
+
} else {
|
|
706
|
+
let r = await E(e, "hook update", {
|
|
707
|
+
body: be(e.endpointUrl, n),
|
|
708
|
+
endpoint: `${T(n)}/${a}`,
|
|
709
|
+
method: "PUT"
|
|
710
|
+
});
|
|
711
|
+
if (r.status == 404) return await t.saveSubscription({}, e.now), { outcome: "pending" };
|
|
712
|
+
D(r, "hook update");
|
|
713
|
+
}
|
|
714
|
+
for (let t of i.filter((e) => e != a)) await Se(e, n, t);
|
|
715
|
+
return await t.saveSubscription({ hookId: a }, Ee(e.now)), { outcome: "ready" };
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
function ye(e) {
|
|
719
|
+
return {
|
|
720
|
+
events: e.events,
|
|
721
|
+
insecureSsl: e.insecureSsl ?? !1,
|
|
722
|
+
project: e.project,
|
|
723
|
+
pushBranchFilter: e.pushBranchFilter ?? ""
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
function T(e) {
|
|
727
|
+
return `/projects/${encodeURIComponent(e.project)}/hooks`;
|
|
728
|
+
}
|
|
729
|
+
function be(e, t) {
|
|
730
|
+
return {
|
|
731
|
+
branch_filter_strategy: "wildcard",
|
|
732
|
+
description: "Managed by Open Flow.",
|
|
733
|
+
enable_ssl_verification: !t.insecureSsl,
|
|
734
|
+
name: `Open Flow ${e.slice(e.lastIndexOf("/") + 1)}`,
|
|
735
|
+
push_events_branch_filter: t.pushBranchFilter,
|
|
736
|
+
url: e,
|
|
737
|
+
...Object.fromEntries(ge.map((e) => [`${e}_events`, t.events.includes(e)]))
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
async function xe(e, t) {
|
|
741
|
+
let n = [];
|
|
742
|
+
for (let r = 1; r <= 10; r += 1) {
|
|
743
|
+
let i = await E(e, "hook list", {
|
|
744
|
+
endpoint: T(t),
|
|
745
|
+
method: "GET",
|
|
746
|
+
query: {
|
|
747
|
+
page: r,
|
|
748
|
+
per_page: 100
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
if (i.status == 404) return null;
|
|
752
|
+
D(i, "hook list");
|
|
753
|
+
let a = Array.isArray(i.data) ? i.data : [];
|
|
754
|
+
for (let t of a) {
|
|
755
|
+
let r = De(t);
|
|
756
|
+
r?.url === e.endpointUrl && (typeof r.id == "number" || typeof r.id == "string") && n.push(String(r.id));
|
|
757
|
+
}
|
|
758
|
+
if (a.length < 100) break;
|
|
759
|
+
}
|
|
760
|
+
return n;
|
|
761
|
+
}
|
|
762
|
+
async function Se(e, t, n) {
|
|
763
|
+
let r = await E(e, "hook delete", {
|
|
764
|
+
endpoint: `${T(t)}/${n}`,
|
|
765
|
+
method: "DELETE"
|
|
766
|
+
});
|
|
767
|
+
r.status != 404 && D(r, "hook delete");
|
|
768
|
+
}
|
|
769
|
+
async function E(e, t, n) {
|
|
770
|
+
try {
|
|
771
|
+
return await e.connector.execute(n, e.signal);
|
|
772
|
+
} catch (e) {
|
|
773
|
+
throw e instanceof v ? e : new b(`GitLab ${t} request failed.`, { cause: e });
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
function D(e, t) {
|
|
777
|
+
if (!(e.status >= 200 && e.status < 300)) throw e.status == 401 || e.status == 403 ? new v(`GitLab ${t} rejected the Connection.`) : [
|
|
778
|
+
400,
|
|
779
|
+
404,
|
|
780
|
+
422
|
|
781
|
+
].includes(e.status) ? new y(`GitLab ${t} rejected the subscription.`) : new b(`GitLab ${t} failed with status ${e.status}.`);
|
|
782
|
+
}
|
|
783
|
+
function Ce(e) {
|
|
784
|
+
let t = De(e)?.id;
|
|
785
|
+
if (typeof t != "number" && typeof t != "string") throw new b("GitLab hook response is missing its ID.");
|
|
786
|
+
return String(t);
|
|
787
|
+
}
|
|
788
|
+
function we(e) {
|
|
789
|
+
if (e == null) throw new y("GitLab Integration state is missing.");
|
|
790
|
+
return e;
|
|
791
|
+
}
|
|
792
|
+
function Te(e) {
|
|
793
|
+
let t = e.subscription.hookId;
|
|
794
|
+
return typeof t == "string" && t.length > 0 ? t : null;
|
|
795
|
+
}
|
|
796
|
+
function Ee(e) {
|
|
797
|
+
return new Date(e.getTime() + 2592e6);
|
|
798
|
+
}
|
|
799
|
+
function De(e) {
|
|
800
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
801
|
+
}
|
|
802
|
+
//#endregion
|
|
803
|
+
//#region src/trigger/providers/gmail/on-message-received.ts
|
|
804
|
+
var Oe = 25, ke = 5, Ae = {
|
|
805
|
+
snapshot: {
|
|
806
|
+
configSchema: {
|
|
807
|
+
additionalProperties: !1,
|
|
808
|
+
description: "Configuration for gmail.on_message_received. Every configured matching field must match.",
|
|
809
|
+
properties: {
|
|
810
|
+
includeDrafts: {
|
|
811
|
+
default: !1,
|
|
812
|
+
description: "Also trigger on draft messages.",
|
|
813
|
+
type: "boolean"
|
|
814
|
+
},
|
|
815
|
+
includeSpamAndTrash: {
|
|
816
|
+
default: !1,
|
|
817
|
+
description: "Also trigger on messages in SPAM and TRASH.",
|
|
818
|
+
type: "boolean"
|
|
819
|
+
},
|
|
820
|
+
labelNamesOrIds: {
|
|
821
|
+
description: "Only trigger on messages carrying all of these labels, referenced by name or ID.",
|
|
822
|
+
items: {
|
|
823
|
+
minLength: 1,
|
|
824
|
+
type: "string"
|
|
825
|
+
},
|
|
826
|
+
type: "array"
|
|
827
|
+
},
|
|
828
|
+
maxMessagesPerPoll: {
|
|
829
|
+
default: Oe,
|
|
830
|
+
maximum: 100,
|
|
831
|
+
minimum: 1,
|
|
832
|
+
type: "integer"
|
|
833
|
+
},
|
|
834
|
+
readStatus: {
|
|
835
|
+
default: "All",
|
|
836
|
+
enum: [
|
|
837
|
+
"Read",
|
|
838
|
+
"Unread",
|
|
839
|
+
"All"
|
|
840
|
+
],
|
|
841
|
+
type: "string"
|
|
842
|
+
},
|
|
843
|
+
search: {
|
|
844
|
+
description: "Gmail search-syntax query the message must match.",
|
|
845
|
+
type: "string"
|
|
846
|
+
},
|
|
847
|
+
sender: {
|
|
848
|
+
description: "Only trigger on messages whose sender matches this address or name.",
|
|
849
|
+
type: "string"
|
|
850
|
+
}
|
|
851
|
+
},
|
|
852
|
+
title: "Gmail Config",
|
|
853
|
+
type: "object"
|
|
854
|
+
},
|
|
855
|
+
definitionVersion: 1,
|
|
856
|
+
description: "Polls the Gmail mailbox and triggers when a new message is received.",
|
|
857
|
+
displayName: "Gmail: New Message Received",
|
|
858
|
+
key: "gmail.on_message_received",
|
|
859
|
+
name: "on_message_received",
|
|
860
|
+
payloadSchema: {
|
|
861
|
+
additionalProperties: !1,
|
|
862
|
+
properties: { events: {
|
|
863
|
+
items: {
|
|
864
|
+
additionalProperties: !1,
|
|
865
|
+
properties: {
|
|
866
|
+
historyId: { type: ["string", "null"] },
|
|
867
|
+
labelIds: {
|
|
868
|
+
items: { type: "string" },
|
|
869
|
+
type: "array"
|
|
870
|
+
},
|
|
871
|
+
messageId: { type: "string" },
|
|
872
|
+
messageTimestamp: { type: "string" },
|
|
873
|
+
sender: { type: "string" },
|
|
874
|
+
subject: { type: "string" },
|
|
875
|
+
threadId: { type: "string" },
|
|
876
|
+
to: { type: "string" }
|
|
877
|
+
},
|
|
878
|
+
required: [
|
|
879
|
+
"messageId",
|
|
880
|
+
"threadId",
|
|
881
|
+
"historyId",
|
|
882
|
+
"labelIds",
|
|
883
|
+
"subject",
|
|
884
|
+
"sender",
|
|
885
|
+
"to",
|
|
886
|
+
"messageTimestamp"
|
|
887
|
+
],
|
|
888
|
+
type: "object"
|
|
889
|
+
},
|
|
890
|
+
type: "array"
|
|
891
|
+
} },
|
|
892
|
+
required: ["events"],
|
|
893
|
+
title: "Gmail New Message Payload",
|
|
894
|
+
type: "object"
|
|
895
|
+
},
|
|
896
|
+
provider: "gmail",
|
|
897
|
+
type: "poll"
|
|
898
|
+
},
|
|
899
|
+
async poll(e) {
|
|
900
|
+
let t = je(e.config);
|
|
901
|
+
if (e.checkpoint === null) return {
|
|
902
|
+
checkpoint: { historyId: await Me(e) },
|
|
903
|
+
events: []
|
|
904
|
+
};
|
|
905
|
+
let n = Ne(e.checkpoint), r = await Pe(e, t.labelNamesOrIds), { candidates: i, lastPage: a } = await Fe(e, n, r, t.maxMessagesPerPoll), o = Ie(n.historyId, a), s = [], c = 0;
|
|
906
|
+
for (let n of i) {
|
|
907
|
+
let i = await Le(e, n.id);
|
|
908
|
+
if (i != null) {
|
|
909
|
+
if (!await Re(e, i, t, r)) {
|
|
910
|
+
c += 1;
|
|
911
|
+
continue;
|
|
912
|
+
}
|
|
913
|
+
s.push(Ve(i));
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
return {
|
|
917
|
+
checkpoint: o.checkpoint,
|
|
918
|
+
events: s,
|
|
919
|
+
filtered: c,
|
|
920
|
+
...o.hasMore ? { hasMore: !0 } : {}
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
function je(e) {
|
|
925
|
+
return {
|
|
926
|
+
includeDrafts: e.includeDrafts ?? !1,
|
|
927
|
+
includeSpamAndTrash: e.includeSpamAndTrash ?? !1,
|
|
928
|
+
labelNamesOrIds: e.labelNamesOrIds ?? [],
|
|
929
|
+
maxMessagesPerPoll: e.maxMessagesPerPoll ?? Oe,
|
|
930
|
+
readStatus: e.readStatus ?? "All",
|
|
931
|
+
search: (e.search ?? "").trim(),
|
|
932
|
+
sender: (e.sender ?? "").trim()
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
async function Me(e) {
|
|
936
|
+
let t = await O(e, "/users/me/profile");
|
|
937
|
+
k(t, "profile fetch");
|
|
938
|
+
let r = j(t.data)?.historyId;
|
|
939
|
+
if (typeof r != "string" || r.length == 0) throw new n("Gmail profile historyId is missing.");
|
|
940
|
+
return r;
|
|
941
|
+
}
|
|
942
|
+
function Ne(e) {
|
|
943
|
+
let n = j(e);
|
|
944
|
+
if (typeof n?.historyId != "string" || n.historyId.length == 0) throw new t("Gmail checkpoint historyId is missing; recreate the Trigger.");
|
|
945
|
+
return {
|
|
946
|
+
historyId: n.historyId,
|
|
947
|
+
...typeof n.pageToken == "string" ? { pageToken: n.pageToken } : {}
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
async function Pe(e, n) {
|
|
951
|
+
if (n.length == 0) return [];
|
|
952
|
+
let r = await O(e, "/users/me/labels");
|
|
953
|
+
k(r, "labels list");
|
|
954
|
+
let i = j(r.data)?.labels, a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map();
|
|
955
|
+
if (Array.isArray(i)) for (let e of i) {
|
|
956
|
+
let t = j(e);
|
|
957
|
+
typeof t?.id == "string" && t.id.length != 0 && (a.add(t.id), typeof t.name == "string" && t.name.length > 0 && o.set(t.name.toLowerCase(), t.id));
|
|
958
|
+
}
|
|
959
|
+
return [...new Set(n.map((e) => {
|
|
960
|
+
let n = a.has(e) ? e : o.get(e.toLowerCase());
|
|
961
|
+
if (n == null) throw new t(`Gmail label "${e}" does not exist.`);
|
|
962
|
+
return n;
|
|
963
|
+
}))];
|
|
964
|
+
}
|
|
965
|
+
async function Fe(e, n, r, i) {
|
|
966
|
+
let a = /* @__PURE__ */ new Map(), o = n.pageToken, s = {};
|
|
967
|
+
for (let c = 0; c < ke; c += 1) {
|
|
968
|
+
let c = await O(e, "/users/me/history", {
|
|
969
|
+
historyTypes: "messageAdded",
|
|
970
|
+
labelId: r[0],
|
|
971
|
+
maxResults: i,
|
|
972
|
+
pageToken: o,
|
|
973
|
+
startHistoryId: n.historyId
|
|
974
|
+
});
|
|
975
|
+
if (c.status == 404) throw new t("Gmail history checkpoint expired; recreate the Trigger.");
|
|
976
|
+
k(c, "history list"), s = j(c.data) ?? {};
|
|
977
|
+
for (let e of s.history ?? []) for (let t of e.messagesAdded ?? []) {
|
|
978
|
+
let e = t.message?.id;
|
|
979
|
+
e != null && e.length > 0 && !a.has(e) && a.set(e, { id: e });
|
|
980
|
+
}
|
|
981
|
+
if (!s.nextPageToken || (o = s.nextPageToken, a.size >= i)) break;
|
|
982
|
+
}
|
|
983
|
+
return {
|
|
984
|
+
candidates: [...a.values()],
|
|
985
|
+
lastPage: s
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
function Ie(e, t) {
|
|
989
|
+
if (t.nextPageToken) return {
|
|
990
|
+
checkpoint: {
|
|
991
|
+
historyId: e,
|
|
992
|
+
pageToken: t.nextPageToken
|
|
993
|
+
},
|
|
994
|
+
hasMore: !0
|
|
995
|
+
};
|
|
996
|
+
if (!t.historyId) throw new n("Gmail history response historyId is missing.");
|
|
997
|
+
return {
|
|
998
|
+
checkpoint: { historyId: t.historyId },
|
|
999
|
+
hasMore: !1
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
async function Le(e, t) {
|
|
1003
|
+
let n = await O(e, `/users/me/messages/${encodeURIComponent(t)}`, { format: "metadata" });
|
|
1004
|
+
return n.status == 404 ? null : (k(n, "message metadata fetch"), j(n.data) ?? null);
|
|
1005
|
+
}
|
|
1006
|
+
async function Re(e, t, n, r) {
|
|
1007
|
+
let i = t.labelIds ?? [];
|
|
1008
|
+
if (!n.includeSpamAndTrash && (i.includes("SPAM") || i.includes("TRASH")) || !n.includeDrafts && i.includes("DRAFT") || n.readStatus == "Unread" && !i.includes("UNREAD") || n.readStatus == "Read" && i.includes("UNREAD") || !r.every((e) => i.includes(e))) return !1;
|
|
1009
|
+
let a = ze(n);
|
|
1010
|
+
return a.length == 0 || await Be(e, t, a, n.includeSpamAndTrash);
|
|
1011
|
+
}
|
|
1012
|
+
function ze(e) {
|
|
1013
|
+
let t = e.search.length == 0 ? [] : [e.search], n = e.sender.replaceAll("\"", "").trim();
|
|
1014
|
+
return n.length > 0 && t.push(`from:${/\s/.test(n) ? `"${n}"` : n}`), t.join(" ");
|
|
1015
|
+
}
|
|
1016
|
+
async function Be(e, t, n, r) {
|
|
1017
|
+
let i = A(t.payload?.headers ?? [], "Message-ID").replace(/^</, "").replace(/>$/, "");
|
|
1018
|
+
if (i.length == 0) return !1;
|
|
1019
|
+
let a = await O(e, "/users/me/messages", {
|
|
1020
|
+
includeSpamTrash: r ? "true" : void 0,
|
|
1021
|
+
q: `${n} rfc822msgid:${i}`
|
|
1022
|
+
});
|
|
1023
|
+
k(a, "query match");
|
|
1024
|
+
let o = j(a.data)?.messages;
|
|
1025
|
+
return Array.isArray(o) && o.some((e) => j(e)?.id === t.id);
|
|
1026
|
+
}
|
|
1027
|
+
function Ve(e) {
|
|
1028
|
+
let t = e.payload?.headers ?? [];
|
|
1029
|
+
return {
|
|
1030
|
+
dedupeKey: e.id,
|
|
1031
|
+
payload: {
|
|
1032
|
+
historyId: e.historyId ?? null,
|
|
1033
|
+
labelIds: e.labelIds ?? [],
|
|
1034
|
+
messageId: e.id,
|
|
1035
|
+
messageTimestamp: He(e.internalDate, A(t, "Date")),
|
|
1036
|
+
sender: A(t, "From"),
|
|
1037
|
+
subject: A(t, "Subject"),
|
|
1038
|
+
threadId: e.threadId ?? "",
|
|
1039
|
+
to: A(t, "To")
|
|
1040
|
+
}
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
async function O(e, t, r = {}) {
|
|
1044
|
+
try {
|
|
1045
|
+
return await e.connector.execute({
|
|
1046
|
+
endpoint: t,
|
|
1047
|
+
method: "GET",
|
|
1048
|
+
query: Object.fromEntries(Object.entries(r).filter((e) => e[1] != null))
|
|
1049
|
+
}, e.signal);
|
|
1050
|
+
} catch (e) {
|
|
1051
|
+
throw new n(`Gmail proxy request to ${t} failed.`, { cause: e });
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
function k(t, r) {
|
|
1055
|
+
if (!(t.status >= 200 && t.status < 300)) throw t.status == 401 || t.status == 403 ? new e(`Gmail ${r} rejected the Connection.`) : new n(`Gmail ${r} failed with status ${t.status}.`);
|
|
1056
|
+
}
|
|
1057
|
+
function A(e, t) {
|
|
1058
|
+
return e.find((e) => e.name.toLowerCase() == t.toLowerCase())?.value ?? "";
|
|
1059
|
+
}
|
|
1060
|
+
function He(e, t) {
|
|
1061
|
+
let n = e == null ? NaN : Number(e);
|
|
1062
|
+
if (Number.isFinite(n)) {
|
|
1063
|
+
let e = new Date(n);
|
|
1064
|
+
if (!Number.isNaN(e.getTime())) return e.toISOString();
|
|
1065
|
+
}
|
|
1066
|
+
let r = Date.parse(t);
|
|
1067
|
+
return Number.isNaN(r) ? "" : new Date(r).toISOString();
|
|
1068
|
+
}
|
|
1069
|
+
function j(e) {
|
|
1070
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
1071
|
+
}
|
|
1072
|
+
//#endregion
|
|
1073
|
+
//#region src/trigger/providers/google-calendar/on-event-changed.ts
|
|
1074
|
+
var M = [
|
|
1075
|
+
"created",
|
|
1076
|
+
"updated",
|
|
1077
|
+
"cancelled"
|
|
1078
|
+
], Ue = /* @__PURE__ */ new Set([
|
|
1079
|
+
"rateLimitExceeded",
|
|
1080
|
+
"userRateLimitExceeded",
|
|
1081
|
+
"quotaExceeded",
|
|
1082
|
+
"usageLimits"
|
|
1083
|
+
]), We = {
|
|
1084
|
+
snapshot: {
|
|
1085
|
+
configSchema: {
|
|
1086
|
+
additionalProperties: !1,
|
|
1087
|
+
properties: {
|
|
1088
|
+
calendarId: {
|
|
1089
|
+
maxLength: 1024,
|
|
1090
|
+
minLength: 1,
|
|
1091
|
+
type: "string"
|
|
1092
|
+
},
|
|
1093
|
+
changes: {
|
|
1094
|
+
default: M,
|
|
1095
|
+
items: {
|
|
1096
|
+
enum: M,
|
|
1097
|
+
type: "string"
|
|
1098
|
+
},
|
|
1099
|
+
minItems: 1,
|
|
1100
|
+
type: "array",
|
|
1101
|
+
uniqueItems: !0
|
|
1102
|
+
},
|
|
1103
|
+
matchTerm: {
|
|
1104
|
+
default: "",
|
|
1105
|
+
type: "string"
|
|
1106
|
+
},
|
|
1107
|
+
maxEventsPerPoll: {
|
|
1108
|
+
default: 100,
|
|
1109
|
+
maximum: 500,
|
|
1110
|
+
minimum: 1,
|
|
1111
|
+
type: "integer"
|
|
1112
|
+
}
|
|
1113
|
+
},
|
|
1114
|
+
required: ["calendarId"],
|
|
1115
|
+
title: "Google Calendar Event Change Config",
|
|
1116
|
+
type: "object"
|
|
1117
|
+
},
|
|
1118
|
+
definitionVersion: 1,
|
|
1119
|
+
description: "Polls a Google Calendar and triggers when an event is created, updated or cancelled.",
|
|
1120
|
+
displayName: "Google Calendar: Event Changed",
|
|
1121
|
+
key: "googlecalendar.on_event_changed",
|
|
1122
|
+
name: "on_event_changed",
|
|
1123
|
+
payloadSchema: {
|
|
1124
|
+
additionalProperties: !1,
|
|
1125
|
+
properties: { events: {
|
|
1126
|
+
items: {
|
|
1127
|
+
additionalProperties: !1,
|
|
1128
|
+
properties: {
|
|
1129
|
+
attendeeEmails: {
|
|
1130
|
+
items: { type: "string" },
|
|
1131
|
+
type: "array"
|
|
1132
|
+
},
|
|
1133
|
+
calendarId: { type: "string" },
|
|
1134
|
+
changeType: {
|
|
1135
|
+
enum: M,
|
|
1136
|
+
type: "string"
|
|
1137
|
+
},
|
|
1138
|
+
created: { type: ["string", "null"] },
|
|
1139
|
+
creatorEmail: { type: ["string", "null"] },
|
|
1140
|
+
description: { type: ["string", "null"] },
|
|
1141
|
+
end: { type: ["object", "null"] },
|
|
1142
|
+
eventId: { type: "string" },
|
|
1143
|
+
eventType: { type: ["string", "null"] },
|
|
1144
|
+
htmlLink: { type: ["string", "null"] },
|
|
1145
|
+
isAllDay: { type: "boolean" },
|
|
1146
|
+
location: { type: ["string", "null"] },
|
|
1147
|
+
organizerEmail: { type: ["string", "null"] },
|
|
1148
|
+
recurringEventId: { type: ["string", "null"] },
|
|
1149
|
+
start: { type: ["object", "null"] },
|
|
1150
|
+
status: { type: "string" },
|
|
1151
|
+
summary: { type: ["string", "null"] },
|
|
1152
|
+
updated: { type: ["string", "null"] }
|
|
1153
|
+
},
|
|
1154
|
+
required: [
|
|
1155
|
+
"changeType",
|
|
1156
|
+
"calendarId",
|
|
1157
|
+
"eventId",
|
|
1158
|
+
"status",
|
|
1159
|
+
"summary",
|
|
1160
|
+
"description",
|
|
1161
|
+
"location",
|
|
1162
|
+
"htmlLink",
|
|
1163
|
+
"start",
|
|
1164
|
+
"end",
|
|
1165
|
+
"isAllDay",
|
|
1166
|
+
"organizerEmail",
|
|
1167
|
+
"creatorEmail",
|
|
1168
|
+
"attendeeEmails",
|
|
1169
|
+
"recurringEventId",
|
|
1170
|
+
"eventType",
|
|
1171
|
+
"created",
|
|
1172
|
+
"updated"
|
|
1173
|
+
],
|
|
1174
|
+
type: "object"
|
|
1175
|
+
},
|
|
1176
|
+
type: "array"
|
|
1177
|
+
} },
|
|
1178
|
+
required: ["events"],
|
|
1179
|
+
title: "Google Calendar Event Change Payload",
|
|
1180
|
+
type: "object"
|
|
1181
|
+
},
|
|
1182
|
+
provider: "googlecalendar",
|
|
1183
|
+
type: "poll"
|
|
1184
|
+
},
|
|
1185
|
+
async poll(e) {
|
|
1186
|
+
let t = Ge(e.config);
|
|
1187
|
+
if (e.checkpoint === null) return qe(e, t, e.now.toISOString());
|
|
1188
|
+
let n = Ke(e.checkpoint);
|
|
1189
|
+
return n.calendarId === t.calendarId ? "seedTimeMin" in n ? qe(e, t, n.seedTimeMin, n.pageToken) : Je(e, t, n) : qe(e, t, e.now.toISOString());
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
function Ge(e) {
|
|
1193
|
+
return {
|
|
1194
|
+
calendarId: e.calendarId,
|
|
1195
|
+
changes: new Set(e.changes ?? M),
|
|
1196
|
+
matchTerm: (e.matchTerm ?? "").trim(),
|
|
1197
|
+
maxEventsPerPoll: e.maxEventsPerPoll ?? 100
|
|
1198
|
+
};
|
|
1199
|
+
}
|
|
1200
|
+
function Ke(e) {
|
|
1201
|
+
let n = N(e), r = typeof n?.pageToken == "string" ? n.pageToken : void 0, i = typeof n?.calendarId == "string" ? n.calendarId : void 0;
|
|
1202
|
+
if (typeof n?.syncToken == "string" && n.syncToken.length > 0) return {
|
|
1203
|
+
calendarId: i,
|
|
1204
|
+
...r == null ? {} : { pageToken: r },
|
|
1205
|
+
syncToken: n.syncToken
|
|
1206
|
+
};
|
|
1207
|
+
if (typeof n?.seedTimeMin == "string" && n.seedTimeMin.length > 0) return {
|
|
1208
|
+
calendarId: i,
|
|
1209
|
+
...r == null ? {} : { pageToken: r },
|
|
1210
|
+
seedTimeMin: n.seedTimeMin
|
|
1211
|
+
};
|
|
1212
|
+
throw new t("Google Calendar checkpoint is invalid; recreate the Trigger.");
|
|
1213
|
+
}
|
|
1214
|
+
async function qe(e, t, r, i) {
|
|
1215
|
+
let a = i;
|
|
1216
|
+
for (let i = 0; i < 2; i += 1) {
|
|
1217
|
+
let i = await Qe(e, t.calendarId, {
|
|
1218
|
+
maxResults: 2500,
|
|
1219
|
+
pageToken: a,
|
|
1220
|
+
showDeleted: "true",
|
|
1221
|
+
singleEvents: "false",
|
|
1222
|
+
timeMin: r
|
|
1223
|
+
});
|
|
1224
|
+
if (a != null && et(i)) return {
|
|
1225
|
+
checkpoint: {
|
|
1226
|
+
calendarId: t.calendarId,
|
|
1227
|
+
seedTimeMin: r
|
|
1228
|
+
},
|
|
1229
|
+
events: []
|
|
1230
|
+
};
|
|
1231
|
+
$e(e, i, "seed full sync");
|
|
1232
|
+
let o = N(i.data) ?? {};
|
|
1233
|
+
if (o.nextSyncToken) return {
|
|
1234
|
+
checkpoint: {
|
|
1235
|
+
calendarId: t.calendarId,
|
|
1236
|
+
syncToken: o.nextSyncToken
|
|
1237
|
+
},
|
|
1238
|
+
events: []
|
|
1239
|
+
};
|
|
1240
|
+
if (!o.nextPageToken) throw new n("Google Calendar seed response has no continuation token.");
|
|
1241
|
+
a = o.nextPageToken;
|
|
1242
|
+
}
|
|
1243
|
+
return {
|
|
1244
|
+
checkpoint: {
|
|
1245
|
+
calendarId: t.calendarId,
|
|
1246
|
+
...a == null ? {} : { pageToken: a },
|
|
1247
|
+
seedTimeMin: r
|
|
1248
|
+
},
|
|
1249
|
+
events: [],
|
|
1250
|
+
hasMore: !0
|
|
1251
|
+
};
|
|
1252
|
+
}
|
|
1253
|
+
async function Je(e, t, r) {
|
|
1254
|
+
let i = [], a = 0, o = r.pageToken;
|
|
1255
|
+
for (let s = 0; s < 5; s += 1) {
|
|
1256
|
+
let s = await Qe(e, t.calendarId, {
|
|
1257
|
+
maxResults: t.maxEventsPerPoll,
|
|
1258
|
+
pageToken: o,
|
|
1259
|
+
showDeleted: "true",
|
|
1260
|
+
singleEvents: "false",
|
|
1261
|
+
syncToken: r.syncToken
|
|
1262
|
+
});
|
|
1263
|
+
if (o != null && et(s)) return {
|
|
1264
|
+
checkpoint: {
|
|
1265
|
+
calendarId: t.calendarId,
|
|
1266
|
+
syncToken: r.syncToken
|
|
1267
|
+
},
|
|
1268
|
+
events: i,
|
|
1269
|
+
filtered: a
|
|
1270
|
+
};
|
|
1271
|
+
$e(e, s, "incremental sync");
|
|
1272
|
+
let c = N(s.data) ?? {};
|
|
1273
|
+
for (let e of c.items ?? []) {
|
|
1274
|
+
if (e.id == null || e.id.length == 0) continue;
|
|
1275
|
+
let n = Ye(e);
|
|
1276
|
+
if (!t.changes.has(n) || !Xe(e, t.matchTerm)) {
|
|
1277
|
+
a += 1;
|
|
1278
|
+
continue;
|
|
1279
|
+
}
|
|
1280
|
+
i.push(Ze(e, e.id, n, t.calendarId));
|
|
1281
|
+
}
|
|
1282
|
+
if (c.nextSyncToken) return {
|
|
1283
|
+
checkpoint: {
|
|
1284
|
+
calendarId: t.calendarId,
|
|
1285
|
+
syncToken: c.nextSyncToken
|
|
1286
|
+
},
|
|
1287
|
+
events: i,
|
|
1288
|
+
filtered: a
|
|
1289
|
+
};
|
|
1290
|
+
if (!c.nextPageToken) throw new n("Google Calendar sync response has no continuation token.");
|
|
1291
|
+
o = c.nextPageToken;
|
|
1292
|
+
}
|
|
1293
|
+
return {
|
|
1294
|
+
checkpoint: {
|
|
1295
|
+
calendarId: t.calendarId,
|
|
1296
|
+
...o == null ? {} : { pageToken: o },
|
|
1297
|
+
syncToken: r.syncToken
|
|
1298
|
+
},
|
|
1299
|
+
events: i,
|
|
1300
|
+
filtered: a,
|
|
1301
|
+
hasMore: !0
|
|
1302
|
+
};
|
|
1303
|
+
}
|
|
1304
|
+
function Ye(e) {
|
|
1305
|
+
if (e.status == "cancelled") return "cancelled";
|
|
1306
|
+
let t = it(e.created), n = it(e.updated);
|
|
1307
|
+
return t != null && t == n ? "created" : "updated";
|
|
1308
|
+
}
|
|
1309
|
+
function Xe(e, t) {
|
|
1310
|
+
if (t.length == 0) return !0;
|
|
1311
|
+
let n = t.toLowerCase();
|
|
1312
|
+
return [
|
|
1313
|
+
e.summary,
|
|
1314
|
+
e.description,
|
|
1315
|
+
e.location,
|
|
1316
|
+
...(e.attendees ?? []).map(({ email: e }) => e)
|
|
1317
|
+
].some((e) => typeof e == "string" && e.toLowerCase().includes(n));
|
|
1318
|
+
}
|
|
1319
|
+
function Ze(e, t, n, r) {
|
|
1320
|
+
return {
|
|
1321
|
+
dedupeKey: `${t}:${e.updated ?? e.etag ?? ""}`,
|
|
1322
|
+
payload: {
|
|
1323
|
+
attendeeEmails: (e.attendees ?? []).flatMap(({ email: e }) => e == null || e.length == 0 ? [] : [e]),
|
|
1324
|
+
calendarId: r,
|
|
1325
|
+
changeType: n,
|
|
1326
|
+
created: rt(e.created),
|
|
1327
|
+
creatorEmail: e.creator?.email ?? null,
|
|
1328
|
+
description: e.description ?? null,
|
|
1329
|
+
end: e.end ?? null,
|
|
1330
|
+
eventId: t,
|
|
1331
|
+
eventType: e.eventType ?? null,
|
|
1332
|
+
htmlLink: e.htmlLink ?? null,
|
|
1333
|
+
isAllDay: e.start?.date != null,
|
|
1334
|
+
location: e.location ?? null,
|
|
1335
|
+
organizerEmail: e.organizer?.email ?? null,
|
|
1336
|
+
recurringEventId: e.recurringEventId ?? null,
|
|
1337
|
+
start: e.start ?? null,
|
|
1338
|
+
status: e.status ?? "",
|
|
1339
|
+
summary: e.summary ?? null,
|
|
1340
|
+
updated: rt(e.updated)
|
|
1341
|
+
}
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
async function Qe(e, t, r) {
|
|
1345
|
+
let i = `/calendars/${encodeURIComponent(t)}/events`;
|
|
1346
|
+
try {
|
|
1347
|
+
return await e.connector.execute({
|
|
1348
|
+
endpoint: i,
|
|
1349
|
+
method: "GET",
|
|
1350
|
+
query: Object.fromEntries(Object.entries(r).filter((e) => e[1] != null))
|
|
1351
|
+
}, e.signal);
|
|
1352
|
+
} catch (e) {
|
|
1353
|
+
throw new n(`Google Calendar proxy request to ${i} failed.`, { cause: e });
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
function $e(r, i, a) {
|
|
1357
|
+
if (!(i.status >= 200 && i.status < 300)) throw i.status == 410 || i.status == 400 && nt(i.data) ? new t("Google Calendar sync token expired; recreate the Trigger.") : i.status == 400 || i.status == 404 && r.checkpoint === null ? new t(`Google Calendar ${a} rejected the configuration.`) : i.status == 401 ? new e(`Google Calendar ${a} rejected the Connection.`) : i.status == 403 ? tt(i.data).some((e) => Ue.has(e)) ? new n(`Google Calendar ${a} was rate limited.`) : new e(`Google Calendar ${a} rejected the Connection.`) : new n(`Google Calendar ${a} failed with status ${i.status}.`);
|
|
1358
|
+
}
|
|
1359
|
+
function et(e) {
|
|
1360
|
+
return e.status == 400 && !nt(e.data);
|
|
1361
|
+
}
|
|
1362
|
+
function tt(e) {
|
|
1363
|
+
let t = N(N(e)?.error)?.errors;
|
|
1364
|
+
return Array.isArray(t) ? t.flatMap((e) => {
|
|
1365
|
+
let t = N(e)?.reason;
|
|
1366
|
+
return typeof t == "string" ? [t] : [];
|
|
1367
|
+
}) : [];
|
|
1368
|
+
}
|
|
1369
|
+
function nt(e) {
|
|
1370
|
+
if (tt(e).includes("fullSyncRequired")) return !0;
|
|
1371
|
+
let t = N(N(e)?.error)?.message;
|
|
1372
|
+
return typeof t == "string" && t.includes("fullSyncRequired");
|
|
1373
|
+
}
|
|
1374
|
+
function rt(e) {
|
|
1375
|
+
if (e == null || e.length == 0) return null;
|
|
1376
|
+
let t = Date.parse(e);
|
|
1377
|
+
return Number.isNaN(t) ? null : new Date(t).toISOString();
|
|
1378
|
+
}
|
|
1379
|
+
function it(e) {
|
|
1380
|
+
if (e == null || e.length == 0) return null;
|
|
1381
|
+
let t = Date.parse(e);
|
|
1382
|
+
return Number.isNaN(t) ? null : Math.floor(t / 1e3);
|
|
1383
|
+
}
|
|
1384
|
+
function N(e) {
|
|
1385
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
1386
|
+
}
|
|
1387
|
+
//#endregion
|
|
1388
|
+
//#region src/trigger/providers/google-drive/changes.ts
|
|
1389
|
+
var at = 6012e5, ot = 36e5, st = 6e4, ct = 6e4, lt = 2, ut = 100, dt = new TextEncoder(), ft = "nextPageToken,newStartPageToken,changes(fileId,kind,changeType,removed,time,driveId,file(id,name,mimeType,webViewLink,createdTime,modifiedTime,size,driveId,parents,shared,starred,trashed))", pt = {
|
|
1390
|
+
initialState: {
|
|
1391
|
+
checkpoint: null,
|
|
1392
|
+
subscription: { channels: [] }
|
|
1393
|
+
},
|
|
1394
|
+
snapshot: {
|
|
1395
|
+
configSchema: {
|
|
1396
|
+
additionalProperties: !1,
|
|
1397
|
+
description: "Configuration for googledrive.changes_detected.",
|
|
1398
|
+
properties: {
|
|
1399
|
+
driveId: {
|
|
1400
|
+
description: "Optional shared drive ID. Omit it to monitor the connected account.",
|
|
1401
|
+
maxLength: 256,
|
|
1402
|
+
minLength: 1,
|
|
1403
|
+
type: "string"
|
|
1404
|
+
},
|
|
1405
|
+
includeCorpusRemovals: {
|
|
1406
|
+
default: !1,
|
|
1407
|
+
description: "Include the accessible file resource when an item leaves the change corpus.",
|
|
1408
|
+
type: "boolean"
|
|
1409
|
+
},
|
|
1410
|
+
includeItemsFromAllDrives: {
|
|
1411
|
+
default: !0,
|
|
1412
|
+
description: "Include items from My Drive and shared drives.",
|
|
1413
|
+
type: "boolean"
|
|
1414
|
+
},
|
|
1415
|
+
includeRemoved: {
|
|
1416
|
+
default: !0,
|
|
1417
|
+
description: "Include changes caused by deletion or loss of access.",
|
|
1418
|
+
type: "boolean"
|
|
1419
|
+
},
|
|
1420
|
+
pageSize: {
|
|
1421
|
+
default: ut,
|
|
1422
|
+
description: "Maximum changes included in one Flow Run.",
|
|
1423
|
+
maximum: 100,
|
|
1424
|
+
minimum: 1,
|
|
1425
|
+
type: "integer"
|
|
1426
|
+
},
|
|
1427
|
+
restrictToMyDrive: {
|
|
1428
|
+
default: !1,
|
|
1429
|
+
description: "Restrict changes to the My Drive hierarchy.",
|
|
1430
|
+
type: "boolean"
|
|
1431
|
+
}
|
|
1432
|
+
},
|
|
1433
|
+
title: "Google Drive Changes Config",
|
|
1434
|
+
type: "object"
|
|
1435
|
+
},
|
|
1436
|
+
definitionVersion: 1,
|
|
1437
|
+
description: "Uses a Google Drive changes.watch channel and triggers when Drive changes are available.",
|
|
1438
|
+
displayName: "Google Drive: Changes Detected",
|
|
1439
|
+
endpoint: {
|
|
1440
|
+
body: {
|
|
1441
|
+
allowArray: !1,
|
|
1442
|
+
allowEmpty: !0,
|
|
1443
|
+
formats: ["json"]
|
|
1444
|
+
},
|
|
1445
|
+
methods: ["POST"],
|
|
1446
|
+
successStatus: 204
|
|
1447
|
+
},
|
|
1448
|
+
key: "googledrive.changes_detected",
|
|
1449
|
+
name: "changes_detected",
|
|
1450
|
+
payloadSchema: {
|
|
1451
|
+
additionalProperties: !1,
|
|
1452
|
+
properties: { events: {
|
|
1453
|
+
items: {
|
|
1454
|
+
additionalProperties: !1,
|
|
1455
|
+
properties: {
|
|
1456
|
+
changeId: { type: "string" },
|
|
1457
|
+
changeType: { type: ["string", "null"] },
|
|
1458
|
+
driveId: { type: ["string", "null"] },
|
|
1459
|
+
file: { type: ["object", "null"] },
|
|
1460
|
+
fileId: { type: ["string", "null"] },
|
|
1461
|
+
notification: {
|
|
1462
|
+
additionalProperties: !1,
|
|
1463
|
+
properties: {
|
|
1464
|
+
changedTypes: {
|
|
1465
|
+
items: { type: "string" },
|
|
1466
|
+
type: "array"
|
|
1467
|
+
},
|
|
1468
|
+
messageNumber: { type: ["string", "null"] },
|
|
1469
|
+
resourceState: { type: "string" },
|
|
1470
|
+
resourceUri: { type: ["string", "null"] }
|
|
1471
|
+
},
|
|
1472
|
+
required: [
|
|
1473
|
+
"resourceState",
|
|
1474
|
+
"changedTypes",
|
|
1475
|
+
"messageNumber",
|
|
1476
|
+
"resourceUri"
|
|
1477
|
+
],
|
|
1478
|
+
type: "object"
|
|
1479
|
+
},
|
|
1480
|
+
removed: { type: "boolean" },
|
|
1481
|
+
time: { type: ["string", "null"] }
|
|
1482
|
+
},
|
|
1483
|
+
required: [
|
|
1484
|
+
"changeId",
|
|
1485
|
+
"changeType",
|
|
1486
|
+
"removed",
|
|
1487
|
+
"time",
|
|
1488
|
+
"fileId",
|
|
1489
|
+
"driveId",
|
|
1490
|
+
"file",
|
|
1491
|
+
"notification"
|
|
1492
|
+
],
|
|
1493
|
+
type: "object"
|
|
1494
|
+
},
|
|
1495
|
+
type: "array"
|
|
1496
|
+
} },
|
|
1497
|
+
required: ["events"],
|
|
1498
|
+
title: "Google Drive Changes Payload",
|
|
1499
|
+
type: "object"
|
|
1500
|
+
},
|
|
1501
|
+
provider: "googledrive",
|
|
1502
|
+
type: "integration"
|
|
1503
|
+
},
|
|
1504
|
+
async receive(e) {
|
|
1505
|
+
let t = P(e.state), n = e.header("x-goog-channel-id"), r = e.header("x-goog-resource-id"), i = e.header("x-goog-resource-state"), a = e.header("x-goog-channel-token");
|
|
1506
|
+
if (n == null || r == null || i == null || a == null) return {
|
|
1507
|
+
body: "",
|
|
1508
|
+
contentType: "text/plain",
|
|
1509
|
+
outcome: "respond",
|
|
1510
|
+
status: 404
|
|
1511
|
+
};
|
|
1512
|
+
let o = gt(t), s = o.find((t) => t.id == n && Date.parse(t.expiration) > e.now.getTime());
|
|
1513
|
+
if (s == null || !kt(a, await Ot(e.callbackSecret, n)) || s.resourceId != null && s.resourceId != r) return {
|
|
1514
|
+
body: "",
|
|
1515
|
+
contentType: "text/plain",
|
|
1516
|
+
outcome: "respond",
|
|
1517
|
+
status: 404
|
|
1518
|
+
};
|
|
1519
|
+
if (s.resourceId ?? (o = o.map((e) => e.id == n ? {
|
|
1520
|
+
...e,
|
|
1521
|
+
resourceId: r
|
|
1522
|
+
} : e), await F(t, o, e.now)), i != "sync" && i != "change") return {
|
|
1523
|
+
outcome: "ignored",
|
|
1524
|
+
reason: "Google Drive notification state is not actionable."
|
|
1525
|
+
};
|
|
1526
|
+
if (!e.admit) return e.current ? {
|
|
1527
|
+
body: "",
|
|
1528
|
+
contentType: "text/plain",
|
|
1529
|
+
outcome: "respond",
|
|
1530
|
+
status: 503
|
|
1531
|
+
} : {
|
|
1532
|
+
outcome: "ignored",
|
|
1533
|
+
reason: "Google Drive channel belongs to a retiring runtime."
|
|
1534
|
+
};
|
|
1535
|
+
if (e.allow != null && !await e.allow()) return {
|
|
1536
|
+
outcome: "ignored",
|
|
1537
|
+
reason: "The Team cannot admit Trigger events."
|
|
1538
|
+
};
|
|
1539
|
+
let c = mt(e.config), l = ht(t.checkpoint), u = await xt(e, c, l), d = L(u.nextPageToken), f = d ?? L(u.newStartPageToken);
|
|
1540
|
+
if (f == null) throw new b("Google Drive changes response is missing its next checkpoint.");
|
|
1541
|
+
let p = {
|
|
1542
|
+
changedTypes: (e.header("x-goog-changed") ?? "").split(",").map((e) => e.trim()).filter((e) => e.length > 0),
|
|
1543
|
+
messageNumber: e.header("x-goog-message-number") ?? null,
|
|
1544
|
+
resourceState: i,
|
|
1545
|
+
resourceUri: e.header("x-goog-resource-uri") ?? null
|
|
1546
|
+
}, m = (u.changes ?? []).map((e) => Dt(e, p)), h = {
|
|
1547
|
+
checkpoint: { pageToken: f },
|
|
1548
|
+
continue: d != null,
|
|
1549
|
+
dedupeKey: `${c.driveId ?? "my-drive"}:${l}`
|
|
1550
|
+
};
|
|
1551
|
+
return m.length == 0 ? {
|
|
1552
|
+
...h,
|
|
1553
|
+
outcome: "ignored",
|
|
1554
|
+
reason: "Google Drive change page is empty."
|
|
1555
|
+
} : {
|
|
1556
|
+
...h,
|
|
1557
|
+
outcome: "event",
|
|
1558
|
+
payload: { events: m }
|
|
1559
|
+
};
|
|
1560
|
+
},
|
|
1561
|
+
async reconcile(e) {
|
|
1562
|
+
let t = P(e.state), n = gt(t), r = e.now.getTime(), i = n.filter((e) => Date.parse(e.expiration) > r);
|
|
1563
|
+
if (i.length != n.length && (n = i, await F(t, n, e.now)), !e.active) return await vt(e, n);
|
|
1564
|
+
let a = n.filter((e) => e.state == "creating" && e.resourceId != null).toSorted((e, t) => Date.parse(t.createdAt) - Date.parse(e.createdAt))[0];
|
|
1565
|
+
a != null && (n = n.map((e) => ({
|
|
1566
|
+
...e,
|
|
1567
|
+
state: e.id == a.id ? "active" : "retiring"
|
|
1568
|
+
})), await F(t, n, e.now));
|
|
1569
|
+
let o = n.find((e) => e.state == "active"), s = n.filter((e) => e.state == "creating").filter((e) => Date.parse(e.createdAt) + st <= r);
|
|
1570
|
+
if (s.length > 0) {
|
|
1571
|
+
let r = new Set(s.map((e) => e.id));
|
|
1572
|
+
n = n.map((e) => r.has(e.id) ? {
|
|
1573
|
+
...e,
|
|
1574
|
+
state: "retiring"
|
|
1575
|
+
} : e), await F(t, n, e.now);
|
|
1576
|
+
}
|
|
1577
|
+
if (o = n.find((e) => e.state == "active"), o != null) {
|
|
1578
|
+
try {
|
|
1579
|
+
n = await yt(e, n);
|
|
1580
|
+
} catch {
|
|
1581
|
+
return { outcome: "ready" };
|
|
1582
|
+
}
|
|
1583
|
+
if (o = n.find((e) => e.state == "active"), o != null && Date.parse(o.expiration) - ot > r) return await F(t, n, I(n, e.now)), { outcome: "ready" };
|
|
1584
|
+
}
|
|
1585
|
+
return n.some((e) => e.state == "creating") || n.filter((e) => e.resourceId == null).length >= lt ? (await F(t, n, I(n, e.now)), { outcome: o == null ? "pending" : "ready" }) : await _t(e, n);
|
|
1586
|
+
}
|
|
1587
|
+
};
|
|
1588
|
+
function P(e) {
|
|
1589
|
+
if (e == null) throw new y("Google Drive Integration state is missing.");
|
|
1590
|
+
return e;
|
|
1591
|
+
}
|
|
1592
|
+
function mt(e) {
|
|
1593
|
+
return {
|
|
1594
|
+
...typeof e.driveId == "string" ? { driveId: e.driveId } : {},
|
|
1595
|
+
includeCorpusRemovals: e.includeCorpusRemovals ?? !1,
|
|
1596
|
+
includeItemsFromAllDrives: e.includeItemsFromAllDrives ?? !0,
|
|
1597
|
+
includeRemoved: e.includeRemoved ?? !0,
|
|
1598
|
+
pageSize: e.pageSize ?? ut,
|
|
1599
|
+
restrictToMyDrive: e.restrictToMyDrive ?? !1
|
|
1600
|
+
};
|
|
1601
|
+
}
|
|
1602
|
+
function ht(e) {
|
|
1603
|
+
let t = R(e) ? L(e.pageToken) : void 0;
|
|
1604
|
+
if (t == null) throw new y("Google Drive checkpoint pageToken is missing.");
|
|
1605
|
+
return t;
|
|
1606
|
+
}
|
|
1607
|
+
function gt(e) {
|
|
1608
|
+
let t = e.subscription.channels;
|
|
1609
|
+
if (!Array.isArray(t)) throw new y("Google Drive channel state is invalid.");
|
|
1610
|
+
let n = t.map((e) => {
|
|
1611
|
+
if (typeof e != "object" || !e || Array.isArray(e)) throw new y("Google Drive channel is invalid.");
|
|
1612
|
+
let t = e;
|
|
1613
|
+
if (typeof t.createdAt != "string" || !Number.isFinite(Date.parse(t.createdAt)) || typeof t.expiration != "string" || !Number.isFinite(Date.parse(t.expiration)) || typeof t.id != "string" || ![
|
|
1614
|
+
"active",
|
|
1615
|
+
"creating",
|
|
1616
|
+
"retiring",
|
|
1617
|
+
"stopping"
|
|
1618
|
+
].includes(String(t.state)) || t.resourceId != null && typeof t.resourceId != "string") throw new y("Google Drive channel fields are invalid.");
|
|
1619
|
+
let n = {
|
|
1620
|
+
createdAt: t.createdAt,
|
|
1621
|
+
expiration: t.expiration,
|
|
1622
|
+
id: t.id,
|
|
1623
|
+
state: t.state
|
|
1624
|
+
};
|
|
1625
|
+
return typeof t.resourceId == "string" ? Object.assign(n, { resourceId: t.resourceId }) : n;
|
|
1626
|
+
});
|
|
1627
|
+
if (new Set(n.map((e) => e.id)).size != n.length) throw new y("Google Drive channel IDs are duplicated.");
|
|
1628
|
+
return n;
|
|
1629
|
+
}
|
|
1630
|
+
async function _t(e, t) {
|
|
1631
|
+
let n = P(e.state), r = mt(e.config), i;
|
|
1632
|
+
n.checkpoint === null ? (i = await bt(e, r), await n.saveCheckpoint({ pageToken: i })) : i = ht(n.checkpoint);
|
|
1633
|
+
let a = {
|
|
1634
|
+
createdAt: e.now.toISOString(),
|
|
1635
|
+
expiration: new Date(e.now.getTime() + at).toISOString(),
|
|
1636
|
+
id: crypto.randomUUID(),
|
|
1637
|
+
state: "creating"
|
|
1638
|
+
};
|
|
1639
|
+
t = [...t, a], await F(n, t, new Date(e.now.getTime() + st));
|
|
1640
|
+
let o;
|
|
1641
|
+
try {
|
|
1642
|
+
o = await Ct(e, {
|
|
1643
|
+
body: {
|
|
1644
|
+
address: e.endpointUrl,
|
|
1645
|
+
expiration: String(Date.parse(a.expiration)),
|
|
1646
|
+
id: a.id,
|
|
1647
|
+
token: await Ot(e.callbackSecret, a.id),
|
|
1648
|
+
type: "web_hook"
|
|
1649
|
+
},
|
|
1650
|
+
endpoint: "/changes/watch",
|
|
1651
|
+
method: "POST",
|
|
1652
|
+
query: {
|
|
1653
|
+
...r.driveId == null ? {} : { driveId: r.driveId },
|
|
1654
|
+
includeItemsFromAllDrives: r.driveId != null || r.includeItemsFromAllDrives,
|
|
1655
|
+
pageToken: i,
|
|
1656
|
+
restrictToMyDrive: r.restrictToMyDrive,
|
|
1657
|
+
supportsAllDrives: !0
|
|
1658
|
+
}
|
|
1659
|
+
}, "changes.watch");
|
|
1660
|
+
} catch (r) {
|
|
1661
|
+
throw (r instanceof v || r instanceof y) && await F(n, t.filter((e) => e.id != a.id), e.now), r;
|
|
1662
|
+
}
|
|
1663
|
+
let s = L(o.resourceId);
|
|
1664
|
+
if (s == null) throw new b("Google Drive changes.watch response is missing resourceId.");
|
|
1665
|
+
let c = At(o.expiration) ?? a.expiration;
|
|
1666
|
+
t = t.map((e) => e.id == a.id ? {
|
|
1667
|
+
...e,
|
|
1668
|
+
expiration: c,
|
|
1669
|
+
resourceId: s,
|
|
1670
|
+
state: "active"
|
|
1671
|
+
} : e.state == "active" ? {
|
|
1672
|
+
...e,
|
|
1673
|
+
state: "retiring"
|
|
1674
|
+
} : e), await F(n, t, I(t, e.now));
|
|
1675
|
+
try {
|
|
1676
|
+
t = await yt(e, t);
|
|
1677
|
+
} catch {
|
|
1678
|
+
return { outcome: "ready" };
|
|
1679
|
+
}
|
|
1680
|
+
return await F(n, t, I(t, e.now)), { outcome: "ready" };
|
|
1681
|
+
}
|
|
1682
|
+
async function vt(e, t) {
|
|
1683
|
+
let n = P(e.state);
|
|
1684
|
+
return t.some((e) => e.state == "active" || e.state == "creating") && (t = t.map((e) => ({
|
|
1685
|
+
...e,
|
|
1686
|
+
state: "retiring"
|
|
1687
|
+
})), await F(n, t, e.now)), t = await yt(e, t), t.length == 0 ? { outcome: "ready" } : (await F(n, t, I(t, e.now)), { outcome: "pending" });
|
|
1688
|
+
}
|
|
1689
|
+
async function yt(e, t) {
|
|
1690
|
+
let n = P(e.state);
|
|
1691
|
+
for (let r of t) {
|
|
1692
|
+
if (r.state != "retiring" && r.state != "stopping" || r.resourceId == null) continue;
|
|
1693
|
+
let i = t.map((e) => e.id == r.id ? {
|
|
1694
|
+
...e,
|
|
1695
|
+
state: "stopping"
|
|
1696
|
+
} : e);
|
|
1697
|
+
await F(n, i, new Date(e.now.getTime() + ct)), await St(e, r), t = i.filter((e) => e.id != r.id), await F(n, t, e.now);
|
|
1698
|
+
}
|
|
1699
|
+
return t;
|
|
1700
|
+
}
|
|
1701
|
+
async function bt(e, t) {
|
|
1702
|
+
let n = await Ct(e, {
|
|
1703
|
+
endpoint: "/changes/startPageToken",
|
|
1704
|
+
method: "GET",
|
|
1705
|
+
query: {
|
|
1706
|
+
...t.driveId == null ? {} : { driveId: t.driveId },
|
|
1707
|
+
supportsAllDrives: !0
|
|
1708
|
+
}
|
|
1709
|
+
}, "changes.getStartPageToken"), r = R(n) ? L(n.startPageToken) : void 0;
|
|
1710
|
+
if (r == null) throw new b("Google Drive startPageToken response is invalid.");
|
|
1711
|
+
return r;
|
|
1712
|
+
}
|
|
1713
|
+
async function xt(e, t, n) {
|
|
1714
|
+
return await Ct(e, {
|
|
1715
|
+
endpoint: "/changes",
|
|
1716
|
+
method: "GET",
|
|
1717
|
+
query: {
|
|
1718
|
+
...t.driveId == null ? {} : { driveId: t.driveId },
|
|
1719
|
+
fields: ft,
|
|
1720
|
+
includeCorpusRemovals: t.includeCorpusRemovals,
|
|
1721
|
+
includeItemsFromAllDrives: t.driveId != null || t.includeItemsFromAllDrives,
|
|
1722
|
+
includeRemoved: t.includeCorpusRemovals || t.includeRemoved,
|
|
1723
|
+
pageSize: t.pageSize,
|
|
1724
|
+
pageToken: n,
|
|
1725
|
+
restrictToMyDrive: t.restrictToMyDrive,
|
|
1726
|
+
supportsAllDrives: !0
|
|
1727
|
+
}
|
|
1728
|
+
}, "changes.list");
|
|
1729
|
+
}
|
|
1730
|
+
async function St(e, t) {
|
|
1731
|
+
let n = await wt(e, {
|
|
1732
|
+
body: {
|
|
1733
|
+
id: t.id,
|
|
1734
|
+
resourceId: t.resourceId
|
|
1735
|
+
},
|
|
1736
|
+
endpoint: "/channels/stop",
|
|
1737
|
+
method: "POST"
|
|
1738
|
+
});
|
|
1739
|
+
n.status >= 200 && n.status < 300 || n.status == 404 || Tt(n, "channels.stop");
|
|
1740
|
+
}
|
|
1741
|
+
async function Ct(e, t, n) {
|
|
1742
|
+
let r = await wt(e, t);
|
|
1743
|
+
if (r.status >= 200 && r.status < 300 && R(r.data)) return r.data;
|
|
1744
|
+
Tt(r, n);
|
|
1745
|
+
}
|
|
1746
|
+
async function wt(e, t) {
|
|
1747
|
+
try {
|
|
1748
|
+
return await e.connector.execute(t, e.signal);
|
|
1749
|
+
} catch (e) {
|
|
1750
|
+
throw e instanceof v ? e : new b("Google Drive proxy request failed.", { cause: e });
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
function Tt(e, t) {
|
|
1754
|
+
let n = Et(e.data);
|
|
1755
|
+
throw e.status == 401 || e.status == 403 && !n.toLowerCase().includes("ratelimit") ? new v(`Google Drive ${t} requires Connection reauthorization.`) : e.status == 408 || e.status == 429 || e.status >= 500 ? new b(`Google Drive ${t} is temporarily unavailable.`) : new y(`Google Drive ${t} rejected the subscription${n == "" ? "." : ` with ${n}.`}`);
|
|
1756
|
+
}
|
|
1757
|
+
function Et(e) {
|
|
1758
|
+
if (!R(e) || !R(e.error)) return "";
|
|
1759
|
+
let t = e.error.errors;
|
|
1760
|
+
return Array.isArray(t) && R(t[0]) && typeof t[0].reason == "string" ? t[0].reason : typeof e.error.status == "string" ? e.error.status : "";
|
|
1761
|
+
}
|
|
1762
|
+
function Dt(e, t) {
|
|
1763
|
+
let n = L(e.driveId), r = L(e.fileId), i = L(e.time), a = L(e.changeType), o = e.removed === !0;
|
|
1764
|
+
return {
|
|
1765
|
+
changeId: [
|
|
1766
|
+
n ?? "my-drive",
|
|
1767
|
+
r ?? "unknown-file",
|
|
1768
|
+
i ?? "unknown-time",
|
|
1769
|
+
a ?? "unknown-change",
|
|
1770
|
+
o ? "removed" : "present"
|
|
1771
|
+
].join(":"),
|
|
1772
|
+
changeType: a ?? null,
|
|
1773
|
+
driveId: n ?? null,
|
|
1774
|
+
file: R(e.file) ? e.file : null,
|
|
1775
|
+
fileId: r ?? null,
|
|
1776
|
+
notification: t,
|
|
1777
|
+
removed: o,
|
|
1778
|
+
time: i ?? null
|
|
1779
|
+
};
|
|
1780
|
+
}
|
|
1781
|
+
async function F(e, t, n) {
|
|
1782
|
+
await e.saveSubscription({ channels: t }, n);
|
|
1783
|
+
}
|
|
1784
|
+
function I(e, t) {
|
|
1785
|
+
let n = e.map((e) => e.state == "active" ? Date.parse(e.expiration) - ot : e.state == "creating" ? Date.parse(e.createdAt) + st : e.resourceId == null ? Date.parse(e.expiration) : t.getTime() + ct), r = n.length == 0 ? t.getTime() + ct : Math.min(...n);
|
|
1786
|
+
return new Date(Math.max(t.getTime(), r));
|
|
1787
|
+
}
|
|
1788
|
+
async function Ot(e, t) {
|
|
1789
|
+
let n = await crypto.subtle.importKey("raw", dt.encode(e), {
|
|
1790
|
+
hash: "SHA-256",
|
|
1791
|
+
name: "HMAC"
|
|
1792
|
+
}, !1, ["sign"]), r = new Uint8Array(await crypto.subtle.sign("HMAC", n, dt.encode(`google-drive-channel/v1/${t}`)));
|
|
1793
|
+
return btoa(String.fromCharCode(...r)).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
|
|
1794
|
+
}
|
|
1795
|
+
function kt(e, t) {
|
|
1796
|
+
if (e.length != t.length) return !1;
|
|
1797
|
+
let n = 0;
|
|
1798
|
+
for (let r = 0; r < t.length; r += 1) n |= e.charCodeAt(r) ^ t.charCodeAt(r);
|
|
1799
|
+
return n == 0;
|
|
1800
|
+
}
|
|
1801
|
+
function At(e) {
|
|
1802
|
+
let t = typeof e == "string" || typeof e == "number" ? Number(e) : NaN;
|
|
1803
|
+
return Number.isFinite(t) && t > 0 ? new Date(t).toISOString() : void 0;
|
|
1804
|
+
}
|
|
1805
|
+
function L(e) {
|
|
1806
|
+
return typeof e == "string" && e.length > 0 ? e : void 0;
|
|
1807
|
+
}
|
|
1808
|
+
function R(e) {
|
|
1809
|
+
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
1810
|
+
}
|
|
1811
|
+
//#endregion
|
|
1812
|
+
//#region src/trigger/providers/google-drive/on-file-change.ts
|
|
1813
|
+
var z = "application/vnd.google-apps.folder", jt = "nextPageToken,incompleteSearch,files(id,name,mimeType,createdTime,modifiedTime,parents,trashed,webViewLink,driveId,size,version,lastModifyingUser(displayName,emailAddress))", Mt = /* @__PURE__ */ new Set([
|
|
1814
|
+
"rateLimitExceeded",
|
|
1815
|
+
"userRateLimitExceeded",
|
|
1816
|
+
"dailyLimitExceeded",
|
|
1817
|
+
"sharingRateLimitExceeded"
|
|
1818
|
+
]), Nt = /* @__PURE__ */ new Set(["insufficientFilePermissions", "appNotAuthorizedToFile"]), Pt = {
|
|
1819
|
+
snapshot: {
|
|
1820
|
+
configSchema: {
|
|
1821
|
+
additionalProperties: !1,
|
|
1822
|
+
properties: {
|
|
1823
|
+
changeType: {
|
|
1824
|
+
enum: ["created", "updated"],
|
|
1825
|
+
type: "string"
|
|
1826
|
+
},
|
|
1827
|
+
driveId: {
|
|
1828
|
+
default: "",
|
|
1829
|
+
pattern: "^[A-Za-z0-9_-]{0,512}$",
|
|
1830
|
+
type: "string"
|
|
1831
|
+
},
|
|
1832
|
+
folderId: {
|
|
1833
|
+
pattern: "^[A-Za-z0-9_-]{2,512}$",
|
|
1834
|
+
type: "string"
|
|
1835
|
+
},
|
|
1836
|
+
itemTypes: {
|
|
1837
|
+
default: ["file"],
|
|
1838
|
+
items: {
|
|
1839
|
+
enum: ["file", "folder"],
|
|
1840
|
+
type: "string"
|
|
1841
|
+
},
|
|
1842
|
+
minItems: 1,
|
|
1843
|
+
type: "array",
|
|
1844
|
+
uniqueItems: !0
|
|
1845
|
+
},
|
|
1846
|
+
maxFilesPerPoll: {
|
|
1847
|
+
default: 50,
|
|
1848
|
+
maximum: 200,
|
|
1849
|
+
minimum: 1,
|
|
1850
|
+
type: "integer"
|
|
1851
|
+
},
|
|
1852
|
+
mimeTypes: {
|
|
1853
|
+
default: [],
|
|
1854
|
+
items: {
|
|
1855
|
+
minLength: 1,
|
|
1856
|
+
type: "string"
|
|
1857
|
+
},
|
|
1858
|
+
type: "array"
|
|
1859
|
+
},
|
|
1860
|
+
namePrefix: {
|
|
1861
|
+
default: "",
|
|
1862
|
+
type: "string"
|
|
1863
|
+
}
|
|
1864
|
+
},
|
|
1865
|
+
required: ["folderId", "changeType"],
|
|
1866
|
+
title: "Google Drive Folder Change Config",
|
|
1867
|
+
type: "object"
|
|
1868
|
+
},
|
|
1869
|
+
definitionVersion: 1,
|
|
1870
|
+
description: "Polls one Google Drive folder and triggers when a file or folder directly inside it is created or updated.",
|
|
1871
|
+
displayName: "Google Drive: File or Folder Change in a Folder",
|
|
1872
|
+
key: "googledrive.on_file_change",
|
|
1873
|
+
name: "on_file_change",
|
|
1874
|
+
payloadSchema: {
|
|
1875
|
+
additionalProperties: !1,
|
|
1876
|
+
properties: { events: {
|
|
1877
|
+
items: {
|
|
1878
|
+
additionalProperties: !1,
|
|
1879
|
+
properties: {
|
|
1880
|
+
createdTime: { type: ["string", "null"] },
|
|
1881
|
+
driveId: { type: ["string", "null"] },
|
|
1882
|
+
eventType: {
|
|
1883
|
+
enum: [
|
|
1884
|
+
"file_created",
|
|
1885
|
+
"file_updated",
|
|
1886
|
+
"folder_created",
|
|
1887
|
+
"folder_updated"
|
|
1888
|
+
],
|
|
1889
|
+
type: "string"
|
|
1890
|
+
},
|
|
1891
|
+
fileId: { type: "string" },
|
|
1892
|
+
itemType: {
|
|
1893
|
+
enum: ["file", "folder"],
|
|
1894
|
+
type: "string"
|
|
1895
|
+
},
|
|
1896
|
+
lastModifyingUser: { type: ["object", "null"] },
|
|
1897
|
+
mimeType: { type: "string" },
|
|
1898
|
+
modifiedTime: { type: ["string", "null"] },
|
|
1899
|
+
name: { type: "string" },
|
|
1900
|
+
parents: {
|
|
1901
|
+
items: { type: "string" },
|
|
1902
|
+
type: "array"
|
|
1903
|
+
},
|
|
1904
|
+
size: { type: "string" },
|
|
1905
|
+
webViewLink: { type: ["string", "null"] }
|
|
1906
|
+
},
|
|
1907
|
+
required: [
|
|
1908
|
+
"eventType",
|
|
1909
|
+
"itemType",
|
|
1910
|
+
"fileId",
|
|
1911
|
+
"name",
|
|
1912
|
+
"mimeType",
|
|
1913
|
+
"createdTime",
|
|
1914
|
+
"modifiedTime",
|
|
1915
|
+
"parents",
|
|
1916
|
+
"webViewLink",
|
|
1917
|
+
"driveId",
|
|
1918
|
+
"lastModifyingUser"
|
|
1919
|
+
],
|
|
1920
|
+
type: "object"
|
|
1921
|
+
},
|
|
1922
|
+
type: "array"
|
|
1923
|
+
} },
|
|
1924
|
+
required: ["events"],
|
|
1925
|
+
title: "Google Drive File Change Payload",
|
|
1926
|
+
type: "object"
|
|
1927
|
+
},
|
|
1928
|
+
provider: "googledrive",
|
|
1929
|
+
type: "poll"
|
|
1930
|
+
},
|
|
1931
|
+
async poll(e) {
|
|
1932
|
+
let t = Ft(e.config);
|
|
1933
|
+
if (e.checkpoint === null) return Lt(e, t);
|
|
1934
|
+
let n = It(e.checkpoint);
|
|
1935
|
+
return n.changeType === t.changeType ? zt(e, t, n) : {
|
|
1936
|
+
checkpoint: Rt(e.now, t.changeType),
|
|
1937
|
+
events: []
|
|
1938
|
+
};
|
|
1939
|
+
}
|
|
1940
|
+
};
|
|
1941
|
+
function Ft(e) {
|
|
1942
|
+
return {
|
|
1943
|
+
changeType: e.changeType,
|
|
1944
|
+
driveId: e.driveId ?? "",
|
|
1945
|
+
folderId: e.folderId,
|
|
1946
|
+
itemTypes: new Set(e.itemTypes ?? ["file"]),
|
|
1947
|
+
maxFilesPerPoll: e.maxFilesPerPoll ?? 50,
|
|
1948
|
+
mimeTypes: e.mimeTypes ?? [],
|
|
1949
|
+
namePrefix: e.namePrefix ?? ""
|
|
1950
|
+
};
|
|
1951
|
+
}
|
|
1952
|
+
function It(e) {
|
|
1953
|
+
let n = B(e);
|
|
1954
|
+
if (typeof n?.since != "string" || Number.isNaN(Date.parse(n.since))) throw new t("Google Drive checkpoint is invalid; recreate the Trigger.");
|
|
1955
|
+
let r = n.boundaryKeys;
|
|
1956
|
+
return {
|
|
1957
|
+
since: n.since,
|
|
1958
|
+
...typeof n.floor == "string" ? { floor: n.floor } : {},
|
|
1959
|
+
...typeof n.pageToken == "string" ? { pageToken: n.pageToken } : {},
|
|
1960
|
+
...typeof n.pageQuery == "string" ? { pageQuery: n.pageQuery } : {},
|
|
1961
|
+
...typeof n.changeType == "string" ? { changeType: n.changeType } : {},
|
|
1962
|
+
...typeof n.maxSeen == "string" ? { maxSeen: n.maxSeen } : {},
|
|
1963
|
+
...Array.isArray(r) ? { boundaryKeys: r.filter((e) => typeof e == "string") } : {}
|
|
1964
|
+
};
|
|
1965
|
+
}
|
|
1966
|
+
async function Lt(e, r) {
|
|
1967
|
+
let i = await qt(e, `/drive/v3/files/${encodeURIComponent(r.folderId)}`, {
|
|
1968
|
+
fields: "id,name,mimeType,driveId,trashed",
|
|
1969
|
+
supportsAllDrives: "true"
|
|
1970
|
+
});
|
|
1971
|
+
Jt(i, "folder probe");
|
|
1972
|
+
let a = B(i.data);
|
|
1973
|
+
if (a == null) throw new n("Google Drive folder probe returned no payload.");
|
|
1974
|
+
if (a.mimeType !== z) throw new t("Google Drive folderId does not point to a folder.");
|
|
1975
|
+
if (a.trashed === !0) throw new t("The Google Drive folder is in the trash.");
|
|
1976
|
+
if (r.driveId.length > 0 && (a.driveId ?? "") !== r.driveId) throw new t("The configured Google Drive shared drive does not contain this folder.");
|
|
1977
|
+
return {
|
|
1978
|
+
checkpoint: Rt(e.now, r.changeType),
|
|
1979
|
+
events: []
|
|
1980
|
+
};
|
|
1981
|
+
}
|
|
1982
|
+
function Rt(e, t) {
|
|
1983
|
+
let n = e.toISOString();
|
|
1984
|
+
return {
|
|
1985
|
+
changeType: t,
|
|
1986
|
+
floor: n,
|
|
1987
|
+
since: n
|
|
1988
|
+
};
|
|
1989
|
+
}
|
|
1990
|
+
async function zt(e, t, n) {
|
|
1991
|
+
let r = Ht(t, n.since, n.floor), i = `${t.driveId}|${r}`, a = n.pageQuery == i ? n.pageToken : void 0, o = await qt(e, "/drive/v3/files", {
|
|
1992
|
+
corpora: t.driveId.length == 0 ? "allDrives" : "drive",
|
|
1993
|
+
driveId: t.driveId.length == 0 ? void 0 : t.driveId,
|
|
1994
|
+
fields: jt,
|
|
1995
|
+
includeItemsFromAllDrives: "true",
|
|
1996
|
+
pageSize: t.maxFilesPerPoll,
|
|
1997
|
+
pageToken: a,
|
|
1998
|
+
q: r,
|
|
1999
|
+
spaces: "drive",
|
|
2000
|
+
supportsAllDrives: "true"
|
|
2001
|
+
});
|
|
2002
|
+
Jt(o, "files list");
|
|
2003
|
+
let s = B(o.data) ?? {}, c = new Set(n.boundaryKeys ?? []), l = [], u = [], d = a == null ? void 0 : n.maxSeen;
|
|
2004
|
+
for (let e of s.files ?? []) {
|
|
2005
|
+
if (e.id == null || e.id.length == 0) continue;
|
|
2006
|
+
let n = Gt(e, t.changeType);
|
|
2007
|
+
if (n == null) continue;
|
|
2008
|
+
let r = Kt(e, e.id, n, t.changeType);
|
|
2009
|
+
u.push(r.dedupeKey), Qt(n, d) && (d = n), c.has(r.dedupeKey) || l.push(r);
|
|
2010
|
+
}
|
|
2011
|
+
if (s.incompleteSearch === !0) {
|
|
2012
|
+
let e = a == null ? {} : Bt(a, i, d);
|
|
2013
|
+
return {
|
|
2014
|
+
checkpoint: Vt(n, t.changeType, n.since, u, e),
|
|
2015
|
+
events: l
|
|
2016
|
+
};
|
|
2017
|
+
}
|
|
2018
|
+
if (s.nextPageToken) return {
|
|
2019
|
+
checkpoint: Vt(n, t.changeType, n.since, u, Bt(s.nextPageToken, i, d)),
|
|
2020
|
+
events: l,
|
|
2021
|
+
hasMore: !0
|
|
2022
|
+
};
|
|
2023
|
+
let f = d ?? n.since;
|
|
2024
|
+
return {
|
|
2025
|
+
checkpoint: Vt(n, t.changeType, f, u),
|
|
2026
|
+
events: l
|
|
2027
|
+
};
|
|
2028
|
+
}
|
|
2029
|
+
function Bt(e, t, n) {
|
|
2030
|
+
return {
|
|
2031
|
+
pageQuery: t,
|
|
2032
|
+
pageToken: e,
|
|
2033
|
+
...n == null ? {} : { maxSeen: n }
|
|
2034
|
+
};
|
|
2035
|
+
}
|
|
2036
|
+
function Vt(e, t, n, r, i = {}) {
|
|
2037
|
+
let a = [.../* @__PURE__ */ new Set([...e.boundaryKeys ?? [], ...r])].map((e) => ({
|
|
2038
|
+
at: Date.parse(e.slice(e.indexOf(":") + 1)),
|
|
2039
|
+
key: e
|
|
2040
|
+
})).filter(({ at: t }) => t >= Ut(n, e.floor)).toSorted((e, t) => t.at - e.at).slice(0, 200).map(({ key: e }) => e);
|
|
2041
|
+
return {
|
|
2042
|
+
changeType: t,
|
|
2043
|
+
since: n,
|
|
2044
|
+
...Wt(e.floor, n),
|
|
2045
|
+
...i,
|
|
2046
|
+
...a.length == 0 ? {} : { boundaryKeys: a }
|
|
2047
|
+
};
|
|
2048
|
+
}
|
|
2049
|
+
function Ht(e, t, n) {
|
|
2050
|
+
let r = e.changeType == "created" ? "createdTime" : "modifiedTime", i = [
|
|
2051
|
+
`'${Zt(e.folderId)}' in parents`,
|
|
2052
|
+
"trashed = false",
|
|
2053
|
+
`${r} >= '${new Date(Ut(t, n)).toISOString()}'`
|
|
2054
|
+
];
|
|
2055
|
+
return e.itemTypes.has("folder") ? e.itemTypes.has("file") || i.push(`mimeType = '${z}'`) : i.push(`mimeType != '${z}'`), e.mimeTypes.length > 0 && i.push(`(${e.mimeTypes.map((e) => `mimeType = '${Zt(e)}'`).join(" or ")})`), e.namePrefix.length > 0 && i.push(`name contains '${Zt(e.namePrefix)}'`), i.join(" and ");
|
|
2056
|
+
}
|
|
2057
|
+
function Ut(e, t) {
|
|
2058
|
+
let n = Date.parse(e) - 6e4, r = t == null ? NaN : Date.parse(t);
|
|
2059
|
+
return Number.isNaN(r) ? n : Math.max(n, r);
|
|
2060
|
+
}
|
|
2061
|
+
function Wt(e, t) {
|
|
2062
|
+
return e == null || Number.isNaN(Date.parse(e)) || Date.parse(t) - 6e4 >= Date.parse(e) ? {} : { floor: e };
|
|
2063
|
+
}
|
|
2064
|
+
function Gt(e, t) {
|
|
2065
|
+
let n = t == "created" ? e.createdTime : e.modifiedTime;
|
|
2066
|
+
return n == null || n.length == 0 || Number.isNaN(Date.parse(n)) ? void 0 : n;
|
|
2067
|
+
}
|
|
2068
|
+
function Kt(e, t, n, r) {
|
|
2069
|
+
let i = e.mimeType == z ? "folder" : "file", a = e.lastModifyingUser;
|
|
2070
|
+
return {
|
|
2071
|
+
dedupeKey: `${t}:${n}`,
|
|
2072
|
+
payload: {
|
|
2073
|
+
createdTime: e.createdTime ?? null,
|
|
2074
|
+
driveId: e.driveId ?? null,
|
|
2075
|
+
eventType: `${i}_${r}`,
|
|
2076
|
+
fileId: t,
|
|
2077
|
+
itemType: i,
|
|
2078
|
+
lastModifyingUser: a == null ? null : {
|
|
2079
|
+
displayName: a.displayName ?? "",
|
|
2080
|
+
emailAddress: a.emailAddress ?? ""
|
|
2081
|
+
},
|
|
2082
|
+
mimeType: e.mimeType ?? "",
|
|
2083
|
+
modifiedTime: e.modifiedTime ?? null,
|
|
2084
|
+
name: e.name ?? "",
|
|
2085
|
+
parents: e.parents ?? [],
|
|
2086
|
+
...e.size == null ? {} : { size: e.size },
|
|
2087
|
+
webViewLink: e.webViewLink ?? null
|
|
2088
|
+
}
|
|
2089
|
+
};
|
|
2090
|
+
}
|
|
2091
|
+
async function qt(e, t, r) {
|
|
2092
|
+
try {
|
|
2093
|
+
return await e.connector.execute({
|
|
2094
|
+
endpoint: t,
|
|
2095
|
+
method: "GET",
|
|
2096
|
+
query: Object.fromEntries(Object.entries(r).filter((e) => e[1] != null))
|
|
2097
|
+
}, e.signal);
|
|
2098
|
+
} catch (e) {
|
|
2099
|
+
throw new n(`Google Drive proxy request to ${t} failed.`, { cause: e });
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
function Jt(r, i) {
|
|
2103
|
+
if (!(r.status >= 200 && r.status < 300)) {
|
|
2104
|
+
if (r.status == 400 || r.status == 404) throw new t(`Google Drive ${i} rejected the configuration.`);
|
|
2105
|
+
if (r.status == 401) throw new e(`Google Drive ${i} rejected the Connection.`);
|
|
2106
|
+
if (r.status == 403) {
|
|
2107
|
+
let a = Yt(r.data);
|
|
2108
|
+
if (a.some((e) => Mt.has(e))) throw new n(`Google Drive ${i} was rate limited.`);
|
|
2109
|
+
if (a.some((e) => Nt.has(e))) throw new t(`Google Drive ${i} was rejected by an ACL.`);
|
|
2110
|
+
if (Xt(r.data)) throw new e(`Google Drive ${i} needs additional scopes.`);
|
|
2111
|
+
}
|
|
2112
|
+
throw new n(`Google Drive ${i} failed with status ${r.status}.`);
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
function Yt(e) {
|
|
2116
|
+
let t = B(B(e)?.error);
|
|
2117
|
+
return [...[t?.errors, t?.details].flatMap((e) => Array.isArray(e) ? e : []).map((e) => B(e)?.reason), t?.status].filter((e) => typeof e == "string");
|
|
2118
|
+
}
|
|
2119
|
+
function Xt(e) {
|
|
2120
|
+
if (Yt(e).includes("ACCESS_TOKEN_SCOPE_INSUFFICIENT")) return !0;
|
|
2121
|
+
let t = B(B(e)?.error)?.message;
|
|
2122
|
+
return typeof t == "string" && t.toLowerCase().includes("insufficient authentication scopes");
|
|
2123
|
+
}
|
|
2124
|
+
function Zt(e) {
|
|
2125
|
+
return e.replaceAll("\\", "\\\\").replaceAll("'", "\\'");
|
|
2126
|
+
}
|
|
2127
|
+
function Qt(e, t) {
|
|
2128
|
+
let n = Date.parse(e);
|
|
2129
|
+
return Number.isNaN(n) ? !1 : t == null || Number.isNaN(Date.parse(t)) || n > Date.parse(t);
|
|
2130
|
+
}
|
|
2131
|
+
function B(e) {
|
|
2132
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
2133
|
+
}
|
|
2134
|
+
//#endregion
|
|
2135
|
+
//#region src/trigger/providers/google-sheets/on-row-added.ts
|
|
2136
|
+
var $t = [
|
|
2137
|
+
"permission_denied",
|
|
2138
|
+
"accessnotconfigured",
|
|
2139
|
+
"insufficientfilepermissions",
|
|
2140
|
+
"appnotauthorizedtofile",
|
|
2141
|
+
"the caller does not have permission",
|
|
2142
|
+
"has not been used in project"
|
|
2143
|
+
], en = ["ratelimitexceeded", "dailylimitexceeded"], tn = {
|
|
2144
|
+
snapshot: {
|
|
2145
|
+
configSchema: {
|
|
2146
|
+
additionalProperties: !1,
|
|
2147
|
+
properties: {
|
|
2148
|
+
columnRange: {
|
|
2149
|
+
default: "A:ZZZ",
|
|
2150
|
+
pattern: "^[A-Za-z]{1,3}(?::[A-Za-z]{1,3})?$",
|
|
2151
|
+
type: "string"
|
|
2152
|
+
},
|
|
2153
|
+
dateTimeRender: {
|
|
2154
|
+
default: "FORMATTED_STRING",
|
|
2155
|
+
enum: ["FORMATTED_STRING", "SERIAL_NUMBER"],
|
|
2156
|
+
type: "string"
|
|
2157
|
+
},
|
|
2158
|
+
firstDataRow: {
|
|
2159
|
+
default: 2,
|
|
2160
|
+
minimum: 1,
|
|
2161
|
+
type: "integer"
|
|
2162
|
+
},
|
|
2163
|
+
headerRow: {
|
|
2164
|
+
default: 1,
|
|
2165
|
+
minimum: 1,
|
|
2166
|
+
type: "integer"
|
|
2167
|
+
},
|
|
2168
|
+
maxRowsPerPoll: {
|
|
2169
|
+
default: 100,
|
|
2170
|
+
maximum: 500,
|
|
2171
|
+
minimum: 1,
|
|
2172
|
+
type: "integer"
|
|
2173
|
+
},
|
|
2174
|
+
sheet: {
|
|
2175
|
+
minLength: 1,
|
|
2176
|
+
type: "string"
|
|
2177
|
+
},
|
|
2178
|
+
spreadsheetId: {
|
|
2179
|
+
minLength: 1,
|
|
2180
|
+
type: "string"
|
|
2181
|
+
},
|
|
2182
|
+
valueRender: {
|
|
2183
|
+
default: "UNFORMATTED_VALUE",
|
|
2184
|
+
enum: [
|
|
2185
|
+
"UNFORMATTED_VALUE",
|
|
2186
|
+
"FORMATTED_VALUE",
|
|
2187
|
+
"FORMULA"
|
|
2188
|
+
],
|
|
2189
|
+
type: "string"
|
|
2190
|
+
}
|
|
2191
|
+
},
|
|
2192
|
+
required: ["spreadsheetId", "sheet"],
|
|
2193
|
+
title: "Google Sheets New Row Config",
|
|
2194
|
+
type: "object"
|
|
2195
|
+
},
|
|
2196
|
+
definitionVersion: 1,
|
|
2197
|
+
description: "Polls a sheet and triggers once for every new row appended below the last row already seen.",
|
|
2198
|
+
displayName: "Google Sheets: New Row Added",
|
|
2199
|
+
key: "googlesheets.on_row_added",
|
|
2200
|
+
name: "on_row_added",
|
|
2201
|
+
payloadSchema: {
|
|
2202
|
+
additionalProperties: !1,
|
|
2203
|
+
properties: { events: {
|
|
2204
|
+
items: {
|
|
2205
|
+
additionalProperties: !1,
|
|
2206
|
+
properties: {
|
|
2207
|
+
row: { type: "object" },
|
|
2208
|
+
rowNumber: { type: "integer" },
|
|
2209
|
+
sheetId: { type: "integer" },
|
|
2210
|
+
sheetTitle: { type: "string" },
|
|
2211
|
+
spreadsheetId: { type: "string" },
|
|
2212
|
+
values: {
|
|
2213
|
+
items: {},
|
|
2214
|
+
type: "array"
|
|
2215
|
+
}
|
|
2216
|
+
},
|
|
2217
|
+
required: [
|
|
2218
|
+
"spreadsheetId",
|
|
2219
|
+
"sheetId",
|
|
2220
|
+
"sheetTitle",
|
|
2221
|
+
"rowNumber",
|
|
2222
|
+
"row",
|
|
2223
|
+
"values"
|
|
2224
|
+
],
|
|
2225
|
+
type: "object"
|
|
2226
|
+
},
|
|
2227
|
+
type: "array"
|
|
2228
|
+
} },
|
|
2229
|
+
required: ["events"],
|
|
2230
|
+
title: "Google Sheets New Row Payload",
|
|
2231
|
+
type: "object"
|
|
2232
|
+
},
|
|
2233
|
+
provider: "googlesheets",
|
|
2234
|
+
type: "poll"
|
|
2235
|
+
},
|
|
2236
|
+
async poll(e) {
|
|
2237
|
+
let t = nn(e.config);
|
|
2238
|
+
if (e.checkpoint === null) return {
|
|
2239
|
+
checkpoint: await on(e, t, await an(e, t)),
|
|
2240
|
+
events: []
|
|
2241
|
+
};
|
|
2242
|
+
let n = rn(e.checkpoint), r = await an(e, t);
|
|
2243
|
+
if (n.spreadsheetId !== t.spreadsheetId || n.sheetId !== r.sheetId || n.lastRowNumber > r.rowCount) return {
|
|
2244
|
+
checkpoint: await on(e, t, r),
|
|
2245
|
+
events: []
|
|
2246
|
+
};
|
|
2247
|
+
let i = await cn(e, t, r), a = Math.min(Math.max(t.firstDataRow, n.lastRowNumber), r.rowCount), o = Math.min(a + t.maxRowsPerPoll, r.rowCount), s = await ln(e, t, r, a, o, "row window fetch");
|
|
2248
|
+
if (s.length == 0 && n.lastRowNumber >= t.firstDataRow) return {
|
|
2249
|
+
checkpoint: await on(e, t, r),
|
|
2250
|
+
events: []
|
|
2251
|
+
};
|
|
2252
|
+
let c = a + s.length - 1;
|
|
2253
|
+
if (c <= n.lastRowNumber) return {
|
|
2254
|
+
checkpoint: n,
|
|
2255
|
+
events: []
|
|
2256
|
+
};
|
|
2257
|
+
let l = [], u = 0;
|
|
2258
|
+
for (let [e, o] of s.entries()) {
|
|
2259
|
+
let s = a + e;
|
|
2260
|
+
if (!(s <= n.lastRowNumber)) {
|
|
2261
|
+
if (s == t.headerRow || dn(o)) {
|
|
2262
|
+
u += 1;
|
|
2263
|
+
continue;
|
|
2264
|
+
}
|
|
2265
|
+
l.push(await fn(t, r, s, o, i));
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
let d = c == o && o < r.rowCount;
|
|
2269
|
+
return {
|
|
2270
|
+
checkpoint: {
|
|
2271
|
+
lastRowNumber: c,
|
|
2272
|
+
sheetId: r.sheetId,
|
|
2273
|
+
spreadsheetId: t.spreadsheetId
|
|
2274
|
+
},
|
|
2275
|
+
events: l,
|
|
2276
|
+
filtered: u,
|
|
2277
|
+
...d ? { hasMore: !0 } : {}
|
|
2278
|
+
};
|
|
2279
|
+
}
|
|
2280
|
+
};
|
|
2281
|
+
function nn(e) {
|
|
2282
|
+
let t = (e.columnRange ?? "A:ZZZ").trim(), n = t.indexOf(":"), r = n < 0 ? t : t.slice(0, n), i = n < 0 ? t : t.slice(n + 1), a = e.spreadsheetId.trim();
|
|
2283
|
+
return {
|
|
2284
|
+
colEnd: i,
|
|
2285
|
+
colStart: r,
|
|
2286
|
+
dateTimeRender: e.dateTimeRender ?? "FORMATTED_STRING",
|
|
2287
|
+
firstDataRow: e.firstDataRow ?? 2,
|
|
2288
|
+
headerRow: e.headerRow ?? 1,
|
|
2289
|
+
maxRowsPerPoll: e.maxRowsPerPoll ?? 100,
|
|
2290
|
+
sheet: e.sheet,
|
|
2291
|
+
spreadsheetId: /\/spreadsheets\/d\/([A-Za-z0-9_-]+)/.exec(a)?.[1] ?? a,
|
|
2292
|
+
valueRender: e.valueRender ?? "UNFORMATTED_VALUE"
|
|
2293
|
+
};
|
|
2294
|
+
}
|
|
2295
|
+
function rn(e) {
|
|
2296
|
+
let n = V(e);
|
|
2297
|
+
if (typeof n?.spreadsheetId != "string" || !Number.isInteger(n.sheetId) || !Number.isInteger(n.lastRowNumber)) throw new t("Google Sheets checkpoint is invalid; recreate the Trigger.");
|
|
2298
|
+
return {
|
|
2299
|
+
lastRowNumber: n.lastRowNumber,
|
|
2300
|
+
sheetId: n.sheetId,
|
|
2301
|
+
spreadsheetId: n.spreadsheetId
|
|
2302
|
+
};
|
|
2303
|
+
}
|
|
2304
|
+
async function an(e, r) {
|
|
2305
|
+
let i = await mn(e, `/spreadsheets/${encodeURIComponent(r.spreadsheetId)}`, { fields: "sheets.properties(sheetId,title,sheetType,gridProperties)" });
|
|
2306
|
+
if (i.status == 404) throw new t("The Google Sheets spreadsheet was not found.");
|
|
2307
|
+
hn(i, "spreadsheet metadata fetch");
|
|
2308
|
+
let a = V(i.data)?.sheets, o = (Array.isArray(a) ? a.map((e) => V(V(e)?.properties)) : []).filter((e) => e != null), s = (/^\d+$/.test(r.sheet) ? o.find(({ sheetId: e }) => e === Number(r.sheet)) : void 0) ?? o.find(({ title: e }) => e === r.sheet);
|
|
2309
|
+
if (s == null) throw new t(`Google Sheets tab "${r.sheet}" does not exist.`);
|
|
2310
|
+
if (s.sheetType != null && s.sheetType !== "GRID") throw new t("The Google Sheets tab is not a grid sheet.");
|
|
2311
|
+
let c = s.gridProperties?.rowCount;
|
|
2312
|
+
if (s.sheetId == null || s.title == null || c == null) throw new n("Google Sheets tab metadata is incomplete.");
|
|
2313
|
+
return {
|
|
2314
|
+
rowCount: c,
|
|
2315
|
+
sheetId: s.sheetId,
|
|
2316
|
+
title: s.title
|
|
2317
|
+
};
|
|
2318
|
+
}
|
|
2319
|
+
async function on(e, t, n) {
|
|
2320
|
+
return {
|
|
2321
|
+
lastRowNumber: await sn(e, t, n),
|
|
2322
|
+
sheetId: n.sheetId,
|
|
2323
|
+
spreadsheetId: t.spreadsheetId
|
|
2324
|
+
};
|
|
2325
|
+
}
|
|
2326
|
+
async function sn(e, t, n) {
|
|
2327
|
+
if (n.rowCount < t.firstDataRow) return t.firstDataRow - 1;
|
|
2328
|
+
let r = await ln(e, t, n, t.firstDataRow, n.rowCount, "full-range scan");
|
|
2329
|
+
return r.length == 0 ? t.firstDataRow - 1 : t.firstDataRow + r.length - 1;
|
|
2330
|
+
}
|
|
2331
|
+
async function cn(e, t, n) {
|
|
2332
|
+
let r = await mn(e, pn(t, n, t.headerRow, t.headerRow), {
|
|
2333
|
+
majorDimension: "ROWS",
|
|
2334
|
+
valueRenderOption: "FORMATTED_VALUE"
|
|
2335
|
+
});
|
|
2336
|
+
return hn(r, "header row fetch"), un(r.data)[0] ?? [];
|
|
2337
|
+
}
|
|
2338
|
+
async function ln(e, t, n, r, i, a) {
|
|
2339
|
+
let o = await mn(e, pn(t, n, r, i), {
|
|
2340
|
+
dateTimeRenderOption: t.dateTimeRender,
|
|
2341
|
+
majorDimension: "ROWS",
|
|
2342
|
+
valueRenderOption: t.valueRender
|
|
2343
|
+
});
|
|
2344
|
+
return hn(o, a), un(o.data);
|
|
2345
|
+
}
|
|
2346
|
+
function un(e) {
|
|
2347
|
+
let t = V(e)?.values;
|
|
2348
|
+
return Array.isArray(t) ? t : [];
|
|
2349
|
+
}
|
|
2350
|
+
function dn(e) {
|
|
2351
|
+
return e.every((e) => e === "" || e == null);
|
|
2352
|
+
}
|
|
2353
|
+
async function fn(e, t, n, r, i) {
|
|
2354
|
+
let a = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify(r))), o = [...new Uint8Array(a)].slice(0, 8).map((e) => e.toString(16).padStart(2, "0")).join(""), s = {}, c = gn(e.colStart);
|
|
2355
|
+
for (let [e, t] of r.entries()) {
|
|
2356
|
+
let n = i[e];
|
|
2357
|
+
s[typeof n == "string" && n.length > 0 ? n : _n(c + e)] = t;
|
|
2358
|
+
}
|
|
2359
|
+
return {
|
|
2360
|
+
dedupeKey: `${t.sheetId}:${n}:${o}`,
|
|
2361
|
+
payload: {
|
|
2362
|
+
row: s,
|
|
2363
|
+
rowNumber: n,
|
|
2364
|
+
sheetId: t.sheetId,
|
|
2365
|
+
sheetTitle: t.title,
|
|
2366
|
+
spreadsheetId: e.spreadsheetId,
|
|
2367
|
+
values: r
|
|
2368
|
+
}
|
|
2369
|
+
};
|
|
2370
|
+
}
|
|
2371
|
+
function pn(e, t, n, r) {
|
|
2372
|
+
let i = encodeURIComponent(`'${t.title.replaceAll("'", "''")}'`);
|
|
2373
|
+
return `/spreadsheets/${encodeURIComponent(e.spreadsheetId)}/values/${i}!${e.colStart}${n}:${e.colEnd}${r}`;
|
|
2374
|
+
}
|
|
2375
|
+
async function mn(e, t, r) {
|
|
2376
|
+
try {
|
|
2377
|
+
return await e.connector.execute({
|
|
2378
|
+
endpoint: t,
|
|
2379
|
+
method: "GET",
|
|
2380
|
+
query: r
|
|
2381
|
+
}, e.signal);
|
|
2382
|
+
} catch (e) {
|
|
2383
|
+
throw new n(`Google Sheets proxy request to ${t} failed.`, { cause: e });
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
function hn(r, i) {
|
|
2387
|
+
if (r.status >= 200 && r.status < 300) return;
|
|
2388
|
+
if (r.status == 401) throw new e(`Google Sheets ${i} rejected the Connection.`);
|
|
2389
|
+
let a = JSON.stringify(r.data ?? null).toLowerCase();
|
|
2390
|
+
if (r.status == 403) {
|
|
2391
|
+
if (en.some((e) => a.includes(e))) throw new n(`Google Sheets ${i} was rate limited.`);
|
|
2392
|
+
if ($t.some((e) => a.includes(e))) throw new e(`Google Sheets ${i} rejected the Connection.`);
|
|
2393
|
+
}
|
|
2394
|
+
throw r.status == 400 && a.includes("unable to parse range") ? new t("Google Sheets rejected the configured range.") : r.status == 413 ? new t("Google Sheets response is too large; narrow columnRange.") : new n(`Google Sheets ${i} failed with status ${r.status}.`);
|
|
2395
|
+
}
|
|
2396
|
+
function gn(e) {
|
|
2397
|
+
let t = 0;
|
|
2398
|
+
for (let n of e.toUpperCase()) t = t * 26 + n.charCodeAt(0) - 64;
|
|
2399
|
+
return t;
|
|
2400
|
+
}
|
|
2401
|
+
function _n(e) {
|
|
2402
|
+
let t = "";
|
|
2403
|
+
for (let n = e; n > 0; n = Math.floor((n - 1) / 26)) t = String.fromCharCode(65 + (n - 1) % 26) + t;
|
|
2404
|
+
return t;
|
|
2405
|
+
}
|
|
2406
|
+
function V(e) {
|
|
2407
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
2408
|
+
}
|
|
2409
|
+
var vn = {
|
|
2410
|
+
snapshot: {
|
|
2411
|
+
configSchema: {
|
|
2412
|
+
additionalProperties: !1,
|
|
2413
|
+
properties: {
|
|
2414
|
+
dataSourceId: {
|
|
2415
|
+
default: "",
|
|
2416
|
+
pattern: "^(?:|[0-9a-fA-F]{8}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{12})$",
|
|
2417
|
+
type: "string"
|
|
2418
|
+
},
|
|
2419
|
+
databaseId: {
|
|
2420
|
+
pattern: "^[0-9a-fA-F]{8}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{12}$",
|
|
2421
|
+
type: "string"
|
|
2422
|
+
},
|
|
2423
|
+
events: {
|
|
2424
|
+
default: ["page_added"],
|
|
2425
|
+
items: {
|
|
2426
|
+
enum: ["page_added", "page_updated"],
|
|
2427
|
+
type: "string"
|
|
2428
|
+
},
|
|
2429
|
+
minItems: 1,
|
|
2430
|
+
type: "array",
|
|
2431
|
+
uniqueItems: !0
|
|
2432
|
+
},
|
|
2433
|
+
includeProperties: {
|
|
2434
|
+
default: !0,
|
|
2435
|
+
type: "boolean"
|
|
2436
|
+
},
|
|
2437
|
+
maxItemsPerPoll: {
|
|
2438
|
+
default: 25,
|
|
2439
|
+
maximum: 100,
|
|
2440
|
+
minimum: 1,
|
|
2441
|
+
type: "integer"
|
|
2442
|
+
}
|
|
2443
|
+
},
|
|
2444
|
+
required: ["databaseId"],
|
|
2445
|
+
title: "Notion Database Page Event Config",
|
|
2446
|
+
type: "object"
|
|
2447
|
+
},
|
|
2448
|
+
definitionVersion: 1,
|
|
2449
|
+
description: "Polls a Notion database and triggers when a page is added to it or an existing page is edited.",
|
|
2450
|
+
displayName: "Notion: Database Page Added or Updated",
|
|
2451
|
+
key: "notion.on_database_page_event",
|
|
2452
|
+
name: "on_database_page_event",
|
|
2453
|
+
payloadSchema: {
|
|
2454
|
+
additionalProperties: !1,
|
|
2455
|
+
properties: { events: {
|
|
2456
|
+
items: {
|
|
2457
|
+
additionalProperties: !1,
|
|
2458
|
+
properties: {
|
|
2459
|
+
createdBy: { type: "object" },
|
|
2460
|
+
createdTime: { type: "string" },
|
|
2461
|
+
dataSourceId: { type: "string" },
|
|
2462
|
+
databaseId: { type: "string" },
|
|
2463
|
+
event: {
|
|
2464
|
+
enum: ["page_added", "page_updated"],
|
|
2465
|
+
type: "string"
|
|
2466
|
+
},
|
|
2467
|
+
lastEditedBy: { type: "object" },
|
|
2468
|
+
lastEditedTime: { type: "string" },
|
|
2469
|
+
pageId: { type: "string" },
|
|
2470
|
+
properties: { type: "object" },
|
|
2471
|
+
title: { type: "string" },
|
|
2472
|
+
url: { type: "string" }
|
|
2473
|
+
},
|
|
2474
|
+
required: [
|
|
2475
|
+
"event",
|
|
2476
|
+
"pageId",
|
|
2477
|
+
"databaseId",
|
|
2478
|
+
"dataSourceId",
|
|
2479
|
+
"url",
|
|
2480
|
+
"title",
|
|
2481
|
+
"createdTime",
|
|
2482
|
+
"lastEditedTime",
|
|
2483
|
+
"createdBy",
|
|
2484
|
+
"lastEditedBy"
|
|
2485
|
+
],
|
|
2486
|
+
type: "object"
|
|
2487
|
+
},
|
|
2488
|
+
type: "array"
|
|
2489
|
+
} },
|
|
2490
|
+
required: ["events"],
|
|
2491
|
+
title: "Notion Database Page Event Payload",
|
|
2492
|
+
type: "object"
|
|
2493
|
+
},
|
|
2494
|
+
provider: "notion",
|
|
2495
|
+
type: "poll"
|
|
2496
|
+
},
|
|
2497
|
+
async poll(e) {
|
|
2498
|
+
let t = yn(e.config);
|
|
2499
|
+
if (e.checkpoint === null) return bn(e, t);
|
|
2500
|
+
let n = Sn(e.checkpoint);
|
|
2501
|
+
return n.target === Pn(t) ? Tn(e, t, wn(n, Cn(t.events))) : bn(e, t);
|
|
2502
|
+
}
|
|
2503
|
+
};
|
|
2504
|
+
function yn(e) {
|
|
2505
|
+
return {
|
|
2506
|
+
dataSourceId: e.dataSourceId ?? "",
|
|
2507
|
+
databaseId: e.databaseId,
|
|
2508
|
+
events: [...new Set(e.events ?? ["page_added"])],
|
|
2509
|
+
includeProperties: e.includeProperties ?? !0,
|
|
2510
|
+
maxItemsPerPoll: e.maxItemsPerPoll ?? 25
|
|
2511
|
+
};
|
|
2512
|
+
}
|
|
2513
|
+
async function bn(e, t) {
|
|
2514
|
+
let n = await xn(e, t), r = Cn(t.events);
|
|
2515
|
+
return Nn(await Mn(e, {
|
|
2516
|
+
body: {
|
|
2517
|
+
page_size: 1,
|
|
2518
|
+
sorts: [{
|
|
2519
|
+
direction: "ascending",
|
|
2520
|
+
timestamp: r
|
|
2521
|
+
}]
|
|
2522
|
+
},
|
|
2523
|
+
endpoint: `/data_sources/${encodeURIComponent(n)}/query`,
|
|
2524
|
+
method: "POST"
|
|
2525
|
+
}), "seed probe query"), {
|
|
2526
|
+
checkpoint: {
|
|
2527
|
+
cursorField: r,
|
|
2528
|
+
dataSourceId: n,
|
|
2529
|
+
since: (/* @__PURE__ */ new Date(Math.ceil(e.now.getTime() / 6e4) * 6e4)).toISOString(),
|
|
2530
|
+
target: Pn(t)
|
|
2531
|
+
},
|
|
2532
|
+
events: []
|
|
2533
|
+
};
|
|
2534
|
+
}
|
|
2535
|
+
async function xn(e, n) {
|
|
2536
|
+
let r = await Mn(e, {
|
|
2537
|
+
endpoint: `/databases/${encodeURIComponent(n.databaseId)}`,
|
|
2538
|
+
method: "GET"
|
|
2539
|
+
});
|
|
2540
|
+
Nn(r, "database resolve");
|
|
2541
|
+
let i = H(r.data)?.data_sources, a = Array.isArray(i) ? i.flatMap((e) => {
|
|
2542
|
+
let t = H(e)?.id;
|
|
2543
|
+
return typeof t == "string" && t.length > 0 ? [t] : [];
|
|
2544
|
+
}) : [];
|
|
2545
|
+
if (n.dataSourceId.length > 0) {
|
|
2546
|
+
let e = Fn(n.dataSourceId), r = a.find((t) => Fn(t) == e);
|
|
2547
|
+
if (r == null) throw new t("The Notion data source does not belong to the configured database.");
|
|
2548
|
+
return r;
|
|
2549
|
+
}
|
|
2550
|
+
if (a.length == 1) return a[0];
|
|
2551
|
+
throw a.length == 0 ? new t("The Notion database has no data sources.") : new t("The Notion database has multiple data sources; configure dataSourceId.");
|
|
2552
|
+
}
|
|
2553
|
+
function Sn(e) {
|
|
2554
|
+
let n = H(e), r = n?.cursorField;
|
|
2555
|
+
if (typeof n?.dataSourceId != "string" || n.dataSourceId.length == 0 || r !== "created_time" && r !== "last_edited_time" || typeof n.since != "string" || n.since.length == 0) throw new t("Notion checkpoint is invalid; recreate the Trigger.");
|
|
2556
|
+
return {
|
|
2557
|
+
cursorField: r,
|
|
2558
|
+
dataSourceId: n.dataSourceId,
|
|
2559
|
+
since: n.since,
|
|
2560
|
+
target: typeof n.target == "string" ? n.target : "",
|
|
2561
|
+
...typeof n.startCursor == "string" && n.startCursor.length > 0 ? { startCursor: n.startCursor } : {},
|
|
2562
|
+
...n.sinceExclusive === !0 ? { sinceExclusive: !0 } : {},
|
|
2563
|
+
...n.sinceOnly === !0 ? { sinceOnly: !0 } : {}
|
|
2564
|
+
};
|
|
2565
|
+
}
|
|
2566
|
+
function Cn(e) {
|
|
2567
|
+
return e.length == 1 && e[0] == "page_added" ? "created_time" : "last_edited_time";
|
|
2568
|
+
}
|
|
2569
|
+
function wn(e, t) {
|
|
2570
|
+
return e.cursorField == t ? e : {
|
|
2571
|
+
cursorField: t,
|
|
2572
|
+
dataSourceId: e.dataSourceId,
|
|
2573
|
+
since: e.since,
|
|
2574
|
+
target: e.target
|
|
2575
|
+
};
|
|
2576
|
+
}
|
|
2577
|
+
async function Tn(e, t, n) {
|
|
2578
|
+
let r = [], i = 0, a = 0, o = null, s = n.startCursor, c = null;
|
|
2579
|
+
for (let l = 0; l < 5; l += 1) {
|
|
2580
|
+
let l = await Mn(e, {
|
|
2581
|
+
body: On(n, t.maxItemsPerPoll - a, s),
|
|
2582
|
+
endpoint: `/data_sources/${encodeURIComponent(n.dataSourceId)}/query`,
|
|
2583
|
+
method: "POST"
|
|
2584
|
+
});
|
|
2585
|
+
if (l.status == 400 && s != null) {
|
|
2586
|
+
c = "restarted";
|
|
2587
|
+
break;
|
|
2588
|
+
}
|
|
2589
|
+
Nn(l, "data source query");
|
|
2590
|
+
let u = H(l.data) ?? {};
|
|
2591
|
+
for (let e of u.results ?? []) {
|
|
2592
|
+
a += 1;
|
|
2593
|
+
let s = n.cursorField == "created_time" ? e.created_time : e.last_edited_time;
|
|
2594
|
+
s != null && s.length > 0 && (o = Ln(o, s));
|
|
2595
|
+
let c = kn(e);
|
|
2596
|
+
t.events.includes(c) ? r.push(An(e, c, t, n)) : i += 1;
|
|
2597
|
+
}
|
|
2598
|
+
if (u.request_status?.type == "incomplete") {
|
|
2599
|
+
c = "truncated";
|
|
2600
|
+
break;
|
|
2601
|
+
}
|
|
2602
|
+
if (u.has_more !== !0 || typeof u.next_cursor != "string" || u.next_cursor.length == 0) {
|
|
2603
|
+
c = "complete";
|
|
2604
|
+
break;
|
|
2605
|
+
}
|
|
2606
|
+
if (s = u.next_cursor, a >= t.maxItemsPerPoll) {
|
|
2607
|
+
c = { nextCursor: u.next_cursor };
|
|
2608
|
+
break;
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
c ??= { nextCursor: s };
|
|
2612
|
+
let l = {
|
|
2613
|
+
cursorField: n.cursorField,
|
|
2614
|
+
dataSourceId: n.dataSourceId,
|
|
2615
|
+
target: n.target
|
|
2616
|
+
};
|
|
2617
|
+
return {
|
|
2618
|
+
checkpoint: typeof c == "object" ? {
|
|
2619
|
+
...l,
|
|
2620
|
+
since: n.since,
|
|
2621
|
+
startCursor: c.nextCursor,
|
|
2622
|
+
...Dn(n)
|
|
2623
|
+
} : {
|
|
2624
|
+
...l,
|
|
2625
|
+
...En(n, c, o, e.now)
|
|
2626
|
+
},
|
|
2627
|
+
events: r,
|
|
2628
|
+
filtered: i,
|
|
2629
|
+
...c == "complete" ? {} : { hasMore: !0 }
|
|
2630
|
+
};
|
|
2631
|
+
}
|
|
2632
|
+
function En(e, t, n, r) {
|
|
2633
|
+
let i = {
|
|
2634
|
+
since: e.since,
|
|
2635
|
+
...Dn(e)
|
|
2636
|
+
}, a = Date.parse(e.since) + 6e4 <= r.getTime() ? {
|
|
2637
|
+
since: e.since,
|
|
2638
|
+
sinceExclusive: !0
|
|
2639
|
+
} : i;
|
|
2640
|
+
return n != null && Rn(n, e.since) ? { since: n } : t == "restarted" ? i : t == "complete" ? e.sinceOnly === !0 || n != null ? a : i : n == null ? i : e.sinceOnly === !0 ? a : {
|
|
2641
|
+
since: e.since,
|
|
2642
|
+
sinceOnly: !0
|
|
2643
|
+
};
|
|
2644
|
+
}
|
|
2645
|
+
function Dn(e) {
|
|
2646
|
+
return {
|
|
2647
|
+
...e.sinceExclusive === !0 ? { sinceExclusive: !0 } : {},
|
|
2648
|
+
...e.sinceOnly === !0 ? { sinceOnly: !0 } : {}
|
|
2649
|
+
};
|
|
2650
|
+
}
|
|
2651
|
+
function On(e, t, n) {
|
|
2652
|
+
let r = e.cursorField;
|
|
2653
|
+
return {
|
|
2654
|
+
filter: e.sinceOnly === !0 ? { and: [{
|
|
2655
|
+
[r]: { on_or_after: e.since },
|
|
2656
|
+
timestamp: r
|
|
2657
|
+
}, {
|
|
2658
|
+
[r]: { on_or_before: e.since },
|
|
2659
|
+
timestamp: r
|
|
2660
|
+
}] } : {
|
|
2661
|
+
[r]: { [e.sinceExclusive === !0 ? "after" : "on_or_after"]: e.since },
|
|
2662
|
+
timestamp: r
|
|
2663
|
+
},
|
|
2664
|
+
page_size: Math.min(100, t),
|
|
2665
|
+
sorts: [{
|
|
2666
|
+
direction: "ascending",
|
|
2667
|
+
timestamp: r
|
|
2668
|
+
}],
|
|
2669
|
+
...n == null ? {} : { start_cursor: n }
|
|
2670
|
+
};
|
|
2671
|
+
}
|
|
2672
|
+
function kn(e) {
|
|
2673
|
+
return zn(e.created_time) === zn(e.last_edited_time) ? "page_added" : "page_updated";
|
|
2674
|
+
}
|
|
2675
|
+
function An(e, t, n, r) {
|
|
2676
|
+
return {
|
|
2677
|
+
dedupeKey: t == "page_added" ? `added:${e.id}` : `updated:${e.id}:${zn(e.last_edited_time) ?? e.last_edited_time ?? ""}`,
|
|
2678
|
+
payload: {
|
|
2679
|
+
createdBy: { id: e.created_by?.id ?? "" },
|
|
2680
|
+
createdTime: e.created_time ?? "",
|
|
2681
|
+
dataSourceId: r.dataSourceId,
|
|
2682
|
+
databaseId: In(n.databaseId),
|
|
2683
|
+
event: t,
|
|
2684
|
+
lastEditedBy: { id: e.last_edited_by?.id ?? "" },
|
|
2685
|
+
lastEditedTime: e.last_edited_time ?? "",
|
|
2686
|
+
pageId: e.id,
|
|
2687
|
+
...n.includeProperties ? { properties: e.properties ?? {} } : {},
|
|
2688
|
+
title: jn(e.properties ?? {}),
|
|
2689
|
+
url: e.url ?? ""
|
|
2690
|
+
}
|
|
2691
|
+
};
|
|
2692
|
+
}
|
|
2693
|
+
function jn(e) {
|
|
2694
|
+
for (let t of Object.values(e)) {
|
|
2695
|
+
let e = H(t);
|
|
2696
|
+
if (!(e?.type !== "title" || !Array.isArray(e.title))) return e.title.map((e) => typeof H(e)?.plain_text == "string" ? H(e).plain_text : "").join("");
|
|
2697
|
+
}
|
|
2698
|
+
return "";
|
|
2699
|
+
}
|
|
2700
|
+
async function Mn(e, t) {
|
|
2701
|
+
try {
|
|
2702
|
+
return await e.connector.execute(t, e.signal);
|
|
2703
|
+
} catch (e) {
|
|
2704
|
+
throw new n(`Notion proxy request to ${t.endpoint} failed.`, { cause: e });
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
function Nn(r, i) {
|
|
2708
|
+
if (!(r.status >= 200 && r.status < 300)) throw r.status == 401 || r.status == 403 ? new e(`Notion ${i} rejected the Connection.`) : r.status == 404 ? new t("The Notion target was not found or is not shared with the Connection.") : r.status == 400 ? new t(`Notion ${i} rejected the configuration.`) : new n(`Notion ${i} failed with status ${r.status}.`);
|
|
2709
|
+
}
|
|
2710
|
+
function Pn(e) {
|
|
2711
|
+
return `${e.databaseId}|${e.dataSourceId}`;
|
|
2712
|
+
}
|
|
2713
|
+
function Fn(e) {
|
|
2714
|
+
return e.replaceAll("-", "").toLowerCase();
|
|
2715
|
+
}
|
|
2716
|
+
function In(e) {
|
|
2717
|
+
let t = Fn(e);
|
|
2718
|
+
return `${t.slice(0, 8)}-${t.slice(8, 12)}-${t.slice(12, 16)}-${t.slice(16, 20)}-${t.slice(20)}`;
|
|
2719
|
+
}
|
|
2720
|
+
function Ln(e, t) {
|
|
2721
|
+
let n = Date.parse(t);
|
|
2722
|
+
return Number.isNaN(n) || e != null && n < Date.parse(e) ? e : t;
|
|
2723
|
+
}
|
|
2724
|
+
function Rn(e, t) {
|
|
2725
|
+
return !Number.isNaN(Date.parse(e)) && !Number.isNaN(Date.parse(t)) && Date.parse(e) > Date.parse(t);
|
|
2726
|
+
}
|
|
2727
|
+
function zn(e) {
|
|
2728
|
+
if (e == null || e.length == 0) return null;
|
|
2729
|
+
let t = Date.parse(e);
|
|
2730
|
+
return Number.isNaN(t) ? null : new Date(t).toISOString();
|
|
2731
|
+
}
|
|
2732
|
+
function H(e) {
|
|
2733
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
2734
|
+
}
|
|
2735
|
+
var Bn = {
|
|
2736
|
+
snapshot: {
|
|
2737
|
+
configSchema: {
|
|
2738
|
+
additionalProperties: !1,
|
|
2739
|
+
properties: {
|
|
2740
|
+
events: {
|
|
2741
|
+
default: ["created", "updated"],
|
|
2742
|
+
items: {
|
|
2743
|
+
enum: [
|
|
2744
|
+
"created",
|
|
2745
|
+
"updated",
|
|
2746
|
+
"deleted"
|
|
2747
|
+
],
|
|
2748
|
+
type: "string"
|
|
2749
|
+
},
|
|
2750
|
+
minItems: 1,
|
|
2751
|
+
type: "array",
|
|
2752
|
+
uniqueItems: !0
|
|
2753
|
+
},
|
|
2754
|
+
itemId: {
|
|
2755
|
+
default: "",
|
|
2756
|
+
type: "string"
|
|
2757
|
+
},
|
|
2758
|
+
itemTypes: {
|
|
2759
|
+
default: ["file"],
|
|
2760
|
+
items: {
|
|
2761
|
+
enum: ["file", "folder"],
|
|
2762
|
+
type: "string"
|
|
2763
|
+
},
|
|
2764
|
+
minItems: 1,
|
|
2765
|
+
type: "array",
|
|
2766
|
+
uniqueItems: !0
|
|
2767
|
+
},
|
|
2768
|
+
maxItemsPerPoll: {
|
|
2769
|
+
default: 50,
|
|
2770
|
+
maximum: 200,
|
|
2771
|
+
minimum: 1,
|
|
2772
|
+
type: "integer"
|
|
2773
|
+
},
|
|
2774
|
+
parentFolderId: {
|
|
2775
|
+
default: "",
|
|
2776
|
+
type: "string"
|
|
2777
|
+
}
|
|
2778
|
+
},
|
|
2779
|
+
title: "OneDrive Item Change Config",
|
|
2780
|
+
type: "object"
|
|
2781
|
+
},
|
|
2782
|
+
definitionVersion: 1,
|
|
2783
|
+
description: "Polls the OneDrive change feed and triggers when a file or folder is created, updated or deleted.",
|
|
2784
|
+
displayName: "OneDrive: File or Folder Changed",
|
|
2785
|
+
key: "one_drive.on_item_changed",
|
|
2786
|
+
name: "on_item_changed",
|
|
2787
|
+
payloadSchema: {
|
|
2788
|
+
additionalProperties: !1,
|
|
2789
|
+
properties: { events: {
|
|
2790
|
+
items: {
|
|
2791
|
+
additionalProperties: !1,
|
|
2792
|
+
properties: {
|
|
2793
|
+
changeType: {
|
|
2794
|
+
enum: [
|
|
2795
|
+
"created",
|
|
2796
|
+
"updated",
|
|
2797
|
+
"deleted"
|
|
2798
|
+
],
|
|
2799
|
+
type: "string"
|
|
2800
|
+
},
|
|
2801
|
+
createdDateTime: { type: ["string", "null"] },
|
|
2802
|
+
driveId: { type: ["string", "null"] },
|
|
2803
|
+
eTag: { type: ["string", "null"] },
|
|
2804
|
+
itemId: { type: "string" },
|
|
2805
|
+
itemType: {
|
|
2806
|
+
enum: ["file", "folder"],
|
|
2807
|
+
type: "string"
|
|
2808
|
+
},
|
|
2809
|
+
lastModifiedDateTime: { type: ["string", "null"] },
|
|
2810
|
+
mimeType: { type: ["string", "null"] },
|
|
2811
|
+
name: { type: "string" },
|
|
2812
|
+
parentFolderId: { type: ["string", "null"] },
|
|
2813
|
+
size: { type: ["number", "null"] },
|
|
2814
|
+
webUrl: { type: "string" }
|
|
2815
|
+
},
|
|
2816
|
+
required: [
|
|
2817
|
+
"itemId",
|
|
2818
|
+
"name",
|
|
2819
|
+
"changeType",
|
|
2820
|
+
"itemType",
|
|
2821
|
+
"size",
|
|
2822
|
+
"mimeType",
|
|
2823
|
+
"webUrl",
|
|
2824
|
+
"parentFolderId",
|
|
2825
|
+
"driveId",
|
|
2826
|
+
"createdDateTime",
|
|
2827
|
+
"lastModifiedDateTime",
|
|
2828
|
+
"eTag"
|
|
2829
|
+
],
|
|
2830
|
+
type: "object"
|
|
2831
|
+
},
|
|
2832
|
+
type: "array"
|
|
2833
|
+
} },
|
|
2834
|
+
required: ["events"],
|
|
2835
|
+
title: "OneDrive Item Change Payload",
|
|
2836
|
+
type: "object"
|
|
2837
|
+
},
|
|
2838
|
+
provider: "one_drive",
|
|
2839
|
+
type: "poll"
|
|
2840
|
+
},
|
|
2841
|
+
async poll(e) {
|
|
2842
|
+
let t = Vn(e.config);
|
|
2843
|
+
if (e.checkpoint === null) return {
|
|
2844
|
+
checkpoint: await Hn(e, t),
|
|
2845
|
+
events: []
|
|
2846
|
+
};
|
|
2847
|
+
let n = Wn(e.checkpoint), { items: r, next: i } = await Gn(e, n, t.maxItemsPerPoll), a = [], o = 0;
|
|
2848
|
+
for (let [e, i] of r) {
|
|
2849
|
+
let r = Kn(e, i, t, new Date(n.lastPolledAt));
|
|
2850
|
+
r != "structural" && (r == "filtered" ? o += 1 : a.push(r));
|
|
2851
|
+
}
|
|
2852
|
+
return {
|
|
2853
|
+
checkpoint: i.checkpoint,
|
|
2854
|
+
events: a,
|
|
2855
|
+
filtered: o,
|
|
2856
|
+
...i.hasMore ? { hasMore: !0 } : {}
|
|
2857
|
+
};
|
|
2858
|
+
}
|
|
2859
|
+
};
|
|
2860
|
+
function Vn(e) {
|
|
2861
|
+
return {
|
|
2862
|
+
events: e.events ?? ["created", "updated"],
|
|
2863
|
+
itemId: (e.itemId ?? "").trim(),
|
|
2864
|
+
itemTypes: e.itemTypes ?? ["file"],
|
|
2865
|
+
maxItemsPerPoll: e.maxItemsPerPoll ?? 50,
|
|
2866
|
+
parentFolderId: (e.parentFolderId ?? "").trim()
|
|
2867
|
+
};
|
|
2868
|
+
}
|
|
2869
|
+
async function Hn(e, r) {
|
|
2870
|
+
let i = await Yn(e, "/me/drive/root/delta", { token: "latest" });
|
|
2871
|
+
if (i.status == 404) throw new t("OneDrive is not provisioned for this account.");
|
|
2872
|
+
Zn(i, "delta seeding");
|
|
2873
|
+
let a = U(i.data)?.["@odata.deltaLink"], o = a == null ? null : er(a);
|
|
2874
|
+
if (o == null) throw new n("OneDrive delta seeding response has no delta token.");
|
|
2875
|
+
return await Un(e, "parentFolderId", r.parentFolderId), await Un(e, "itemId", r.itemId), {
|
|
2876
|
+
deltaToken: o,
|
|
2877
|
+
lastPolledAt: e.now.toISOString()
|
|
2878
|
+
};
|
|
2879
|
+
}
|
|
2880
|
+
async function Un(e, n, r) {
|
|
2881
|
+
if (r.length == 0) return;
|
|
2882
|
+
let i = await Yn(e, `/me/drive/items/${encodeURIComponent(r)}`, {});
|
|
2883
|
+
if (i.status == 400 || i.status == 404) throw new t(`OneDrive ${n} does not identify an item in this drive.`);
|
|
2884
|
+
Zn(i, `${n} validation`);
|
|
2885
|
+
}
|
|
2886
|
+
function Wn(e) {
|
|
2887
|
+
let n = U(e);
|
|
2888
|
+
if (typeof n?.deltaToken != "string" || n.deltaToken.length == 0 || typeof n.lastPolledAt != "string" || Number.isNaN(Date.parse(n.lastPolledAt))) throw new t("OneDrive checkpoint is invalid; recreate the Trigger.");
|
|
2889
|
+
return {
|
|
2890
|
+
deltaToken: n.deltaToken,
|
|
2891
|
+
lastPolledAt: n.lastPolledAt,
|
|
2892
|
+
...typeof n.pageToken == "string" && n.pageToken.length > 0 ? { pageToken: n.pageToken } : {}
|
|
2893
|
+
};
|
|
2894
|
+
}
|
|
2895
|
+
async function Gn(e, t, r) {
|
|
2896
|
+
let i = /* @__PURE__ */ new Map(), a = t.pageToken ?? t.deltaToken;
|
|
2897
|
+
for (let t = 0; t < 5; t += 1) {
|
|
2898
|
+
let t = await Yn(e, "/me/drive/root/delta", {
|
|
2899
|
+
$top: r,
|
|
2900
|
+
token: a
|
|
2901
|
+
});
|
|
2902
|
+
Xn(t);
|
|
2903
|
+
let o = U(t.data) ?? {};
|
|
2904
|
+
for (let e of o.value ?? []) e.id != null && e.id.length > 0 && i.set(e.id, e);
|
|
2905
|
+
if (o["@odata.deltaLink"]) return {
|
|
2906
|
+
items: i,
|
|
2907
|
+
next: {
|
|
2908
|
+
checkpoint: {
|
|
2909
|
+
deltaToken: $n(o["@odata.deltaLink"]),
|
|
2910
|
+
lastPolledAt: e.now.toISOString()
|
|
2911
|
+
},
|
|
2912
|
+
hasMore: !1
|
|
2913
|
+
}
|
|
2914
|
+
};
|
|
2915
|
+
if (!o["@odata.nextLink"]) throw new n("OneDrive delta response has no continuation link.");
|
|
2916
|
+
a = $n(o["@odata.nextLink"]);
|
|
2917
|
+
}
|
|
2918
|
+
return {
|
|
2919
|
+
items: i,
|
|
2920
|
+
next: {
|
|
2921
|
+
checkpoint: {
|
|
2922
|
+
deltaToken: t.deltaToken,
|
|
2923
|
+
lastPolledAt: t.lastPolledAt,
|
|
2924
|
+
pageToken: a
|
|
2925
|
+
},
|
|
2926
|
+
hasMore: !0
|
|
2927
|
+
}
|
|
2928
|
+
};
|
|
2929
|
+
}
|
|
2930
|
+
function Kn(e, t, n, r) {
|
|
2931
|
+
if (t.root != null) return "structural";
|
|
2932
|
+
let i = qn(t);
|
|
2933
|
+
if (i == null) return "structural";
|
|
2934
|
+
let a = t.deleted == null ? tr(t.createdDateTime, r) ? "created" : "updated" : "deleted";
|
|
2935
|
+
return !n.events.includes(a) || !n.itemTypes.includes(i) || n.parentFolderId.length > 0 && t.parentReference?.id !== n.parentFolderId || n.itemId.length > 0 && e !== n.itemId ? "filtered" : Jn(e, t, a, i);
|
|
2936
|
+
}
|
|
2937
|
+
function qn(e) {
|
|
2938
|
+
return e.file == null ? e.folder == null ? e.deleted == null ? null : "file" : "folder" : "file";
|
|
2939
|
+
}
|
|
2940
|
+
function Jn(e, t, n, r) {
|
|
2941
|
+
return {
|
|
2942
|
+
dedupeKey: t.deleted == null ? `${e}:${t.eTag ?? t.lastModifiedDateTime}` : `${e}:deleted`,
|
|
2943
|
+
payload: {
|
|
2944
|
+
changeType: n,
|
|
2945
|
+
createdDateTime: t.createdDateTime ?? t.fileSystemInfo?.createdDateTime ?? null,
|
|
2946
|
+
driveId: t.parentReference?.driveId ?? null,
|
|
2947
|
+
eTag: t.eTag ?? null,
|
|
2948
|
+
itemId: e,
|
|
2949
|
+
itemType: r,
|
|
2950
|
+
lastModifiedDateTime: t.lastModifiedDateTime ?? t.fileSystemInfo?.lastModifiedDateTime ?? null,
|
|
2951
|
+
mimeType: t.file?.mimeType ?? null,
|
|
2952
|
+
name: t.name ?? "",
|
|
2953
|
+
parentFolderId: t.parentReference?.id ?? null,
|
|
2954
|
+
size: t.size ?? null,
|
|
2955
|
+
webUrl: t.webUrl ?? ""
|
|
2956
|
+
}
|
|
2957
|
+
};
|
|
2958
|
+
}
|
|
2959
|
+
async function Yn(e, t, r) {
|
|
2960
|
+
try {
|
|
2961
|
+
return await e.connector.execute({
|
|
2962
|
+
endpoint: t,
|
|
2963
|
+
method: "GET",
|
|
2964
|
+
query: r
|
|
2965
|
+
}, e.signal);
|
|
2966
|
+
} catch (e) {
|
|
2967
|
+
throw new n(`OneDrive proxy request to ${t} failed.`, { cause: e });
|
|
2968
|
+
}
|
|
2969
|
+
}
|
|
2970
|
+
function Xn(e) {
|
|
2971
|
+
if (e.status == 410 && Qn(e.data)) throw new t("OneDrive delta token expired; recreate the Trigger.");
|
|
2972
|
+
if (e.status == 404) throw new t("OneDrive is not provisioned for this account.");
|
|
2973
|
+
if (e.status == 400) throw new t("OneDrive rejected the delta token; recreate the Trigger.");
|
|
2974
|
+
Zn(e, "delta list");
|
|
2975
|
+
}
|
|
2976
|
+
function Zn(t, r) {
|
|
2977
|
+
if (!(t.status >= 200 && t.status < 300)) throw t.status == 401 || t.status == 403 ? new e(`OneDrive ${r} rejected the Connection.`) : new n(`OneDrive ${r} failed with status ${t.status}.`);
|
|
2978
|
+
}
|
|
2979
|
+
function Qn(e) {
|
|
2980
|
+
let t = U(e)?.error;
|
|
2981
|
+
for (; t != null;) {
|
|
2982
|
+
let e = U(t);
|
|
2983
|
+
if (e == null) break;
|
|
2984
|
+
if (e.code == "resyncChangesApplyDifferences" || e.code == "resyncChangesUploadDifferences") return !0;
|
|
2985
|
+
t = e.innerError ?? e.innererror;
|
|
2986
|
+
}
|
|
2987
|
+
return !1;
|
|
2988
|
+
}
|
|
2989
|
+
function $n(e) {
|
|
2990
|
+
let t = er(e);
|
|
2991
|
+
if (t == null) throw new n("OneDrive delta link has no token.");
|
|
2992
|
+
return t;
|
|
2993
|
+
}
|
|
2994
|
+
function er(e) {
|
|
2995
|
+
let t = /[?&]token=([^&#]+)/.exec(e)?.[1] ?? /\(token='([^']+)'\)/.exec(e)?.[1];
|
|
2996
|
+
if (t == null) return null;
|
|
2997
|
+
try {
|
|
2998
|
+
return decodeURIComponent(t);
|
|
2999
|
+
} catch {
|
|
3000
|
+
return t;
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
function tr(e, t) {
|
|
3004
|
+
if (e == null || e.length == 0) return !1;
|
|
3005
|
+
let n = new Date(e);
|
|
3006
|
+
return !Number.isNaN(n.getTime()) && n >= t;
|
|
3007
|
+
}
|
|
3008
|
+
function U(e) {
|
|
3009
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
3010
|
+
}
|
|
3011
|
+
//#endregion
|
|
3012
|
+
//#region src/trigger/providers/outlook/on-message-received.ts
|
|
3013
|
+
var nr = "inbox", rr = 25, ir = 100, ar = "1970-01-01T00:00:00Z", or = "id,internetMessageId,conversationId,subject,bodyPreview,from,toRecipients,receivedDateTime,hasAttachments,isRead,isDraft,importance,categories,parentFolderId,webLink", sr = {
|
|
3014
|
+
snapshot: {
|
|
3015
|
+
configSchema: {
|
|
3016
|
+
additionalProperties: !1,
|
|
3017
|
+
description: "Configuration for outlook.on_message_received. Every configured matching field must match.",
|
|
3018
|
+
properties: {
|
|
3019
|
+
folder: {
|
|
3020
|
+
default: nr,
|
|
3021
|
+
description: "A well-known mail folder name, folder ID, or an empty string for the whole mailbox.",
|
|
3022
|
+
pattern: "^[A-Za-z0-9_=-]*$",
|
|
3023
|
+
type: "string"
|
|
3024
|
+
},
|
|
3025
|
+
includeDrafts: {
|
|
3026
|
+
default: !1,
|
|
3027
|
+
type: "boolean"
|
|
3028
|
+
},
|
|
3029
|
+
maxMessagesPerPoll: {
|
|
3030
|
+
default: rr,
|
|
3031
|
+
maximum: 100,
|
|
3032
|
+
minimum: 1,
|
|
3033
|
+
type: "integer"
|
|
3034
|
+
},
|
|
3035
|
+
readStatus: {
|
|
3036
|
+
default: "All",
|
|
3037
|
+
enum: [
|
|
3038
|
+
"All",
|
|
3039
|
+
"Read",
|
|
3040
|
+
"Unread"
|
|
3041
|
+
],
|
|
3042
|
+
type: "string"
|
|
3043
|
+
},
|
|
3044
|
+
senderAddress: {
|
|
3045
|
+
default: "",
|
|
3046
|
+
description: "Exact sender address, or empty for any sender.",
|
|
3047
|
+
type: "string"
|
|
3048
|
+
},
|
|
3049
|
+
subjectContains: {
|
|
3050
|
+
default: "",
|
|
3051
|
+
description: "Case-insensitive subject text.",
|
|
3052
|
+
type: "string"
|
|
3053
|
+
},
|
|
3054
|
+
withAttachmentsOnly: {
|
|
3055
|
+
default: !1,
|
|
3056
|
+
type: "boolean"
|
|
3057
|
+
}
|
|
3058
|
+
},
|
|
3059
|
+
title: "Outlook New Message Config",
|
|
3060
|
+
type: "object"
|
|
3061
|
+
},
|
|
3062
|
+
definitionVersion: 1,
|
|
3063
|
+
description: "Polls a Microsoft Outlook mail folder and triggers when a new message arrives.",
|
|
3064
|
+
displayName: "Outlook: New Message Received",
|
|
3065
|
+
key: "outlook.on_message_received",
|
|
3066
|
+
name: "on_message_received",
|
|
3067
|
+
payloadSchema: {
|
|
3068
|
+
additionalProperties: !1,
|
|
3069
|
+
properties: { events: {
|
|
3070
|
+
items: {
|
|
3071
|
+
additionalProperties: !1,
|
|
3072
|
+
properties: {
|
|
3073
|
+
bodyPreview: { type: "string" },
|
|
3074
|
+
categories: {
|
|
3075
|
+
items: { type: "string" },
|
|
3076
|
+
type: "array"
|
|
3077
|
+
},
|
|
3078
|
+
conversationId: { type: "string" },
|
|
3079
|
+
from: { type: "string" },
|
|
3080
|
+
fromName: { type: "string" },
|
|
3081
|
+
hasAttachments: { type: "boolean" },
|
|
3082
|
+
importance: { type: "string" },
|
|
3083
|
+
internetMessageId: { type: "string" },
|
|
3084
|
+
isDraft: { type: "boolean" },
|
|
3085
|
+
isRead: { type: "boolean" },
|
|
3086
|
+
messageId: { type: "string" },
|
|
3087
|
+
parentFolderId: { type: "string" },
|
|
3088
|
+
receivedDateTime: { type: "string" },
|
|
3089
|
+
subject: { type: "string" },
|
|
3090
|
+
to: {
|
|
3091
|
+
items: { type: "string" },
|
|
3092
|
+
type: "array"
|
|
3093
|
+
},
|
|
3094
|
+
webLink: { type: "string" }
|
|
3095
|
+
},
|
|
3096
|
+
required: [
|
|
3097
|
+
"messageId",
|
|
3098
|
+
"internetMessageId",
|
|
3099
|
+
"conversationId",
|
|
3100
|
+
"subject",
|
|
3101
|
+
"bodyPreview",
|
|
3102
|
+
"from",
|
|
3103
|
+
"fromName",
|
|
3104
|
+
"to",
|
|
3105
|
+
"receivedDateTime",
|
|
3106
|
+
"hasAttachments",
|
|
3107
|
+
"isRead",
|
|
3108
|
+
"isDraft",
|
|
3109
|
+
"importance",
|
|
3110
|
+
"categories",
|
|
3111
|
+
"parentFolderId",
|
|
3112
|
+
"webLink"
|
|
3113
|
+
],
|
|
3114
|
+
type: "object"
|
|
3115
|
+
},
|
|
3116
|
+
type: "array"
|
|
3117
|
+
} },
|
|
3118
|
+
required: ["events"],
|
|
3119
|
+
title: "Outlook New Message Payload",
|
|
3120
|
+
type: "object"
|
|
3121
|
+
},
|
|
3122
|
+
provider: "outlook",
|
|
3123
|
+
type: "poll"
|
|
3124
|
+
},
|
|
3125
|
+
async poll(e) {
|
|
3126
|
+
let n = cr(e.config);
|
|
3127
|
+
if (e.checkpoint === null) return {
|
|
3128
|
+
checkpoint: await lr(e, n),
|
|
3129
|
+
events: []
|
|
3130
|
+
};
|
|
3131
|
+
let r = ur(e.checkpoint), i = await hr(e, dr(n.folder), {
|
|
3132
|
+
$filter: fr(n, r.lastReceivedDateTime),
|
|
3133
|
+
$orderby: "receivedDateTime asc",
|
|
3134
|
+
$select: or,
|
|
3135
|
+
$top: n.maxMessagesPerPoll
|
|
3136
|
+
});
|
|
3137
|
+
gr(i, "message list");
|
|
3138
|
+
let a = vr(i.data);
|
|
3139
|
+
if (a.length == 0) return {
|
|
3140
|
+
checkpoint: r,
|
|
3141
|
+
events: []
|
|
3142
|
+
};
|
|
3143
|
+
let o = Date.parse(r.lastReceivedDateTime), s = o, c = r.lastReceivedDateTime;
|
|
3144
|
+
for (let e of a) {
|
|
3145
|
+
let t = W(e.receivedDateTime);
|
|
3146
|
+
e.receivedDateTime != null && t != null && t > s && (s = t, c = e.receivedDateTime);
|
|
3147
|
+
}
|
|
3148
|
+
let l = s > o, u = new Set(r.boundaryMessageIds), d = a.length >= n.maxMessagesPerPoll;
|
|
3149
|
+
if (d && !l && a.every((e) => typeof e.id == "string" && u.has(e.id))) throw new t("Outlook cursor is stuck on a full timestamp boundary; increase maxMessagesPerPoll and resume the Trigger.");
|
|
3150
|
+
let f = new Set(l ? [] : r.boundaryMessageIds), p = [], m = 0;
|
|
3151
|
+
for (let e of a) if (e.id != null && e.id.length != 0 && (W(e.receivedDateTime) == s && f.add(e.id), !u.has(e.id))) {
|
|
3152
|
+
if (!pr(e, n)) {
|
|
3153
|
+
m += 1;
|
|
3154
|
+
continue;
|
|
3155
|
+
}
|
|
3156
|
+
p.push(mr(e, e.id));
|
|
3157
|
+
}
|
|
3158
|
+
let h = d && (l || p.length > 0);
|
|
3159
|
+
return {
|
|
3160
|
+
checkpoint: {
|
|
3161
|
+
boundaryMessageIds: [...f],
|
|
3162
|
+
lastReceivedDateTime: c
|
|
3163
|
+
},
|
|
3164
|
+
events: p,
|
|
3165
|
+
filtered: m,
|
|
3166
|
+
...h ? { hasMore: !0 } : {}
|
|
3167
|
+
};
|
|
3168
|
+
}
|
|
3169
|
+
};
|
|
3170
|
+
function cr(e) {
|
|
3171
|
+
return {
|
|
3172
|
+
folder: e.folder ?? nr,
|
|
3173
|
+
includeDrafts: e.includeDrafts ?? !1,
|
|
3174
|
+
maxMessagesPerPoll: e.maxMessagesPerPoll ?? rr,
|
|
3175
|
+
readStatus: e.readStatus ?? "All",
|
|
3176
|
+
senderAddress: (e.senderAddress ?? "").trim(),
|
|
3177
|
+
subjectContains: (e.subjectContains ?? "").trim(),
|
|
3178
|
+
withAttachmentsOnly: e.withAttachmentsOnly ?? !1
|
|
3179
|
+
};
|
|
3180
|
+
}
|
|
3181
|
+
async function lr(e, t) {
|
|
3182
|
+
let n = await hr(e, dr(t.folder), {
|
|
3183
|
+
$orderby: "receivedDateTime desc",
|
|
3184
|
+
$select: "id,receivedDateTime",
|
|
3185
|
+
$top: ir
|
|
3186
|
+
});
|
|
3187
|
+
gr(n, "seed marker fetch"), gr(await hr(e, dr(t.folder), {
|
|
3188
|
+
$filter: fr(t, ar),
|
|
3189
|
+
$orderby: "receivedDateTime desc",
|
|
3190
|
+
$top: 1
|
|
3191
|
+
}), "seed filter shape check");
|
|
3192
|
+
let r = yr(vr(n.data));
|
|
3193
|
+
if (r == null) return {
|
|
3194
|
+
boundaryMessageIds: [],
|
|
3195
|
+
lastReceivedDateTime: e.now.toISOString()
|
|
3196
|
+
};
|
|
3197
|
+
let i = vr(n.data).filter((e) => W(e.receivedDateTime) == r.ms);
|
|
3198
|
+
return i.length >= t.maxMessagesPerPoll ? {
|
|
3199
|
+
boundaryMessageIds: [],
|
|
3200
|
+
lastReceivedDateTime: new Date(r.ms + 1e3).toISOString()
|
|
3201
|
+
} : {
|
|
3202
|
+
boundaryMessageIds: i.flatMap((e) => e.id == null || e.id.length == 0 ? [] : [e.id]),
|
|
3203
|
+
lastReceivedDateTime: r.iso
|
|
3204
|
+
};
|
|
3205
|
+
}
|
|
3206
|
+
function ur(e) {
|
|
3207
|
+
let n = G(e), r = n?.lastReceivedDateTime;
|
|
3208
|
+
if (typeof r != "string" || W(r) == null) throw new t("Outlook checkpoint is invalid; recreate the Trigger.");
|
|
3209
|
+
let i = n?.boundaryMessageIds;
|
|
3210
|
+
return {
|
|
3211
|
+
boundaryMessageIds: Array.isArray(i) ? i.filter((e) => typeof e == "string" && e.length > 0) : [],
|
|
3212
|
+
lastReceivedDateTime: r
|
|
3213
|
+
};
|
|
3214
|
+
}
|
|
3215
|
+
function dr(e) {
|
|
3216
|
+
return e.length == 0 ? "/me/messages" : `/me/mailFolders/${encodeURIComponent(e)}/messages`;
|
|
3217
|
+
}
|
|
3218
|
+
function fr(e, t) {
|
|
3219
|
+
let n = [`receivedDateTime ge ${t}`];
|
|
3220
|
+
return e.readStatus == "Unread" && n.push("isRead eq false"), e.readStatus == "Read" && n.push("isRead eq true"), e.withAttachmentsOnly && n.push("hasAttachments eq true"), e.senderAddress.length > 0 && n.push(`from/emailAddress/address eq '${e.senderAddress.replaceAll("'", "''")}'`), n.join(" and ");
|
|
3221
|
+
}
|
|
3222
|
+
function pr(e, t) {
|
|
3223
|
+
return e.isDraft === !0 && !t.includeDrafts ? !1 : t.subjectContains.length == 0 || (e.subject ?? "").toLowerCase().includes(t.subjectContains.toLowerCase());
|
|
3224
|
+
}
|
|
3225
|
+
function mr(e, t) {
|
|
3226
|
+
return {
|
|
3227
|
+
dedupeKey: t,
|
|
3228
|
+
payload: {
|
|
3229
|
+
bodyPreview: e.bodyPreview ?? "",
|
|
3230
|
+
categories: e.categories ?? [],
|
|
3231
|
+
conversationId: e.conversationId ?? "",
|
|
3232
|
+
from: e.from?.emailAddress?.address ?? "",
|
|
3233
|
+
fromName: e.from?.emailAddress?.name ?? "",
|
|
3234
|
+
hasAttachments: e.hasAttachments ?? !1,
|
|
3235
|
+
importance: e.importance ?? "",
|
|
3236
|
+
internetMessageId: e.internetMessageId ?? "",
|
|
3237
|
+
isDraft: e.isDraft ?? !1,
|
|
3238
|
+
isRead: e.isRead ?? !1,
|
|
3239
|
+
messageId: t,
|
|
3240
|
+
parentFolderId: e.parentFolderId ?? "",
|
|
3241
|
+
receivedDateTime: e.receivedDateTime ?? "",
|
|
3242
|
+
subject: e.subject ?? "",
|
|
3243
|
+
to: (e.toRecipients ?? []).flatMap(({ emailAddress: e }) => e?.address == null ? [] : [e.address]),
|
|
3244
|
+
webLink: e.webLink ?? ""
|
|
3245
|
+
}
|
|
3246
|
+
};
|
|
3247
|
+
}
|
|
3248
|
+
async function hr(e, t, r) {
|
|
3249
|
+
try {
|
|
3250
|
+
return await e.connector.execute({
|
|
3251
|
+
endpoint: t,
|
|
3252
|
+
headers: { Prefer: "IdType=\"ImmutableId\"" },
|
|
3253
|
+
method: "GET",
|
|
3254
|
+
query: r
|
|
3255
|
+
}, e.signal);
|
|
3256
|
+
} catch (e) {
|
|
3257
|
+
throw new n(`Outlook proxy request to ${t} failed.`, { cause: e });
|
|
3258
|
+
}
|
|
3259
|
+
}
|
|
3260
|
+
function gr(r, i) {
|
|
3261
|
+
if (r.status >= 200 && r.status < 300) return;
|
|
3262
|
+
let a = _r(r.data);
|
|
3263
|
+
throw r.status == 401 ? new e(`Outlook ${i} rejected the Connection.`) : r.status == 403 && a.has("mailboxnotenabledforrestapi") ? new t("The Outlook mailbox is not reachable through the Graph mail APIs.") : r.status == 403 && (a.has("accessdenied") || a.has("erroraccessdenied")) ? new e(`Outlook ${i} rejected the Connection.`) : r.status == 404 && (a.has("erroritemnotfound") || a.has("itemnotfound")) ? new t("The configured Outlook folder does not exist.") : r.status == 400 && (a.has("errorinvalididmalformed") || a.has("inefficientfilter")) ? new t("Outlook rejected the configured folder or filters.") : new n(`Outlook ${i} failed with status ${r.status}.`);
|
|
3264
|
+
}
|
|
3265
|
+
function _r(e) {
|
|
3266
|
+
let t = /* @__PURE__ */ new Set(), n = G(e)?.error;
|
|
3267
|
+
for (let e = 0; e < 4; e += 1) {
|
|
3268
|
+
let e = G(n);
|
|
3269
|
+
if (e == null) break;
|
|
3270
|
+
typeof e.code == "string" && e.code.length > 0 && t.add(e.code.toLowerCase()), n = e.innerError ?? e.innererror;
|
|
3271
|
+
}
|
|
3272
|
+
return t;
|
|
3273
|
+
}
|
|
3274
|
+
function vr(e) {
|
|
3275
|
+
let t = G(e)?.value;
|
|
3276
|
+
return Array.isArray(t) ? t : [];
|
|
3277
|
+
}
|
|
3278
|
+
function yr(e) {
|
|
3279
|
+
let t = null;
|
|
3280
|
+
for (let n of e) {
|
|
3281
|
+
let e = W(n.receivedDateTime);
|
|
3282
|
+
n.receivedDateTime != null && e != null && (t == null || e > t.ms) && (t = {
|
|
3283
|
+
iso: n.receivedDateTime,
|
|
3284
|
+
ms: e
|
|
3285
|
+
});
|
|
3286
|
+
}
|
|
3287
|
+
return t;
|
|
3288
|
+
}
|
|
3289
|
+
function W(e) {
|
|
3290
|
+
if (e == null || e.length == 0) return null;
|
|
3291
|
+
let t = Date.parse(e);
|
|
3292
|
+
return Number.isNaN(t) ? null : t;
|
|
3293
|
+
}
|
|
3294
|
+
function G(e) {
|
|
3295
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
3296
|
+
}
|
|
3297
|
+
var br = {
|
|
3298
|
+
initialState: {
|
|
3299
|
+
checkpoint: null,
|
|
3300
|
+
subscription: {}
|
|
3301
|
+
},
|
|
3302
|
+
snapshot: {
|
|
3303
|
+
configSchema: {
|
|
3304
|
+
additionalProperties: !1,
|
|
3305
|
+
properties: { topics: {
|
|
3306
|
+
items: {
|
|
3307
|
+
enum: /* @__PURE__ */ "app/scopes_update,app/uninstalled,app_purchases_one_time/update,app_subscriptions/approaching_capped_amount,app_subscriptions/update,bulk_operations/finish,carts/create,carts/update,channels/delete,checkout_and_accounts_configurations/update,checkouts/create,checkouts/delete,checkouts/update,collection_listings/add,collection_listings/remove,collection_listings/update,collection_publications/create,collection_publications/delete,collection_publications/update,collections/create,collections/delete,collections/update,companies/create,companies/delete,companies/update,company_contact_roles/assign,company_contact_roles/revoke,company_contacts/create,company_contacts/delete,company_contacts/update,company_locations/create,company_locations/delete,company_locations/update,customer.joined_segment,customer.left_segment,customer.tags_added,customer.tags_removed,customer_account_settings/update,customer_groups/create,customer_groups/delete,customer_groups/update,customers/create,customers/delete,customers/disable,customers/enable,customers/purchasing_summary,customers/update,customers_email_marketing_consent/update,customers_marketing_consent/update,delivery_promise_settings/update,disputes/create,disputes/update,domains/create,domains/destroy,domains/update,draft_orders/create,draft_orders/delete,draft_orders/update,fulfillment_events/create,fulfillment_events/delete,fulfillment_holds/added,fulfillment_holds/released,fulfillment_orders/cancellation_request_accepted,fulfillment_orders/cancellation_request_rejected,fulfillment_orders/cancellation_request_submitted,fulfillment_orders/cancelled,fulfillment_orders/fulfillment_request_accepted,fulfillment_orders/fulfillment_request_rejected,fulfillment_orders/fulfillment_request_submitted,fulfillment_orders/fulfillment_service_failed_to_complete,fulfillment_orders/hold_released,fulfillment_orders/line_items_prepared_for_local_delivery,fulfillment_orders/line_items_prepared_for_pickup,fulfillment_orders/manually_reported_progress_stopped,fulfillment_orders/merged,fulfillment_orders/moved,fulfillment_orders/order_routing_complete,fulfillment_orders/placed_on_hold,fulfillment_orders/progress_reported,fulfillment_orders/rescheduled,fulfillment_orders/scheduled_fulfillment_order_ready,fulfillment_orders/split,fulfillments/create,fulfillments/update,inventory_items/create,inventory_items/delete,inventory_items/update,inventory_levels/connect,inventory_levels/disconnect,inventory_levels/update,locales/create,locales/destroy,locales/update,locations/activate,locations/create,locations/deactivate,locations/delete,locations/update,machine_translation_batch/completed,metafield_definitions/create,metafield_definitions/delete,metafield_definitions/update,order_transactions/create,orders/cancelled,orders/create,orders/delete,orders/edited,orders/fulfilled,orders/link_requested,orders/paid,orders/partially_fulfilled,orders/risk_assessment_changed,orders/shopify_protect_eligibility_changed,orders/updated,payment_schedules/due,payment_terms/create,payment_terms/delete,payment_terms/update,product_feeds/create,product_feeds/full_sync,product_feeds/full_sync_finish,product_feeds/incremental_sync,product_feeds/update,product_listings/add,product_listings/remove,product_listings/update,product_publications/create,product_publications/delete,product_publications/update,products/create,products/delete,products/update,profiles/create,profiles/delete,profiles/update,publications/delete,refunds/create,returns/approve,returns/cancel,returns/close,returns/decline,returns/process,returns/reopen,returns/request,returns/update,reverse_deliveries/attach_deliverable,reverse_fulfillment_orders/dispose,scheduled_product_listings/add,scheduled_product_listings/remove,scheduled_product_listings/update,segments/create,segments/delete,segments/update,selling_plan_groups/create,selling_plan_groups/delete,selling_plan_groups/update,shop/update,subscription_billing_attempts/challenged,subscription_billing_attempts/failure,subscription_billing_attempts/success,subscription_billing_cycle_edits/create,subscription_billing_cycle_edits/delete,subscription_billing_cycle_edits/update,subscription_billing_cycles/skip,subscription_billing_cycles/unskip,subscription_contracts/activate,subscription_contracts/cancel,subscription_contracts/create,subscription_contracts/expire,subscription_contracts/fail,subscription_contracts/pause,subscription_contracts/update,tax_partners/update,tax_summaries/create,tender_transactions/create,themes/create,themes/delete,themes/publish,themes/update,variants/in_stock,variants/out_of_stock".split(","),
|
|
3308
|
+
type: "string"
|
|
3309
|
+
},
|
|
3310
|
+
maxItems: 20,
|
|
3311
|
+
minItems: 1,
|
|
3312
|
+
type: "array",
|
|
3313
|
+
uniqueItems: !0
|
|
3314
|
+
} },
|
|
3315
|
+
required: ["topics"],
|
|
3316
|
+
title: "Shopify Store Event Config",
|
|
3317
|
+
type: "object"
|
|
3318
|
+
},
|
|
3319
|
+
definitionVersion: 1,
|
|
3320
|
+
description: "Triggers when selected Shopify webhook topics occur in the connected store.",
|
|
3321
|
+
displayName: "Shopify: Store Event",
|
|
3322
|
+
endpoint: {
|
|
3323
|
+
body: {
|
|
3324
|
+
allowArray: !1,
|
|
3325
|
+
allowEmpty: !1,
|
|
3326
|
+
formats: ["json"]
|
|
3327
|
+
},
|
|
3328
|
+
methods: ["POST"],
|
|
3329
|
+
successStatus: 202
|
|
3330
|
+
},
|
|
3331
|
+
key: "shopify.on_shop_event",
|
|
3332
|
+
name: "on_shop_event",
|
|
3333
|
+
payloadSchema: {
|
|
3334
|
+
additionalProperties: !1,
|
|
3335
|
+
properties: {
|
|
3336
|
+
apiVersion: { type: "string" },
|
|
3337
|
+
body: { type: "object" },
|
|
3338
|
+
eventId: { type: "string" },
|
|
3339
|
+
shopDomain: { type: "string" },
|
|
3340
|
+
topic: { type: "string" },
|
|
3341
|
+
triggeredAt: { type: "string" },
|
|
3342
|
+
webhookId: { type: "string" }
|
|
3343
|
+
},
|
|
3344
|
+
required: [
|
|
3345
|
+
"topic",
|
|
3346
|
+
"webhookId",
|
|
3347
|
+
"eventId",
|
|
3348
|
+
"shopDomain",
|
|
3349
|
+
"apiVersion",
|
|
3350
|
+
"triggeredAt",
|
|
3351
|
+
"body"
|
|
3352
|
+
],
|
|
3353
|
+
title: "Shopify Store Event Payload",
|
|
3354
|
+
type: "object"
|
|
3355
|
+
},
|
|
3356
|
+
provider: "shopify",
|
|
3357
|
+
type: "integration"
|
|
3358
|
+
},
|
|
3359
|
+
receive(e) {
|
|
3360
|
+
let t = e.header("x-shopify-topic")?.trim();
|
|
3361
|
+
if (!t) return {
|
|
3362
|
+
outcome: "ignored",
|
|
3363
|
+
reason: "Shopify topic header is missing."
|
|
3364
|
+
};
|
|
3365
|
+
if (!xr(e.config).includes(t)) return {
|
|
3366
|
+
outcome: "ignored",
|
|
3367
|
+
reason: "Shopify topic is not subscribed."
|
|
3368
|
+
};
|
|
3369
|
+
let n = e.header("x-shopify-webhook-id") ?? "";
|
|
3370
|
+
return {
|
|
3371
|
+
dedupeKey: n.length == 0 ? void 0 : n,
|
|
3372
|
+
outcome: "event",
|
|
3373
|
+
payload: {
|
|
3374
|
+
apiVersion: e.header("x-shopify-api-version") ?? "",
|
|
3375
|
+
body: e.payload,
|
|
3376
|
+
eventId: e.header("x-shopify-event-id") ?? "",
|
|
3377
|
+
shopDomain: e.header("x-shopify-shop-domain") ?? "",
|
|
3378
|
+
topic: t,
|
|
3379
|
+
triggeredAt: e.header("x-shopify-triggered-at") ?? "",
|
|
3380
|
+
webhookId: n
|
|
3381
|
+
}
|
|
3382
|
+
};
|
|
3383
|
+
},
|
|
3384
|
+
async reconcile(e) {
|
|
3385
|
+
let t = Or(e.state), n = await Cr(e);
|
|
3386
|
+
if (n == null) {
|
|
3387
|
+
if (!e.active) return { outcome: "ready" };
|
|
3388
|
+
throw new y("The Shopify store or webhook resource is unavailable.");
|
|
3389
|
+
}
|
|
3390
|
+
if (!e.active) {
|
|
3391
|
+
for (let t of n.values()) await wr(e, t);
|
|
3392
|
+
return await t.saveSubscription({}, kr(e.now)), { outcome: "ready" };
|
|
3393
|
+
}
|
|
3394
|
+
let r = xr(e.config), i = [], a = [];
|
|
3395
|
+
try {
|
|
3396
|
+
for (let t of r) {
|
|
3397
|
+
let r = n.get(t);
|
|
3398
|
+
if (r != null) i.push(r);
|
|
3399
|
+
else {
|
|
3400
|
+
let n = await Sr(e, t);
|
|
3401
|
+
i.push(n.id), n.created && a.push(n.id);
|
|
3402
|
+
}
|
|
3403
|
+
}
|
|
3404
|
+
} catch (t) {
|
|
3405
|
+
throw await Promise.allSettled(a.map((t) => wr(e, t))), t;
|
|
3406
|
+
}
|
|
3407
|
+
for (let [t, i] of n) r.includes(t) || await wr(e, i);
|
|
3408
|
+
return await t.saveSubscription({ webhookIds: i }, kr(e.now)), { outcome: "ready" };
|
|
3409
|
+
}
|
|
3410
|
+
};
|
|
3411
|
+
function xr(e) {
|
|
3412
|
+
return [...new Set(e.topics)];
|
|
3413
|
+
}
|
|
3414
|
+
async function Sr(e, t) {
|
|
3415
|
+
let n = await Tr(e, "subscription create", {
|
|
3416
|
+
body: { webhook: {
|
|
3417
|
+
address: e.endpointUrl,
|
|
3418
|
+
format: "json",
|
|
3419
|
+
topic: t
|
|
3420
|
+
} },
|
|
3421
|
+
endpoint: "/webhooks.json",
|
|
3422
|
+
method: "POST"
|
|
3423
|
+
});
|
|
3424
|
+
if (n.status == 422) {
|
|
3425
|
+
let n = (await Cr(e))?.get(t);
|
|
3426
|
+
if (n != null) return {
|
|
3427
|
+
created: !1,
|
|
3428
|
+
id: n
|
|
3429
|
+
};
|
|
3430
|
+
}
|
|
3431
|
+
Er(n, "subscription create");
|
|
3432
|
+
let r = Dr(K(K(n.data)?.webhook)?.id);
|
|
3433
|
+
if (r == null) throw new b("Shopify subscription response is missing its ID.");
|
|
3434
|
+
return {
|
|
3435
|
+
created: !0,
|
|
3436
|
+
id: r
|
|
3437
|
+
};
|
|
3438
|
+
}
|
|
3439
|
+
async function Cr(e) {
|
|
3440
|
+
let t = await Tr(e, "subscription list", {
|
|
3441
|
+
endpoint: "/webhooks.json",
|
|
3442
|
+
method: "GET",
|
|
3443
|
+
query: {
|
|
3444
|
+
address: e.endpointUrl,
|
|
3445
|
+
limit: 250
|
|
3446
|
+
}
|
|
3447
|
+
});
|
|
3448
|
+
if (t.status == 404) return null;
|
|
3449
|
+
Er(t, "subscription list");
|
|
3450
|
+
let n = K(t.data)?.webhooks, r = /* @__PURE__ */ new Map();
|
|
3451
|
+
if (!Array.isArray(n)) return r;
|
|
3452
|
+
for (let t of n) {
|
|
3453
|
+
let n = K(t), i = Dr(n?.id);
|
|
3454
|
+
n?.address === e.endpointUrl && typeof n.topic == "string" && i != null && r.set(n.topic, i);
|
|
3455
|
+
}
|
|
3456
|
+
return r;
|
|
3457
|
+
}
|
|
3458
|
+
async function wr(e, t) {
|
|
3459
|
+
let n = await Tr(e, "subscription delete", {
|
|
3460
|
+
endpoint: `/webhooks/${encodeURIComponent(t)}.json`,
|
|
3461
|
+
method: "DELETE"
|
|
3462
|
+
});
|
|
3463
|
+
n.status != 404 && Er(n, "subscription delete");
|
|
3464
|
+
}
|
|
3465
|
+
async function Tr(e, t, n) {
|
|
3466
|
+
try {
|
|
3467
|
+
return await e.connector.execute(n, e.signal);
|
|
3468
|
+
} catch (e) {
|
|
3469
|
+
throw e instanceof v ? e : new b(`Shopify ${t} request failed.`, { cause: e });
|
|
3470
|
+
}
|
|
3471
|
+
}
|
|
3472
|
+
function Er(e, t) {
|
|
3473
|
+
if (!(e.status >= 200 && e.status < 300)) throw e.status == 401 || e.status == 403 ? new v(`Shopify ${t} rejected the Connection.`) : [
|
|
3474
|
+
402,
|
|
3475
|
+
404,
|
|
3476
|
+
422,
|
|
3477
|
+
423,
|
|
3478
|
+
501
|
|
3479
|
+
].includes(e.status) ? new y(`Shopify ${t} rejected the subscription.`) : new b(`Shopify ${t} failed with status ${e.status}.`);
|
|
3480
|
+
}
|
|
3481
|
+
function Dr(e) {
|
|
3482
|
+
return typeof e == "string" ? e.trim().length == 0 ? null : e : typeof e == "number" && Number.isFinite(e) ? String(e) : null;
|
|
3483
|
+
}
|
|
3484
|
+
function Or(e) {
|
|
3485
|
+
if (e == null) throw new y("Shopify Integration state is missing.");
|
|
3486
|
+
return e;
|
|
3487
|
+
}
|
|
3488
|
+
function kr(e) {
|
|
3489
|
+
return new Date(e.getTime() + 2592e6);
|
|
3490
|
+
}
|
|
3491
|
+
function K(e) {
|
|
3492
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
3493
|
+
}
|
|
3494
|
+
//#endregion
|
|
3495
|
+
//#region src/trigger/providers/slack/on-message-posted.ts
|
|
3496
|
+
var Ar = 15, jr = 6e4, Mr = /* @__PURE__ */ new Set([
|
|
3497
|
+
"file_share",
|
|
3498
|
+
"thread_broadcast",
|
|
3499
|
+
"me_message",
|
|
3500
|
+
"bot_message"
|
|
3501
|
+
]), Nr = /* @__PURE__ */ new Set([
|
|
3502
|
+
"invalid_auth",
|
|
3503
|
+
"not_authed",
|
|
3504
|
+
"token_revoked",
|
|
3505
|
+
"token_expired",
|
|
3506
|
+
"account_inactive",
|
|
3507
|
+
"two_factor_setup_required"
|
|
3508
|
+
]), Pr = /* @__PURE__ */ new Set([
|
|
3509
|
+
"channel_not_found",
|
|
3510
|
+
"not_in_channel",
|
|
3511
|
+
"missing_scope",
|
|
3512
|
+
"not_allowed_token_type",
|
|
3513
|
+
"access_denied",
|
|
3514
|
+
"channel_is_limited_access",
|
|
3515
|
+
"ekm_access_denied",
|
|
3516
|
+
"enterprise_is_restricted",
|
|
3517
|
+
"no_permission",
|
|
3518
|
+
"team_access_not_granted",
|
|
3519
|
+
"invalid_ts_oldest",
|
|
3520
|
+
"invalid_ts_latest",
|
|
3521
|
+
"method_deprecated",
|
|
3522
|
+
"deprecated_endpoint",
|
|
3523
|
+
"accesslimited"
|
|
3524
|
+
]), Fr = {
|
|
3525
|
+
snapshot: {
|
|
3526
|
+
configSchema: {
|
|
3527
|
+
additionalProperties: !1,
|
|
3528
|
+
description: "Configuration for slack.on_message_posted. The trigger polls one conversation and emits every new message that passes the configured filters.",
|
|
3529
|
+
properties: {
|
|
3530
|
+
channelId: {
|
|
3531
|
+
description: "Slack conversation ID to watch, e.g. C0122KQ70S7E.",
|
|
3532
|
+
pattern: "^[CDG][A-Z0-9]{2,31}$",
|
|
3533
|
+
type: "string"
|
|
3534
|
+
},
|
|
3535
|
+
fromUserIds: {
|
|
3536
|
+
default: [],
|
|
3537
|
+
description: "Only trigger on messages written by these Slack user IDs. Empty means any author.",
|
|
3538
|
+
items: {
|
|
3539
|
+
pattern: "^[UW][A-Z0-9]{2,31}$",
|
|
3540
|
+
type: "string"
|
|
3541
|
+
},
|
|
3542
|
+
type: "array"
|
|
3543
|
+
},
|
|
3544
|
+
ignoreUserIds: {
|
|
3545
|
+
default: [],
|
|
3546
|
+
description: "Never trigger on messages written by these Slack user IDs.",
|
|
3547
|
+
items: {
|
|
3548
|
+
pattern: "^[UW][A-Z0-9]{2,31}$",
|
|
3549
|
+
type: "string"
|
|
3550
|
+
},
|
|
3551
|
+
type: "array"
|
|
3552
|
+
},
|
|
3553
|
+
includeBotMessages: {
|
|
3554
|
+
default: !1,
|
|
3555
|
+
description: "Also trigger on messages posted by bots and apps.",
|
|
3556
|
+
type: "boolean"
|
|
3557
|
+
},
|
|
3558
|
+
includeSystemMessages: {
|
|
3559
|
+
default: !1,
|
|
3560
|
+
description: "Also trigger on Slack system notices.",
|
|
3561
|
+
type: "boolean"
|
|
3562
|
+
},
|
|
3563
|
+
maxMessagesPerPoll: {
|
|
3564
|
+
default: Ar,
|
|
3565
|
+
description: "Maximum number of messages processed per poll.",
|
|
3566
|
+
maximum: 100,
|
|
3567
|
+
minimum: 1,
|
|
3568
|
+
type: "integer"
|
|
3569
|
+
},
|
|
3570
|
+
textContains: {
|
|
3571
|
+
default: "",
|
|
3572
|
+
description: "Only trigger when message text contains this string, case-insensitively.",
|
|
3573
|
+
type: "string"
|
|
3574
|
+
}
|
|
3575
|
+
},
|
|
3576
|
+
required: ["channelId"],
|
|
3577
|
+
title: "Slack New Channel Message Config",
|
|
3578
|
+
type: "object"
|
|
3579
|
+
},
|
|
3580
|
+
definitionVersion: 1,
|
|
3581
|
+
description: "Polls one Slack conversation and triggers when a new message is posted to it.",
|
|
3582
|
+
displayName: "Slack: New Channel Message",
|
|
3583
|
+
key: "slack.on_message_posted",
|
|
3584
|
+
name: "on_message_posted",
|
|
3585
|
+
payloadSchema: {
|
|
3586
|
+
additionalProperties: !1,
|
|
3587
|
+
properties: { events: {
|
|
3588
|
+
items: {
|
|
3589
|
+
additionalProperties: !1,
|
|
3590
|
+
properties: {
|
|
3591
|
+
botId: { type: ["string", "null"] },
|
|
3592
|
+
channelId: { type: "string" },
|
|
3593
|
+
files: {
|
|
3594
|
+
items: {
|
|
3595
|
+
additionalProperties: !1,
|
|
3596
|
+
properties: {
|
|
3597
|
+
id: { type: "string" },
|
|
3598
|
+
mimetype: { type: "string" },
|
|
3599
|
+
name: { type: "string" }
|
|
3600
|
+
},
|
|
3601
|
+
required: [
|
|
3602
|
+
"id",
|
|
3603
|
+
"name",
|
|
3604
|
+
"mimetype"
|
|
3605
|
+
],
|
|
3606
|
+
type: "object"
|
|
3607
|
+
},
|
|
3608
|
+
type: "array"
|
|
3609
|
+
},
|
|
3610
|
+
messageTs: { type: "string" },
|
|
3611
|
+
subtype: { type: ["string", "null"] },
|
|
3612
|
+
text: { type: "string" },
|
|
3613
|
+
threadTs: { type: ["string", "null"] },
|
|
3614
|
+
userId: { type: ["string", "null"] }
|
|
3615
|
+
},
|
|
3616
|
+
required: [
|
|
3617
|
+
"channelId",
|
|
3618
|
+
"messageTs",
|
|
3619
|
+
"threadTs",
|
|
3620
|
+
"userId",
|
|
3621
|
+
"botId",
|
|
3622
|
+
"subtype",
|
|
3623
|
+
"text",
|
|
3624
|
+
"files"
|
|
3625
|
+
],
|
|
3626
|
+
type: "object"
|
|
3627
|
+
},
|
|
3628
|
+
type: "array"
|
|
3629
|
+
} },
|
|
3630
|
+
required: ["events"],
|
|
3631
|
+
title: "Slack New Channel Message Payload",
|
|
3632
|
+
type: "object"
|
|
3633
|
+
},
|
|
3634
|
+
provider: "slack",
|
|
3635
|
+
type: "poll"
|
|
3636
|
+
},
|
|
3637
|
+
async poll(e) {
|
|
3638
|
+
let t = Ir(e.config);
|
|
3639
|
+
if (e.checkpoint === null) return {
|
|
3640
|
+
checkpoint: { lastTs: await Lr(e, t.channelId) },
|
|
3641
|
+
events: []
|
|
3642
|
+
};
|
|
3643
|
+
let n = Rr(e.checkpoint), r = await zr(e, t, n), i = Hr(r), a = [], o = 0;
|
|
3644
|
+
for (let e of i.toReversed()) {
|
|
3645
|
+
if (!Wr(e.message, t)) {
|
|
3646
|
+
o += 1;
|
|
3647
|
+
continue;
|
|
3648
|
+
}
|
|
3649
|
+
a.push(Gr(e, t.channelId));
|
|
3650
|
+
}
|
|
3651
|
+
return {
|
|
3652
|
+
checkpoint: Ur(n, r, i),
|
|
3653
|
+
events: a,
|
|
3654
|
+
filtered: o
|
|
3655
|
+
};
|
|
3656
|
+
}
|
|
3657
|
+
};
|
|
3658
|
+
function Ir(e) {
|
|
3659
|
+
return {
|
|
3660
|
+
channelId: e.channelId,
|
|
3661
|
+
fromUserIds: e.fromUserIds ?? [],
|
|
3662
|
+
ignoreUserIds: e.ignoreUserIds ?? [],
|
|
3663
|
+
includeBotMessages: e.includeBotMessages ?? !1,
|
|
3664
|
+
includeSystemMessages: e.includeSystemMessages ?? !1,
|
|
3665
|
+
maxMessagesPerPoll: e.maxMessagesPerPoll ?? Ar,
|
|
3666
|
+
textContains: e.textContains ?? ""
|
|
3667
|
+
};
|
|
3668
|
+
}
|
|
3669
|
+
async function Lr(e, t) {
|
|
3670
|
+
let n = await Br(e, {
|
|
3671
|
+
channel: t,
|
|
3672
|
+
limit: 1
|
|
3673
|
+
});
|
|
3674
|
+
Vr(n, "baseline history fetch");
|
|
3675
|
+
let r = n.data.messages?.[0]?.ts;
|
|
3676
|
+
return r != null && Kr(r) ? r : `${Math.floor((e.now.getTime() - jr) / 1e3)}.000000`;
|
|
3677
|
+
}
|
|
3678
|
+
function Rr(e) {
|
|
3679
|
+
let n = e;
|
|
3680
|
+
if (typeof n.lastTs != "string" || n.lastTs.length == 0) throw new t("Slack checkpoint lastTs is missing.");
|
|
3681
|
+
let r = n.drainLatest, i = n.pendingHighTs;
|
|
3682
|
+
if (r == null && i == null) return { lastTs: n.lastTs };
|
|
3683
|
+
if (typeof r != "string" || r.length == 0 || typeof i != "string" || i.length == 0) throw new t("Slack checkpoint drain fields are incomplete.");
|
|
3684
|
+
return {
|
|
3685
|
+
drainLatest: r,
|
|
3686
|
+
lastTs: n.lastTs,
|
|
3687
|
+
pendingHighTs: i
|
|
3688
|
+
};
|
|
3689
|
+
}
|
|
3690
|
+
async function zr(e, t, n) {
|
|
3691
|
+
let r = await Br(e, {
|
|
3692
|
+
channel: t.channelId,
|
|
3693
|
+
inclusive: "false",
|
|
3694
|
+
latest: n.drainLatest,
|
|
3695
|
+
limit: t.maxMessagesPerPoll,
|
|
3696
|
+
oldest: n.lastTs
|
|
3697
|
+
});
|
|
3698
|
+
return Vr(r, "history list"), r.data;
|
|
3699
|
+
}
|
|
3700
|
+
async function Br(e, t) {
|
|
3701
|
+
try {
|
|
3702
|
+
return await e.connector.execute({
|
|
3703
|
+
endpoint: "/conversations.history",
|
|
3704
|
+
method: "GET",
|
|
3705
|
+
query: Object.fromEntries(Object.entries(t).filter((e) => e[1] != null))
|
|
3706
|
+
}, e.signal);
|
|
3707
|
+
} catch (e) {
|
|
3708
|
+
throw new n("Slack proxy request failed.", { cause: e });
|
|
3709
|
+
}
|
|
3710
|
+
}
|
|
3711
|
+
function Vr(r, i) {
|
|
3712
|
+
let a = r.data;
|
|
3713
|
+
if (r.status >= 200 && r.status < 300 && a.ok === !0) return;
|
|
3714
|
+
let o = typeof a.error == "string" ? a.error : "";
|
|
3715
|
+
throw Nr.has(o) ? new e(`Slack ${i} rejected with ${o}.`) : Pr.has(o) ? new t(`Slack ${i} rejected with ${o}.`) : new n(`Slack ${i} failed with ${o || `status ${r.status}`}.`);
|
|
3716
|
+
}
|
|
3717
|
+
function Hr(e) {
|
|
3718
|
+
return (e.messages ?? []).flatMap((e) => e.ts != null && Kr(e.ts) ? [{
|
|
3719
|
+
message: e,
|
|
3720
|
+
ts: e.ts
|
|
3721
|
+
}] : []);
|
|
3722
|
+
}
|
|
3723
|
+
function Ur(e, t, r) {
|
|
3724
|
+
let i = r[0]?.ts, a = r.at(-1)?.ts;
|
|
3725
|
+
if (t.has_more === !0) {
|
|
3726
|
+
if (i == null || a == null) throw new n("Slack history reports has_more without a usable timestamp.");
|
|
3727
|
+
return {
|
|
3728
|
+
drainLatest: a,
|
|
3729
|
+
lastTs: e.lastTs,
|
|
3730
|
+
pendingHighTs: e.pendingHighTs ?? i
|
|
3731
|
+
};
|
|
3732
|
+
}
|
|
3733
|
+
return e.pendingHighTs == null ? { lastTs: i ?? e.lastTs } : { lastTs: e.pendingHighTs };
|
|
3734
|
+
}
|
|
3735
|
+
function Wr(e, t) {
|
|
3736
|
+
return !t.includeBotMessages && (e.bot_id != null || e.subtype == "bot_message") || !t.includeSystemMessages && e.subtype != null && !Mr.has(e.subtype) || t.fromUserIds.length > 0 && (e.user == null || !t.fromUserIds.includes(e.user)) || e.user != null && t.ignoreUserIds.includes(e.user) ? !1 : t.textContains.length == 0 || (e.text ?? "").toLowerCase().includes(t.textContains.toLowerCase());
|
|
3737
|
+
}
|
|
3738
|
+
function Gr(e, t) {
|
|
3739
|
+
return {
|
|
3740
|
+
dedupeKey: `${t}:${e.ts}`,
|
|
3741
|
+
payload: {
|
|
3742
|
+
botId: e.message.bot_id ?? null,
|
|
3743
|
+
channelId: t,
|
|
3744
|
+
files: (e.message.files ?? []).map((e) => ({
|
|
3745
|
+
id: e.id ?? "",
|
|
3746
|
+
mimetype: e.mimetype ?? "",
|
|
3747
|
+
name: e.name ?? ""
|
|
3748
|
+
})),
|
|
3749
|
+
messageTs: e.ts,
|
|
3750
|
+
subtype: e.message.subtype ?? null,
|
|
3751
|
+
text: e.message.text ?? "",
|
|
3752
|
+
threadTs: e.message.thread_ts ?? null,
|
|
3753
|
+
userId: e.message.user ?? null
|
|
3754
|
+
}
|
|
3755
|
+
};
|
|
3756
|
+
}
|
|
3757
|
+
function Kr(e) {
|
|
3758
|
+
return /^\d+(?:\.\d+)?$/.test(e) && !Number.isNaN(new Date(Math.round(Number(e) * 1e3)).getTime());
|
|
3759
|
+
}
|
|
3760
|
+
//#endregion
|
|
3761
|
+
//#region src/trigger/providers/stripe/on-event.ts
|
|
3762
|
+
var q = "/v1/webhook_endpoints", qr = { "Content-Type": "application/x-www-form-urlencoded" }, Jr = {
|
|
3763
|
+
initialState: {
|
|
3764
|
+
checkpoint: null,
|
|
3765
|
+
subscription: {}
|
|
3766
|
+
},
|
|
3767
|
+
snapshot: {
|
|
3768
|
+
configSchema: {
|
|
3769
|
+
additionalProperties: !1,
|
|
3770
|
+
properties: {
|
|
3771
|
+
apiVersion: {
|
|
3772
|
+
default: "",
|
|
3773
|
+
maxLength: 40,
|
|
3774
|
+
type: "string"
|
|
3775
|
+
},
|
|
3776
|
+
events: {
|
|
3777
|
+
items: {
|
|
3778
|
+
maxLength: 120,
|
|
3779
|
+
pattern: "^(\\*|[a-z0-9_]+(?:\\.[a-z0-9_]+)+)$",
|
|
3780
|
+
type: "string"
|
|
3781
|
+
},
|
|
3782
|
+
minItems: 1,
|
|
3783
|
+
type: "array",
|
|
3784
|
+
uniqueItems: !0
|
|
3785
|
+
},
|
|
3786
|
+
includeConnectedAccounts: {
|
|
3787
|
+
default: !1,
|
|
3788
|
+
type: "boolean"
|
|
3789
|
+
}
|
|
3790
|
+
},
|
|
3791
|
+
required: ["events"],
|
|
3792
|
+
title: "Stripe Event Config",
|
|
3793
|
+
type: "object"
|
|
3794
|
+
},
|
|
3795
|
+
definitionVersion: 1,
|
|
3796
|
+
description: "Triggers when selected Stripe events happen on the connected account.",
|
|
3797
|
+
displayName: "Stripe: Account Event",
|
|
3798
|
+
endpoint: {
|
|
3799
|
+
body: {
|
|
3800
|
+
allowArray: !1,
|
|
3801
|
+
allowEmpty: !1,
|
|
3802
|
+
formats: ["json"]
|
|
3803
|
+
},
|
|
3804
|
+
methods: ["POST"],
|
|
3805
|
+
successStatus: 202
|
|
3806
|
+
},
|
|
3807
|
+
key: "stripe.on_event",
|
|
3808
|
+
name: "on_event",
|
|
3809
|
+
payloadSchema: {
|
|
3810
|
+
additionalProperties: !1,
|
|
3811
|
+
properties: {
|
|
3812
|
+
body: { type: "object" },
|
|
3813
|
+
event: { type: "string" },
|
|
3814
|
+
eventId: { type: "string" },
|
|
3815
|
+
livemode: { type: "boolean" }
|
|
3816
|
+
},
|
|
3817
|
+
required: [
|
|
3818
|
+
"event",
|
|
3819
|
+
"eventId",
|
|
3820
|
+
"livemode",
|
|
3821
|
+
"body"
|
|
3822
|
+
],
|
|
3823
|
+
title: "Stripe Event Payload",
|
|
3824
|
+
type: "object"
|
|
3825
|
+
},
|
|
3826
|
+
provider: "stripe",
|
|
3827
|
+
type: "integration"
|
|
3828
|
+
},
|
|
3829
|
+
receive(e) {
|
|
3830
|
+
if (e.payload == null || typeof e.payload != "object" || Array.isArray(e.payload)) return {
|
|
3831
|
+
outcome: "ignored",
|
|
3832
|
+
reason: "Stripe event body is missing."
|
|
3833
|
+
};
|
|
3834
|
+
let t = e.payload, n = t.type, r = t.id;
|
|
3835
|
+
if (typeof n != "string" || typeof r != "string") return {
|
|
3836
|
+
outcome: "ignored",
|
|
3837
|
+
reason: "Stripe event identity is missing."
|
|
3838
|
+
};
|
|
3839
|
+
let i = Yr(e.config);
|
|
3840
|
+
return !i.events.includes("*") && !i.events.includes(n) ? {
|
|
3841
|
+
outcome: "ignored",
|
|
3842
|
+
reason: "Stripe event is not subscribed."
|
|
3843
|
+
} : {
|
|
3844
|
+
dedupeKey: r,
|
|
3845
|
+
outcome: "event",
|
|
3846
|
+
payload: {
|
|
3847
|
+
body: t,
|
|
3848
|
+
event: n,
|
|
3849
|
+
eventId: r,
|
|
3850
|
+
livemode: t.livemode === !0
|
|
3851
|
+
}
|
|
3852
|
+
};
|
|
3853
|
+
},
|
|
3854
|
+
async reconcile(e) {
|
|
3855
|
+
let t = ei(e.state), n = Yr(e.config), r = ti(t);
|
|
3856
|
+
if (!e.active) {
|
|
3857
|
+
if (r ??= await Qr(e), r != null) {
|
|
3858
|
+
let t = await J(e, "endpoint delete", {
|
|
3859
|
+
endpoint: `${q}/${r}`,
|
|
3860
|
+
method: "DELETE"
|
|
3861
|
+
});
|
|
3862
|
+
t.status != 404 && Y(t, "endpoint delete");
|
|
3863
|
+
}
|
|
3864
|
+
return await t.saveSubscription({}, ni(e.now)), { outcome: "ready" };
|
|
3865
|
+
}
|
|
3866
|
+
if (r ??= await Qr(e), r == null) {
|
|
3867
|
+
let t = await J(e, "endpoint create", {
|
|
3868
|
+
body: Xr(e.endpointUrl, n),
|
|
3869
|
+
endpoint: q,
|
|
3870
|
+
headers: qr,
|
|
3871
|
+
method: "POST"
|
|
3872
|
+
});
|
|
3873
|
+
Y(t, "endpoint create"), r = $r(t.data);
|
|
3874
|
+
}
|
|
3875
|
+
let i = await J(e, "endpoint update", {
|
|
3876
|
+
body: Zr([
|
|
3877
|
+
...n.events.map((e, t) => [`enabled_events[${t}]`, e]),
|
|
3878
|
+
["disabled", "false"],
|
|
3879
|
+
["description", "Managed by Open Flow."]
|
|
3880
|
+
]),
|
|
3881
|
+
endpoint: `${q}/${r}`,
|
|
3882
|
+
headers: qr,
|
|
3883
|
+
method: "POST"
|
|
3884
|
+
});
|
|
3885
|
+
return i.status == 404 ? (await t.saveSubscription({}, e.now), { outcome: "pending" }) : (Y(i, "endpoint update"), await t.saveSubscription({ endpointId: r }, ni(e.now)), { outcome: "ready" });
|
|
3886
|
+
}
|
|
3887
|
+
};
|
|
3888
|
+
function Yr(e) {
|
|
3889
|
+
return {
|
|
3890
|
+
apiVersion: e.apiVersion ?? "",
|
|
3891
|
+
events: [...new Set(e.events)],
|
|
3892
|
+
includeConnectedAccounts: e.includeConnectedAccounts ?? !1
|
|
3893
|
+
};
|
|
3894
|
+
}
|
|
3895
|
+
function Xr(e, t) {
|
|
3896
|
+
let n = [
|
|
3897
|
+
["url", e],
|
|
3898
|
+
...t.events.map((e, t) => [`enabled_events[${t}]`, e]),
|
|
3899
|
+
["description", "Managed by Open Flow."]
|
|
3900
|
+
];
|
|
3901
|
+
return t.includeConnectedAccounts && n.push(["connect", "true"]), t.apiVersion.length > 0 && n.push(["api_version", t.apiVersion]), Zr(n);
|
|
3902
|
+
}
|
|
3903
|
+
function Zr(e) {
|
|
3904
|
+
let t = new URLSearchParams();
|
|
3905
|
+
for (let [n, r] of e) t.append(n, r);
|
|
3906
|
+
return t.toString();
|
|
3907
|
+
}
|
|
3908
|
+
async function Qr(e) {
|
|
3909
|
+
let t;
|
|
3910
|
+
for (let n = 0; n < 10; n += 1) {
|
|
3911
|
+
let n = await J(e, "endpoint list", {
|
|
3912
|
+
endpoint: q,
|
|
3913
|
+
method: "GET",
|
|
3914
|
+
query: {
|
|
3915
|
+
limit: 100,
|
|
3916
|
+
...t == null ? {} : { starting_after: t }
|
|
3917
|
+
}
|
|
3918
|
+
});
|
|
3919
|
+
Y(n, "endpoint list");
|
|
3920
|
+
let r = X(n.data), i = Array.isArray(r?.data) ? r.data : [];
|
|
3921
|
+
for (let t of i) {
|
|
3922
|
+
let n = X(t);
|
|
3923
|
+
if (n?.url === e.endpointUrl && typeof n.id == "string") return n.id;
|
|
3924
|
+
}
|
|
3925
|
+
let a = X(i.at(-1))?.id;
|
|
3926
|
+
if (r?.has_more !== !0 || typeof a != "string") return null;
|
|
3927
|
+
t = a;
|
|
3928
|
+
}
|
|
3929
|
+
return null;
|
|
3930
|
+
}
|
|
3931
|
+
async function J(e, t, n) {
|
|
3932
|
+
try {
|
|
3933
|
+
return await e.connector.execute(n, e.signal);
|
|
3934
|
+
} catch (e) {
|
|
3935
|
+
throw e instanceof v ? e : new b(`Stripe ${t} request failed.`, { cause: e });
|
|
3936
|
+
}
|
|
3937
|
+
}
|
|
3938
|
+
function Y(e, t) {
|
|
3939
|
+
if (!(e.status >= 200 && e.status < 300)) {
|
|
3940
|
+
if (e.status == 401 || e.status == 403) throw new v(`Stripe ${t} rejected the Connection.`);
|
|
3941
|
+
if (e.status == 400 || e.status == 404) {
|
|
3942
|
+
let n = X(X(e.data)?.error)?.message;
|
|
3943
|
+
throw new y(`Stripe ${t} rejected the subscription${typeof n == "string" ? `: ${n}` : "."}`);
|
|
3944
|
+
}
|
|
3945
|
+
throw new b(`Stripe ${t} failed with status ${e.status}.`);
|
|
3946
|
+
}
|
|
3947
|
+
}
|
|
3948
|
+
function $r(e) {
|
|
3949
|
+
let t = X(e)?.id;
|
|
3950
|
+
if (typeof t != "string") throw new b("Stripe endpoint response is missing its ID.");
|
|
3951
|
+
return t;
|
|
3952
|
+
}
|
|
3953
|
+
function ei(e) {
|
|
3954
|
+
if (e == null) throw new y("Stripe Integration state is missing.");
|
|
3955
|
+
return e;
|
|
3956
|
+
}
|
|
3957
|
+
function ti(e) {
|
|
3958
|
+
let t = e.subscription.endpointId;
|
|
3959
|
+
return typeof t == "string" && t.length > 0 ? t : null;
|
|
3960
|
+
}
|
|
3961
|
+
function ni(e) {
|
|
3962
|
+
return new Date(e.getTime() + 2592e6);
|
|
3963
|
+
}
|
|
3964
|
+
function X(e) {
|
|
3965
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
3966
|
+
}
|
|
3967
|
+
//#endregion
|
|
3968
|
+
//#region src/trigger/providers/telegram/on-update.ts
|
|
3969
|
+
var ri = /* @__PURE__ */ new Set([
|
|
3970
|
+
"chat_member",
|
|
3971
|
+
"message_reaction",
|
|
3972
|
+
"message_reaction_count"
|
|
3973
|
+
]), ii = /* @__PURE__ */ "*.message.edited_message.channel_post.edited_channel_post.business_connection.business_message.edited_business_message.deleted_business_messages.guest_message.message_reaction.message_reaction_count.inline_query.chosen_inline_result.callback_query.shipping_query.pre_checkout_query.purchased_paid_media.poll.poll_answer.my_chat_member.chat_member.chat_join_request.chat_boost.removed_chat_boost.managed_bot.subscription".split("."), ai = ii.filter((e) => e != "*" && !ri.has(e)), oi = {
|
|
3974
|
+
snapshot: {
|
|
3975
|
+
configSchema: {
|
|
3976
|
+
additionalProperties: !1,
|
|
3977
|
+
description: "Configuration for telegram.on_update.",
|
|
3978
|
+
properties: {
|
|
3979
|
+
chatIds: {
|
|
3980
|
+
default: [],
|
|
3981
|
+
description: "Only accept updates from these numeric Telegram chat IDs. Empty means every chat.",
|
|
3982
|
+
items: {
|
|
3983
|
+
pattern: "^-?[0-9]{1,20}$",
|
|
3984
|
+
type: "string"
|
|
3985
|
+
},
|
|
3986
|
+
maxItems: 100,
|
|
3987
|
+
type: "array",
|
|
3988
|
+
uniqueItems: !0
|
|
3989
|
+
},
|
|
3990
|
+
dropPendingUpdates: {
|
|
3991
|
+
default: !0,
|
|
3992
|
+
description: "Discard updates queued before the webhook is created or resumed.",
|
|
3993
|
+
type: "boolean"
|
|
3994
|
+
},
|
|
3995
|
+
updates: {
|
|
3996
|
+
description: "Telegram update types that trigger a Run. Use * for the Telegram default set.",
|
|
3997
|
+
items: { enum: ii },
|
|
3998
|
+
minItems: 1,
|
|
3999
|
+
type: "array",
|
|
4000
|
+
uniqueItems: !0
|
|
4001
|
+
},
|
|
4002
|
+
userIds: {
|
|
4003
|
+
default: [],
|
|
4004
|
+
description: "Only accept updates from these numeric Telegram user IDs. Empty means every user.",
|
|
4005
|
+
items: {
|
|
4006
|
+
pattern: "^[0-9]{1,20}$",
|
|
4007
|
+
type: "string"
|
|
4008
|
+
},
|
|
4009
|
+
maxItems: 100,
|
|
4010
|
+
type: "array",
|
|
4011
|
+
uniqueItems: !0
|
|
4012
|
+
}
|
|
4013
|
+
},
|
|
4014
|
+
required: ["updates"],
|
|
4015
|
+
title: "Telegram Bot Update Config",
|
|
4016
|
+
type: "object"
|
|
4017
|
+
},
|
|
4018
|
+
definitionVersion: 1,
|
|
4019
|
+
description: "Triggers when the connected Telegram bot receives a selected update.",
|
|
4020
|
+
displayName: "Telegram: Bot Update",
|
|
4021
|
+
endpoint: {
|
|
4022
|
+
body: {
|
|
4023
|
+
allowArray: !1,
|
|
4024
|
+
allowEmpty: !1,
|
|
4025
|
+
formats: ["json"]
|
|
4026
|
+
},
|
|
4027
|
+
methods: ["POST"],
|
|
4028
|
+
successStatus: 200
|
|
4029
|
+
},
|
|
4030
|
+
key: "telegram.on_update",
|
|
4031
|
+
name: "on_update",
|
|
4032
|
+
payloadSchema: {
|
|
4033
|
+
additionalProperties: !1,
|
|
4034
|
+
properties: {
|
|
4035
|
+
body: { type: "object" },
|
|
4036
|
+
deliveryId: { type: "string" },
|
|
4037
|
+
event: { type: "string" }
|
|
4038
|
+
},
|
|
4039
|
+
required: [
|
|
4040
|
+
"event",
|
|
4041
|
+
"deliveryId",
|
|
4042
|
+
"body"
|
|
4043
|
+
],
|
|
4044
|
+
title: "Telegram Bot Update Payload",
|
|
4045
|
+
type: "object"
|
|
4046
|
+
},
|
|
4047
|
+
provider: "telegram",
|
|
4048
|
+
type: "integration"
|
|
4049
|
+
},
|
|
4050
|
+
receive(e) {
|
|
4051
|
+
if (!li(e.header("x-telegram-bot-api-secret-token"), e.callbackSecret)) return {
|
|
4052
|
+
body: "",
|
|
4053
|
+
contentType: "text/plain",
|
|
4054
|
+
outcome: "respond",
|
|
4055
|
+
status: 404
|
|
4056
|
+
};
|
|
4057
|
+
if (!Z(e.payload) || !Number.isSafeInteger(e.payload.update_id)) return {
|
|
4058
|
+
outcome: "ignored",
|
|
4059
|
+
reason: "Telegram update_id is missing."
|
|
4060
|
+
};
|
|
4061
|
+
let t = Object.keys(e.payload).find((e) => e != "update_id");
|
|
4062
|
+
if (t == null) return {
|
|
4063
|
+
outcome: "ignored",
|
|
4064
|
+
reason: "Telegram update body is missing."
|
|
4065
|
+
};
|
|
4066
|
+
let n = si(e.config);
|
|
4067
|
+
if (!(ci(n) ?? ai).includes(t)) return {
|
|
4068
|
+
outcome: "ignored",
|
|
4069
|
+
reason: "Telegram update type is not subscribed."
|
|
4070
|
+
};
|
|
4071
|
+
let r = e.payload[t];
|
|
4072
|
+
if (n.chatIds.length > 0) {
|
|
4073
|
+
let e = ui(r);
|
|
4074
|
+
if (e == null || !n.chatIds.includes(e)) return {
|
|
4075
|
+
outcome: "ignored",
|
|
4076
|
+
reason: "Telegram chat does not match."
|
|
4077
|
+
};
|
|
4078
|
+
}
|
|
4079
|
+
if (n.userIds.length > 0) {
|
|
4080
|
+
let e = di(r);
|
|
4081
|
+
if (e == null || !n.userIds.includes(e)) return {
|
|
4082
|
+
outcome: "ignored",
|
|
4083
|
+
reason: "Telegram user does not match."
|
|
4084
|
+
};
|
|
4085
|
+
}
|
|
4086
|
+
let i = String(e.payload.update_id);
|
|
4087
|
+
return {
|
|
4088
|
+
dedupeKey: i,
|
|
4089
|
+
outcome: "event",
|
|
4090
|
+
payload: {
|
|
4091
|
+
body: e.payload,
|
|
4092
|
+
deliveryId: i,
|
|
4093
|
+
event: t
|
|
4094
|
+
}
|
|
4095
|
+
};
|
|
4096
|
+
},
|
|
4097
|
+
async reconcile(e) {
|
|
4098
|
+
let t = await fi(e);
|
|
4099
|
+
if (!e.active) return t == e.endpointUrl && await pi(e), { outcome: "ready" };
|
|
4100
|
+
if (t != "" && t != e.endpointUrl) throw new y(`The Telegram bot already sends updates to ${hi(t)}.`);
|
|
4101
|
+
let n = si(e.config);
|
|
4102
|
+
return await mi(e, "setWebhook", {
|
|
4103
|
+
allowed_updates: ci(n) ?? [],
|
|
4104
|
+
drop_pending_updates: t == "" && n.dropPendingUpdates,
|
|
4105
|
+
secret_token: e.callbackSecret,
|
|
4106
|
+
url: e.endpointUrl
|
|
4107
|
+
}), { outcome: "ready" };
|
|
4108
|
+
}
|
|
4109
|
+
};
|
|
4110
|
+
function si(e) {
|
|
4111
|
+
return {
|
|
4112
|
+
chatIds: e.chatIds ?? [],
|
|
4113
|
+
dropPendingUpdates: e.dropPendingUpdates ?? !0,
|
|
4114
|
+
updates: e.updates,
|
|
4115
|
+
userIds: e.userIds ?? []
|
|
4116
|
+
};
|
|
4117
|
+
}
|
|
4118
|
+
function ci(e) {
|
|
4119
|
+
if (!e.updates.includes("*")) return e.updates;
|
|
4120
|
+
let t = e.updates.filter((e) => e != "*");
|
|
4121
|
+
return t.length == 0 ? null : [.../* @__PURE__ */ new Set([...ai, ...t])];
|
|
4122
|
+
}
|
|
4123
|
+
function li(e, t) {
|
|
4124
|
+
if (e == null || e.length != t.length) return !1;
|
|
4125
|
+
let n = 0;
|
|
4126
|
+
for (let r = 0; r < t.length; r += 1) n |= e.charCodeAt(r) ^ t.charCodeAt(r);
|
|
4127
|
+
return n == 0;
|
|
4128
|
+
}
|
|
4129
|
+
function Z(e) {
|
|
4130
|
+
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
4131
|
+
}
|
|
4132
|
+
function Q(e) {
|
|
4133
|
+
if (Z(e)) return typeof e.id == "string" || typeof e.id == "number" ? String(e.id) : void 0;
|
|
4134
|
+
}
|
|
4135
|
+
function ui(e) {
|
|
4136
|
+
if (Z(e)) return Q(e.chat) ?? (Z(e.message) ? Q(e.message.chat) : void 0);
|
|
4137
|
+
}
|
|
4138
|
+
function di(e) {
|
|
4139
|
+
if (Z(e)) return Q(e.from) ?? Q(e.user);
|
|
4140
|
+
}
|
|
4141
|
+
async function fi(e) {
|
|
4142
|
+
let t = await mi(e, "getWebhookInfo"), n = Z(t.result) ? t.result.url : void 0;
|
|
4143
|
+
if (typeof n != "string") throw new b("Telegram getWebhookInfo response is missing result.url.");
|
|
4144
|
+
return n;
|
|
4145
|
+
}
|
|
4146
|
+
async function pi(e) {
|
|
4147
|
+
await mi(e, "deleteWebhook", { drop_pending_updates: !1 });
|
|
4148
|
+
}
|
|
4149
|
+
async function mi(e, t, n) {
|
|
4150
|
+
let r;
|
|
4151
|
+
try {
|
|
4152
|
+
r = await e.connector.execute({
|
|
4153
|
+
...n == null ? {} : { body: n },
|
|
4154
|
+
endpoint: `/${t}`,
|
|
4155
|
+
method: n == null ? "GET" : "POST"
|
|
4156
|
+
}, e.signal);
|
|
4157
|
+
} catch (e) {
|
|
4158
|
+
throw e instanceof v ? e : new b(`Telegram ${t} request failed.`, { cause: e });
|
|
4159
|
+
}
|
|
4160
|
+
let i = Z(r.data) ? r.data : {};
|
|
4161
|
+
if (r.status >= 200 && r.status < 300 && i.ok === !0) return i;
|
|
4162
|
+
let a = typeof i.description == "string" ? i.description : `HTTP ${r.status}`;
|
|
4163
|
+
throw r.status == 401 || r.status == 403 ? new v(`Telegram ${t} rejected the Connection.`) : r.status >= 400 && r.status < 500 && r.status != 429 ? new y(`Telegram ${t} rejected the subscription: ${a}`) : new b(`Telegram ${t} failed: ${a}`);
|
|
4164
|
+
}
|
|
4165
|
+
function hi(e) {
|
|
4166
|
+
try {
|
|
4167
|
+
return new URL(e).host;
|
|
4168
|
+
} catch {
|
|
4169
|
+
return "an invalid URL";
|
|
4170
|
+
}
|
|
4171
|
+
}
|
|
4172
|
+
var gi = {
|
|
4173
|
+
initialState: {
|
|
4174
|
+
checkpoint: null,
|
|
4175
|
+
subscription: {}
|
|
4176
|
+
},
|
|
4177
|
+
snapshot: {
|
|
4178
|
+
configSchema: {
|
|
4179
|
+
additionalProperties: !1,
|
|
4180
|
+
properties: {
|
|
4181
|
+
events: {
|
|
4182
|
+
items: {
|
|
4183
|
+
enum: [
|
|
4184
|
+
"coupon.created",
|
|
4185
|
+
"coupon.updated",
|
|
4186
|
+
"coupon.deleted",
|
|
4187
|
+
"coupon.restored",
|
|
4188
|
+
"customer.created",
|
|
4189
|
+
"customer.updated",
|
|
4190
|
+
"customer.deleted",
|
|
4191
|
+
"order.created",
|
|
4192
|
+
"order.updated",
|
|
4193
|
+
"order.deleted",
|
|
4194
|
+
"order.restored",
|
|
4195
|
+
"product.created",
|
|
4196
|
+
"product.updated",
|
|
4197
|
+
"product.deleted",
|
|
4198
|
+
"product.restored",
|
|
4199
|
+
"product.published"
|
|
4200
|
+
],
|
|
4201
|
+
type: "string"
|
|
4202
|
+
},
|
|
4203
|
+
maxItems: 16,
|
|
4204
|
+
minItems: 1,
|
|
4205
|
+
type: "array",
|
|
4206
|
+
uniqueItems: !0
|
|
4207
|
+
},
|
|
4208
|
+
webhookName: {
|
|
4209
|
+
default: "OOMOL Trigger",
|
|
4210
|
+
maxLength: 120,
|
|
4211
|
+
minLength: 1,
|
|
4212
|
+
type: "string"
|
|
4213
|
+
}
|
|
4214
|
+
},
|
|
4215
|
+
required: ["events"],
|
|
4216
|
+
title: "WooCommerce Store Event Config",
|
|
4217
|
+
type: "object"
|
|
4218
|
+
},
|
|
4219
|
+
definitionVersion: 1,
|
|
4220
|
+
description: "Triggers when selected WooCommerce store events occur.",
|
|
4221
|
+
displayName: "WooCommerce: Store Event",
|
|
4222
|
+
endpoint: {
|
|
4223
|
+
body: {
|
|
4224
|
+
allowArray: !1,
|
|
4225
|
+
allowEmpty: !1,
|
|
4226
|
+
formats: ["json"]
|
|
4227
|
+
},
|
|
4228
|
+
methods: ["POST"],
|
|
4229
|
+
successStatus: 202
|
|
4230
|
+
},
|
|
4231
|
+
key: "woocommerce.on_store_event",
|
|
4232
|
+
name: "on_store_event",
|
|
4233
|
+
payloadSchema: {
|
|
4234
|
+
additionalProperties: !1,
|
|
4235
|
+
properties: {
|
|
4236
|
+
body: { type: "object" },
|
|
4237
|
+
deliveryId: { type: "string" },
|
|
4238
|
+
event: { type: "string" },
|
|
4239
|
+
resource: { type: "string" },
|
|
4240
|
+
source: { type: "string" },
|
|
4241
|
+
topic: { type: "string" },
|
|
4242
|
+
webhookId: { type: "string" }
|
|
4243
|
+
},
|
|
4244
|
+
required: [
|
|
4245
|
+
"topic",
|
|
4246
|
+
"resource",
|
|
4247
|
+
"event",
|
|
4248
|
+
"webhookId",
|
|
4249
|
+
"deliveryId",
|
|
4250
|
+
"source",
|
|
4251
|
+
"body"
|
|
4252
|
+
],
|
|
4253
|
+
title: "WooCommerce Store Event Payload",
|
|
4254
|
+
type: "object"
|
|
4255
|
+
},
|
|
4256
|
+
provider: "woocommerce",
|
|
4257
|
+
type: "integration"
|
|
4258
|
+
},
|
|
4259
|
+
receive(e) {
|
|
4260
|
+
let t = e.header("x-wc-webhook-topic")?.trim();
|
|
4261
|
+
if (!t) return {
|
|
4262
|
+
outcome: "ignored",
|
|
4263
|
+
reason: "WooCommerce topic header is missing."
|
|
4264
|
+
};
|
|
4265
|
+
if (!_i(e.config).events.includes(t)) return {
|
|
4266
|
+
outcome: "ignored",
|
|
4267
|
+
reason: "WooCommerce topic is not subscribed."
|
|
4268
|
+
};
|
|
4269
|
+
let n = e.header("x-wc-webhook-delivery-id") ?? "";
|
|
4270
|
+
return {
|
|
4271
|
+
dedupeKey: n.length == 0 ? void 0 : n,
|
|
4272
|
+
outcome: "event",
|
|
4273
|
+
payload: {
|
|
4274
|
+
body: e.payload,
|
|
4275
|
+
deliveryId: n,
|
|
4276
|
+
event: e.header("x-wc-webhook-event") ?? "",
|
|
4277
|
+
resource: e.header("x-wc-webhook-resource") ?? "",
|
|
4278
|
+
source: e.header("x-wc-webhook-source") ?? "",
|
|
4279
|
+
topic: t,
|
|
4280
|
+
webhookId: e.header("x-wc-webhook-id") ?? ""
|
|
4281
|
+
}
|
|
4282
|
+
};
|
|
4283
|
+
},
|
|
4284
|
+
async reconcile(e) {
|
|
4285
|
+
let t = Oi(e.state), n = _i(e.config), r = await bi(e);
|
|
4286
|
+
if (!e.active) {
|
|
4287
|
+
for (let t of r) await xi(e, t.id);
|
|
4288
|
+
return await t.saveSubscription({}, ki(e.now)), { outcome: "ready" };
|
|
4289
|
+
}
|
|
4290
|
+
let i = /* @__PURE__ */ new Map();
|
|
4291
|
+
for (let e of r) n.events.includes(e.topic) && !i.has(e.topic) && i.set(e.topic, e.id);
|
|
4292
|
+
let a = new Set(i.values());
|
|
4293
|
+
for (let t of r) a.has(t.id) || await xi(e, t.id);
|
|
4294
|
+
let o = [];
|
|
4295
|
+
for (let t of n.events) {
|
|
4296
|
+
let r = i.get(t);
|
|
4297
|
+
o.push(r == null ? await vi(e, n, t) : await yi(e, r, t));
|
|
4298
|
+
}
|
|
4299
|
+
return await t.saveSubscription({ webhookIds: o }, ki(e.now)), { outcome: "ready" };
|
|
4300
|
+
}
|
|
4301
|
+
};
|
|
4302
|
+
function _i(e) {
|
|
4303
|
+
return {
|
|
4304
|
+
events: [...new Set(e.events)],
|
|
4305
|
+
webhookName: e.webhookName ?? "OOMOL Trigger"
|
|
4306
|
+
};
|
|
4307
|
+
}
|
|
4308
|
+
async function vi(e, t, n) {
|
|
4309
|
+
let r = await Si(e, `webhook create (${n})`, {
|
|
4310
|
+
body: {
|
|
4311
|
+
delivery_url: e.endpointUrl,
|
|
4312
|
+
name: `${t.webhookName} - ${n}`,
|
|
4313
|
+
topic: n
|
|
4314
|
+
},
|
|
4315
|
+
endpoint: "/webhooks",
|
|
4316
|
+
method: "POST"
|
|
4317
|
+
});
|
|
4318
|
+
return Ci(r, `webhook create (${n})`), Ei(r.data);
|
|
4319
|
+
}
|
|
4320
|
+
async function yi(e, t, n) {
|
|
4321
|
+
let r = await Si(e, `webhook update (${n})`, {
|
|
4322
|
+
body: {
|
|
4323
|
+
delivery_url: e.endpointUrl,
|
|
4324
|
+
status: "active",
|
|
4325
|
+
topic: n
|
|
4326
|
+
},
|
|
4327
|
+
endpoint: `/webhooks/${t}`,
|
|
4328
|
+
method: "PUT"
|
|
4329
|
+
});
|
|
4330
|
+
return wi(r) ? vi(e, _i(e.config), n) : (Ci(r, `webhook update (${n})`), t);
|
|
4331
|
+
}
|
|
4332
|
+
async function bi(e) {
|
|
4333
|
+
let t = [];
|
|
4334
|
+
for (let n = 1; n <= 10; n += 1) {
|
|
4335
|
+
let r = await Si(e, "webhook list", {
|
|
4336
|
+
endpoint: "/webhooks",
|
|
4337
|
+
method: "GET",
|
|
4338
|
+
query: {
|
|
4339
|
+
context: "view",
|
|
4340
|
+
page: n,
|
|
4341
|
+
per_page: 100,
|
|
4342
|
+
status: "all"
|
|
4343
|
+
}
|
|
4344
|
+
});
|
|
4345
|
+
Ci(r, "webhook list");
|
|
4346
|
+
let i = Array.isArray(r.data) ? r.data : [];
|
|
4347
|
+
for (let n of i) {
|
|
4348
|
+
let r = Ai(n);
|
|
4349
|
+
if (r?.delivery_url !== e.endpointUrl || typeof r.topic != "string") continue;
|
|
4350
|
+
let i = Di(r.id);
|
|
4351
|
+
i != null && t.push({
|
|
4352
|
+
id: i,
|
|
4353
|
+
topic: r.topic
|
|
4354
|
+
});
|
|
4355
|
+
}
|
|
4356
|
+
if (i.length < 100) return t;
|
|
4357
|
+
}
|
|
4358
|
+
throw new b("WooCommerce webhook list did not finish within ten pages.");
|
|
4359
|
+
}
|
|
4360
|
+
async function xi(e, t) {
|
|
4361
|
+
let n = await Si(e, "webhook delete", {
|
|
4362
|
+
endpoint: `/webhooks/${t}`,
|
|
4363
|
+
method: "DELETE",
|
|
4364
|
+
query: { force: "true" }
|
|
4365
|
+
});
|
|
4366
|
+
n.status != 404 && Ci(n, "webhook delete");
|
|
4367
|
+
}
|
|
4368
|
+
async function Si(e, t, n) {
|
|
4369
|
+
try {
|
|
4370
|
+
return await e.connector.execute(n, e.signal);
|
|
4371
|
+
} catch (e) {
|
|
4372
|
+
throw e instanceof v ? e : new b(`WooCommerce ${t} request failed.`, { cause: e });
|
|
4373
|
+
}
|
|
4374
|
+
}
|
|
4375
|
+
function Ci(e, t) {
|
|
4376
|
+
if (e.status >= 200 && e.status < 300) return;
|
|
4377
|
+
let n = Ti(e.data);
|
|
4378
|
+
throw e.status == 401 || e.status == 403 ? new v(`WooCommerce ${t} rejected the Connection.`) : e.status == 404 || e.status == 400 && (n.endsWith("_invalid_topic") || n.endsWith("_invalid_delivery_url")) || e.status == 501 && n == "woocommerce_rest_trash_not_supported" ? new y(`WooCommerce ${t} rejected the subscription.`) : new b(`WooCommerce ${t} failed with status ${e.status}.`);
|
|
4379
|
+
}
|
|
4380
|
+
function wi(e) {
|
|
4381
|
+
return e.status == 400 && Ti(e.data) == "woocommerce_rest_webhook_invalid_id";
|
|
4382
|
+
}
|
|
4383
|
+
function Ti(e) {
|
|
4384
|
+
let t = Ai(e)?.code;
|
|
4385
|
+
return typeof t == "string" ? t : "";
|
|
4386
|
+
}
|
|
4387
|
+
function Ei(e) {
|
|
4388
|
+
let t = Di(Ai(e)?.id);
|
|
4389
|
+
if (t == null) throw new b("WooCommerce webhook response is missing its ID.");
|
|
4390
|
+
return t;
|
|
4391
|
+
}
|
|
4392
|
+
function Di(e) {
|
|
4393
|
+
return typeof e == "string" && e.length > 0 ? e : typeof e == "number" && Number.isFinite(e) ? String(e) : null;
|
|
4394
|
+
}
|
|
4395
|
+
function Oi(e) {
|
|
4396
|
+
if (e == null) throw new y("WooCommerce Integration state is missing.");
|
|
4397
|
+
return e;
|
|
4398
|
+
}
|
|
4399
|
+
function ki(e) {
|
|
4400
|
+
return new Date(e.getTime() + 2592e6);
|
|
4401
|
+
}
|
|
4402
|
+
function Ai(e) {
|
|
4403
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
4404
|
+
}
|
|
4405
|
+
//#endregion
|
|
4406
|
+
//#region src/trigger/providers/zendesk/on-event.ts
|
|
4407
|
+
var ji = /* @__PURE__ */ "zen:event-type:ticket.agent_assignment_changed,zen:event-type:ticket.attachment_linked_to_comment,zen:event-type:ticket.attachment_redacted_from_comment,zen:event-type:ticket.brand_changed,zen:event-type:ticket.comment_added,zen:event-type:ticket.comment_made_private,zen:event-type:ticket.comment_redacted,zen:event-type:ticket.created,zen:event-type:ticket.csat_received,zen:event-type:ticket.csat_requested,zen:event-type:ticket.custom_field_changed,zen:event-type:ticket.custom_status_changed,zen:event-type:ticket.description_changed,zen:event-type:ticket.email_ccs_changed,zen:event-type:ticket.external_id_changed,zen:event-type:ticket.followers_changed,zen:event-type:ticket.form_changed,zen:event-type:ticket.group_assignment_changed,zen:event-type:ticket.marked_as_spam,zen:event-type:ticket.merged,zen:event-type:ticket.next_sla_breach_changed,zen:event-type:ticket.ola_policy_changed,zen:event-type:ticket.organization_changed,zen:event-type:ticket.permanently_deleted,zen:event-type:ticket.priority_changed,zen:event-type:ticket.problem_link_changed,zen:event-type:ticket.requester_changed,zen:event-type:ticket.schedule_changed,zen:event-type:ticket.sla_policy_changed,zen:event-type:ticket.soft_deleted,zen:event-type:ticket.status_changed,zen:event-type:ticket.subject_changed,zen:event-type:ticket.submitter_changed,zen:event-type:ticket.tags_changed,zen:event-type:ticket.task_due_at_changed,zen:event-type:ticket.type_changed,zen:event-type:ticket.undeleted,zen:event-type:organization.created,zen:event-type:organization.custom_field_changed,zen:event-type:organization.deleted,zen:event-type:organization.external_id_changed,zen:event-type:organization.name_changed,zen:event-type:organization.tags_changed,zen:event-type:user.active_changed,zen:event-type:user.alias_changed,zen:event-type:user.created,zen:event-type:user.custom_field_changed,zen:event-type:user.custom_role_changed,zen:event-type:user.default_group_changed,zen:event-type:user.deleted,zen:event-type:user.details_changed,zen:event-type:user.external_id_changed,zen:event-type:user.group_membership_created,zen:event-type:user.group_membership_deleted,zen:event-type:user.identity_changed,zen:event-type:user.identity_created,zen:event-type:user.identity_deleted,zen:event-type:user.last_login_changed,zen:event-type:user.merged,zen:event-type:user.name_changed,zen:event-type:user.notes_changed,zen:event-type:user.only_private_comments_changed,zen:event-type:user.organization_membership_created,zen:event-type:user.organization_membership_deleted,zen:event-type:user.password_changed,zen:event-type:user.photo_changed,zen:event-type:user.role_changed,zen:event-type:user.suspended_changed,zen:event-type:user.tags_changed,zen:event-type:user.time_zone_changed".split(","), Mi = "/api/v2/webhooks", Ni = {
|
|
4408
|
+
initialState: {
|
|
4409
|
+
checkpoint: null,
|
|
4410
|
+
subscription: {}
|
|
4411
|
+
},
|
|
4412
|
+
snapshot: {
|
|
4413
|
+
configSchema: {
|
|
4414
|
+
additionalProperties: !1,
|
|
4415
|
+
properties: { events: {
|
|
4416
|
+
items: {
|
|
4417
|
+
enum: ji,
|
|
4418
|
+
type: "string"
|
|
4419
|
+
},
|
|
4420
|
+
minItems: 1,
|
|
4421
|
+
type: "array",
|
|
4422
|
+
uniqueItems: !0
|
|
4423
|
+
} },
|
|
4424
|
+
required: ["events"],
|
|
4425
|
+
title: "Zendesk Event Subscription Config",
|
|
4426
|
+
type: "object"
|
|
4427
|
+
},
|
|
4428
|
+
definitionVersion: 1,
|
|
4429
|
+
description: "Triggers when one of the selected Zendesk account events occurs.",
|
|
4430
|
+
displayName: "Zendesk: Event Subscription",
|
|
4431
|
+
endpoint: {
|
|
4432
|
+
body: {
|
|
4433
|
+
allowArray: !1,
|
|
4434
|
+
allowEmpty: !1,
|
|
4435
|
+
formats: ["json"]
|
|
4436
|
+
},
|
|
4437
|
+
methods: ["POST"],
|
|
4438
|
+
successStatus: 202
|
|
4439
|
+
},
|
|
4440
|
+
key: "zendesk.on_event",
|
|
4441
|
+
name: "on_event",
|
|
4442
|
+
payloadSchema: {
|
|
4443
|
+
additionalProperties: !1,
|
|
4444
|
+
properties: {
|
|
4445
|
+
body: { type: "object" },
|
|
4446
|
+
deliveryId: { type: "string" },
|
|
4447
|
+
event: { type: "string" },
|
|
4448
|
+
subject: { type: "string" }
|
|
4449
|
+
},
|
|
4450
|
+
required: [
|
|
4451
|
+
"event",
|
|
4452
|
+
"deliveryId",
|
|
4453
|
+
"body"
|
|
4454
|
+
],
|
|
4455
|
+
title: "Zendesk Event Payload",
|
|
4456
|
+
type: "object"
|
|
4457
|
+
},
|
|
4458
|
+
provider: "zendesk",
|
|
4459
|
+
type: "integration"
|
|
4460
|
+
},
|
|
4461
|
+
receive(e) {
|
|
4462
|
+
if (e.payload == null || typeof e.payload != "object" || Array.isArray(e.payload)) return {
|
|
4463
|
+
outcome: "ignored",
|
|
4464
|
+
reason: "Zendesk event body is missing."
|
|
4465
|
+
};
|
|
4466
|
+
let t = e.payload, n = t.type;
|
|
4467
|
+
if (typeof n != "string" || n.length == 0) return {
|
|
4468
|
+
outcome: "ignored",
|
|
4469
|
+
reason: "Zendesk event type is missing."
|
|
4470
|
+
};
|
|
4471
|
+
if (!e.config.events.includes(n)) return {
|
|
4472
|
+
outcome: "ignored",
|
|
4473
|
+
reason: "Zendesk event is not subscribed."
|
|
4474
|
+
};
|
|
4475
|
+
let r = typeof t.id == "string" ? t.id : "", i = t.subject;
|
|
4476
|
+
return {
|
|
4477
|
+
dedupeKey: r.length == 0 ? void 0 : r,
|
|
4478
|
+
outcome: "event",
|
|
4479
|
+
payload: {
|
|
4480
|
+
body: t,
|
|
4481
|
+
deliveryId: r,
|
|
4482
|
+
event: n,
|
|
4483
|
+
...typeof i == "string" ? { subject: i } : {}
|
|
4484
|
+
}
|
|
4485
|
+
};
|
|
4486
|
+
},
|
|
4487
|
+
async reconcile(e) {
|
|
4488
|
+
let t = Vi(e.state), n = await Fi(e), r = Hi(t);
|
|
4489
|
+
if (!e.active) {
|
|
4490
|
+
for (let t of r == null ? n : [.../* @__PURE__ */ new Set([r, ...n])]) await Ii(e, t);
|
|
4491
|
+
return await t.saveSubscription({}, Ui(e.now)), { outcome: "ready" };
|
|
4492
|
+
}
|
|
4493
|
+
let i = r ?? n[0];
|
|
4494
|
+
if (i == null) {
|
|
4495
|
+
let t = await Li(e, "webhook create", {
|
|
4496
|
+
body: Pi(e),
|
|
4497
|
+
endpoint: Mi,
|
|
4498
|
+
method: "POST"
|
|
4499
|
+
});
|
|
4500
|
+
Ri(t, "webhook create"), i = Bi($(t.data)?.webhook);
|
|
4501
|
+
} else {
|
|
4502
|
+
let n = await Li(e, "webhook update", {
|
|
4503
|
+
body: Pi(e),
|
|
4504
|
+
endpoint: `${Mi}/${i}`,
|
|
4505
|
+
method: "PUT"
|
|
4506
|
+
});
|
|
4507
|
+
if (n.status == 404) return await t.saveSubscription({}, e.now), { outcome: "pending" };
|
|
4508
|
+
Ri(n, "webhook update");
|
|
4509
|
+
}
|
|
4510
|
+
for (let t of n.filter((e) => e != i)) await Ii(e, t);
|
|
4511
|
+
return await t.saveSubscription({ webhookId: i }, Ui(e.now)), { outcome: "ready" };
|
|
4512
|
+
}
|
|
4513
|
+
};
|
|
4514
|
+
function Pi(e) {
|
|
4515
|
+
return { webhook: {
|
|
4516
|
+
description: "Managed by Open Flow. Do not edit.",
|
|
4517
|
+
endpoint: e.endpointUrl,
|
|
4518
|
+
http_method: "POST",
|
|
4519
|
+
name: zi(e.endpointUrl),
|
|
4520
|
+
request_format: "json",
|
|
4521
|
+
status: "active",
|
|
4522
|
+
subscriptions: [...new Set(e.config.events)]
|
|
4523
|
+
} };
|
|
4524
|
+
}
|
|
4525
|
+
async function Fi(e) {
|
|
4526
|
+
let t = [], n;
|
|
4527
|
+
for (let r = 0; r < 10; r += 1) {
|
|
4528
|
+
let r = await Li(e, "webhook list", {
|
|
4529
|
+
endpoint: Mi,
|
|
4530
|
+
method: "GET",
|
|
4531
|
+
query: {
|
|
4532
|
+
"filter[name_contains]": zi(e.endpointUrl),
|
|
4533
|
+
"page[size]": "100",
|
|
4534
|
+
...n == null ? {} : { "page[after]": n }
|
|
4535
|
+
}
|
|
4536
|
+
});
|
|
4537
|
+
Ri(r, "webhook list");
|
|
4538
|
+
let i = $(r.data), a = Array.isArray(i?.webhooks) ? i.webhooks : [];
|
|
4539
|
+
for (let n of a) {
|
|
4540
|
+
let r = $(n);
|
|
4541
|
+
r?.endpoint === e.endpointUrl && typeof r.id == "string" && t.push(r.id);
|
|
4542
|
+
}
|
|
4543
|
+
let o = $(i?.meta);
|
|
4544
|
+
if (o?.has_more !== !0 || typeof o.after_cursor != "string") return t;
|
|
4545
|
+
n = o.after_cursor;
|
|
4546
|
+
}
|
|
4547
|
+
return t;
|
|
4548
|
+
}
|
|
4549
|
+
async function Ii(e, t) {
|
|
4550
|
+
let n = await Li(e, "webhook delete", {
|
|
4551
|
+
endpoint: `${Mi}/${t}`,
|
|
4552
|
+
method: "DELETE"
|
|
4553
|
+
});
|
|
4554
|
+
n.status != 404 && Ri(n, "webhook delete");
|
|
4555
|
+
}
|
|
4556
|
+
async function Li(e, t, n) {
|
|
4557
|
+
try {
|
|
4558
|
+
return await e.connector.execute(n, e.signal);
|
|
4559
|
+
} catch (e) {
|
|
4560
|
+
throw e instanceof v ? e : new b(`Zendesk ${t} request failed.`, { cause: e });
|
|
4561
|
+
}
|
|
4562
|
+
}
|
|
4563
|
+
function Ri(e, t) {
|
|
4564
|
+
if (!(e.status >= 200 && e.status < 300)) throw e.status == 401 || e.status == 403 ? new v(`Zendesk ${t} rejected the Connection.`) : [
|
|
4565
|
+
400,
|
|
4566
|
+
404,
|
|
4567
|
+
422
|
|
4568
|
+
].includes(e.status) ? new y(`Zendesk ${t} rejected the subscription.`) : new b(`Zendesk ${t} failed with status ${e.status}.`);
|
|
4569
|
+
}
|
|
4570
|
+
function zi(e) {
|
|
4571
|
+
return `open-flow-${e.slice(e.lastIndexOf("/") + 1)}`;
|
|
4572
|
+
}
|
|
4573
|
+
function Bi(e) {
|
|
4574
|
+
let t = $(e)?.id;
|
|
4575
|
+
if (typeof t != "string") throw new b("Zendesk webhook response is missing its ID.");
|
|
4576
|
+
return t;
|
|
4577
|
+
}
|
|
4578
|
+
function Vi(e) {
|
|
4579
|
+
if (e == null) throw new y("Zendesk Integration state is missing.");
|
|
4580
|
+
return e;
|
|
4581
|
+
}
|
|
4582
|
+
function Hi(e) {
|
|
4583
|
+
let t = e.subscription.webhookId;
|
|
4584
|
+
return typeof t == "string" && t.length > 0 ? t : null;
|
|
4585
|
+
}
|
|
4586
|
+
function Ui(e) {
|
|
4587
|
+
return new Date(e.getTime() + 2592e6);
|
|
4588
|
+
}
|
|
4589
|
+
function $(e) {
|
|
4590
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
4591
|
+
}
|
|
4592
|
+
//#endregion
|
|
4593
|
+
//#region src/trigger/providers/definitions.ts
|
|
4594
|
+
var Wi = [
|
|
4595
|
+
i,
|
|
4596
|
+
Ae,
|
|
4597
|
+
ce,
|
|
4598
|
+
ve,
|
|
4599
|
+
We,
|
|
4600
|
+
pt,
|
|
4601
|
+
Pt,
|
|
4602
|
+
tn,
|
|
4603
|
+
vn,
|
|
4604
|
+
Bn,
|
|
4605
|
+
sr,
|
|
4606
|
+
br,
|
|
4607
|
+
Fr,
|
|
4608
|
+
Jr,
|
|
4609
|
+
oi,
|
|
4610
|
+
gi,
|
|
4611
|
+
Ni
|
|
4612
|
+
], Gi = Wi.filter((e) => e.snapshot.type == "poll"), Ki = Wi.filter((e) => e.snapshot.type == "integration");
|
|
4613
|
+
//#endregion
|
|
4614
|
+
export { Ki as integrationDefinitions, Gi as pollDefinitions, Wi as triggerDefinitions };
|