@slates/provider-handler 1.0.0-rc.29 → 1.0.0-rc.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +329 -102
- package/dist/index.module.js +329 -102
- package/package.json +3 -3
- package/src/index.ts +320 -97
- package/src/spec.ts +87 -14
package/src/index.ts
CHANGED
|
@@ -18,13 +18,18 @@ import {
|
|
|
18
18
|
} from '@slates/provider';
|
|
19
19
|
import { PQueue } from './pQueue';
|
|
20
20
|
import {
|
|
21
|
+
evaluateTriggerMatches,
|
|
21
22
|
getAction,
|
|
22
23
|
getActionWithType,
|
|
23
24
|
getAdapter,
|
|
24
25
|
getAuthMethod,
|
|
26
|
+
getTriggerGroup,
|
|
27
|
+
getWebhookAutoRegistration,
|
|
28
|
+
getWebhookManualRegistration,
|
|
25
29
|
mapAction,
|
|
26
30
|
mapAdapter,
|
|
27
|
-
mapAuthMethod
|
|
31
|
+
mapAuthMethod,
|
|
32
|
+
mapTriggerGroup
|
|
28
33
|
} from './spec';
|
|
29
34
|
import { State } from './state';
|
|
30
35
|
import { toJsonSchema, validate } from './validation';
|
|
@@ -185,6 +190,7 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
185
190
|
|
|
186
191
|
let hubCapabilities = new State<{
|
|
187
192
|
attachments?: { directUpload?: { enabled: boolean; maxAttachmentSizeBytes?: number } };
|
|
193
|
+
triggers?: boolean;
|
|
188
194
|
} | null>(null);
|
|
189
195
|
let liveInvocation = new State<Pick<SlateLiveInvocationInfo, 'token' | 'baseUrl'> | null>(
|
|
190
196
|
null
|
|
@@ -203,6 +209,8 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
203
209
|
};
|
|
204
210
|
};
|
|
205
211
|
|
|
212
|
+
let supportsTriggerGroups = () => !!hubCapabilities.get()?.triggers;
|
|
213
|
+
|
|
206
214
|
let logger = new SlateLogger(listeners);
|
|
207
215
|
let providerTrace = {
|
|
208
216
|
providerId: slate.spec.key,
|
|
@@ -392,6 +400,9 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
392
400
|
hub: {
|
|
393
401
|
capabilitiesNotification: true,
|
|
394
402
|
liveInvocation: true
|
|
403
|
+
},
|
|
404
|
+
provider: {
|
|
405
|
+
triggerGroups: true
|
|
395
406
|
}
|
|
396
407
|
}
|
|
397
408
|
}));
|
|
@@ -857,6 +868,10 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
857
868
|
? slate.actions
|
|
858
869
|
: slate.actions.filter(action => !action.adapter);
|
|
859
870
|
|
|
871
|
+
if (!supportsTriggerGroups()) {
|
|
872
|
+
actions = actions.filter(action => action.type !== 'trigger');
|
|
873
|
+
}
|
|
874
|
+
|
|
860
875
|
return {
|
|
861
876
|
actions: actions.map(a => mapAction(slate, a))
|
|
862
877
|
};
|
|
@@ -888,6 +903,23 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
888
903
|
};
|
|
889
904
|
});
|
|
890
905
|
|
|
906
|
+
manager.onRequest('slates/trigger_groups.list', async () => {
|
|
907
|
+
getContextBasic();
|
|
908
|
+
|
|
909
|
+
return {
|
|
910
|
+
triggerGroups: slate.triggerGroups.map(mapTriggerGroup)
|
|
911
|
+
};
|
|
912
|
+
});
|
|
913
|
+
|
|
914
|
+
manager.onRequest('slates/trigger_group.get', async ({ params }) => {
|
|
915
|
+
getContextBasic();
|
|
916
|
+
let triggerGroup = getTriggerGroup(slate, params.triggerGroupId);
|
|
917
|
+
|
|
918
|
+
return {
|
|
919
|
+
triggerGroup: mapTriggerGroup(triggerGroup)
|
|
920
|
+
};
|
|
921
|
+
});
|
|
922
|
+
|
|
891
923
|
manager.onRequest('slates/action.tool.invoke', async ({ params }) => {
|
|
892
924
|
let action = getActionWithType(slate, 'tool', params.actionId);
|
|
893
925
|
|
|
@@ -995,27 +1027,76 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
995
1027
|
outputKeyCount: getObjectKeyCount(result.output)
|
|
996
1028
|
})
|
|
997
1029
|
},
|
|
998
|
-
() => runWithContext(context, () => action.
|
|
1030
|
+
() => runWithContext(context, () => action.map(context))
|
|
999
1031
|
);
|
|
1000
1032
|
|
|
1001
1033
|
return withRequestTraces(context, { id: res.id, type: res.type, output: res.output });
|
|
1002
1034
|
});
|
|
1003
1035
|
|
|
1004
1036
|
manager.onRequest('slates/action.trigger.poll_events', async ({ params }) => {
|
|
1005
|
-
|
|
1006
|
-
|
|
1037
|
+
getContextBasic();
|
|
1038
|
+
|
|
1039
|
+
if (supportsTriggerGroups()) {
|
|
1040
|
+
throw new ServiceError(
|
|
1041
|
+
badRequestError({
|
|
1042
|
+
message: `Legacy trigger polling is disabled once trigger_group support is announced: ${params.actionId}`
|
|
1043
|
+
})
|
|
1044
|
+
);
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
return { inputs: [], updatedState: params.state };
|
|
1048
|
+
});
|
|
1049
|
+
|
|
1050
|
+
manager.onRequest('slates/action.trigger.webhook_handle', async ({ params }) => {
|
|
1051
|
+
getContextBasic();
|
|
1052
|
+
|
|
1053
|
+
if (supportsTriggerGroups()) {
|
|
1054
|
+
throw new ServiceError(
|
|
1055
|
+
badRequestError({
|
|
1056
|
+
message: `Legacy trigger webhook handling is disabled once trigger_group support is announced: ${params.actionId}`
|
|
1057
|
+
})
|
|
1058
|
+
);
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
return { inputs: [], updatedState: params.state, response: null };
|
|
1062
|
+
});
|
|
1063
|
+
|
|
1064
|
+
manager.onRequest('slates/action.trigger.webhook_register', async ({ params }) => {
|
|
1065
|
+
getContextBasic();
|
|
1066
|
+
|
|
1067
|
+
if (supportsTriggerGroups()) {
|
|
1068
|
+
throw new ServiceError(
|
|
1069
|
+
badRequestError({
|
|
1070
|
+
message: `Legacy trigger webhook registration is disabled once trigger_group support is announced: ${params.actionId}`
|
|
1071
|
+
})
|
|
1072
|
+
);
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
return { registrationDetails: null };
|
|
1076
|
+
});
|
|
1077
|
+
|
|
1078
|
+
manager.onRequest('slates/action.trigger.webhook_unregister', async ({ params }) => {
|
|
1079
|
+
getContextBasic();
|
|
1007
1080
|
|
|
1008
|
-
if (
|
|
1081
|
+
if (supportsTriggerGroups()) {
|
|
1009
1082
|
throw new ServiceError(
|
|
1010
1083
|
badRequestError({
|
|
1011
|
-
message: `
|
|
1084
|
+
message: `Legacy trigger webhook unregistration is disabled once trigger_group support is announced: ${params.actionId}`
|
|
1012
1085
|
})
|
|
1013
1086
|
);
|
|
1014
1087
|
}
|
|
1015
1088
|
|
|
1089
|
+
return {};
|
|
1090
|
+
});
|
|
1091
|
+
|
|
1092
|
+
manager.onRequest('slates/trigger_group.webhook.targets_list', async ({ params }) => {
|
|
1093
|
+
let ctx = getContextFull();
|
|
1094
|
+
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1095
|
+
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1096
|
+
|
|
1016
1097
|
let context = new SlateContext(
|
|
1017
1098
|
ctx.config,
|
|
1018
|
-
{
|
|
1099
|
+
{ pageToken: params.pageToken ?? null },
|
|
1019
1100
|
ctx.auth?.output!,
|
|
1020
1101
|
slate.spec,
|
|
1021
1102
|
logger
|
|
@@ -1023,39 +1104,184 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
1023
1104
|
let res = await traceProviderCall(
|
|
1024
1105
|
{
|
|
1025
1106
|
component: 'action',
|
|
1026
|
-
functionName: '
|
|
1027
|
-
message: `
|
|
1107
|
+
functionName: 'webhookTargetList',
|
|
1108
|
+
message: `Listing webhook targets for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1028
1109
|
successMessage: result =>
|
|
1029
|
-
`
|
|
1030
|
-
errorMessage: `Trigger ${formatEntityLabel(
|
|
1110
|
+
`Listed ${result.targets.length} webhook target(s) for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1111
|
+
errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while listing webhook targets`,
|
|
1031
1112
|
metadata: {
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
actionType: action.type,
|
|
1035
|
-
hasPreviousState: params.state !== null
|
|
1113
|
+
triggerGroupId: group.key,
|
|
1114
|
+
triggerGroupName: group.name
|
|
1036
1115
|
},
|
|
1037
1116
|
onSuccess: result => ({
|
|
1038
|
-
|
|
1039
|
-
|
|
1117
|
+
targetCount: result.targets.length,
|
|
1118
|
+
hasNextPageToken: result.nextPageToken !== null
|
|
1040
1119
|
})
|
|
1041
1120
|
},
|
|
1042
|
-
() => runWithContext(context, () =>
|
|
1121
|
+
() => runWithContext(context, () => autoRegistration.webhookTargetList(context))
|
|
1043
1122
|
);
|
|
1044
1123
|
|
|
1045
1124
|
return withRequestTraces(context, {
|
|
1046
|
-
|
|
1047
|
-
|
|
1125
|
+
targets: res.targets,
|
|
1126
|
+
nextPageToken: res.nextPageToken ?? null
|
|
1048
1127
|
});
|
|
1049
1128
|
});
|
|
1050
1129
|
|
|
1051
|
-
manager.onRequest('slates/
|
|
1130
|
+
manager.onRequest('slates/trigger_group.webhook.register', async ({ params }) => {
|
|
1052
1131
|
let ctx = getContextFull();
|
|
1053
|
-
let
|
|
1132
|
+
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1133
|
+
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1134
|
+
|
|
1135
|
+
let context = new SlateContext(
|
|
1136
|
+
ctx.config,
|
|
1137
|
+
{
|
|
1138
|
+
webhookTargetIdentifier: params.webhookTargetIdentifier,
|
|
1139
|
+
webhookTargetPayload: params.webhookTargetPayload,
|
|
1140
|
+
webhookUrl: params.webhookUrl
|
|
1141
|
+
},
|
|
1142
|
+
ctx.auth?.output!,
|
|
1143
|
+
slate.spec,
|
|
1144
|
+
logger
|
|
1145
|
+
);
|
|
1146
|
+
let res = await traceProviderCall(
|
|
1147
|
+
{
|
|
1148
|
+
component: 'action',
|
|
1149
|
+
functionName: 'webhookRegister',
|
|
1150
|
+
message: `Registering webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1151
|
+
successMessage: `Registered webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1152
|
+
errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while registering a webhook`,
|
|
1153
|
+
metadata: {
|
|
1154
|
+
triggerGroupId: group.key,
|
|
1155
|
+
triggerGroupName: group.name,
|
|
1156
|
+
webhookTargetIdentifier: params.webhookTargetIdentifier
|
|
1157
|
+
}
|
|
1158
|
+
},
|
|
1159
|
+
() => runWithContext(context, () => autoRegistration.webhookRegister(context))
|
|
1160
|
+
);
|
|
1161
|
+
|
|
1162
|
+
return withRequestTraces(context, {
|
|
1163
|
+
webhookRegistrationIdentifier: res.webhookRegistrationIdentifier,
|
|
1164
|
+
webhookRegistrationPayload: res.webhookRegistrationPayload
|
|
1165
|
+
});
|
|
1166
|
+
});
|
|
1167
|
+
|
|
1168
|
+
manager.onRequest('slates/trigger_group.webhook.unregister', async ({ params }) => {
|
|
1169
|
+
let ctx = getContextFull();
|
|
1170
|
+
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1171
|
+
let autoRegistration = getWebhookAutoRegistration(group);
|
|
1172
|
+
|
|
1173
|
+
let context = new SlateContext(
|
|
1174
|
+
ctx.config,
|
|
1175
|
+
{
|
|
1176
|
+
webhookRegistrationIdentifier: params.webhookRegistrationIdentifier,
|
|
1177
|
+
webhookRegistrationPayload: params.webhookRegistrationPayload
|
|
1178
|
+
},
|
|
1179
|
+
ctx.auth?.output!,
|
|
1180
|
+
slate.spec,
|
|
1181
|
+
logger
|
|
1182
|
+
);
|
|
1183
|
+
await traceProviderCall(
|
|
1184
|
+
{
|
|
1185
|
+
component: 'action',
|
|
1186
|
+
functionName: 'webhookUnregister',
|
|
1187
|
+
message: `Unregistering webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1188
|
+
successMessage: `Unregistered webhook for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1189
|
+
errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while unregistering a webhook`,
|
|
1190
|
+
metadata: {
|
|
1191
|
+
triggerGroupId: group.key,
|
|
1192
|
+
triggerGroupName: group.name,
|
|
1193
|
+
webhookRegistrationIdentifier: params.webhookRegistrationIdentifier
|
|
1194
|
+
}
|
|
1195
|
+
},
|
|
1196
|
+
() => runWithContext(context, () => autoRegistration.webhookUnregister(context))
|
|
1197
|
+
);
|
|
1198
|
+
|
|
1199
|
+
return withRequestTraces(context, {});
|
|
1200
|
+
});
|
|
1201
|
+
|
|
1202
|
+
manager.onRequest('slates/trigger_group.webhook.manual_setup', async ({ params }) => {
|
|
1203
|
+
getContextBasic();
|
|
1204
|
+
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1205
|
+
let manualRegistration = getWebhookManualRegistration(group);
|
|
1206
|
+
|
|
1207
|
+
let context = new SlateContext(
|
|
1208
|
+
{},
|
|
1209
|
+
{ webhookUrl: params.webhookUrl },
|
|
1210
|
+
{},
|
|
1211
|
+
slate.spec as any,
|
|
1212
|
+
logger
|
|
1213
|
+
);
|
|
1214
|
+
let res = await traceProviderCall(
|
|
1215
|
+
{
|
|
1216
|
+
component: 'action',
|
|
1217
|
+
functionName: 'webhookManualSetup',
|
|
1218
|
+
message: `Building manual webhook setup for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1219
|
+
successMessage: `Built manual webhook setup for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1220
|
+
errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while building a manual webhook setup`,
|
|
1221
|
+
metadata: {
|
|
1222
|
+
triggerGroupId: group.key,
|
|
1223
|
+
triggerGroupName: group.name
|
|
1224
|
+
}
|
|
1225
|
+
},
|
|
1226
|
+
() => runWithContext(context, () => manualRegistration.setup(context))
|
|
1227
|
+
);
|
|
1054
1228
|
|
|
1055
|
-
|
|
1229
|
+
return {
|
|
1230
|
+
webhookSetupDocument: res.webhookSetupDocument,
|
|
1231
|
+
partialWebhookRegistrationPayload: res.partialWebhookRegistrationPayload
|
|
1232
|
+
};
|
|
1233
|
+
});
|
|
1234
|
+
|
|
1235
|
+
manager.onRequest('slates/trigger_group.webhook.manual_finish', async ({ params }) => {
|
|
1236
|
+
getContextBasic();
|
|
1237
|
+
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1238
|
+
let manualRegistration = getWebhookManualRegistration(group);
|
|
1239
|
+
|
|
1240
|
+
if (!manualRegistration.finish) {
|
|
1056
1241
|
throw new ServiceError(
|
|
1057
1242
|
badRequestError({
|
|
1058
|
-
message: `Trigger
|
|
1243
|
+
message: `Trigger group does not support manual webhook finish: ${params.triggerGroupId}`
|
|
1244
|
+
})
|
|
1245
|
+
);
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
let context = new SlateContext(
|
|
1249
|
+
{},
|
|
1250
|
+
{
|
|
1251
|
+
webhookUrl: params.webhookUrl,
|
|
1252
|
+
partialWebhookRegistrationPayload: params.partialWebhookRegistrationPayload,
|
|
1253
|
+
userWebhookRegistrationPayload: params.userWebhookRegistrationPayload
|
|
1254
|
+
},
|
|
1255
|
+
{},
|
|
1256
|
+
slate.spec as any,
|
|
1257
|
+
logger
|
|
1258
|
+
);
|
|
1259
|
+
let res = await traceProviderCall(
|
|
1260
|
+
{
|
|
1261
|
+
component: 'action',
|
|
1262
|
+
functionName: 'webhookManualFinish',
|
|
1263
|
+
message: `Finishing manual webhook setup for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1264
|
+
successMessage: `Finished manual webhook setup for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1265
|
+
errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while finishing a manual webhook setup`,
|
|
1266
|
+
metadata: {
|
|
1267
|
+
triggerGroupId: group.key,
|
|
1268
|
+
triggerGroupName: group.name
|
|
1269
|
+
}
|
|
1270
|
+
},
|
|
1271
|
+
() => runWithContext(context, () => manualRegistration.finish!(context))
|
|
1272
|
+
);
|
|
1273
|
+
|
|
1274
|
+
return withRequestTraces(context, {
|
|
1275
|
+
webhookRegistrationPayload: res.webhookRegistrationPayload
|
|
1276
|
+
});
|
|
1277
|
+
});
|
|
1278
|
+
|
|
1279
|
+
manager.onRequest('slates/trigger_group.webhook.process', async ({ params }) => {
|
|
1280
|
+
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1281
|
+
if (group.source !== 'webhook' || !group.webhook) {
|
|
1282
|
+
throw new ServiceError(
|
|
1283
|
+
badRequestError({
|
|
1284
|
+
message: `Trigger group does not support webhook processing: ${params.triggerGroupId}`
|
|
1059
1285
|
})
|
|
1060
1286
|
);
|
|
1061
1287
|
}
|
|
@@ -1069,139 +1295,136 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
1069
1295
|
});
|
|
1070
1296
|
|
|
1071
1297
|
let context = new SlateContext(
|
|
1072
|
-
|
|
1298
|
+
{},
|
|
1073
1299
|
{
|
|
1074
1300
|
request: req,
|
|
1075
|
-
|
|
1076
|
-
registrationDetails: params.registrationDetails ?? null
|
|
1301
|
+
webhookRegistrationPayload: params.webhookRegistrationPayload
|
|
1077
1302
|
},
|
|
1078
|
-
|
|
1079
|
-
slate.spec,
|
|
1303
|
+
{},
|
|
1304
|
+
slate.spec as any,
|
|
1080
1305
|
logger
|
|
1081
1306
|
);
|
|
1082
1307
|
let res = await traceProviderCall(
|
|
1083
1308
|
{
|
|
1084
1309
|
component: 'action',
|
|
1085
|
-
functionName: '
|
|
1086
|
-
message: `
|
|
1310
|
+
functionName: 'webhookProcess',
|
|
1311
|
+
message: `Processing webhook request for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1087
1312
|
successMessage: result =>
|
|
1088
|
-
`
|
|
1089
|
-
errorMessage: `Trigger ${formatEntityLabel(
|
|
1313
|
+
`Extracted ${result.events.length} event(s) from webhook request for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1314
|
+
errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while processing a webhook request`,
|
|
1090
1315
|
metadata: {
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
actionType: action.type,
|
|
1316
|
+
triggerGroupId: group.key,
|
|
1317
|
+
triggerGroupName: group.name,
|
|
1094
1318
|
requestMethod: params.method,
|
|
1095
|
-
hasRequestBody: !!params.body
|
|
1096
|
-
hasPreviousState: params.state !== null
|
|
1319
|
+
hasRequestBody: !!params.body
|
|
1097
1320
|
},
|
|
1098
1321
|
onSuccess: result => ({
|
|
1099
|
-
|
|
1100
|
-
hasUpdatedState: result.updatedState !== undefined,
|
|
1322
|
+
eventCount: result.events.length,
|
|
1101
1323
|
hasResponse: result.response !== undefined
|
|
1102
1324
|
})
|
|
1103
1325
|
},
|
|
1104
|
-
() => runWithContext(context, () =>
|
|
1326
|
+
() => runWithContext(context, () => group.webhook!.process(context))
|
|
1105
1327
|
);
|
|
1106
1328
|
|
|
1329
|
+
for (let event of res.events) {
|
|
1330
|
+
if (!event.matchers) {
|
|
1331
|
+
throw new ServiceError(
|
|
1332
|
+
preconditionFailedError({
|
|
1333
|
+
message: `Trigger group "${group.key}" process handler must return matchers for every event (return [] if there is nothing to assert)`
|
|
1334
|
+
})
|
|
1335
|
+
);
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1107
1339
|
let response =
|
|
1108
1340
|
res.response === undefined
|
|
1109
1341
|
? undefined
|
|
1110
1342
|
: await serializeWebhookHttpResponse(res.response);
|
|
1111
1343
|
|
|
1112
1344
|
return withRequestTraces(context, {
|
|
1113
|
-
|
|
1114
|
-
|
|
1345
|
+
events: res.events.map(event => ({
|
|
1346
|
+
matchers: event.matchers,
|
|
1347
|
+
payload: event.payload,
|
|
1348
|
+
idempotencyKey: event.idempotencyKey,
|
|
1349
|
+
triggerIds: evaluateTriggerMatches(slate, group.key, event.payload)
|
|
1350
|
+
})),
|
|
1115
1351
|
response
|
|
1116
1352
|
});
|
|
1117
1353
|
});
|
|
1118
1354
|
|
|
1119
|
-
manager.onRequest('slates/
|
|
1355
|
+
manager.onRequest('slates/trigger_group.routing_matchers.get', async ({ params }) => {
|
|
1120
1356
|
let ctx = getContextFull();
|
|
1121
|
-
let
|
|
1122
|
-
|
|
1123
|
-
if (!action.autoRegisterWebhook) {
|
|
1124
|
-
throw new ServiceError(
|
|
1125
|
-
badRequestError({
|
|
1126
|
-
message: `Trigger action does not support webhook auto-registration: ${params.actionId}`
|
|
1127
|
-
})
|
|
1128
|
-
);
|
|
1129
|
-
}
|
|
1357
|
+
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1130
1358
|
|
|
1131
|
-
let context = new SlateContext(
|
|
1132
|
-
|
|
1133
|
-
{ webhookBaseUrl: params.webhookBaseUrl },
|
|
1134
|
-
ctx.auth?.output!,
|
|
1135
|
-
slate.spec,
|
|
1136
|
-
logger
|
|
1137
|
-
);
|
|
1138
|
-
let res = await traceProviderCall(
|
|
1359
|
+
let context = new SlateContext(ctx.config, {}, ctx.auth?.output!, slate.spec, logger);
|
|
1360
|
+
let matchers = await traceProviderCall(
|
|
1139
1361
|
{
|
|
1140
1362
|
component: 'action',
|
|
1141
|
-
functionName: '
|
|
1142
|
-
message: `
|
|
1143
|
-
successMessage:
|
|
1144
|
-
|
|
1363
|
+
functionName: 'routingMatchers',
|
|
1364
|
+
message: `Getting routing matchers for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1365
|
+
successMessage: result =>
|
|
1366
|
+
`Retrieved ${result.length} routing matcher(s) for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1367
|
+
errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while getting routing matchers`,
|
|
1145
1368
|
metadata: {
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
actionType: action.type
|
|
1369
|
+
triggerGroupId: group.key,
|
|
1370
|
+
triggerGroupName: group.name
|
|
1149
1371
|
},
|
|
1150
1372
|
onSuccess: result => ({
|
|
1151
|
-
|
|
1152
|
-
hasState: result.state !== undefined
|
|
1373
|
+
matcherCount: result.length
|
|
1153
1374
|
})
|
|
1154
1375
|
},
|
|
1155
|
-
() => runWithContext(context, () =>
|
|
1376
|
+
() => runWithContext(context, () => group.routingMatchers(context))
|
|
1156
1377
|
);
|
|
1157
1378
|
|
|
1158
|
-
return withRequestTraces(context, {
|
|
1159
|
-
registrationDetails: res.registrationDetails,
|
|
1160
|
-
state: res.state
|
|
1161
|
-
});
|
|
1379
|
+
return withRequestTraces(context, { matchers });
|
|
1162
1380
|
});
|
|
1163
1381
|
|
|
1164
|
-
manager.onRequest('slates/
|
|
1382
|
+
manager.onRequest('slates/trigger_group.polling.poll', async ({ params }) => {
|
|
1165
1383
|
let ctx = getContextFull();
|
|
1166
|
-
let
|
|
1167
|
-
|
|
1168
|
-
if (!action.autoUnregisterWebhook) {
|
|
1384
|
+
let group = getTriggerGroup(slate, params.triggerGroupId);
|
|
1385
|
+
if (group.source !== 'polling' || !group.polling) {
|
|
1169
1386
|
throw new ServiceError(
|
|
1170
1387
|
badRequestError({
|
|
1171
|
-
message: `Trigger
|
|
1388
|
+
message: `Trigger group does not support polling: ${params.triggerGroupId}`
|
|
1172
1389
|
})
|
|
1173
1390
|
);
|
|
1174
1391
|
}
|
|
1175
1392
|
|
|
1176
1393
|
let context = new SlateContext(
|
|
1177
1394
|
ctx.config,
|
|
1178
|
-
{
|
|
1179
|
-
webhookBaseUrl: params.webhookBaseUrl,
|
|
1180
|
-
registrationDetails: params.registrationDetails,
|
|
1181
|
-
state: params.state
|
|
1182
|
-
},
|
|
1395
|
+
{ state: params.state },
|
|
1183
1396
|
ctx.auth?.output!,
|
|
1184
1397
|
slate.spec,
|
|
1185
1398
|
logger
|
|
1186
1399
|
);
|
|
1187
|
-
await traceProviderCall(
|
|
1400
|
+
let res = await traceProviderCall(
|
|
1188
1401
|
{
|
|
1189
1402
|
component: 'action',
|
|
1190
|
-
functionName: '
|
|
1191
|
-
message: `
|
|
1192
|
-
successMessage:
|
|
1193
|
-
|
|
1403
|
+
functionName: 'pollEvents',
|
|
1404
|
+
message: `Polling events for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1405
|
+
successMessage: result =>
|
|
1406
|
+
`Polled ${result.events.length} event(s) for trigger group ${formatEntityLabel(group.name, group.key)}`,
|
|
1407
|
+
errorMessage: `Trigger group ${formatEntityLabel(group.name, group.key)} failed while polling events`,
|
|
1194
1408
|
metadata: {
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
actionType: action.type,
|
|
1198
|
-
hasRegistrationDetails: params.registrationDetails !== null,
|
|
1409
|
+
triggerGroupId: group.key,
|
|
1410
|
+
triggerGroupName: group.name,
|
|
1199
1411
|
hasPreviousState: params.state !== null
|
|
1200
|
-
}
|
|
1412
|
+
},
|
|
1413
|
+
onSuccess: result => ({
|
|
1414
|
+
eventCount: result.events.length,
|
|
1415
|
+
hasUpdatedState: result.updatedState !== undefined
|
|
1416
|
+
})
|
|
1201
1417
|
},
|
|
1202
|
-
() => runWithContext(context, () =>
|
|
1418
|
+
() => runWithContext(context, () => group.polling!.pollEvents(context))
|
|
1203
1419
|
);
|
|
1204
1420
|
|
|
1205
|
-
return withRequestTraces(context, {
|
|
1421
|
+
return withRequestTraces(context, {
|
|
1422
|
+
updatedState: res.updatedState,
|
|
1423
|
+
events: res.events.map(event => ({
|
|
1424
|
+
payload: event.payload,
|
|
1425
|
+
idempotencyKey: event.idempotencyKey,
|
|
1426
|
+
triggerIds: evaluateTriggerMatches(slate, group.key, event.payload)
|
|
1427
|
+
}))
|
|
1428
|
+
});
|
|
1206
1429
|
});
|
|
1207
1430
|
});
|