@flowrunner/cli 0.1.10 → 0.1.12-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/ai-docs/instructions/service-code-format/01-service-structure.md +1 -0
  2. package/ai-docs/instructions/service-code-format/06-oauth2.md +20 -1
  3. package/ai-docs/instructions/service-code-format/09-realtime-triggers.md +89 -5
  4. package/ai-docs/instructions/service-code-format/11-output-model.md +1 -1
  5. package/ai-docs/instructions/service-code-format/13-runtime-contracts.md +6 -3
  6. package/dist/cli.js +105 -22
  7. package/dist/cli.js.map +2 -2
  8. package/dist/index.js +104 -21
  9. package/dist/index.js.map +2 -2
  10. package/dist/types/flow-extension-runner/src/v2/model/model-types.d.ts +1 -1
  11. package/dist/types/flow-extension-runner/src/v2/realtime-triggers/trigger-method.d.ts +8 -1
  12. package/dist/types/flow-extension-runner/src/v2/realtime-triggers/types.d.ts +6 -2
  13. package/dist/types/flow-extension-runner/src/v2/types.d.ts +5 -0
  14. package/dist/types/shared/src/constants/shared-extensions.d.ts +12 -0
  15. package/dist/types/shared/src/scheme/access-keys/dto.d.ts +101 -0
  16. package/dist/types/shared/src/scheme/access-keys/index.d.ts +2 -0
  17. package/dist/types/shared/src/scheme/flowrunner/custom-elements.d.ts +8 -8
  18. package/dist/types/shared/src/scheme/index.d.ts +1 -0
  19. package/dist/types/shared/src/scheme/mcp-oauth/dto.d.ts +7 -5
  20. package/dist/types/shared/src/scheme/shared-extensions/base.d.ts +1 -1
  21. package/dist/types/shared/src/scheme/shared-extensions/custom-extensions.d.ts +9 -9
  22. package/dist/types/shared/src/scheme/shared-extensions/extension.d.ts +8 -8
  23. package/dist/types/shared/src/scheme/shared-extensions/index.d.ts +1 -0
  24. package/dist/types/shared/src/scheme/shared-extensions/list.d.ts +209 -0
  25. package/dist/types/shared/src/scheme/shared-extensions/resolve.d.ts +6 -6
  26. package/dist/types/shared/src/scheme/shared-extensions/search.d.ts +4 -4
  27. package/dist/types/shared/src/scheme/shared-extensions/service-info.d.ts +1 -1
  28. package/package.json +1 -1
  29. package/runtime/index.js +103 -20
  30. package/runtime/index.js.map +2 -2
  31. package/runtime/types/flow-extension-runner/src/v2/model/model-types.d.ts +1 -1
  32. package/runtime/types/flow-extension-runner/src/v2/realtime-triggers/trigger-method.d.ts +8 -1
  33. package/runtime/types/flow-extension-runner/src/v2/realtime-triggers/types.d.ts +6 -2
  34. package/runtime/types/flow-extension-runner/src/v2/types.d.ts +5 -0
  35. package/runtime/types/shared/src/constants/shared-extensions.d.ts +12 -0
  36. package/runtime/types/shared/src/scheme/access-keys/dto.d.ts +101 -0
  37. package/runtime/types/shared/src/scheme/access-keys/index.d.ts +2 -0
  38. package/runtime/types/shared/src/scheme/flowrunner/custom-elements.d.ts +8 -8
  39. package/runtime/types/shared/src/scheme/index.d.ts +1 -0
  40. package/runtime/types/shared/src/scheme/mcp-oauth/dto.d.ts +7 -5
  41. package/runtime/types/shared/src/scheme/shared-extensions/base.d.ts +1 -1
  42. package/runtime/types/shared/src/scheme/shared-extensions/custom-extensions.d.ts +9 -9
  43. package/runtime/types/shared/src/scheme/shared-extensions/extension.d.ts +8 -8
  44. package/runtime/types/shared/src/scheme/shared-extensions/index.d.ts +1 -0
  45. package/runtime/types/shared/src/scheme/shared-extensions/list.d.ts +209 -0
  46. package/runtime/types/shared/src/scheme/shared-extensions/resolve.d.ts +6 -6
  47. package/runtime/types/shared/src/scheme/shared-extensions/search.d.ts +4 -4
  48. package/runtime/types/shared/src/scheme/shared-extensions/service-info.d.ts +1 -1
@@ -0,0 +1,209 @@
1
+ import { z } from 'zod';
2
+ export declare const SHARED_EXTENSIONS_LIST_MAX_LIMIT = 100;
3
+ export declare const SharedExtensionListStatusSchema: z.ZodEnum<{
4
+ up_to_date: "up_to_date";
5
+ update_available: "update_available";
6
+ legacy: "legacy";
7
+ }>;
8
+ export declare const SharedExtensionConfigStatusSchema: z.ZodEnum<{
9
+ configured: "configured";
10
+ missing: "missing";
11
+ not_needed: "not_needed";
12
+ }>;
13
+ export declare const InstalledSharedExtensionsSortFieldSchema: z.ZodEnum<{
14
+ status: "status";
15
+ name: "name";
16
+ serviceId: "serviceId";
17
+ updatedAt: "updatedAt";
18
+ runnerVersion: "runnerVersion";
19
+ }>;
20
+ export declare const InstalledSharedExtensionsQuerySchema: z.ZodObject<{
21
+ runnerVersion: z.ZodOptional<z.ZodEnum<{
22
+ v1: "v1";
23
+ v2: "v2";
24
+ }>>;
25
+ status: z.ZodOptional<z.ZodEnum<{
26
+ up_to_date: "up_to_date";
27
+ update_available: "update_available";
28
+ legacy: "legacy";
29
+ }>>;
30
+ oauth: z.ZodOptional<z.ZodEnum<{
31
+ true: "true";
32
+ false: "false";
33
+ }>>;
34
+ config: z.ZodOptional<z.ZodEnum<{
35
+ configured: "configured";
36
+ missing: "missing";
37
+ }>>;
38
+ sortBy: z.ZodDefault<z.ZodEnum<{
39
+ status: "status";
40
+ name: "name";
41
+ serviceId: "serviceId";
42
+ updatedAt: "updatedAt";
43
+ runnerVersion: "runnerVersion";
44
+ }>>;
45
+ sortOrder: z.ZodDefault<z.ZodEnum<{
46
+ asc: "asc";
47
+ desc: "desc";
48
+ }>>;
49
+ search: z.ZodOptional<z.ZodString>;
50
+ page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
51
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
52
+ }, z.core.$strip>;
53
+ export declare const InstalledSharedExtensionListItemSchema: z.ZodObject<{
54
+ serviceId: z.ZodString;
55
+ name: z.ZodString;
56
+ sourceHash: z.ZodString;
57
+ sourceLatestHash: z.ZodNullable<z.ZodString>;
58
+ runnerVersion: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
59
+ v1: "v1";
60
+ v2: "v2";
61
+ }>>>;
62
+ enabled: z.ZodBoolean;
63
+ status: z.ZodEnum<{
64
+ up_to_date: "up_to_date";
65
+ update_available: "update_available";
66
+ legacy: "legacy";
67
+ }>;
68
+ requireOAuth: z.ZodBoolean;
69
+ configStatus: z.ZodEnum<{
70
+ configured: "configured";
71
+ missing: "missing";
72
+ not_needed: "not_needed";
73
+ }>;
74
+ iconUrl: z.ZodNullable<z.ZodString>;
75
+ updatedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
76
+ }, z.core.$strip>;
77
+ export declare const InstalledSharedExtensionsCountsSchema: z.ZodObject<{
78
+ all: z.ZodNumber;
79
+ runner: z.ZodObject<{
80
+ any: z.ZodNumber;
81
+ v1: z.ZodNumber;
82
+ v2: z.ZodNumber;
83
+ }, z.core.$strip>;
84
+ status: z.ZodObject<{
85
+ any: z.ZodNumber;
86
+ upToDate: z.ZodNumber;
87
+ updateAvailable: z.ZodNumber;
88
+ legacy: z.ZodNumber;
89
+ }, z.core.$strip>;
90
+ oauth: z.ZodObject<{
91
+ any: z.ZodNumber;
92
+ enabled: z.ZodNumber;
93
+ none: z.ZodNumber;
94
+ }, z.core.$strip>;
95
+ config: z.ZodObject<{
96
+ any: z.ZodNumber;
97
+ configured: z.ZodNumber;
98
+ missing: z.ZodNumber;
99
+ }, z.core.$strip>;
100
+ }, z.core.$strip>;
101
+ export declare const InstalledSharedExtensionsPageSchema: z.ZodObject<{
102
+ items: z.ZodArray<z.ZodObject<{
103
+ serviceId: z.ZodString;
104
+ name: z.ZodString;
105
+ sourceHash: z.ZodString;
106
+ sourceLatestHash: z.ZodNullable<z.ZodString>;
107
+ runnerVersion: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
108
+ v1: "v1";
109
+ v2: "v2";
110
+ }>>>;
111
+ enabled: z.ZodBoolean;
112
+ status: z.ZodEnum<{
113
+ up_to_date: "up_to_date";
114
+ update_available: "update_available";
115
+ legacy: "legacy";
116
+ }>;
117
+ requireOAuth: z.ZodBoolean;
118
+ configStatus: z.ZodEnum<{
119
+ configured: "configured";
120
+ missing: "missing";
121
+ not_needed: "not_needed";
122
+ }>;
123
+ iconUrl: z.ZodNullable<z.ZodString>;
124
+ updatedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
125
+ }, z.core.$strip>>;
126
+ total: z.ZodNumber;
127
+ page: z.ZodNumber;
128
+ limit: z.ZodNumber;
129
+ counts: z.ZodObject<{
130
+ all: z.ZodNumber;
131
+ runner: z.ZodObject<{
132
+ any: z.ZodNumber;
133
+ v1: z.ZodNumber;
134
+ v2: z.ZodNumber;
135
+ }, z.core.$strip>;
136
+ status: z.ZodObject<{
137
+ any: z.ZodNumber;
138
+ upToDate: z.ZodNumber;
139
+ updateAvailable: z.ZodNumber;
140
+ legacy: z.ZodNumber;
141
+ }, z.core.$strip>;
142
+ oauth: z.ZodObject<{
143
+ any: z.ZodNumber;
144
+ enabled: z.ZodNumber;
145
+ none: z.ZodNumber;
146
+ }, z.core.$strip>;
147
+ config: z.ZodObject<{
148
+ any: z.ZodNumber;
149
+ configured: z.ZodNumber;
150
+ missing: z.ZodNumber;
151
+ }, z.core.$strip>;
152
+ }, z.core.$strip>;
153
+ }, z.core.$strip>;
154
+ export declare const NotInstalledSharedExtensionsSortFieldSchema: z.ZodEnum<{
155
+ name: "name";
156
+ serviceId: "serviceId";
157
+ }>;
158
+ export declare const NotInstalledSharedExtensionsQuerySchema: z.ZodObject<{
159
+ sortBy: z.ZodDefault<z.ZodEnum<{
160
+ name: "name";
161
+ serviceId: "serviceId";
162
+ }>>;
163
+ sortOrder: z.ZodDefault<z.ZodEnum<{
164
+ asc: "asc";
165
+ desc: "desc";
166
+ }>>;
167
+ search: z.ZodOptional<z.ZodString>;
168
+ page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
169
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
170
+ }, z.core.$strip>;
171
+ export declare const NotInstalledSharedExtensionsPageSchema: z.ZodObject<{
172
+ items: z.ZodArray<z.ZodObject<{
173
+ serviceId: z.ZodString;
174
+ serviceName: z.ZodString;
175
+ sourceHash: z.ZodString;
176
+ }, z.core.$strip>>;
177
+ total: z.ZodNumber;
178
+ page: z.ZodNumber;
179
+ limit: z.ZodNumber;
180
+ }, z.core.$strip>;
181
+ export declare const SharedExtensionBulkTargetSchema: z.ZodObject<{
182
+ serviceId: z.ZodString;
183
+ enabled: z.ZodBoolean;
184
+ }, z.core.$strip>;
185
+ export declare const SharedExtensionBulkTargetsSchema: z.ZodObject<{
186
+ update: z.ZodArray<z.ZodObject<{
187
+ serviceId: z.ZodString;
188
+ enabled: z.ZodBoolean;
189
+ }, z.core.$strip>>;
190
+ reinstall: z.ZodArray<z.ZodObject<{
191
+ serviceId: z.ZodString;
192
+ enabled: z.ZodBoolean;
193
+ }, z.core.$strip>>;
194
+ install: z.ZodArray<z.ZodString>;
195
+ }, z.core.$strip>;
196
+ export type SharedExtensionListStatus = z.infer<typeof SharedExtensionListStatusSchema>;
197
+ export type SharedExtensionConfigStatus = z.infer<typeof SharedExtensionConfigStatusSchema>;
198
+ export type InstalledSharedExtensionsSortField = z.infer<typeof InstalledSharedExtensionsSortFieldSchema>;
199
+ export type InstalledSharedExtensionsQuery = z.infer<typeof InstalledSharedExtensionsQuerySchema>;
200
+ export type InstalledSharedExtensionsQueryInput = z.input<typeof InstalledSharedExtensionsQuerySchema>;
201
+ export type InstalledSharedExtensionListItem = z.infer<typeof InstalledSharedExtensionListItemSchema>;
202
+ export type InstalledSharedExtensionsCounts = z.infer<typeof InstalledSharedExtensionsCountsSchema>;
203
+ export type InstalledSharedExtensionsPage = z.infer<typeof InstalledSharedExtensionsPageSchema>;
204
+ export type NotInstalledSharedExtensionsSortField = z.infer<typeof NotInstalledSharedExtensionsSortFieldSchema>;
205
+ export type NotInstalledSharedExtensionsQuery = z.infer<typeof NotInstalledSharedExtensionsQuerySchema>;
206
+ export type NotInstalledSharedExtensionsQueryInput = z.input<typeof NotInstalledSharedExtensionsQuerySchema>;
207
+ export type NotInstalledSharedExtensionsPage = z.infer<typeof NotInstalledSharedExtensionsPageSchema>;
208
+ export type SharedExtensionBulkTarget = z.infer<typeof SharedExtensionBulkTargetSchema>;
209
+ export type SharedExtensionBulkTargets = z.infer<typeof SharedExtensionBulkTargetsSchema>;
@@ -31,7 +31,7 @@ export declare const ExtensionResolveUpdatedSchema: z.ZodObject<{
31
31
  sourceHash: z.ZodString;
32
32
  elementsBundle: z.ZodObject<{
33
33
  serviceInfo: z.ZodObject<{
34
- serviceClassName: z.ZodString;
34
+ serviceClassName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
35
35
  integrationName: z.ZodString;
36
36
  integrationIcon: z.ZodNullable<z.ZodString>;
37
37
  description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -61,7 +61,7 @@ export declare const ExtensionResolveUpdatedSchema: z.ZodObject<{
61
61
  serviceId: z.ZodString;
62
62
  newServiceId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
63
63
  legacyServiceId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
64
- serviceName: z.ZodString;
64
+ serviceName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
65
65
  oauthConnectionsGroupId: z.ZodString;
66
66
  legacyOauthConnectionsGroupId: z.ZodString;
67
67
  runnerVersion: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
@@ -147,7 +147,7 @@ export declare const ExtensionResolveResultItemSchema: z.ZodDiscriminatedUnion<[
147
147
  sourceHash: z.ZodString;
148
148
  elementsBundle: z.ZodObject<{
149
149
  serviceInfo: z.ZodObject<{
150
- serviceClassName: z.ZodString;
150
+ serviceClassName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
151
151
  integrationName: z.ZodString;
152
152
  integrationIcon: z.ZodNullable<z.ZodString>;
153
153
  description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -177,7 +177,7 @@ export declare const ExtensionResolveResultItemSchema: z.ZodDiscriminatedUnion<[
177
177
  serviceId: z.ZodString;
178
178
  newServiceId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
179
179
  legacyServiceId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
180
- serviceName: z.ZodString;
180
+ serviceName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
181
181
  oauthConnectionsGroupId: z.ZodString;
182
182
  legacyOauthConnectionsGroupId: z.ZodString;
183
183
  runnerVersion: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
@@ -262,7 +262,7 @@ export declare const ExtensionResolveResponseSchema: z.ZodArray<z.ZodDiscriminat
262
262
  sourceHash: z.ZodString;
263
263
  elementsBundle: z.ZodObject<{
264
264
  serviceInfo: z.ZodObject<{
265
- serviceClassName: z.ZodString;
265
+ serviceClassName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
266
266
  integrationName: z.ZodString;
267
267
  integrationIcon: z.ZodNullable<z.ZodString>;
268
268
  description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -292,7 +292,7 @@ export declare const ExtensionResolveResponseSchema: z.ZodArray<z.ZodDiscriminat
292
292
  serviceId: z.ZodString;
293
293
  newServiceId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
294
294
  legacyServiceId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
295
- serviceName: z.ZodString;
295
+ serviceName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
296
296
  oauthConnectionsGroupId: z.ZodString;
297
297
  legacyOauthConnectionsGroupId: z.ZodString;
298
298
  runnerVersion: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
@@ -40,7 +40,7 @@ export declare const SharedExtensionSearchResultMethodSchema: z.ZodObject<{
40
40
  fields: z.ZodArray<z.ZodType<import("./params-schema").ParamsSchemaField, unknown, z.core.$ZodTypeInternals<import("./params-schema").ParamsSchemaField, unknown>>>;
41
41
  }, z.core.$loose>>>;
42
42
  serviceInfo: z.ZodObject<{
43
- serviceClassName: z.ZodString;
43
+ serviceClassName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
44
44
  integrationName: z.ZodString;
45
45
  integrationIcon: z.ZodNullable<z.ZodString>;
46
46
  description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -70,7 +70,7 @@ export declare const SharedExtensionSearchResultMethodSchema: z.ZodObject<{
70
70
  serviceId: z.ZodString;
71
71
  newServiceId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
72
72
  legacyServiceId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
73
- serviceName: z.ZodString;
73
+ serviceName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
74
74
  oauthConnectionsGroupId: z.ZodString;
75
75
  legacyOauthConnectionsGroupId: z.ZodString;
76
76
  runnerVersion: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
@@ -138,7 +138,7 @@ export declare const SearchSharedExtensionsResponseSchema: z.ZodObject<{
138
138
  fields: z.ZodArray<z.ZodType<import("./params-schema").ParamsSchemaField, unknown, z.core.$ZodTypeInternals<import("./params-schema").ParamsSchemaField, unknown>>>;
139
139
  }, z.core.$loose>>>;
140
140
  serviceInfo: z.ZodObject<{
141
- serviceClassName: z.ZodString;
141
+ serviceClassName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
142
142
  integrationName: z.ZodString;
143
143
  integrationIcon: z.ZodNullable<z.ZodString>;
144
144
  description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -168,7 +168,7 @@ export declare const SearchSharedExtensionsResponseSchema: z.ZodObject<{
168
168
  serviceId: z.ZodString;
169
169
  newServiceId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
170
170
  legacyServiceId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
171
- serviceName: z.ZodString;
171
+ serviceName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
172
172
  oauthConnectionsGroupId: z.ZodString;
173
173
  legacyOauthConnectionsGroupId: z.ZodString;
174
174
  runnerVersion: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  export declare const ParsedFlowExtensionServiceInfoSchema: z.ZodObject<{
3
- serviceClassName: z.ZodString;
3
+ serviceClassName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
4
4
  integrationName: z.ZodString;
5
5
  integrationIcon: z.ZodNullable<z.ZodString>;
6
6
  description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowrunner/cli",
3
- "version": "0.1.10",
3
+ "version": "0.1.12-dev.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/runtime/index.js CHANGED
@@ -4094,7 +4094,7 @@ var OAuth2 = class {
4094
4094
  {
4095
4095
  name: REFRESH_TOKEN,
4096
4096
  scheme: z.object({ refreshToken: RefreshTokenSchema }),
4097
- run: ({ refreshToken }, ctx) => this.#refresh(refreshToken, anonymous(ctx))
4097
+ run: ({ refreshToken }, ctx) => this.#refresh(refreshToken, ctx)
4098
4098
  }
4099
4099
  ]);
4100
4100
  }
@@ -4532,7 +4532,15 @@ function readExtract(extract, body) {
4532
4532
  return void 0;
4533
4533
  }
4534
4534
  function isEmptyBody(body) {
4535
- return body == null || typeof body === "object" && Object.keys(body).length === 0;
4535
+ return body == null || body === "" || typeof body === "object" && Object.keys(body).length === 0;
4536
+ }
4537
+ function hasHandshakeResponse(result) {
4538
+ return result.responseToExternalService !== void 0 || !!result.responseHeaders || !!result.responseToWebhook;
4539
+ }
4540
+ function handshakeErrorStatus(error) {
4541
+ const { statusCode, status } = error ?? {};
4542
+ const candidate = typeof statusCode === "number" ? statusCode : status;
4543
+ return typeof candidate === "number" && candidate >= 400 && candidate < 500 ? candidate : 400;
4536
4544
  }
4537
4545
  var RealtimeSetup = class {
4538
4546
  constructor(extension, props) {
@@ -4643,19 +4651,9 @@ var RealtimeSetup = class {
4643
4651
  const body = invocation.body;
4644
4652
  const rawBody = invocation.rawBody;
4645
4653
  const webhookData = invocation.webhookData ?? null;
4646
- if (this.props.handshake) {
4647
- const result = await this.props.handshake(ctx.bagWith({ requestBody: body, headers, rawBody, webhookData }));
4648
- if (result && (result.responseToExternalService !== void 0 || result.responseHeaders || result.responseToWebhook)) {
4649
- return {
4650
- handshake: true,
4651
- responseToExternalService: result.responseToExternalService,
4652
- responseHeaders: result.responseHeaders,
4653
- responseToWebhook: result.responseToWebhook
4654
- };
4655
- }
4656
- }
4657
- if (isEmptyBody(body)) {
4658
- return { handshake: true, events: [] };
4654
+ const handshake = await this.#handshake(body, headers, rawBody, webhookData, ctx);
4655
+ if (handshake) {
4656
+ return handshake;
4659
4657
  }
4660
4658
  if (!await this.#verify(rawBody, headers, webhookData, ctx)) {
4661
4659
  ctx.logger.warn(`[flow-extension:${this.extension.id}] webhook signature verification failed \u2014 answering 401`);
@@ -4696,6 +4694,52 @@ var RealtimeSetup = class {
4696
4694
  return { events, eventScopeId, connectionId: invocation.connectionId };
4697
4695
  }
4698
4696
  // The author's own check wins; otherwise the declarative one; otherwise nothing was asked for.
4697
+ /**
4698
+ * Whether this delivery is an endpoint-verification handshake, and if so the answer to it; `null` → proceed.
4699
+ *
4700
+ * Without a `handshake` hook the default applies: an EMPTY body is a handshake, acked with a plain 200 —
4701
+ * the URL-verification ping most providers send. A declared hook REPLACES that default rather than running
4702
+ * before it, so it alone decides: some providers deliver real events with no body at all (Google Drive
4703
+ * puts everything in `X-Goog-*` headers), and a hook that can't overrule the empty-body rule leaves them
4704
+ * no way to reach `resolveEvents`.
4705
+ *
4706
+ * `true` → handshake, plain 200
4707
+ * `{ responseToWebhook, … }` → handshake, answered with that response
4708
+ * nothing / `false` / `{}` → not a handshake, the delivery proceeds
4709
+ * throws → answered with the error, as a 4xx carrying its message
4710
+ *
4711
+ * The throw is turned into a RESPONSE for the same reason a failed signature check is: a throw leaves the
4712
+ * pod as a failed invocation and the provider receives a 500 telling it nothing. The hook runs BEFORE
4713
+ * verification, so the message reaches an unverified caller — throw what the provider may read.
4714
+ */
4715
+ async #handshake(body, headers, rawBody, webhookData, ctx) {
4716
+ if (!this.props.handshake) {
4717
+ return isEmptyBody(body) ? { handshake: true, events: [] } : null;
4718
+ }
4719
+ let result;
4720
+ try {
4721
+ result = await this.props.handshake(ctx.bagWith({ requestBody: body, headers, rawBody, webhookData }));
4722
+ } catch (error) {
4723
+ const message = error?.message ?? String(error);
4724
+ ctx.logger.error(`[flow-extension:${this.extension.id}] handshake failed \u2014 ${message}`);
4725
+ return {
4726
+ events: [],
4727
+ responseToWebhook: { httpStatus: handshakeErrorStatus(error), body: { message } }
4728
+ };
4729
+ }
4730
+ if (result === true) {
4731
+ return { handshake: true, events: [] };
4732
+ }
4733
+ if (result && typeof result === "object" && hasHandshakeResponse(result)) {
4734
+ return {
4735
+ handshake: true,
4736
+ responseToExternalService: result.responseToExternalService,
4737
+ responseHeaders: result.responseHeaders,
4738
+ responseToWebhook: result.responseToWebhook
4739
+ };
4740
+ }
4741
+ return null;
4742
+ }
4699
4743
  async #verify(rawBody, headers, webhookData, ctx) {
4700
4744
  if (this.props.verifyRequest) {
4701
4745
  return !!await this.props.verifyRequest(ctx.bagWith({ rawBody, headers, webhookData, config: ctx.config }));
@@ -4715,14 +4759,38 @@ var RealtimeSetup = class {
4715
4759
  // opposite way to `#toSubTriggers`. This is the DATA PLANE: the platform has already answered the
4716
4760
  // provider and detached this work, so a throw reaches nobody — and worse, it aborts every remaining event
4717
4761
  // of the same delivery, dropping the good ones beside the stale name.
4762
+ /**
4763
+ * The event data `match` decides on: the delivered data plus whatever `extendMatchData` fetched, read ONCE
4764
+ * for every instance — the case is an id-only webhook (Xero names an invoice, not its type or status) whose
4765
+ * instance filters need the resource itself.
4766
+ *
4767
+ * A failed read is NOT a failed delivery. Select is the data plane: nothing is waiting on it, and a throw
4768
+ * would abort the delivery's other events. So it is logged and the instances are matched against the data
4769
+ * that WAS delivered — an instance filtering on the missing fields declines, an unfiltered one still fires.
4770
+ */
4771
+ async #withMatchData(trigger, eventData, webhookData, ctx) {
4772
+ try {
4773
+ const extra = await trigger.extendMatchData(eventData, ctx, webhookData);
4774
+ return extra && typeof extra === "object" ? { ...eventData, ...extra } : eventData;
4775
+ } catch (error) {
4776
+ ctx.logger.warn(
4777
+ `[flow-extension:${this.extension.id}] extendMatchData of "${trigger.id}" failed \u2014 matching on the delivered data: ${error?.message ?? error}`
4778
+ );
4779
+ return eventData;
4780
+ }
4781
+ }
4718
4782
  async #selectMatched(invocation, ctx) {
4719
4783
  const trigger = invocation.eventName ? this.extension.findRealtimeTrigger(invocation.eventName) : void 0;
4720
4784
  if (!trigger) {
4721
4785
  return { ids: [], enrichedEventData: null };
4722
4786
  }
4723
- const eventData = invocation.eventData;
4724
4787
  const webhookData = invocation.webhookData ?? null;
4725
- const ids = (invocation.triggers ?? []).filter((instance) => trigger.matches(instance.data ?? {}, eventData, webhookData)).map((instance) => instance.id);
4788
+ const instances = invocation.triggers ?? [];
4789
+ const eventData = trigger.needsMatchData(instances.length) ? await this.#withMatchData(trigger, invocation.eventData, webhookData, ctx) : invocation.eventData;
4790
+ const verdicts = await Promise.all(
4791
+ instances.map((instance) => trigger.matches(instance.data ?? {}, eventData, webhookData))
4792
+ );
4793
+ const ids = instances.filter((_instance, index) => verdicts[index]).map((instance) => instance.id);
4726
4794
  const enrichedEventData = ids.length && trigger.hasExtendResult() ? await trigger.extendResult(eventData, ctx, webhookData) : null;
4727
4795
  return { ids, enrichedEventData };
4728
4796
  }
@@ -4780,6 +4848,19 @@ var RealtimeTriggerMethod = class extends ExtensionMethod {
4780
4848
  extendEventData(requestBody, providerEventData) {
4781
4849
  return this.props.extendEventData?.({ requestBody, providerEventData });
4782
4850
  }
4851
+ /**
4852
+ * Whether `extendMatchData` should run for an event about to be matched against `instanceCount` instances.
4853
+ * Only when something will READ its result: with no instances there is nothing to decide, and with no
4854
+ * `match` every instance fires regardless — either way the API call would be pure cost.
4855
+ */
4856
+ needsMatchData(instanceCount) {
4857
+ return typeof this.props.extendMatchData === "function" && !!this.props.match && instanceCount > 0;
4858
+ }
4859
+ // Runs ONCE per event, before any instance is matched, with the full handler bag (`apiRequest` on the
4860
+ // connection's token) — for an instance filter on data the delivery does not carry.
4861
+ extendMatchData(providerEventData, ctx, webhookData = null) {
4862
+ return this.props.extendMatchData?.(ctx.bagWith({ providerEventData, webhookData }));
4863
+ }
4783
4864
  /**
4784
4865
  * Whether one CONFIGURED INSTANCE of this trigger cares about an event. Declarative form: type-coerced
4785
4866
  * equality per filled param, where an empty param means "any" — that is what lets a user leave a filter
@@ -4789,13 +4870,13 @@ var RealtimeTriggerMethod = class extends ExtensionMethod {
4789
4870
  * subscription registered (a tenant id, a resource the webhook was scoped to) has nowhere else to get it.
4790
4871
  * Returning a new document is not a thing this seam can do; only subscribe/refresh/unsubscribe persist.
4791
4872
  */
4792
- matches(params, providerEventData, webhookData = null) {
4873
+ async matches(params, providerEventData, webhookData = null) {
4793
4874
  const match = this.props.match;
4794
4875
  if (!match) {
4795
4876
  return true;
4796
4877
  }
4797
4878
  if (typeof match === "function") {
4798
- return !!match({ params, providerEventData, webhookData });
4879
+ return !!await match({ params, providerEventData, webhookData });
4799
4880
  }
4800
4881
  for (const [paramKey, path2] of Object.entries(match)) {
4801
4882
  const paramValue = params[paramKey];
@@ -5020,7 +5101,9 @@ var Extension = class {
5020
5101
  }
5021
5102
  toServiceInfo() {
5022
5103
  return {
5023
- serviceClassName: this.props.id,
5104
+ // Only a shared extension migrated from v1 has one: its v1 class name, which the legacy ids of its elements,
5105
+ // configs and OAuth connections are built from. A service written as v2 is identified by its id alone
5106
+ ...this.props.serviceClassName ? { serviceClassName: this.props.serviceClassName } : {},
5024
5107
  integrationName: this.props.name,
5025
5108
  integrationIcon: this.props.logo ?? null,
5026
5109
  description: this.props.description || null,